List of usage examples for java.util HashMap entrySet
Set entrySet
To view the source code for java.util HashMap entrySet.
Click Source Link
From source file:com.wso2telco.gsma.authenticators.util.OutboundMessage.java
/** * Prepare the USSD/SMS message from database config table for service provider, operator specific message or * default message stored in mobile-connect.xml. Message template can have ${variable} and relevant data to apply * to the template should be passed with map parameter. * * @param clientId sp client id//from ww w .j av a 2 s. c o m * @param messageType ussd/sms message type * @param map additional variable data map for the message template * @param operator operator name * @return prepared ussd message */ public static String prepare(String clientId, MessageType messageType, HashMap<String, String> map, String operator) { MobileConnectConfig.OperatorSpecificMessage operatorSpecificMessage = null; String template = null; Map<String, String> data = new HashMap<String, String>(); // add default map values here // data.put("key", "value"); if (map != null && map.size() > 0) { for (Map.Entry<String, String> entry : map.entrySet()) { data.put(entry.getKey(), entry.getValue()); } } // Load operator specific message from hash map if (operator != null) { if (messageType == MessageType.USSD_LOGIN || messageType == MessageType.USSD_REGISTRATION) { operatorSpecificMessage = operatorSpecificMessageMap.get(operator); } else if (messageType == MessageType.USSD_PIN_LOGIN || messageType == MessageType.USSD_PIN_REGISTRATION) { operatorSpecificMessage = operatorSpecificPinMessageMap.get(operator); } else if (messageType == MessageType.SMS_LOGIN || messageType == MessageType.SMS_REGISTRATION) { operatorSpecificMessage = operatorSpecificSmsMessageMap.get(operator); } else if (messageType == MessageType.SMS_OTP) { operatorSpecificMessage = operatorSpecificSmsotpMessageMap.get(operator); } data.put("operator", operator); } // RULE 1 : first try to get login/registration messages from sp config table if (messageType == MessageType.USSD_LOGIN) { template = spConfigService.getUSSDLoginMessage(clientId); } else if (messageType == MessageType.USSD_REGISTRATION) { template = spConfigService.getUSSDRegistrationMessage(clientId); } else if (messageType == MessageType.USSD_PIN_LOGIN) { template = spConfigService.getUSSDPinLoginMessage(clientId); } else if (messageType == MessageType.USSD_PIN_REGISTRATION) { template = spConfigService.getUSSDPinRegistrationMessage(clientId); } else if (messageType == MessageType.SMS_LOGIN) { template = spConfigService.getSMSLoginMessage(clientId); } else if (messageType == MessageType.SMS_REGISTRATION) { template = spConfigService.getSMSRegistrationMessage(clientId); } else if (messageType == MessageType.SMS_OTP) { template = spConfigService.getSMSOTPMessage(clientId); } if (template == null) { // RULE 2 : if message template is not found, try loading them from operator specific config from xml if (operatorSpecificMessage != null) { if (messageType == MessageType.USSD_LOGIN) { template = operatorSpecificMessage.getLoginMessage(); } else if (messageType == MessageType.USSD_REGISTRATION) { template = operatorSpecificMessage.getRegistrationMessage(); } else if (messageType == MessageType.USSD_PIN_LOGIN) { template = operatorSpecificMessage.getLoginMessage(); } else if (messageType == MessageType.USSD_PIN_REGISTRATION) { template = operatorSpecificMessage.getRegistrationMessage(); } else if (messageType == MessageType.SMS_LOGIN) { template = operatorSpecificMessage.getLoginMessage(); } else if (messageType == MessageType.SMS_REGISTRATION) { template = operatorSpecificMessage.getRegistrationMessage(); } else if (messageType == MessageType.SMS_OTP) { template = operatorSpecificMessage.getSmsotpMessage(); } } else { // RULE 3 : if no operator specific message is found, try loading from common messages if (messageType == MessageType.USSD_LOGIN) { template = ussdConfig.getUssdLoginMessage(); } else if (messageType == MessageType.USSD_REGISTRATION) { template = ussdConfig.getUssdRegistrationMessage(); } else if (messageType == MessageType.USSD_PIN_LOGIN) { template = ussdConfig.getPinLoginMessage(); } else if (messageType == MessageType.USSD_PIN_REGISTRATION) { template = ussdConfig.getPinRegistrationMessage(); } else if (messageType == MessageType.SMS_LOGIN) { template = smsConfig.getLoginMessage(); } else if (messageType == MessageType.SMS_REGISTRATION) { template = smsConfig.getRegistrationMessage(); } else if (messageType == MessageType.SMS_OTP) { template = smsConfig.getSmsotpMessage(); } } } return template == null ? null : StrSubstitutor.replace(template, data); }
From source file:fr.paris.lutece.plugins.workflow.modules.ticketingfacilfamilles.web.task.AutomaticAssignmentTaskComponent.java
/** * build and return display Config Form Url * /* w w w.j a v a 2 s. c o m*/ * @param task * task * @param mapParams * map of parameters to add to redirect url * @return display Config Form Url */ private static String getDisplayConfigFormUrl(ITask task, HashMap<String, String> mapParams) { UrlItem url = new UrlItem(URL_DISPLAY_CONFIG_FORM); url.addParameter(PARAMETER_TASK_ID, task.getId()); if ((mapParams != null) && (mapParams.size() > 0)) { for (Map.Entry<String, String> entry : mapParams.entrySet()) { url.addParameter(entry.getKey(), entry.getValue()); } } return url.toString(); }
From source file:osh.comdriver.simulation.cruisecontrol.ScheduleDrawer.java
/** * Creates a dataset, consisting of two series of monthly data. * * @return The dataset.//from ww w . jav a 2s .c o m */ private static XYDataset[] createDataset(List<Schedule> schedules, HashMap<VirtualCommodity, PriceSignal> ps, HashMap<VirtualCommodity, PowerLimitSignal> pls, long currentTime) { XYSeriesCollection dataset1 = new XYSeriesCollection(); //power axis if (pls != null) { for (Entry<VirtualCommodity, PowerLimitSignal> e : pls.entrySet()) { long time = (long) ((currentTime / 86400.0) * 86400); PowerLimitSignal currentPls = e.getValue(); XYSeries upperLimit = new XYSeries(e.getKey().getCommodity() + "_upper_limit"); XYSeries lowerLimit = new XYSeries(e.getKey().getCommodity() + "_lower_limit"); while (currentPls != null && currentPls.getNextPowerLimitChange(time) != null) { upperLimit.add(time * 1000, currentPls.getPowerUpperLimit(time)); lowerLimit.add(time * 1000, currentPls.getPowerLowerLimit(time)); time = currentPls.getNextPowerLimitChange(time); upperLimit.add((time - 1) * 1000, currentPls.getPowerUpperLimit(time - 1)); lowerLimit.add((time - 1) * 1000, currentPls.getPowerLowerLimit(time - 1)); } dataset1.addSeries(upperLimit); dataset1.addSeries(lowerLimit); } } XYSeriesCollection dataset2 = new XYSeriesCollection(); //costs axis if (ps != null) { for (Entry<VirtualCommodity, PriceSignal> e : ps.entrySet()) { long time = (long) ((currentTime / 86400.0) * 86400); PriceSignal currentPs = e.getValue(); XYSeries currentxySeries = new XYSeries(e.getKey().getCommodity() + "_price"); while (currentPs != null && currentPs.getNextPriceChange(time) != null) { currentxySeries.add(time * 1000, currentPs.getPrice(time)); time = currentPs.getNextPriceChange(time); currentxySeries.add((time - 1) * 1000, currentPs.getPrice(time - 1)); } dataset2.addSeries(currentxySeries); } } XYSeriesCollection dataset3 = new XYSeriesCollection(); if (schedules != null) { int cntr = 1; SparseLoadProfile powerSum = new SparseLoadProfile(); if (schedules != null) { for (Schedule i : schedules) { XYSeries[] powerProfile = (XYSeries[]) renderSeries(i.getProfile(), Integer.toString(cntr++), currentTime); for (int j = 0; j < powerProfile.length; j++) { dataset3.addSeries(powerProfile[j]); } powerSum = (SparseLoadProfile) powerSum.merge(i.getProfile(), 0); } } XYSeries[] powerProfileSum = (XYSeries[]) renderSeries(powerSum, "sum", currentTime); for (int j = 0; j < powerProfileSum.length; j++) { dataset3.addSeries(powerProfileSum[j]); } } return new XYDataset[] { dataset1, dataset2, dataset3 }; }
From source file:eu.europa.ec.fisheries.uvms.exchange.search.SearchFieldMapper.java
/** * Created the complete search SQL with joins and sets the values based on * the criterias/*from w w w .j ava 2 s .co m*/ * * @param criterias * @param dynamic * @return * @throws ParseException */ private static String createSearchSql(List<SearchValue> criterias, boolean dynamic) throws ParseException { String OPERATOR = " OR "; if (dynamic) { OPERATOR = " AND "; } StringBuilder builder = new StringBuilder(); HashMap<ExchangeSearchField, List<SearchValue>> orderedValues = combineSearchFields(criterias); if (!orderedValues.isEmpty()) { builder.append("WHERE "); boolean first = true; for (Map.Entry<ExchangeSearchField, List<SearchValue>> criteria : orderedValues.entrySet()) { if (first) { first = false; } else { builder.append(OPERATOR); } if (criteria.getValue().size() == 1) { SearchValue searchValue = criteria.getValue().get(0); builder.append(" ( ").append(buildTableAliasname(searchValue.getField())) .append(setParameter(searchValue)) // .append(" OR ").append(buildTableAliasname(searchValue.getField())).append(" IS NULL ") .append(" ) "); } else if (criteria.getValue().size() > 1) { builder.append(" ( ").append(buildTableAliasname(criteria.getKey())).append(" IN (:") .append(criteria.getKey().getSQLReplacementToken()).append(") ") // .append(" OR ").append(buildTableAliasname(criteria.getKey())).append(" IS NULL ") .append(" ) "); } } } return builder.toString(); }
From source file:net.bioclipse.dbxp.business.DbxpManager.java
public static HttpResponse postValues(HashMap<String, String> postvars, String url) throws NoSuchAlgorithmException, ClientProtocolException, IOException { DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(userName, password)); List<NameValuePair> formparams = new ArrayList<NameValuePair>(); Iterator<Entry<String, String>> it = postvars.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> next = (Map.Entry<String, String>) it.next(); Map.Entry<String, String> pairs = next; formparams.add(new BasicNameValuePair(pairs.getKey(), pairs.getValue())); }/* w w w . j a va 2 s . co m*/ UrlEncodedFormEntity entity = new UrlEncodedFormEntity(formparams, "UTF-8"); HttpPost httppost = new HttpPost(url); httppost.setEntity(entity); HttpContext localContext = new BasicHttpContext(); return httpclient.execute(httppost, localContext); }
From source file:com.baasbox.dao.PermissionsHelper.java
/*** * Set th ACL for a given document//from ww w . j a v a 2 s .c om * @param doc * @param aclJson the json representing the acl to set. * {"_allowRead": * [ * {"name":"registered","isRole":true}, * {"name":"johnny", "isRole":false} * ] * } * Keys are: _allowRead,_allowWrite,_allowDelete,_allowUpdate * @throws Exception */ public static void setAcl(ODocument doc, PermissionJsonWrapper acl) throws AclNotValidException { if (acl.getAclJson() == null) return; DbHelper.requestTransaction(); try { revokeAll(doc); HashMap<Permissions, ArrayNode> hmp = new HashMap<Permissions, ArrayNode>(); if (acl.getAllowRead() != null) hmp.put(Permissions.ALLOW_READ, acl.getAllowRead()); if (acl.getAllowUpdate() != null) hmp.put(Permissions.ALLOW_UPDATE, acl.getAllowUpdate()); if (acl.getAllowDelete() != null) hmp.put(Permissions.ALLOW_DELETE, acl.getAllowDelete()); Iterator<Entry<Permissions, ArrayNode>> itAllows = hmp.entrySet().iterator(); while (itAllows.hasNext()) { Entry<Permissions, ArrayNode> allows = itAllows.next(); ArrayNode allow = allows.getValue(); Permissions perm = allows.getKey(); Iterator<JsonNode> itElements = allow.elements(); while (itElements.hasNext()) { JsonNode elem = itElements.next(); if (!elem.isObject()) throw new AclNotValidException(Type.ACL_NOT_OBJECT, perm + " must contains array of objects"); String name = ((ObjectNode) elem).get("name").asText(); if (StringUtils.isEmpty(name)) throw new AclNotValidException(Type.ACL_KEY_NOT_VALID, "An element of the " + perm + " field has no name"); boolean isRole = isARole(elem); if (!isRole) { grant(doc, perm, UserService.getOUserByUsername(name)); } else grant(doc, perm, RoleService.getORole(name)); } } DbHelper.commitTransaction(); } catch (AclNotValidException e) { DbHelper.rollbackTransaction(); throw e; } catch (Exception e) { DbHelper.rollbackTransaction(); throw e; } }
From source file:net.palette_software.pet.restart.HelperHttpClient.java
static void modifyWorker(String targetURL, BalancerManagerManagedWorker w, HashMap<String, Integer> switches, int simulation) throws Exception { try (CloseableHttpClient client = HttpClients.createDefault()) { if (!(simulation < 1)) { return; }//from w ww .j a va 2 s . c o m //connect to Balancer Manager HttpPost httpPost = new HttpPost(targetURL); List<NameValuePair> params = new ArrayList<>(); //check the switches map for the keys are acceptable to interact with Balancer Manager for (Map.Entry<String, Integer> entry : switches.entrySet()) { String key = entry.getKey(); String value = entry.getValue().toString(); if (!BalancerManagerAcceptedPostKeysContains(key)) { HelperLogger.loggerStdOut.info("Bad key in modifyWorker (" + key + "," + value + ")"); continue; } params.add(new BasicNameValuePair(key, value)); } //add the necessary parameters params.add(new BasicNameValuePair("b", w.getBalancerMemberName())); params.add(new BasicNameValuePair("w", w.getName())); params.add(new BasicNameValuePair("nonce", w.getNonce())); httpPost.setEntity(new UrlEncodedFormEntity(params)); //send the request CloseableHttpResponse response = client.execute(httpPost); //throw an exception is the result status is abnormal. int responseCode = response.getStatusLine().getStatusCode(); if (200 != responseCode) { throw new Exception("Balancer-manager returned a http response of " + responseCode); } } }
From source file:edu.jhu.cvrg.timeseriesstore.opentsdb.TimeSeriesRetriever.java
private static JSONObject retrieveTimeSeriesGET(String urlString, long startEpoch, long endEpoch, String metric, HashMap<String, String> tags, boolean showTSUIDs) { urlString = urlString + API_METHOD;// w w w . j a v a2 s .c om String result = ""; StringBuilder builder = new StringBuilder(); builder.append("?start="); builder.append(startEpoch); builder.append("&end="); builder.append(endEpoch); builder.append("&show_tsuids="); builder.append(showTSUIDs); builder.append("&m=sum:"); builder.append(metric); if (tags != null) { builder.append("{"); Iterator<Entry<String, String>> entries = tags.entrySet().iterator(); while (entries.hasNext()) { @SuppressWarnings("rawtypes") Map.Entry entry = (Map.Entry) entries.next(); builder.append((String) entry.getKey()); builder.append("="); builder.append((String) entry.getValue()); if (entries.hasNext()) { builder.append(","); } } builder.append("}"); } try { HttpURLConnection httpConnection = TimeSeriesUtility .openHTTPConnectionGET(urlString + builder.toString()); result = TimeSeriesUtility.readHttpResponse(httpConnection); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (OpenTSDBException e) { e.printStackTrace(); result = String.valueOf(e.responseCode); } return TimeSeriesUtility.makeResponseJSONObject(result); }
From source file:com.databasepreservation.testing.unit.cli.ModuleFactoryTestHelper.java
protected static void validate_arguments(ModuleFactoryTestHelper testFactory, List<String> args, HashMap<String, String> expectedImportValues, HashMap<String, String> expectedExportValues) { // verify that arguments create the correct import and export modules testFactory.assertCorrectModuleClass(args); // get information needed to test the actual parameters Map<String, Parameter> parameters = testFactory.getModuleParameters(args); Map<Parameter, String> importModuleArguments = testFactory.getImportModuleArguments(args); Map<Parameter, String> exportModuleArguments = testFactory.getExportModuleArguments(args); for (Map.Entry<String, String> entry : expectedImportValues.entrySet()) { String property = entry.getKey(); String expectation = entry.getValue(); assertThat("Property '" + property + "' must have value '" + expectation + "'", importModuleArguments.get(parameters.get(property)), equalTo(expectation)); }//w ww.j a v a 2 s. co m for (Map.Entry<String, String> entry : expectedExportValues.entrySet()) { String property = entry.getKey(); String expectation = entry.getValue(); assertThat("Property '" + property + "' must have value '" + expectation + "'", exportModuleArguments.get(parameters.get(property)), equalTo(expectation)); } }
From source file:com.dgtlrepublic.model.test.DataTest.java
@SuppressWarnings("unchecked") private static void verify(Map entry) throws Exception { String fileName = (String) entry.getOrDefault("file_name", ""); boolean ignore = (Boolean) entry.getOrDefault("ignore", false); int id = (Integer) entry.getOrDefault("id", -1); HashMap<String, Object> testCases = (HashMap<String, Object>) entry.getOrDefault("results", new HashMap<String, Object>()); if (ignore || StringUtils.isBlank(fileName) || testCases.size() == 0) { System.out.println(String.format("Ignoring [%s] : { id: %s | results: %s | explicit: %s }", fileName, id, testCases.size(), ignore)); return;//from ww w .jav a 2 s . c om } System.out.println("Parsing: " + fileName); HashMap<String, Object> parseResults = (HashMap<String, Object>) DataJsonConverter.toTestCaseMap(fileName) .getOrDefault("results", null); for (Entry<String, Object> testCase : testCases.entrySet()) { Object elValue = parseResults.get(testCase.getKey()); if (elValue == null) { throw new Exception(String.format("%n[%s] Missing Element: %s [%s]", fileName, testCase.getKey(), testCase.getValue())); } else if (elValue instanceof String && !elValue.equals(testCase.getValue())) { throw new Exception(String.format("%n[%s] Incorrect Value:(%s) [%s] { required: [%s] } ", fileName, testCase.getKey(), elValue, testCase.getValue())); } else if (elValue instanceof List && !((List) elValue).containsAll((Collection<?>) testCase.getValue())) { throw new Exception(String.format("%n[%s] Incorrect List Values:(%s) [%s] { required: [%s] } ", fileName, testCase.getKey(), elValue, testCase.getValue())); } } }