List of usage examples for com.fasterxml.jackson.databind.node ObjectNode get
public JsonNode get(String paramString)
From source file:com.edp.service.product.BpmnJsonConverter.java
private void readShapeDI(JsonNode objectNode, double parentX, double parentY, Map<String, JsonNode> shapeMap, Map<String, JsonNode> sourceRefMap, BpmnModel bpmnModel) { if (objectNode.get(EDITOR_CHILD_SHAPES) != null) { for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) { String stencilId = BpmnJsonConverterUtil.getStencilId(jsonChildNode); if (STENCIL_SEQUENCE_FLOW.equals(stencilId) == false) { GraphicInfo graphicInfo = new GraphicInfo(); JsonNode boundsNode = jsonChildNode.get(EDITOR_BOUNDS); ObjectNode upperLeftNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_UPPER_LEFT); graphicInfo.setX(upperLeftNode.get(EDITOR_BOUNDS_X).asDouble() + parentX); graphicInfo.setY(upperLeftNode.get(EDITOR_BOUNDS_Y).asDouble() + parentY); ObjectNode lowerRightNode = (ObjectNode) boundsNode.get(EDITOR_BOUNDS_LOWER_RIGHT); graphicInfo.setWidth(/* w w w. ja v a 2 s. co m*/ lowerRightNode.get(EDITOR_BOUNDS_X).asDouble() - graphicInfo.getX() + parentX); graphicInfo.setHeight( lowerRightNode.get(EDITOR_BOUNDS_Y).asDouble() - graphicInfo.getY() + parentY); String childShapeId = jsonChildNode.get(EDITOR_SHAPE_ID).asText(); bpmnModel.addGraphicInfo(BpmnJsonConverterUtil.getElementId(jsonChildNode), graphicInfo); shapeMap.put(childShapeId, jsonChildNode); ArrayNode outgoingNode = (ArrayNode) jsonChildNode.get("outgoing"); if ((outgoingNode != null) && (outgoingNode.size() > 0)) { for (JsonNode outgoingChildNode : outgoingNode) { JsonNode resourceNode = outgoingChildNode.get(EDITOR_SHAPE_ID); if (resourceNode != null) { sourceRefMap.put(resourceNode.asText(), jsonChildNode); } } } readShapeDI(jsonChildNode, graphicInfo.getX(), graphicInfo.getY(), shapeMap, sourceRefMap, bpmnModel); } } } }
From source file:io.wcm.caravan.pipeline.impl.JsonPipelineImpl.java
@Override public JsonPipeline merge(JsonPipeline secondarySource, String targetProperty) { Observable<JsonNode> zippedSource = dataSource.zipWith(secondarySource.getOutput(), (jsonFromPrimary, jsonFromSecondary) -> { log.debug("zipping object from secondary source into target property " + targetProperty); if (!(jsonFromPrimary.isObject())) { throw new JsonPipelineOutputException( "Only pipelines with JSON *Objects* can be used as a target for a merge operation, but response data for " + this.getDescriptor() + " contained " + jsonFromPrimary.getClass().getSimpleName()); }// www. j a v a2s. co m // start with cloning the the response of the primary pipeline ObjectNode mergedObject = jsonFromPrimary.deepCopy(); // if a target property is specified, the JSON to be merged is inserted into this property if (isNotBlank(targetProperty)) { if (!mergedObject.has(targetProperty)) { // the target property does not exist yet, so we just can set the property mergedObject.set(targetProperty, jsonFromSecondary); } else { // the target property already exists - let's hope we can merge! JsonNode targetNode = mergedObject.get(targetProperty); if (!targetNode.isObject()) { throw new JsonPipelineOutputException( "When merging two pipelines into the same target property, both most contain JSON *Object* responses"); } if (!(jsonFromSecondary.isObject())) { throw new JsonPipelineOutputException( "Only pipelines with JSON *Object* responses can be merged into an existing target property"); } mergeAllPropertiesInto((ObjectNode) jsonFromSecondary, (ObjectNode) targetNode); } } else { // if no target property is specified, all properties of the secondary pipeline are copied into the merged object if (!(jsonFromSecondary.isObject())) { throw new JsonPipelineOutputException( "Only pipelines with JSON *Object* responses can be merged without specify a target property"); } mergeAllPropertiesInto((ObjectNode) jsonFromSecondary, mergedObject); } return mergedObject; }); String targetSuffix = isNotBlank(targetProperty) ? " INTO " + targetProperty : ""; String transformationDesc = "MERGE(" + secondarySource.getDescriptor() + targetSuffix + ")"; JsonPipelineImpl mergedPipeline = cloneWith(zippedSource, transformationDesc); mergedPipeline.sourceServiceNames.addAll(secondarySource.getSourceServices()); return mergedPipeline; }
From source file:org.wrml.runtime.format.text.html.WrmldocFormatter.java
protected ArrayNode buildReferencesArrayNode(final ObjectMapper objectMapper, final Map<URI, ObjectNode> schemaNodes, final Map<URI, LinkRelation> linkRelationCache, final Resource resource, final Prototype defaultPrototype) { final Context context = getContext(); final SchemaLoader schemaLoader = context.getSchemaLoader(); final SyntaxLoader syntaxLoader = context.getSyntaxLoader(); final URI defaultSchemaUri = (defaultPrototype != null) ? defaultPrototype.getSchemaUri() : null; final String defaultSchemaName = (defaultPrototype != null) ? defaultPrototype.getUniqueName().getLocalName() : null;/*w w w . ja v a 2 s .c om*/ final ArrayNode referencesNode = objectMapper.createArrayNode(); final ConcurrentHashMap<URI, LinkTemplate> referenceTemplates = resource.getReferenceTemplates(); final Set<URI> referenceRelationUris = referenceTemplates.keySet(); if (referenceTemplates != null && !referenceTemplates.isEmpty()) { String selfResponseSchemaName = null; List<String> resourceParameterList = null; final UriTemplate uriTemplate = resource.getUriTemplate(); final String[] parameterNames = uriTemplate.getParameterNames(); if (parameterNames != null && parameterNames.length > 0) { resourceParameterList = new ArrayList<>(); for (int i = 0; i < parameterNames.length; i++) { final String parameterName = parameterNames[i]; URI keyedSchemaUri = null; if (defaultPrototype != null) { final Set<String> allKeySlotNames = defaultPrototype.getAllKeySlotNames(); if (allKeySlotNames != null && allKeySlotNames.contains(parameterName)) { keyedSchemaUri = defaultSchemaUri; } } if (keyedSchemaUri == null) { final Set<URI> referenceLinkRelationUris = resource .getReferenceLinkRelationUris(Method.Get); if (referenceLinkRelationUris != null && !referenceLinkRelationUris.isEmpty()) { for (URI linkRelationUri : referenceLinkRelationUris) { final LinkTemplate referenceTemplate = referenceTemplates.get(linkRelationUri); final URI responseSchemaUri = referenceTemplate.getResponseSchemaUri(); final Prototype responseSchemaPrototype = schemaLoader .getPrototype(responseSchemaUri); if (responseSchemaPrototype != null) { final Set<String> allKeySlotNames = responseSchemaPrototype .getAllKeySlotNames(); if (allKeySlotNames != null && allKeySlotNames.contains(parameterName)) { keyedSchemaUri = responseSchemaUri; break; } } } } } String parameterTypeString = "?"; if (keyedSchemaUri != null) { final Prototype keyedPrototype = schemaLoader.getPrototype(keyedSchemaUri); final ProtoSlot keyProtoSlot = keyedPrototype.getProtoSlot(parameterName); if (keyProtoSlot instanceof PropertyProtoSlot) { final PropertyProtoSlot keyPropertyProtoSlot = (PropertyProtoSlot) keyProtoSlot; final ValueType parameterValueType = keyPropertyProtoSlot.getValueType(); final Type parameterHeapType = keyPropertyProtoSlot.getHeapValueType(); switch (parameterValueType) { case Text: { if (!String.class.equals(parameterHeapType)) { final Class<?> syntaxClass = (Class<?>) parameterHeapType; parameterTypeString = syntaxClass.getSimpleName(); } else { parameterTypeString = parameterValueType.name(); } break; } case SingleSelect: { final Class<?> choicesEnumClass = (Class<?>) parameterHeapType; if (choicesEnumClass.isEnum()) { parameterTypeString = choicesEnumClass.getSimpleName(); } else { // ? parameterTypeString = parameterValueType.name(); } break; } default: { parameterTypeString = parameterValueType.name(); break; } } } } resourceParameterList.add(parameterTypeString + " " + parameterName); } } for (final Method method : Method.values()) { for (final URI linkRelationUri : referenceRelationUris) { final LinkTemplate referenceTemplate = referenceTemplates.get(linkRelationUri); final LinkRelation linkRelation = getLinkRelation(linkRelationCache, linkRelationUri); if (method != linkRelation.getMethod()) { continue; } final ObjectNode referenceNode = objectMapper.createObjectNode(); referencesNode.add(referenceNode); referenceNode.put(PropertyName.method.name(), method.getProtocolGivenName()); referenceNode.put(PropertyName.rel.name(), syntaxLoader.formatSyntaxValue(linkRelationUri)); final String relationTitle = linkRelation.getTitle(); referenceNode.put(PropertyName.relationTitle.name(), relationTitle); final URI responseSchemaUri = referenceTemplate.getResponseSchemaUri(); String responseSchemaName = null; if (responseSchemaUri != null) { final ObjectNode responseSchemaNode = getSchemaNode(objectMapper, schemaNodes, responseSchemaUri, schemaLoader); referenceNode.put(PropertyName.responseSchema.name(), responseSchemaNode); responseSchemaName = responseSchemaNode .get(SchemaDesignFormatter.PropertyName.localName.name()).asText(); } final URI requestSchemaUri = referenceTemplate.getRequestSchemaUri(); String requestSchemaName = null; if (requestSchemaUri != null) { final ObjectNode requestSchemaNode = getSchemaNode(objectMapper, schemaNodes, requestSchemaUri, schemaLoader); referenceNode.put(PropertyName.requestSchema.name(), requestSchemaNode); requestSchemaName = requestSchemaNode .get(SchemaDesignFormatter.PropertyName.localName.name()).asText(); } final StringBuilder signatureBuilder = new StringBuilder(); if (responseSchemaName != null) { signatureBuilder.append(responseSchemaName); } else { signatureBuilder.append("void"); } signatureBuilder.append(" "); String functionName = relationTitle; if (SystemLinkRelation.self.getUri().equals(linkRelationUri)) { functionName = "get" + responseSchemaName; selfResponseSchemaName = responseSchemaName; } else if (SystemLinkRelation.save.getUri().equals(linkRelationUri)) { functionName = "save" + responseSchemaName; } else if (SystemLinkRelation.delete.getUri().equals(linkRelationUri)) { functionName = "delete"; if (defaultSchemaName != null) { functionName += defaultSchemaName; } else if (selfResponseSchemaName != null) { functionName += selfResponseSchemaName; } } signatureBuilder.append(functionName).append(" ( "); String parameterString = null; if (resourceParameterList != null) { final StringBuilder parameterStringBuilder = new StringBuilder(); final int parameterCount = resourceParameterList.size(); for (int i = 0; i < parameterCount; i++) { final String parameter = resourceParameterList.get(i); parameterStringBuilder.append(parameter); if (i < parameterCount - 1) { parameterStringBuilder.append(" , "); } } parameterString = parameterStringBuilder.toString(); signatureBuilder.append(parameterString); } if (requestSchemaName != null) { if (StringUtils.isNotBlank(parameterString)) { signatureBuilder.append(" , "); } signatureBuilder.append(requestSchemaName); signatureBuilder.append(" "); final String parameterName = Character.toLowerCase(requestSchemaName.charAt(0)) + requestSchemaName.substring(1); signatureBuilder.append(parameterName); } signatureBuilder.append(" ) "); final String signature = signatureBuilder.toString(); referenceNode.put(PropertyName.signature.name(), signature); } } } return referencesNode; }
From source file:com.ikanow.aleph2.management_db.mongodb.services.TestIkanowV1SyncService_LibraryJars.java
@Test public void test_createDeleteLibraryBean() throws InterruptedException, ExecutionException, JsonProcessingException, IOException, ParseException { final String temp_dir = System.getProperty("java.io.tmpdir") + File.separator; @SuppressWarnings("unchecked") ICrudService<JsonNode> v1_share_db = this._service_context.getCoreManagementDbService() .getUnderlyingPlatformDriver(ICrudService.class, Optional.of("social.share")).get(); final DBCollection dbc = v1_share_db.getUnderlyingPlatformDriver(DBCollection.class, Optional.empty()) .get();/*from w w w . j a v a 2 s. c om*/ v1_share_db.deleteDatastore().get(); IManagementCrudService<SharedLibraryBean> library_db = this._service_context.getCoreManagementDbService() .getSharedLibraryStore(); library_db.deleteDatastore().get(); final ObjectMapper mapper = BeanTemplateUtils.configureMapper(Optional.empty()); final ObjectNode v1_share_1 = (ObjectNode) mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_share.json")); final DBObject v1_share_1_dbo = (DBObject) JSON.parse(v1_share_1.toString()); v1_share_1_dbo.put("_id", new ObjectId(v1_share_1.get("_id").asText())); final String fileref_share = IOUtils .toString(this.getClass().getResourceAsStream("test_v1_sync_sample_share_fileref.json"), "UTF-8") .replace("XXX_TEMPDIR_XXX", temp_dir.replace("\\", "\\\\")); final ObjectNode v1_share_1b = (ObjectNode) mapper.readTree(fileref_share); final DBObject v1_share_1b_dbo = (DBObject) JSON.parse(v1_share_1b.toString()); v1_share_1b_dbo.put("_id", new ObjectId(v1_share_1b.get("_id").asText())); assertEquals(0L, (long) v1_share_db.countObjects().get()); dbc.save(v1_share_1_dbo); dbc.save(v1_share_1b_dbo); //v1_share_db.storeObjects(Arrays.asList(v1_share_1)).get(); assertEquals(2L, (long) v1_share_db.countObjects().get()); final ObjectNode v1_share_2 = (ObjectNode) mapper .readTree(this.getClass().getResourceAsStream("test_v1_sync_sample_share.json")); v1_share_2.set("_id", new TextNode("655d44e3347d336b3e8c4cbe")); final SharedLibraryBean share2 = IkanowV1SyncService_LibraryJars.getLibraryBeanFromV1Share(v1_share_2); library_db.storeObject(share2).get(); assertEquals(1L, (long) library_db.countObjects().get()); // Create directory FileUtils.forceMkdir(new File(temp_dir + "/library/")); FileUtils.deleteQuietly(new File(temp_dir + "/library/misc")); assertFalse(new File(temp_dir + "/library/misc").exists()); FileUtils.write(new File(temp_dir + "/v1_library.jar"), "test12345"); final GridFS share_fs = Mockito.mock(GridFS.class); final GridFSDBFile share_file = Mockito.mock(GridFSDBFile.class, new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().getName().equals("writeTo")) { ByteArrayOutputStream baos = (ByteArrayOutputStream) invocation.getArguments()[0]; if (null != baos) { try { baos.write("test123".getBytes()); } catch (IOException e) { e.printStackTrace(); } } } return null; } }); Mockito.when(share_fs.find(Mockito.<ObjectId>any())).thenReturn(share_file); // Create Date modified_test = null; { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); modified_test = library_db.getObjectById(res.get().get().toString()).get().get().modified(); // Created file: final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); assertEquals("test123", FileUtils.readFileToString(f)); } // Create - use file reference { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1b.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1b.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); modified_test = library_db.getObjectById(res.get().get().toString()).get().get().modified(); // Created file: final File f = new File(temp_dir + "/library/misc/v1_library.jar"); assertTrue(f.exists()); assertEquals("test12345", FileUtils.readFileToString(f)); } // Create duplicate { final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), true, v1_share_db, share_fs, _service_context); try { res.get(); fail("Should have thrown dup error"); } catch (Exception e) { } // good } // Update { v1_share_1_dbo.put("modified", new Date()); dbc.save(v1_share_1_dbo); final GridFSDBFile share_file2 = Mockito.mock(GridFSDBFile.class, new Answer<Void>() { @Override public Void answer(InvocationOnMock invocation) throws Throwable { if (invocation.getMethod().getName().equals("writeTo")) { ByteArrayOutputStream baos = (ByteArrayOutputStream) invocation.getArguments()[0]; if (null != baos) { try { baos.write("test1234".getBytes()); } catch (IOException e) { e.printStackTrace(); } } } return null; } }); Mockito.when(share_fs.find(Mockito.<ObjectId>any())).thenReturn(share_file2); final ManagementFuture<Supplier<Object>> res = IkanowV1SyncService_LibraryJars.createLibraryBean( v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService(), false, v1_share_db, share_fs, _service_context); assertEquals("v1_" + v1_share_1.get("_id").asText(), res.get().get().toString()); // Wrote DB entry assertTrue(library_db.getObjectById(res.get().get().toString()).get().isPresent()); // Created file: final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); assertEquals("test1234", FileUtils.readFileToString(f)); final Date modified_2 = library_db.getObjectById(res.get().get().toString()).get().get().modified(); assertTrue("Mod time should change " + modified_test + " < " + modified_2, modified_2.getTime() > modified_test.getTime()); } // Delete { IkanowV1SyncService_LibraryJars.deleteLibraryBean(v1_share_1.get("_id").asText(), library_db, _service_context.getStorageService()); assertFalse(library_db.getObjectById("v1_" + v1_share_1.get("_id").asText()).get().isPresent()); final File f = new File(temp_dir + "/library/misc/library.jar"); assertTrue(f.exists()); IkanowV1SyncService_LibraryJars.deleteLibraryBean(v1_share_2.get("_id").asText(), library_db, _service_context.getStorageService()); assertFalse(f.exists()); } }
From source file:com.unboundid.scim2.server.utils.SchemaChecker.java
/** * Internal method to check a SCIM resource. * * @param prefix The issue prefix./* w ww. j a v a 2s.co m*/ * @param objectNode The partial resource. * @param results The schema check results. * @param currentObjectNode The current resource. * @param isReplace Whether this is a replace. * @throws ScimException If an error occurs. */ private void checkResource(final String prefix, final ObjectNode objectNode, final Results results, final ObjectNode currentObjectNode, final boolean isReplace) throws ScimException { // Iterate through the schemas JsonNode schemas = objectNode.get(SchemaUtils.SCHEMAS_ATTRIBUTE_DEFINITION.getName()); if (schemas != null && schemas.isArray()) { boolean coreFound = false; for (JsonNode schema : schemas) { if (!schema.isTextual()) { // Go to the next one if the schema URI is not valid. We will report // this issue later when we check the values for the schemas // attribute. continue; } // Get the extension namespace object node. JsonNode extensionNode = objectNode.remove(schema.textValue()); if (extensionNode == null) { // Extension listed in schemas but no namespace in resource. Treat it // as an empty namesapce to check for required attributes. extensionNode = JsonUtils.getJsonNodeFactory().objectNode(); } if (!extensionNode.isObject()) { // Go to the next one if the extension namespace is not valid results.syntaxIssues.add(prefix + "Extended attributes namespace " + schema.textValue() + " must be a JSON object"); continue; } // Find the schema definition. Map.Entry<SchemaResource, Boolean> extensionDefinition = null; if (schema.textValue().equals(resourceType.getCoreSchema().getId())) { // Skip the core schema. coreFound = true; continue; } else { for (Map.Entry<SchemaResource, Boolean> schemaExtension : resourceType.getSchemaExtensions() .entrySet()) { if (schema.textValue().equals(schemaExtension.getKey().getId())) { extensionDefinition = schemaExtension; break; } } } if (extensionDefinition == null) { // Bail if we can't find the schema definition. We will report this // issue later when we check the values for the schemas attribute. continue; } checkObjectNode(prefix, Path.root(schema.textValue()), extensionDefinition.getKey().getAttributes(), (ObjectNode) extensionNode, results, currentObjectNode, isReplace, false, isReplace); } if (!coreFound) { // Make sure core schemas was included. results.syntaxIssues.add(prefix + "Value for attribute schemas must " + " contain schema URI " + resourceType.getCoreSchema().getId() + " because it is the core schema for this resource type"); } // Make sure all required extension schemas were included. for (Map.Entry<SchemaResource, Boolean> schemaExtension : resourceType.getSchemaExtensions() .entrySet()) { if (schemaExtension.getValue()) { boolean found = false; for (JsonNode schema : schemas) { if (schema.textValue().equals(schemaExtension.getKey().getId())) { found = true; break; } } if (!found) { results.syntaxIssues.add(prefix + "Value for attribute schemas " + "must contain schema URI " + schemaExtension.getKey().getId() + " because it is a required schema extension for this " + "resource type"); } } } } // All defined schema extensions should be removed. // Remove any additional extended attribute namespaces not included in // the schemas attribute. Iterator<Map.Entry<String, JsonNode>> i = objectNode.fields(); while (i.hasNext()) { String fieldName = i.next().getKey(); if (SchemaUtils.isUrn(fieldName)) { results.syntaxIssues.add(prefix + "Extended attributes namespace " + fieldName + " must be included in the schemas attribute"); i.remove(); } } // Check common and core schema checkObjectNode(prefix, Path.root(), commonAndCoreAttributes, objectNode, results, currentObjectNode, isReplace, false, isReplace); }
From source file:com.github.reinert.jjschema.JsonSchemaGenerator.java
/** * Merges two schemas.//www .j a v a 2s . co m * * @param parent A parent schema considering inheritance * @param child A child schema considering inheritance * @param overwriteChildProperties A boolean to check whether properties (from parent or child) must have higher priority * @return The tow schemas merged */ protected ObjectNode mergeSchema(ObjectNode parent, ObjectNode child, boolean overwriteChildProperties) { Iterator<String> namesIterator = child.fieldNames(); if (overwriteChildProperties) { while (namesIterator.hasNext()) { String propertyName = namesIterator.next(); overwriteProperty(parent, child, propertyName); } } else { while (namesIterator.hasNext()) { String propertyName = namesIterator.next(); if (!TAG_PROPERTIES.equals(propertyName)) { overwriteProperty(parent, child, propertyName); } } ObjectNode properties = (ObjectNode) child.get(TAG_PROPERTIES); if (properties != null) { if (parent.get(TAG_PROPERTIES) == null) { parent.putObject(TAG_PROPERTIES); } Iterator<Entry<String, JsonNode>> it = properties.fields(); while (it.hasNext()) { Entry<String, JsonNode> entry = it.next(); String pName = entry.getKey(); ObjectNode pSchema = (ObjectNode) entry.getValue(); ObjectNode actualSchema = (ObjectNode) parent.get(TAG_PROPERTIES).get(pName); if (actualSchema != null) { mergeSchema(pSchema, actualSchema, false); } ((ObjectNode) parent.get(TAG_PROPERTIES)).put(pName, pSchema); } } } return parent; }
From source file:org.lendingclub.mercator.newrelic.NewRelicScanner.java
/** * Scans all the servers ( reporting and non-reporting ) in NewRelic. * //from ww w . java 2 s. c om */ private void scanServers() { Instant startTime = Instant.now(); ObjectNode servers = getNewRelicClient().getServers(); Preconditions.checkNotNull(getProjector().getNeoRxClient(), "neorx client must be set"); String cypher = "WITH {json} as data " + "UNWIND data.servers as server " + "MERGE ( s:NewRelicServer { nr_serverId: toString(server.id), nr_accountId:{accountId} } ) " + "ON CREATE SET s.name = server.name, s.host = server.host, s.healthStatus = server.health_status, s.reporting = server.reporting, " + "s.lastReportedAt = server.last_reported_at, s.createTs = timestamp(), s.updateTs = timestamp() " + "ON MATCH SET s.name = server.name, s.host = server.host, s.healthStatus = server.health_status, s.reporting = server.reporting, " + "s.lastReportedAt = server.last_reported_at, s.updateTs = timestamp()"; getProjector().getNeoRxClient().execCypher(cypher, "json", servers, "accountId", clientSupplier.get().getAccountId()); Instant endTime = Instant.now(); logger.info("Updating neo4j with the latest information about {} NewRelic Servers took {} secs", servers.get("servers").size(), Duration.between(startTime, endTime).getSeconds()); }
From source file:org.wrml.runtime.format.application.schema.json.JsonSchema.java
private void parseProperties() { final ObjectNode propertiesNode = (ObjectNode) Definitions.PropertyType.Properties.getValueNode(_RootNode); if (propertiesNode != null) { final Iterator<String> propertyNames = propertiesNode.fieldNames(); while (propertyNames.hasNext()) { final String name = propertyNames.next(); final ObjectNode propertyNode = (ObjectNode) propertiesNode.get(name); Property property;/*from w w w.j a v a 2s . c o m*/ try { property = new Property(this, name, propertyNode); } catch (final IOException e) { continue; } // Add to the required set if noted Object value = property.getValue(PropertyType.Required); if (value != null && (Boolean) value) { _Required.add(property); } _Properties.put(name, property); } } }
From source file:com.almende.eve.monitor.ResultMonitorFactory.java
@Access(AccessType.PUBLIC) @Override/*from w w w . ja va2 s. c om*/ public final void registerPush(@Name("pushId") final String id, @Name("config") final ObjectNode pushParams, @Sender final String senderUrl) { final String pushKey = "_push_" + senderUrl + "_" + id; pushParams.put("url", senderUrl); pushParams.put("pushId", id); if (myAgent.getState().containsKey(pushKey)) { LOG.warning("reregistration of existing push, canceling old version."); try { unregisterPush(id, senderUrl); } catch (final Exception e) { LOG.warning("Failed to unregister push:" + e); } } final ObjectNode result = JOM.createObjectNode(); result.put("config", pushParams); final ObjectNode params = JOM.createObjectNode(); params.put("pushKey", pushKey); LOG.info("Register Push:" + pushKey); if (pushParams.has("interval")) { final int interval = pushParams.get("interval").intValue(); final JSONRequest request = new JSONRequest("monitor.doPush", params); result.put("taskId", myAgent.getScheduler().createTask(request, interval, true, false)); } String event = ""; if (pushParams.has("event")) { // Event param overrules event = pushParams.get("event").textValue(); } if (pushParams.has("onChange") && pushParams.get("onChange").booleanValue()) { event = "change"; try { final CallTuple res = NamespaceUtil.get(myAgent, pushParams.get("method").textValue()); final AnnotatedMethod method = res.getMethod(); final EventTriggered annotation = method.getAnnotation(EventTriggered.class); if (annotation != null) { // If no Event param, get it from annotation, else // use default. event = annotation.value(); } } catch (final Exception e) { LOG.log(Level.WARNING, "", e); } } if (!event.equals("")) { try { result.put("subscriptionId", myAgent.getEventsFactory().subscribe(myAgent.getFirstUrl(), event, "monitor.doPush", params)); } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to register push Event", e); } } myAgent.getState().put(pushKey, result.toString()); }
From source file:org.apache.asterix.test.common.TestExecutor.java
public InputStream executeAnyAQLAsync(String statement, boolean defer, OutputFormat fmt, URI uri, Map<String, Object> variableCtx) throws Exception { // Create a method instance. HttpUriRequest request = RequestBuilder.post(uri) .addParameter("mode", defer ? "asynchronous-deferred" : "asynchronous") .setEntity(new StringEntity(statement, StandardCharsets.UTF_8)).setHeader("Accept", fmt.mimeType()) .build();// ww w.ja v a2s .c o m String handleVar = getHandleVariable(statement); HttpResponse response = executeAndCheckHttpRequest(request); InputStream resultStream = response.getEntity().getContent(); String resultStr = IOUtils.toString(resultStream, "UTF-8"); ObjectNode resultJson = new ObjectMapper().readValue(resultStr, ObjectNode.class); final JsonNode jsonHandle = resultJson.get("handle"); final String strHandle = jsonHandle.asText(); if (handleVar != null) { variableCtx.put(handleVar, strHandle); return resultStream; } return null; }