List of usage examples for org.json.simple JSONArray contains
public boolean contains(Object o)
From source file:org.alfresco.tutorial.doclibaction.evaluator.CheckIfDocIsEmailedEvaluator.java
@Override public boolean evaluate(JSONObject jsonObject) { try {/*from w ww. j a va 2s.c om*/ JSONArray nodeAspects = getNodeAspects(jsonObject); if (nodeAspects == null) { return false; } else { if (nodeAspects.contains(ASPECT_EMAILED)) { return true; } else { return false; } } } catch (Exception err) { throw new RuntimeException("JSONException whilst running action evaluator: " + err.getMessage()); } }
From source file:org.exoplatform.addons.es.client.ElasticContentRequestBuilderTest.java
@Test public void getCreateDocumentRequestContent_ifSimpleConnectorAndEntityId_shouldReturnCreateQuery() throws ParseException, org.json.simple.parser.ParseException { // Given/*from ww w .java2 s .co m*/ initDocumentMock(); // When String request = elasticContentRequestBuilder .getCreateDocumentRequestContent(elasticIndexingServiceConnector, "1"); // Then String[] lines = request.split("\n"); JSONObject parsedRequestLine1 = (JSONObject) JSONValue.parseWithException(lines[0]); JSONObject create = (JSONObject) parsedRequestLine1.get("create"); assertThat((String) create.get("_type"), is("type1")); assertThat((String) create.get("_id"), is("1")); assertThat((String) create.get("_index"), is("test")); JSONObject parsedRequestLine2 = (JSONObject) JSONValue.parseWithException(lines[1]); assertThat((String) parsedRequestLine2.get("author"), is("Michael Jordan")); assertThat((String) parsedRequestLine2.get("quote"), is("I've missed more than 9000 shots in my career. I've lost almost 300 games. " + "26 times, I've been trusted to take the game winning shot and missed. " + "I've failed over and over and over again in my life. And that is why I succeed.")); JSONArray permissions = (JSONArray) parsedRequestLine2.get("permissions"); assertTrue(permissions.contains("vizir")); assertTrue(permissions.contains("goleador")); assertThat((Long) parsedRequestLine2.get("lastUpdatedDate"), is(601171200000L)); assertThat((String) parsedRequestLine2.get("url"), is("MyUrlBaby")); }
From source file:org.exoplatform.addons.es.client.ElasticContentRequestBuilderTest.java
@Test public void getUpdateDocumentRequestContent_ifSimpleConnectorAndEntityId_shouldReturnUpdateQuery() throws ParseException, org.json.simple.parser.ParseException { // Given//from www. j a va 2 s. c om initDocumentMock(); // When String request = elasticContentRequestBuilder .getUpdateDocumentRequestContent(elasticIndexingServiceConnector, "1"); // Then String[] lines = request.split("\n"); JSONObject parsedRequestLine1 = (JSONObject) JSONValue.parseWithException(lines[0]); JSONObject create = (JSONObject) parsedRequestLine1.get("index"); assertThat((String) create.get("_type"), is("type1")); assertThat((String) create.get("_id"), is("1")); assertThat((String) create.get("_index"), is("test")); JSONObject parsedRequestLine2 = (JSONObject) JSONValue.parseWithException(lines[1]); assertThat((String) parsedRequestLine2.get("author"), is("Michael Jordan")); assertThat((String) parsedRequestLine2.get("quote"), is("I've missed more than 9000 shots in my career. I've lost almost 300 games. " + "26 times, I've been trusted to take the game winning shot and missed. " + "I've failed over and over and over again in my life. And that is why I succeed.")); JSONArray permissions = (JSONArray) parsedRequestLine2.get("permissions"); assertTrue(permissions.contains("vizir")); assertTrue(permissions.contains("goleador")); assertThat((Long) parsedRequestLine2.get("lastUpdatedDate"), is(601171200000L)); assertThat((String) parsedRequestLine2.get("url"), is("MyUrlBaby")); }
From source file:org.jolokia.converter.json.ArrayExtractorTest.java
@Test public void simple() throws AttributeNotFoundException { JSONArray res = (JSONArray) extractJson(new String[] { "eins", "zwei", "drei" }); assertEquals(res.size(), 3);/* w w w . j a va 2s . com*/ assertTrue(res.contains("eins")); assertTrue(res.contains("zwei")); assertTrue(res.contains("drei")); }
From source file:org.mozilla.gecko.sync.repositories.android.AndroidBrowserBookmarksRepositorySession.java
@SuppressWarnings("unchecked") private void finishUp() { try {// w ww . jav a 2 s . c o m Logger.debug(LOG_TAG, "Have " + parentToChildArray.size() + " folders whose children might need repositioning."); for (Entry<String, JSONArray> entry : parentToChildArray.entrySet()) { String guid = entry.getKey(); JSONArray onServer = entry.getValue(); try { final long folderID = getIDForGUID(guid); JSONArray inDB = getChildrenArray(folderID, false); // If the local children and the remote children are already // the same, then we don't need to bump the modified time of the // parent: we wouldn't upload a different record, so avoid the cycle. if (!Utils.sameArrays(onServer, inDB)) { int added = 0; for (Object o : inDB) { if (!onServer.contains(o)) { onServer.add(o); added++; } } Logger.debug(LOG_TAG, "Added " + added + " items locally."); dataAccessor.bumpModified(folderID, now()); // Wow, this is spectacularly wasteful. Logger.debug(LOG_TAG, "Untracking " + guid); final Record record = retrieveByGUIDDuringStore(guid); if (record == null) { return; } untrackRecord(record); } // Until getChildrenArray can tell us if it needed to make // any changes at all, always update positions. dataAccessor.updatePositions(new ArrayList<String>(onServer)); } catch (Exception e) { Logger.warn(LOG_TAG, "Error repositioning children for " + guid, e); } } } finally { super.storeDone(); } }
From source file:org.wso2.developerstudio.datamapper.diagram.tree.generator.SchemaTransformer.java
/** * Gets the required array/*from w w w. j a v a 2 s . com*/ * * @param requiredArayArray * @param schemaElement * @return */ @SuppressWarnings("unchecked") private JSONArray getJSONArray(JSONArray requiredArayArray, String schemaElement) { JSONObject jsonObj; Pattern logEntry = Pattern.compile("\\{(.*?)\\}"); Matcher matchPattern = logEntry.matcher(schemaElement); while (matchPattern.find()) { jsonObj = new JSONObject(); String value = matchPattern.group(1); String[] stringArrs = value.split(","); for (String stringArr : stringArrs) { if (stringArr.contains("=")) { String[] array = stringArr.split("="); String firstElement = array[0].trim(); String secondElement = array[1].trim(); if (firstElement.contains("\\") || secondElement.contains("\\")) { String first = firstElement.replace("\\", ""); String second = secondElement.replace("\\", ""); jsonObj.put(first, second); } else { jsonObj.put(firstElement, secondElement); } } } // Adds the object if it doesn't already available in the array if (!requiredArayArray.contains(jsonObj)) { requiredArayArray.add(jsonObj); } } return requiredArayArray; }
From source file:org.wso2.identity.scenarios.commons.OAuth2CommonClient.java
/** * Validate application creation response. * * @param requestJSON DCR request body. * @param responseJSON DCR response body. *//*from w ww .j av a 2 s .com*/ public void validateApplicationCreationResponse(JSONObject requestJSON, JSONObject responseJSON) { assertEquals(responseJSON.get(OAuth2Constants.DCRResponseElements.CLIENT_NAME).toString(), requestJSON.get(OAuth2Constants.DCRRequestElements.CLIENT_NAME).toString(), "Received client_name value is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); if (requestJSON.get(OAuth2Constants.DCRRequestElements.CLIENT_ID) != null) { assertEquals(responseJSON.get(OAuth2Constants.DCRResponseElements.CLIENT_ID).toString(), requestJSON.get(OAuth2Constants.DCRRequestElements.CLIENT_ID).toString(), "Received client_id value is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); } else { assertNotNull(responseJSON.get(OAuth2Constants.DCRResponseElements.CLIENT_ID), "Received client_id value is null. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); } if (requestJSON.get(OAuth2Constants.DCRRequestElements.CLIENT_SECRET) != null) { assertEquals(responseJSON.get(OAuth2Constants.DCRResponseElements.CLIENT_SECRET).toString(), requestJSON.get(OAuth2Constants.DCRRequestElements.CLIENT_SECRET).toString(), "Received client_secret value is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); } else { assertNotNull(responseJSON.get(OAuth2Constants.DCRResponseElements.CLIENT_SECRET), "Received client_secret value is null. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); } if (requestJSON.get(OAuth2Constants.DCRRequestElements.REDIRECT_URIS) != null && ((JSONArray) requestJSON.get(OAuth2Constants.DCRResponseElements.REDIRECT_URIS)).size() > 0) { JSONArray redirectUris = (JSONArray) requestJSON.get(OAuth2Constants.DCRRequestElements.REDIRECT_URIS); assertNotNull(responseJSON.get(OAuth2Constants.DCRResponseElements.REDIRECT_URIS), "Received redirect_uris value is null. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); JSONArray returnedRedirectUris = (JSONArray) responseJSON .get(OAuth2Constants.DCRResponseElements.REDIRECT_URIS); assertEquals(returnedRedirectUris.size(), redirectUris.size(), "Received redirect_uris size is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); for (Object redirectUrl : redirectUris) { assertTrue(returnedRedirectUris.contains(redirectUrl), "Received redirect_uris content is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + responseJSON.toJSONString()); } } }
From source file:org.wso2.identity.scenarios.sso.test.dcr.DCRTestCase.java
private void validateResponse(JSONObject requestJSON, HttpResponse response, boolean isSetClientId) throws IOException { JSONObject applicationJSON = getJSONFromResponse(response); assertEquals(applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_NAME).toString(), requestJSON.get(Constants.RegistrationRequestElements.CLIENT_NAME).toString(), "Received client_name value is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); if (registerRequestJSON.get(Constants.RegistrationRequestElements.CLIENT_ID) != null) { assertEquals(applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_ID).toString(), registerRequestJSON.get(Constants.RegistrationRequestElements.CLIENT_ID).toString(), "Received client_id value is invalid. Request Object: " + registerRequestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); } else {/*from w ww . java2s. c om*/ assertNotNull(applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_ID), "Received client_id value is null. Request Object: " + registerRequestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); } if (isSetClientId) { this.clientId = applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_ID).toString(); } if (registerRequestJSON.get(Constants.RegistrationRequestElements.CLIENT_SECRET) != null) { assertEquals(applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_SECRET).toString(), registerRequestJSON.get(Constants.RegistrationRequestElements.CLIENT_SECRET).toString(), "Received client_secret value is invalid. Request Object: " + registerRequestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); } else { assertNotNull(applicationJSON.get(Constants.ApplicationResponseElements.CLIENT_SECRET), "Received client_secret value is null. Request Object: " + registerRequestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); } if (requestJSON.get(Constants.RegistrationRequestElements.REDIRECT_URIS) != null && ((JSONArray) requestJSON.get(Constants.ApplicationResponseElements.REDIRECT_URIS)).size() > 0) { JSONArray redirectUris = (JSONArray) requestJSON .get(Constants.RegistrationRequestElements.REDIRECT_URIS); assertNotNull(applicationJSON.get(Constants.ApplicationResponseElements.REDIRECT_URIS), "Received redirect_uris value is null. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); JSONArray returnedRedirectUris = (JSONArray) applicationJSON .get(Constants.ApplicationResponseElements.REDIRECT_URIS); assertEquals(returnedRedirectUris.size(), redirectUris.size(), "Received redirect_uris size is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); for (Object redirectUrl : redirectUris) { assertTrue(returnedRedirectUris.contains(redirectUrl), "Received redirect_uris content is invalid. Request Object: " + requestJSON.toJSONString() + ", Response Object: " + applicationJSON.toJSONString()); } } }
From source file:se.alingsas.alfresco.share.evaluator.documentlibrary.action.IsAlingsasDocument.java
@Override public boolean evaluate(JSONObject jsonObject) { try {// w w w . ja va 2 s. c o m JSONArray nodeAspects = getNodeAspects(jsonObject); if (nodeAspects == null) { return false; } else { if (nodeAspects.contains(ASPECT_AK_COMMON)) { return true; } else { return false; } } } catch (Exception err) { throw new AlfrescoRuntimeException( "JSONException whilst running action evaluator: " + err.getMessage()); } }
From source file:uk.org.openeyes.BiometryFunctions.java
private String mergeIolRefValues(EtOphinbiometryIolRefValues currentIolRefValues, String newIolRefValues, String side) {/*w w w .j ava 2s. c om*/ String IOLJSON = ""; if (side.equals("L")) { IOLJSON = currentIolRefValues.getIolRefValuesLeft(); } else if (side.equals("R")) { IOLJSON = currentIolRefValues.getIolRefValuesRight(); } if (IOLJSON == null) { return newIolRefValues; } else { JSONObject currentIOLRefData = decodeJSONData(IOLJSON); JSONObject newIOLRefData = decodeJSONData(newIolRefValues); // merge logic based on IOL values JSONArray currentIOLArray = (JSONArray) currentIOLRefData.get("IOL"); JSONArray currentREFArray = (JSONArray) currentIOLRefData.get("REF"); JSONArray newIOLArray = (JSONArray) newIOLRefData.get("IOL"); JSONArray newREFArray = (JSONArray) newIOLRefData.get("REF"); JSONObject mergedIOLRefData = new JSONObject(); for (Integer i = 0; i < newIOLArray.size(); i++) { if (!currentIOLArray.contains(newIOLArray.get(i))) { currentIOLArray.add(newIOLArray.get(i)); currentREFArray.add(newREFArray.get(i)); } } mergedIOLRefData.put("IOL", currentIOLArray); mergedIOLRefData.put("REF", currentREFArray); return mergedIOLRefData.toJSONString(); } }