List of usage examples for java.util Map clear
void clear();
From source file:com.microsoft.alm.plugin.external.commands.InfoCommand.java
/** * Example of output//from ww w . j ava2 s . com * Local information: * Local path: D:\tmp\TFVC_1\build.xml * Server path: $/TFVC_1/build.xml * Changeset: 18 * Change: none * Type: file * Server information: * Server path: $/TFVC_1/build.xml * Changeset: 18 * Deletion ID: 0 * Lock: none * Lock owner: * Last modified: Nov 18, 2016 11:10:20 AM * Type: file * File type: windows-1252 * Size: 1385 */ @Override public List<ItemInfo> parseOutput(final String stdout, final String stderr) { super.throwIfError(stderr); final List<ItemInfo> itemInfos = new ArrayList<ItemInfo>(itemPaths.size()); final Map<String, String> propertyMap = new HashMap<String, String>(15); final String[] output = getLines(stdout); String prefix = ""; for (final String line : output) { if (StringUtils.startsWithIgnoreCase(line, "local information:")) { // switch to local mode prefix = ""; if (!propertyMap.isEmpty()) { itemInfos.add(getItemInfo(propertyMap)); } propertyMap.clear(); } else if (StringUtils.startsWithIgnoreCase(line, "server information:")) { // switch to server mode prefix = "server "; } else if (StringUtils.isNotBlank(line)) { // add property final int colonPos = line.indexOf(":"); if (colonPos > 0) { final String key = prefix + line.substring(0, colonPos).trim().toLowerCase(); final String value = colonPos + 1 < line.length() ? line.substring(colonPos + 1).trim() : StringUtils.EMPTY; propertyMap.put(key, value); } } } if (!propertyMap.isEmpty()) { itemInfos.add(getItemInfo(propertyMap)); } return itemInfos; }
From source file:com.glaf.core.service.impl.MxSysDataItemServiceImpl.java
@SuppressWarnings("unchecked") public JSONArray getJsonData(long id, Map<String, Object> parameter) { JSONArray result = new JSONArray(); SysDataItem sysDataItem = this.getSysDataItemById(id); if (sysDataItem != null) { String cacheKey = "sys_dataitem_data_" + id; if (StringUtils.equals("Y", sysDataItem.getCacheFlag())) { String text = CacheFactory.getString(cacheKey); if (StringUtils.isNotEmpty(text)) { try { result = JSON.parseArray(text); return result; } catch (Exception ex) { // Ignore error }//ww w . ja v a 2s . c o m } } if (StringUtils.isNotEmpty(sysDataItem.getQueryId())) { List<Object> list = sqlSessionTemplate.selectList(sysDataItem.getQueryId(), parameter); if (list != null && !list.isEmpty()) { Map<String, Object> newDataMap = new CaseInsensitiveHashMap(); for (Object object : list) { newDataMap.clear(); JSONObject json = new JSONObject(); if (object instanceof Map) { Map<String, Object> dataMap = (Map<String, Object>) object; Iterator<Entry<String, Object>> iterator = dataMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String name = entry.getKey(); Object value = entry.getValue(); newDataMap.put(name, value); newDataMap.put(name.toLowerCase(), value); json.put(name, value); } } else { Map<String, Object> dataMap = Tools.getDataMap(object); Iterator<Entry<String, Object>> iterator = dataMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String name = entry.getKey(); Object value = entry.getValue(); newDataMap.put(name, value); newDataMap.put(name.toLowerCase(), value); json.put(name, value); } } if (StringUtils.isNotEmpty(sysDataItem.getTextField())) { json.put("text", newDataMap.get(sysDataItem.getTextField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getValueField())) { json.put("value", newDataMap.get(sysDataItem.getValueField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeIdField())) { json.put("id", newDataMap.get(sysDataItem.getTreeIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeParentIdField())) { json.put("parentId", newDataMap.get(sysDataItem.getTreeParentIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeNameField())) { json.put("name", newDataMap.get(sysDataItem.getTreeNameField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeTreeIdField())) { json.put("treeId", newDataMap.get(sysDataItem.getTreeTreeIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeListNoField())) { json.put("listno", newDataMap.get(sysDataItem.getTreeListNoField().toLowerCase())); } result.add(json); } } } else if (StringUtils.isNotEmpty(sysDataItem.getQuerySQL())) { if (!DBUtils.isLegalQuerySql(sysDataItem.getQuerySQL())) { throw new RuntimeException(" SQL statement illegal "); } Map<String, Object> params = new HashMap<String, Object>(); params.put("queryString", sysDataItem.getQuerySQL()); params.put("parameter", parameter); List<Map<String, Object>> list = tablePageMapper.getSqlQueryList(params); if (list != null && !list.isEmpty()) { Map<String, Object> newDataMap = new CaseInsensitiveHashMap(); for (Map<String, Object> dataMap : list) { newDataMap.clear(); JSONObject json = new JSONObject(); Iterator<Entry<String, Object>> iterator = dataMap.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> entry = iterator.next(); String name = entry.getKey(); Object value = entry.getValue(); newDataMap.put(name, value); newDataMap.put(name.toLowerCase(), value); json.put(name, value); } if (StringUtils.isNotEmpty(sysDataItem.getTextField())) { json.put("text", newDataMap.get(sysDataItem.getTextField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getValueField())) { json.put("value", newDataMap.get(sysDataItem.getValueField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeIdField())) { json.put("id", newDataMap.get(sysDataItem.getTreeIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeParentIdField())) { json.put("parentId", newDataMap.get(sysDataItem.getTreeParentIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeNameField())) { json.put("name", newDataMap.get(sysDataItem.getTreeNameField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeTreeIdField())) { json.put("treeId", newDataMap.get(sysDataItem.getTreeTreeIdField().toLowerCase())); } if (StringUtils.isNotEmpty(sysDataItem.getTreeListNoField())) { json.put("listno", newDataMap.get(sysDataItem.getTreeListNoField().toLowerCase())); } result.add(json); } } } if (StringUtils.equals("Y", sysDataItem.getCacheFlag())) { if (!result.isEmpty()) { CacheFactory.put(cacheKey, result.toJSONString()); } } } return result; }
From source file:com.redhat.rhtracking.core.services.InvoiceServiceHandler.java
@Override public Map<String, Object> saveInvoice(Map<String, Object> event) { logger.debug("ssssssssss " + event); Map<String, Object> response = new HashMap<>(); int totalHours = (int) event.get("platformQuantity") + (int) event.get("middlewareQuantity") + (int) event.get("workshopQuantity"); BigDecimal invoiceTotal = ((BigDecimal) event.get("platformPrice")) .multiply(new BigDecimal((int) event.get("platformQuantity"))); invoiceTotal = invoiceTotal.add(((BigDecimal) event.get("middlewarePrice")) .multiply(new BigDecimal((int) event.get("middlewareQuantity")))); invoiceTotal = invoiceTotal.add(((BigDecimal) event.get("workshopPrice")) .multiply(new BigDecimal((int) event.get("workshopQuantity")))); Map<String, Object> invoice = new HashMap<>(); invoice.put("date", (Date) event.get("date")); invoice.put("deliveryMatrixId", (long) event.get("deliveryMatrixId")); invoice.put("hoursTotal", totalHours); invoice.put("invoiceTotal", invoiceTotal); invoice.put("invoiceRequest", (String) event.get("invoiceRequest")); boolean confirmed = false; if (event.containsKey("invoiceNumber")) { invoice.put("invoiceNumber", (String) event.get("invoiceNumber")); invoice.put("invoiceStatus", InvoiceStatus.CONFIRMED.toString()); confirmed = true;//ww w .j a va 2s . c o m } else { invoice.put("invoiceNumber", null); invoice.put("invoiceStatus", InvoiceStatus.REQUESTED.toString()); } invoice.put("deliveryMatrixId", (long) event.get("deliveryMatrixId")); // get opportunity Map<String, Object> opportunityRequest = new HashMap<>(); opportunityRequest.put("deliveryMatrixId", (long) event.get("deliveryMatrixId")); Map<String, Object> opportunity = opportunityPersistanceService.findBy(opportunityRequest); opportunityRequest.clear(); opportunityRequest.put("id", (long) opportunity.get("id")); Map<String, Object> opportunityHours = opportunityPersistanceService .listOpportunityHours(opportunityRequest); List<Map<String, Object>> hoursList = (List<Map<String, Object>>) opportunityHours.get("list"); // verificar horas for (Map<String, Object> oHours : hoursList) { HourType type = HourType.valueOf((String) oHours.get("hourType")); int aviableHours = (int) oHours.get("quantity") - (int) oHours.get("hoursToBill"); if ((int) event.get(type.toString().toLowerCase() + "Quantity") > aviableHours) { // mas horas de las disponibles response.put("status", EventStatus.EXCEPTION); return response; } } // save invoice Map<String, Object> saveInvoice = invoicePersistanceService.saveInvoice(invoice); if ((EventStatus) saveInvoice.get("status") != EventStatus.SUCCESS) { response.put("status", EventStatus.EXCEPTION); return response; } // update opportunity remaining hours if (confirmed) { opportunity.put("billedHours", (int) opportunity.get("billedHours") + totalHours); } opportunity.put("hoursToBill", (int) opportunity.get("hoursToBill") + totalHours); Map<String, Object> updateOpportunity = opportunityPersistanceService.updateOpportunity(opportunity); if ((EventStatus) updateOpportunity.get("status") != EventStatus.SUCCESS) { throw new RuntimeException("Error at save opportunity"); } // add the hours to invoice hours for (HourType t : HourType.values()) { if ((int) event.get(t.toString().toLowerCase() + "Quantity") < 1) continue; Map<String, Object> hour = new HashMap<>(); hour.put("invoiceOrder", (long) saveInvoice.get("id")); hour.put("quantity", (int) event.get(t.toString().toLowerCase() + "Quantity")); hour.put("hourType", t.toString()); hour.put("unitPrice", (BigDecimal) event.get(t.toString().toLowerCase() + "Price")); hour.put("amount", ((BigDecimal) hour.get("unitPrice")).multiply(new BigDecimal((int) hour.get("quantity")))); Map<String, Object> saveHour = invoicePersistanceService.saveInvoiceHours(hour); if ((EventStatus) saveHour.get("status") != EventStatus.SUCCESS) { response.put("status", EventStatus.EXCEPTION); return response; } // update opportunity hours for (Map<String, Object> oHours : hoursList) { HourType type = HourType.valueOf((String) oHours.get("hourType")); if (type == t) { if (confirmed) { oHours.put("billedHours", (int) oHours.get("billedHours") + (int) hour.get("quantity")); } oHours.put("hoursToBill", (int) oHours.get("hoursToBill") + (int) hour.get("quantity")); Map<String, Object> updateOpportunityHours = opportunityPersistanceService .updateOpportunityHours(oHours); logger.debug("updatr response " + updateOpportunityHours); if ((EventStatus) updateOpportunityHours.get("status") != EventStatus.SUCCESS) { throw new RuntimeException("Error at update opportunity hours"); } break; } } } if (event.containsKey("pdf")) { Map<String, Object> pdf = new HashMap<>(); pdf.put("mimetype", "application/pdf"); pdf.put("data", (byte[]) event.get("pdf")); Map<String, Object> saveAttachment = invoicePersistanceService.saveInvoiceAttachments(pdf); if ((EventStatus) saveAttachment.get("status") != EventStatus.SUCCESS) { response.put("status", EventStatus.EXCEPTION); return response; } } if (event.containsKey("xml")) { Map<String, Object> pdf = new HashMap<>(); pdf.put("mimetype", "application/xml"); pdf.put("data", (byte[]) event.get("xml")); Map<String, Object> saveAttachment = invoicePersistanceService.saveInvoiceAttachments(pdf); if ((EventStatus) saveAttachment.get("status") != EventStatus.SUCCESS) { response.put("status", EventStatus.EXCEPTION); return response; } } response.put("status", com.redhat.rhtracking.events.EventStatus.SUCCESS); return response; }
From source file:org.ancoron.osgi.test.glassfish.GlassfishDerbyTest.java
@Test(timeOut = 10000, dependsOnGroups = { "glassfish-osgi-startup" }) public void testMovieServicesAvailability() { logTest();// w ww. j a v a 2 s .c o m Map<String, String> svcs = new HashMap<String, String>(); svcs.put(MoviePersistenceService.class.getName(), null); svcs.put(MovieJPAService.class.getName(), null); svcs.put(MovieService.class.getName(), null); waitForServices(svcs); svcs.clear(); }
From source file:com.esd.ps.InspectorController.java
/** * ?/*www . j a v a 2 s .c om*/ * @param arr * @param inspectorId * @return */ @RequestMapping(value = "/assignT", method = RequestMethod.POST) @ResponseBody public Map<String, Object> assignTPost(String workerIds, int inspectorId) { logger.debug("workerIds:{},inspectorId:{}", workerIds, inspectorId); Map<String, Object> map = new HashMap<String, Object>(); String[] workerId = workerIds.split("/"); int l = workerId.length; if (l < 1) { map.clear(); map.put(Constants.REPLAY, 0); return map; } for (int i = 0; i < l; i++) { int id = Integer.parseInt(workerId[i]); workerRecordService.updateByWorkerId(5, -1, id, "", inspectorId, null, -1); } map.clear(); map.put(Constants.REPLAY, 1); return map; }
From source file:com.netsteadfast.greenstep.bsc.action.DegreeFeedbackProjectScoreSaveOrUpdateAction.java
private void fetchScores() throws ControllerException, AuthorityException, ServiceException, Exception { this.checkFields("fetch"); BbEmployee rater = this.employeeService.findByAccountOid(this.getAccountOid()); if (null == rater || StringUtils.isBlank(rater.getOid())) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_ERRORS)); }/*from w ww . ja v a2 s . co m*/ BbEmployee owner = this.employeeService.findByPKng(this.getFields().get("ownerOid")); if (null == owner || StringUtils.isBlank(owner.getOid())) { throw new ServiceException(SysMessageUtil.get(GreenStepSysMsgConstants.DATA_NO_EXIST)); } String projectOid = this.getFields().get("projectOid"); DegreeFeedbackAssignVO assing = new DegreeFeedbackAssignVO(); assing.setProjectOid(projectOid); assing.setOwnerId(owner.getEmpId()); assing.setRaterId(rater.getEmpId()); DefaultResult<DegreeFeedbackAssignVO> result = this.degreeFeedbackAssignService.findByUK(assing); if (result.getValue() == null) { throw new ServiceException(result.getSystemMessage().getValue()); } assing = result.getValue(); Map<String, Object> paramMap = new HashMap<String, Object>(); paramMap.put("assignOid", assing.getOid()); paramMap.put("projectOid", projectOid); this.projectScores = this.degreeFeedbackScoreService.findListVOByParams(paramMap); paramMap.clear(); paramMap.put("projectOid", projectOid); this.projectLevels = this.degreeFeedbackLevelService.findListVOByParams(paramMap); paramMap.clear(); BbDegreeFeedbackLevel minLevel = this.degreeFeedbackLevelService.findForMinByProject(projectOid); if (minLevel != null) { this.minLevelOid = minLevel.getOid(); } this.success = IS_YES; }
From source file:hoot.services.controllers.osm.OSMTestUtils.java
static Set<Long> createTestNodes(long changesetId, BoundingBox bounds) throws Exception { Map<String, String> tags = new HashMap<>(); tags.put("key 1", "val 1"); tags.put("key 2", "val 2"); Set<Long> nodeIds = new LinkedHashSet<>(); nodeIds.add(insertNew(changesetId, getMapId(), bounds.getMinLat(), bounds.getMinLon(), tags)); tags.clear(); nodeIds.add(insertNew(changesetId, getMapId(), bounds.getMaxLat(), bounds.getMaxLon(), tags)); nodeIds.add(insertNew(changesetId, getMapId(), bounds.getMinLat(), bounds.getMinLon(), tags)); tags.put("key 3", "val 3"); nodeIds.add(insertNew(changesetId, getMapId(), bounds.getMinLat(), bounds.getMinLon(), tags)); tags.clear();//from ww w .j a v a 2 s. c o m tags.put("key 4", "val 4"); nodeIds.add(insertNew(changesetId, getMapId(), bounds.getMinLat(), bounds.getMinLon(), tags)); tags.clear(); return nodeIds; }
From source file:hoot.services.controllers.osm.OSMTestUtils.java
static Set<Long> createTestRelationsNoWays(long changesetId, Set<Long> nodeIds) throws Exception { Long[] nodeIdsArr = nodeIds.toArray(new Long[nodeIds.size()]); List<RelationMember> members = new ArrayList<>(); members.add(new RelationMember(nodeIdsArr[0], ElementType.Node, "role1")); members.add(new RelationMember(nodeIdsArr[2], ElementType.Node)); Map<String, String> tags = new HashMap<>(); tags.put("key 1", "val 1"); long firstRelationId = insertNewRelation(changesetId, getMapId(), members, tags); Set<Long> relationIds = new LinkedHashSet<>(); relationIds.add(firstRelationId);// w ww . j a v a2s . c o m tags.clear(); members.clear(); tags.put("key 2", "val 2"); tags.put("key 3", "val 3"); members.add(new RelationMember(nodeIdsArr[4], ElementType.Node, "role1")); members.add(new RelationMember(firstRelationId, ElementType.Relation, "role1")); relationIds.add(insertNewRelation(changesetId, getMapId(), members, tags)); tags.clear(); members.clear(); tags.put("key 4", "val 4"); members.add(new RelationMember(nodeIdsArr[2], ElementType.Node, "role1")); relationIds.add(insertNewRelation(changesetId, getMapId(), members, tags)); tags.clear(); members.clear(); return relationIds; }
From source file:com.fiveamsolutions.nci.commons.authentication.LoginModuleTest.java
@Test(expected = CredentialExpiredException.class) public void testPasswordExpiration() throws Exception { String un = "user"; String pw = "Password1"; LoginModule module = new CommonLoginModule(); Map<String, ?> options = new HashMap<String, Object>(); Map<String, ?> sharedState = new HashMap<String, Object>(); Subject subject = new Subject(); CallbackHandler cbh = new MockCallbackHandler(un, pw.toCharArray()); module.initialize(subject, cbh, sharedState, options); Long userId = createUser(un, pw); assertTrue(module.login());//from w ww.j ava 2 s .c o m assertTrue(!sharedState.isEmpty()); sharedState.clear(); updatePasswordExpirationDate(userId, null); assertTrue(module.login()); assertTrue(!sharedState.isEmpty()); sharedState.clear(); updatePasswordExpirationDate(userId, DateUtils.addDays(new Date(), -1)); module.login(); }
From source file:com.tonbeller.jpivot.mondrian.ScriptableMondrianDrillThroughTableModel.java
/** * execute sql query/*from w w w . j a v a 2 s . c o m*/ * @throws Exception */ private void executeQuery() { Connection con = null; try { InputStream catExtIs = ScriptableMondrianDrillThroughTableModel.class.getClassLoader() .getResourceAsStream("/" + catalogExtension); Digester catExtDigester = new Digester(); catExtDigester.push(this); catExtDigester.addSetProperties("extension"); catExtDigester.addObjectCreate("extension/script", "com.tonbeller.jpivot.mondrian.script.ScriptColumn"); catExtDigester.addSetProperties("extension/script"); catExtDigester.addSetNext("extension/script", "addScript"); catExtDigester.parse(catExtIs); URL scriptsBaseURL = Thread.currentThread().getContextClassLoader().getResource(scriptRootUrl); scriptEngine = new GroovyScriptEngine(new URL[] { scriptsBaseURL }); con = getConnection(); Statement s = con.createStatement(); s.setMaxRows(maxResults); ResultSet rs = s.executeQuery(sql); ResultSetMetaData md = rs.getMetaData(); int numCols = md.getColumnCount(); List columnTitlesList = new ArrayList(); // set column headings for (int i = 0; i < numCols; i++) { // columns are 1 based columnTitlesList.add(i, md.getColumnName(i + 1)); } // loop on script columns for (ListIterator sIt = scripts.listIterator(); sIt.hasNext();) { final ScriptColumn sc = (ScriptColumn) sIt.next(); columnTitlesList.add(sc.getPosition() - 1, sc.getTitle()); } columnTitles = (String[]) columnTitlesList.toArray(new String[0]); // loop through rows List tempRows = new ArrayList(); Map scriptInput = new HashMap(); Binding binding = new Binding(); while (rs.next()) { List rowList = new ArrayList(); scriptInput.clear(); // loop on columns, 1 based for (int i = 0; i < numCols; i++) { rowList.add(i, rs.getObject(i + 1)); scriptInput.put(columnTitles[i], rs.getObject(i + 1)); } binding.setVariable("input", scriptInput); // loop on script columns for (ListIterator sIt = scripts.listIterator(); sIt.hasNext();) { final ScriptColumn sc = (ScriptColumn) sIt.next(); scriptEngine.run(sc.getFile(), binding); final Object output = binding.getVariable("output"); if (output instanceof Map) { Map outMap = (Map) output; rowList.add(sc.getPosition() - 1, new DefaultCell((String) outMap.get("URL"), (String) outMap.get("Value"))); } else if (output instanceof String) { rowList.add(sc.getPosition() - 1, (String) output); } else { throw new Exception("Unknown groovy script return type (not a Map nor String)."); } } tempRows.add(new DefaultTableRow(rowList.toArray())); } rs.close(); rows = (TableRow[]) tempRows.toArray(new TableRow[0]); } catch (Exception e) { e.printStackTrace(); logger.error("?", e); // problem occured, set table model to zero size rows = new TableRow[1]; columnTitles = new String[1]; columnTitles[0] = "An error occured"; Object[] row = new Object[1]; row[0] = e.toString(); rows[0] = new DefaultTableRow(row); ready = false; return; } finally { try { con.close(); } catch (Exception e1) { // ignore } } ready = true; }