List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.attribyte.essem.DefaultResponseGenerator.java
/** * Adds the metadata to a graph built from an ES aggregation. * @param graphObj The graph object.// w ww . j a va 2 s.c om * @param targetMeta The target (input) meta. */ private void addAggregationMeta(final ObjectNode graphObj, final ObjectNode targetMeta) { ObjectNode meta = targetMeta.deepCopy(); List<String> metaList = Lists.newArrayListWithExpectedSize(4); if (meta.has("application")) { metaList.add(meta.get("application").asText()); } if (meta.has("host")) { metaList.add(meta.get("host").asText()); } if (meta.has("instance")) { metaList.add(meta.get("instance").asText()); } if (meta.has("name")) { metaList.add(meta.get("name").asText()); } meta.put("key", keyJoiner.join(metaList)); graphObj.set("meta", meta); }
From source file:com.msopentech.odatajclient.engine.data.json.JSONEntryDeserializer.java
/** * {@inheritDoc }//w w w . j av a 2s .c om */ @Override public JSONEntry deserialize(final JsonParser parser, final DeserializationContext ctxt) throws IOException, JsonProcessingException { final ObjectNode tree = (ObjectNode) parser.getCodec().readTree(parser); if (tree.has(ODataConstants.JSON_VALUE) && tree.get(ODataConstants.JSON_VALUE).isArray()) { throw new JsonParseException("Expected OData Entity, found EntitySet", parser.getCurrentLocation()); } final boolean isMediaEntry = tree.hasNonNull(ODataConstants.JSON_MEDIAREAD_LINK) && tree.hasNonNull(ODataConstants.JSON_MEDIA_CONTENT_TYPE); final JSONEntry entry = new JSONEntry(); if (tree.hasNonNull(ODataConstants.JSON_METADATA)) { entry.setMetadata(URI.create(tree.get(ODataConstants.JSON_METADATA).textValue())); tree.remove(ODataConstants.JSON_METADATA); } if (tree.hasNonNull(ODataConstants.JSON_MEDIA_ETAG)) { entry.setMediaETag(tree.get(ODataConstants.JSON_MEDIA_ETAG).textValue()); tree.remove(ODataConstants.JSON_MEDIA_ETAG); } if (tree.hasNonNull(ODataConstants.JSON_ETAG)) { entry.setETag(tree.get(ODataConstants.JSON_ETAG).textValue()); tree.remove(ODataConstants.JSON_ETAG); } if (tree.hasNonNull(ODataConstants.JSON_TYPE)) { entry.setType(tree.get(ODataConstants.JSON_TYPE).textValue()); tree.remove(ODataConstants.JSON_TYPE); } if (tree.hasNonNull(ODataConstants.JSON_ID)) { entry.setId(tree.get(ODataConstants.JSON_ID).textValue()); tree.remove(ODataConstants.JSON_ID); } if (tree.hasNonNull(ODataConstants.JSON_READ_LINK)) { final JSONLink link = new JSONLink(); link.setRel(ODataConstants.SELF_LINK_REL); link.setHref(tree.get(ODataConstants.JSON_READ_LINK).textValue()); entry.setSelfLink(link); tree.remove(ODataConstants.JSON_READ_LINK); } if (tree.hasNonNull(ODataConstants.JSON_EDIT_LINK)) { final JSONLink link = new JSONLink(); link.setRel(ODataConstants.EDIT_LINK_REL); link.setHref(tree.get(ODataConstants.JSON_EDIT_LINK).textValue()); entry.setEditLink(link); tree.remove(ODataConstants.JSON_EDIT_LINK); } if (tree.hasNonNull(ODataConstants.JSON_MEDIAREAD_LINK)) { entry.setMediaContentSource(tree.get(ODataConstants.JSON_MEDIAREAD_LINK).textValue()); tree.remove(ODataConstants.JSON_MEDIAREAD_LINK); } if (tree.hasNonNull(ODataConstants.JSON_MEDIAEDIT_LINK)) { final JSONLink link = new JSONLink(); link.setHref(tree.get(ODataConstants.JSON_MEDIAEDIT_LINK).textValue()); entry.addMediaEditLink(link); tree.remove(ODataConstants.JSON_MEDIAEDIT_LINK); } if (tree.hasNonNull(ODataConstants.JSON_MEDIA_CONTENT_TYPE)) { entry.setMediaContentType(tree.get(ODataConstants.JSON_MEDIA_CONTENT_TYPE).textValue()); tree.remove(ODataConstants.JSON_MEDIA_CONTENT_TYPE); } final Set<String> toRemove = new HashSet<String>(); final Iterator<Map.Entry<String, JsonNode>> itor = tree.fields(); while (itor.hasNext()) { final Map.Entry<String, JsonNode> field = itor.next(); if (field.getKey().endsWith(ODataConstants.JSON_NAVIGATION_LINK_SUFFIX) || field.getKey().endsWith(ODataConstants.JSON_NAVIGATION_LINK_ODATA_4_SUFFIX)) { final JSONLink link = new JSONLink(); link.setTitle(getTitle(field)); link.setRel(ODataConstants.NAVIGATION_LINK_REL + getTitle(field)); if (field.getValue().isValueNode()) { link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); } // NOTE: this should be expected to happen, but it isn't - at least up to OData 4.0 /* if (field.getValue().isArray()) { * link.setHref(field.getValue().asText()); * link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); * } */ entry.addNavigationLink(link); toRemove.add(field.getKey()); toRemove.add(setInline(field.getKey(), field.getKey().endsWith(ODataConstants.JSON_NAVIGATION_LINK_SUFFIX) ? ODataConstants.JSON_NAVIGATION_LINK_SUFFIX : ODataConstants.JSON_NAVIGATION_LINK_ODATA_4_SUFFIX, tree, parser.getCodec(), link)); } else if (field.getKey().endsWith(ODataConstants.JSON_ASSOCIATION_LINK_SUFFIX)) { final JSONLink link = new JSONLink(); link.setTitle(getTitle(field)); link.setRel(ODataConstants.ASSOCIATION_LINK_REL + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.ASSOCIATION.toString()); entry.addAssociationLink(link); toRemove.add(field.getKey()); } else if (field.getKey().endsWith(ODataConstants.JSON_MEDIAEDIT_LINK_SUFFIX)) { final JSONLink link = new JSONLink(); link.setTitle(getTitle(field)); link.setRel(ODataConstants.MEDIA_EDIT_LINK_REL + getTitle(field)); link.setHref(field.getValue().textValue()); link.setType(ODataLinkType.MEDIA_EDIT.toString()); entry.addMediaEditLink(link); toRemove.add(field.getKey()); toRemove.add(setInline(field.getKey(), ODataConstants.JSON_MEDIAEDIT_LINK_SUFFIX, tree, parser.getCodec(), link)); } else if (field.getKey().charAt(0) == '#') { final ODataOperation operation = new ODataOperation(); operation.setMetadataAnchor(field.getKey()); final ObjectNode opNode = (ObjectNode) tree.get(field.getKey()); operation.setTitle(opNode.get(ODataConstants.ATTR_TITLE).asText()); operation.setTarget(URI.create(opNode.get(ODataConstants.ATTR_TARGET).asText())); entry.addOperation(operation); toRemove.add(field.getKey()); } } tree.remove(toRemove); try { final DocumentBuilder builder = ODataConstants.DOC_BUILDER_FACTORY.newDocumentBuilder(); final Document document = builder.newDocument(); final Element properties = document.createElementNS(ODataConstants.NS_METADATA, ODataConstants.ELEM_PROPERTIES); DOMTreeUtils.buildSubtree(properties, tree); if (isMediaEntry) { entry.setMediaEntryProperties(properties); } else { entry.setContent(properties); } } catch (ParserConfigurationException e) { throw new JsonParseException("Cannot build entry content", parser.getCurrentLocation(), e); } return entry; }
From source file:com.marklogic.entityservices.tests.TestInstanceConverterGenerator.java
private String moduleImport(String entityType) { InputStream is = this.getClass().getResourceAsStream("/json-models/" + entityType); ObjectMapper mapper = new ObjectMapper(); ObjectNode controlFile = null; try {//from w w w .j a v a 2s.c o m controlFile = (ObjectNode) mapper.readTree(is); } catch (IOException e) { throw new RuntimeException(e); } JsonNode baseUriNode = controlFile.get("info").get("baseUri"); String baseUri = null; if (baseUriNode == null) { baseUri = "http://example.org/"; } else { baseUri = baseUriNode.asText(); } String uriPrefix = baseUri; if (!baseUri.matches(".*[#/]$")) { uriPrefix += "#"; } String entityTypeName = entityType.replace(".json", ""); String moduleName = "/ext/" + entityTypeName + ".xqy"; return "import module namespace conv = \"" + uriPrefix + entityTypeName + "\" at \"" + moduleName + "\"; "; }
From source file:kz.nurlan.kaspandr.KaspandrWindow.java
private HashMap<String, ArrayNode> groupByLessonsByGroup(String lessons) { HashMap<String, ArrayNode> groupMap = new HashMap<String, ArrayNode>(); try {//from w ww.j av a2 s.c om ObjectNode rootNode1 = mapper.readValue("{\"lessons\":[" + lessons + "]}", ObjectNode.class); JsonNode lessonsNode1 = rootNode1.get("lessons"); if (lessonsNode1 != null && lessonsNode1.isArray()) { Iterator<JsonNode> it = lessonsNode1.elements(); while (it.hasNext()) { JsonNode lesson = it.next(); if (lesson.get("id") != null && !lesson.get("status").textValue().equalsIgnoreCase("deleted") && lesson.get("group") != null && !lesson.get("group").textValue().isEmpty()) { if (groupMap.containsKey(lesson.get("group").textValue())) groupMap.put(lesson.get("group").textValue(), groupMap.get(lesson.get("group").textValue()).add(lesson)); else { groupMap.put(lesson.get("group").textValue(), mapper.createArrayNode().add(lesson)); } } } } } catch (Exception e) { e.printStackTrace(); } return groupMap; }
From source file:kz.nurlan.kaspandr.KaspandrWindow.java
private HashMap<String, Integer> getCountedLessonsByGroup(String lessons) { HashMap<String, Integer> groupMap = new HashMap<String, Integer>(); try {//from w ww .j a v a 2 s.c om ObjectNode rootNode1 = mapper.readValue("{\"lessons\":[" + lessons + "]}", ObjectNode.class); JsonNode lessonsNode1 = rootNode1.get("lessons"); groupMap.put("all", 0); if (lessonsNode1 != null && lessonsNode1.isArray()) { Iterator<JsonNode> it = lessonsNode1.elements(); while (it.hasNext()) { JsonNode lesson = it.next(); if (lesson.get("id") != null && !lesson.get("status").textValue().equalsIgnoreCase("deleted") && lesson.get("group") != null && !lesson.get("group").textValue().isEmpty()) { if (groupMap.containsKey(lesson.get("group").textValue())) groupMap.put(lesson.get("group").textValue(), groupMap.get(lesson.get("group").textValue()) + 1); else groupMap.put(lesson.get("group").textValue(), 1); } } } } catch (Exception e) { e.printStackTrace(); } return groupMap; }
From source file:ai.serotonin.backup.Base.java
List<Archive> getInventory() throws Exception { final String vaultName = getVaultName(); final InitiateJobRequest initJobRequest = new InitiateJobRequest() // .withVaultName(vaultName) // .withJobParameters(new JobParameters() // .withType("inventory-retrieval") // //.withSNSTopic("*** provide SNS topic ARN ****") // );//from w w w . j av a2s. co m String jobId; try { LOG.info("Initiating inventory job..."); final InitiateJobResult initJobResult = client.initiateJob(initJobRequest); jobId = initJobResult.getJobId(); } catch (final ResourceNotFoundException e) { // Ignore. No inventory is available. LOG.warn("Inventory not available: " + e.getErrorMessage()); return null; } // Wait for the inventory job to complete. waitForJob(vaultName, jobId); // Get the output of the inventory job. LOG.info("Inventory job completed. Getting output..."); final GetJobOutputRequest jobOutputRequest = new GetJobOutputRequest().withVaultName(vaultName) .withJobId(jobId); final GetJobOutputResult jobOutputResult = client.getJobOutput(jobOutputRequest); final ObjectMapper mapper = new ObjectMapper(); final ObjectNode rootNode = mapper.readValue(jobOutputResult.getBody(), ObjectNode.class); final List<Archive> archives = new ArrayList<>(); for (final JsonNode archiveNode : rootNode.get("ArchiveList")) archives.add(new Archive(archiveNode)); Collections.sort(archives); return archives; }
From source file:org.activiti.rest.service.api.identity.UserInfoResourceTest.java
/** * Test getting the collection of info for a user. *//*from w w w . java 2 s.c o m*/ public void testGetUserInfoCollection() throws Exception { User savedUser = null; try { User newUser = identityService.newUser("testuser"); newUser.setFirstName("Fred"); newUser.setLastName("McDonald"); newUser.setEmail("no-reply@activiti.org"); identityService.saveUser(newUser); savedUser = newUser; identityService.setUserInfo(newUser.getId(), "key1", "Value 1"); identityService.setUserInfo(newUser.getId(), "key2", "Value 2"); CloseableHttpResponse response = executeRequest( new HttpGet(SERVER_URL_PREFIX + RestUrls .createRelativeResourceUrl(RestUrls.URL_USER_INFO_COLLECTION, newUser.getId())), HttpStatus.SC_OK); JsonNode responseNode = objectMapper.readTree(response.getEntity().getContent()); closeResponse(response); assertNotNull(responseNode); assertTrue(responseNode.isArray()); assertEquals(2, responseNode.size()); boolean foundFirst = false; boolean foundSecond = false; for (int i = 0; i < responseNode.size(); i++) { ObjectNode info = (ObjectNode) responseNode.get(i); assertNotNull(info.get("key").textValue()); assertNotNull(info.get("url").textValue()); if (info.get("key").textValue().equals("key1")) { foundFirst = true; assertTrue(info.get("url").textValue().endsWith( RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key1"))); } else if (info.get("key").textValue().equals("key2")) { assertTrue(info.get("url").textValue().endsWith( RestUrls.createRelativeResourceUrl(RestUrls.URL_USER_INFO, newUser.getId(), "key2"))); foundSecond = true; } } assertTrue(foundFirst); assertTrue(foundSecond); } finally { // Delete user after test passes or fails if (savedUser != null) { identityService.deleteUser(savedUser.getId()); } } }
From source file:com.ethlo.geodata.restdocs.AbstractJacksonFieldSnippet.java
private void handleRef(Class<?> type, ObjectNode root, ObjectNode definitionsNode, ObjectNode currentNode, FieldDescriptor descriptor, Iterator<String> pathParts) { final String typeStr = currentNode.fieldNames().next(); switch (typeStr) { case "$ref": final String refValue = currentNode.get(typeStr).asText(); Assert.notNull(refValue, "Value of $ref should not be null"); final String typeName = refValue.substring(refValue.lastIndexOf('/') + 1); final ObjectNode refType = (ObjectNode) definitionsNode.get(typeName); handleSchema(type, refType, definitionsNode, descriptor, pathParts); allSchemas.put(type, refType);//from www. j a v a 2s . c om break; default: logger.warn("Unhandled type: {}", typeStr); } }
From source file:org.apache.taverna.scufl2.translator.t2flow.TestComponentActivityParser.java
@Test public void parseSimpleTell() throws Exception { WorkflowBundle researchObj = parseWorkflow(WF_SIMPLE_COMPONENT); Profile profile = researchObj.getMainProfile(); assertNotNull("could not find profile in bundle", profile); Processor comp = researchObj.getMainWorkflow().getProcessors().getByName("combiner"); assertNotNull("could not find processor 'combiner'", comp); Configuration config = scufl2Tools.configurationForActivityBoundToProcessor(comp, profile); Activity act = (Activity) config.getConfigures(); assertEquals(ACTIVITY_URI, act.getType()); ObjectNode resource = config.getJsonAsObjectNode(); assertEquals(ACTIVITY_URI.resolve("#Config"), config.getType()); int length = 0; Iterator<?> i = resource.fieldNames(); while (i.hasNext()) { i.next();//from w w w . j a v a 2 s . c om length++; } assertEquals("must be exactly 4 items in the translated component", 4, length); assertEquals("http://www.myexperiment.org", resource.get("registryBase").textValue()); assertEquals("SCAPE Utility Components", resource.get("familyName").textValue()); assertEquals("MeasuresDocCombiner", resource.get("componentName").textValue()); assertEquals(1, resource.get("componentVersion").asInt()); assertEquals(2, comp.getInputPorts().size()); assertEquals(1, comp.getOutputPorts().size()); }
From source file:org.keycloak.authz.server.services.common.KeycloakIdentity.java
@Override public Attributes getAttributes() { HashMap<String, Collection<String>> attributes = new HashMap<>(); try {//from w w w . j av a 2s . c o m ObjectNode objectNode = JsonSerialization.createObjectNode(this.accessToken); Iterator<String> iterator = objectNode.fieldNames(); List<String> roleNames = new ArrayList<>(); while (iterator.hasNext()) { String fieldName = iterator.next(); JsonNode fieldValue = objectNode.get(fieldName); List<String> values = new ArrayList<>(); values.add(fieldValue.asText()); if (fieldName.equals("realm_access")) { JsonNode grantedRoles = fieldValue.get("roles"); if (grantedRoles != null) { Iterator<JsonNode> rolesIt = grantedRoles.iterator(); while (rolesIt.hasNext()) { roleNames.add(rolesIt.next().asText()); } } } if (fieldName.equals("resource_access")) { Iterator<JsonNode> resourceAccessIt = fieldValue.iterator(); while (resourceAccessIt.hasNext()) { JsonNode grantedRoles = resourceAccessIt.next().get("roles"); if (grantedRoles != null) { Iterator<JsonNode> rolesIt = grantedRoles.iterator(); while (rolesIt.hasNext()) { roleNames.add(rolesIt.next().asText()); } } } } attributes.put(fieldName, values); } attributes.put("roles", roleNames); } catch (Exception e) { throw new RuntimeException("Error while reading attributes from security token.", e); } return Attributes.from(attributes); }