@Override public List<String> getSupportedCountries(MerchantStore store) throws ServiceException { List<String> supportedCountries = new ArrayList<String>(); MerchantConfiguration configuration = merchantConfigurationService.getMerchantConfiguration(SUPPORTED_COUNTRIES, store); if(configuration!=null) { String countries = configuration.getValue(); if(!StringUtils.isBlank(countries)) { Object objRegions=JSONValue.parse(countries); JSONArray arrayRegions=(JSONArray)objRegions; @SuppressWarnings("rawtypes") Iterator i = arrayRegions.iterator(); while(i.hasNext()) { supportedCountries.add((String)i.next()); } } } return supportedCountries; }
try { JSONArray acls = (JSONArray) ((JSONObject) new JSONParser().parse(jsonAcl)).get("acls"); for (Iterator it = acls.iterator(); it.hasNext();) { JSONObject acl = (JSONObject) it.next(); String scheme = ((String) acl.get("scheme")).trim();
if (authenticated) { JSONArray jsonRoleSet = (JSONArray) ((JSONObject) new JSONParser().parse(globalProps.getProperty("ldapRoleSet"))).get("users"); for (Iterator it = jsonRoleSet.iterator(); it.hasNext();) { JSONObject jsonUser = (JSONObject) it.next(); if (jsonUser.get("username") != null && jsonUser.get("username").equals("*")) { for (Iterator it = jsonRoleSet.iterator(); it.hasNext();) { JSONObject jsonUser = (JSONObject) it.next(); if (jsonUser.get("username").equals(username) && jsonUser.get("password").equals(password)) {
JSONArray arrayRegions=(JSONArray)objRegions; @SuppressWarnings("rawtypes") Iterator i = arrayRegions.iterator(); while(i.hasNext()) { supportedCountries.add((String)i.next());
public HostFromJSONListAdapter(String jsonList) { JSONArray jsonArray = (JSONArray) JSONValue.parse(jsonList); Iterator jsonArrayIterator = jsonArray.iterator(); while(jsonArrayIterator.hasNext()) { JSONObject jsonObject = (JSONObject) jsonArrayIterator.next(); String host = (String) jsonObject.remove("ip"); _known_hosts.put(host, jsonObject); } }
@Test public void testBatchedMetricsSerialization() throws Exception { final BatchedMetricsJSONOutputSerializer serializer = new BatchedMetricsJSONOutputSerializer(); final Map<Locator, MetricData> metrics = new HashMap<Locator, MetricData>(); for (int i = 0; i < 2; i++) { final MetricData metricData = new MetricData(FakeMetricDataGenerator.generateFakeRollupPoints(), "unknown"); metrics.put(Locator.createLocatorFromPathComponents(tenantId, String.valueOf(i)), metricData); } JSONObject jsonMetrics = serializer.transformRollupData(metrics, filterStats); Assert.assertTrue(jsonMetrics.get("metrics") != null); JSONArray jsonMetricsArray = (JSONArray) jsonMetrics.get("metrics"); Iterator<JSONObject> metricsObjects = jsonMetricsArray.iterator(); Assert.assertTrue(metricsObjects.hasNext()); while (metricsObjects.hasNext()) { JSONObject singleMetricObject = metricsObjects.next(); Assert.assertTrue(singleMetricObject.get("unit").equals("unknown")); Assert.assertTrue(singleMetricObject.get("type").equals("number")); JSONArray data = (JSONArray) singleMetricObject.get("data"); Assert.assertTrue(data != null); } } }
@Test public void testInitializeAdapter() throws Exception { Map<String, JSONObject> mapKnownHosts = new HashMap<>(); HostFromPropertiesFileAdapter hfa = new HostFromPropertiesFileAdapter(mapKnownHosts); Assert.assertFalse(hfa.initializeAdapter(null)); JSONArray jsonArray = (JSONArray) JSONValue.parse(expectedKnownHostsString); Iterator jsonArrayIterator = jsonArray.iterator(); while(jsonArrayIterator.hasNext()) { JSONObject jsonObject = (JSONObject) jsonArrayIterator.next(); String host = (String) jsonObject.remove("ip"); mapKnownHosts.put(host, jsonObject); } hfa = new HostFromPropertiesFileAdapter(mapKnownHosts); Assert.assertTrue(hfa.initializeAdapter(null)); }
@Test public void testEnrich() throws Exception { Map<String, JSONObject> mapKnownHosts = new HashMap<>(); JSONArray jsonArray = (JSONArray) JSONValue.parse(expectedKnownHostsString); Iterator jsonArrayIterator = jsonArray.iterator(); while(jsonArrayIterator.hasNext()) { JSONObject jsonObject = (JSONObject) jsonArrayIterator.next(); String host = (String) jsonObject.remove("ip"); mapKnownHosts.put(host, jsonObject); } HostFromPropertiesFileAdapter hfa = new HostFromPropertiesFileAdapter(mapKnownHosts); JSONObject actualMessage = hfa.enrich(new CacheKey("dummy", ip, null)); Assert.assertNotNull(actualMessage); Assert.assertEquals(expectedMessage, actualMessage); actualMessage = hfa.enrich(new CacheKey("dummy", ip1, null)); JSONObject emptyJson = new JSONObject(); Assert.assertEquals(emptyJson, actualMessage); }
protected Set<String> getSchemaFields(String schema) throws FileNotFoundException, IOException, ParseException, URISyntaxException { Set<String> res = new HashSet<>(); JSONParser parser = new JSONParser(); JSONObject jsonObject = (JSONObject) parser.parse(new FileReader(this.getClass().getResource(schema).toURI().getPath())); JSONArray jsonArray = (JSONArray) jsonObject.get("fields"); jsonArray.iterator().forEachRemaining(o -> res.add(((JSONObject) o).get("name").toString())); return res; }
public List<Comment> getComments() { List<Comment> tempComments = new ArrayList<Comment>(); Iterator itr = comments.iterator(); while (itr.hasNext()) { JSONObject comment = (JSONObject) itr.next(); tempComments.add(new Comment(comment, postId, commentId)); } return tempComments; }
private JSONArray getDeviceIdsFromDevices(JSONArray devices) { JSONArray deviceIdentifiers = new JSONArray(); Iterator<JSONObject> iterator = devices.iterator(); while (iterator.hasNext()) { JSONObject deviceObj = iterator.next(); JSONObject obj = new JSONObject(); obj.put(Constants.ID, deviceObj.get(Constants.DEVICE_IDENTIFIER).toString()); obj.put(Constants.TYPE, deviceObj.get(Constants.TYPE).toString()); deviceIdentifiers.add(obj); } return deviceIdentifiers; }
private Map<String, Scope> extractScopesFromJson(JSONObject scopesJson) { Map<String, Scope> scopeMap = new HashMap<>(); if (scopesJson != null) { Iterator<?> scopesIterator = ((JSONArray) ((JSONObject) scopesJson .get(APIMgtConstants.SWAGGER_OBJECT_NAME_APIM)).get(APIMgtConstants.SWAGGER_X_WSO2_SCOPES)) .iterator(); while (scopesIterator.hasNext()) { Scope scope = new Gson().fromJson(((JSONObject) scopesIterator.next()).toJSONString(), Scope.class); scopeMap.put(scope.getName(), scope); } } else { if (log.isDebugEnabled()) { log.debug("Unable to extract scopes from provided json as it is null."); } } log.debug("Scopes of extracted from Swagger: {}", scopeMap); return scopeMap; }
private Map<String, Scope> extractScopesFromJson(JSONObject scopesJson) { Map<String, Scope> scopeMap = new HashMap<>(); if (scopesJson != null) { Iterator<?> scopesIterator = ((JSONArray) ((JSONObject) scopesJson .get(APIMgtConstants.SWAGGER_OBJECT_NAME_APIM)).get(APIMgtConstants.SWAGGER_X_WSO2_SCOPES)) .iterator(); while (scopesIterator.hasNext()) { Scope scope = new Gson().fromJson(((JSONObject) scopesIterator.next()).toJSONString(), Scope.class); scopeMap.put(scope.getName(), scope); } } else { if (log.isDebugEnabled()) { log.debug("Unable to extract scopes from provided json as it is null."); } } log.debug("Scopes of extracted from Swagger: {}", scopeMap); return scopeMap; }
/** * Method to return the model with only the required properties and their definitions * * @param objModel model from which the required only properties are to be * @return JSONObject model representation with only the required properties and their definitions */ @SuppressWarnings("unchecked") private JSONObject getRequiredOnlyDefs(JSONObject objModel) { JSONObject returnObjProps = new JSONObject(); JSONObject allProps = (JSONObject) objModel.get("properties"); JSONArray reqProps = (JSONArray) objModel.get("required"); if (reqProps != null) { Iterator<String> i = reqProps.iterator(); Set<String> keyset = allProps.keySet(); while (i.hasNext()) { String req_property = i.next().toString(); for (String s : keyset) { if (req_property.equals(s.toString())) { returnObjProps.put(s, allProps.get(s)); } } } } return returnObjProps; }
public void toString( StringBuilder sb ){ sb.append( "[" ); Iterator<Object> iter=iterator(); boolean first = true; while(iter.hasNext()){ if ( first ){ first = false; }else{ sb.append( "," ); } Object value=iter.next(); if(value instanceof String){ sb.append( "\"" ); JSONObject.escape(sb, (String)value); sb.append( "\""); }else if ( value instanceof JSONObject ){ ((JSONObject)value).toString( sb ); }else if ( value instanceof JSONArray ){ ((JSONArray)value).toString( sb ); }else{ sb.append(String.valueOf(value)); } } sb.append( "]" ); } }
@SuppressWarnings("unchecked") @Override public boolean parseVertex(LongWritable key, Text value, Vertex<Text, NullWritable, DoubleWritable> vertex) throws Exception { JSONArray jsonArray = (JSONArray) new JSONParser() .parse(value.toString()); vertex.setVertexID(new Text(jsonArray.get(0).toString())); Iterator<JSONArray> iter = ((JSONArray) jsonArray.get(2)).iterator(); while (iter.hasNext()) { JSONArray edge = iter.next(); vertex.addEdge(new Edge<Text, NullWritable>(new Text(edge.get(0) .toString()), null)); } return true; } }
@SuppressWarnings("unchecked") @Override public boolean parseVertex(LongWritable key, Text value, Vertex<Text, NullWritable, DoubleWritable> vertex) throws Exception { JSONArray jsonArray = (JSONArray) new JSONParser() .parse(value.toString()); vertex.setVertexID(new Text(jsonArray.get(0).toString())); Iterator<JSONArray> iter = ((JSONArray) jsonArray.get(2)).iterator(); while (iter.hasNext()) { JSONArray edge = (JSONArray) iter.next(); vertex.addEdge(new Edge<Text, NullWritable>(new Text(edge.get(0) .toString()), null)); } return true; } }
private static boolean getUpdateMappingColumnDefs(JSONObject jobj, List<MappingDefinition> mappingDefs) throws Exception { Object obj = null; JSONArray mappings; if ((obj = getFromJsonObject(jobj, Constants.MAPPINGS)) != null) { mappings = (JSONArray) obj; Iterator<?> it = mappings.iterator(); while (it.hasNext()) { JSONObject mappingObj = (JSONObject) it.next(); MappingDefinition md = getMappingDef(mappingObj); if (md != null) { mappingDefs.add(md); } else { log.error("Error in parsing mappingdef: " + mappingObj.toString()); return false; } } } return true; }
public String toString(){ ItemList list=new ItemList(); Iterator<Object> iter=iterator(); while(iter.hasNext()){ Object value=iter.next(); if(value instanceof String){ list.add("\""+JSONObject.escape((String)value)+"\""); } else list.add(String.valueOf(value)); } return "["+list.toString()+"]"; }