List of usage examples for com.fasterxml.jackson.databind JsonNode textValue
public String textValue()
From source file:org.envirocar.server.rest.decoding.json.MeasurementDecoder.java
@Override public Measurement decode(JsonNode j, MediaType mediaType) { Measurement measurement = getEntityFactory().createMeasurement(); if (j.has(JSONConstants.GEOMETRY_KEY)) { measurement.setGeometry(geometryDecoder.decode(j.path(JSONConstants.GEOMETRY_KEY), mediaType)); }/*from ww w .j a v a2 s . c o m*/ if (j.has(GeoJSONConstants.PROPERTIES_KEY)) { JsonNode p = j.path(GeoJSONConstants.PROPERTIES_KEY); if (p.has(JSONConstants.SENSOR_KEY)) { measurement.setSensor(sensorDao.getByIdentifier(p.path(JSONConstants.SENSOR_KEY).textValue())); } if (p.has(JSONConstants.TIME_KEY)) { measurement.setTime(getDateTimeFormat().parseDateTime(p.path(JSONConstants.TIME_KEY).textValue())); } if (p.has(JSONConstants.PHENOMENONS_KEY)) { JsonNode phens = p.path(JSONConstants.PHENOMENONS_KEY); Iterator<Entry<String, JsonNode>> fields = phens.fields(); while (fields.hasNext()) { Entry<String, JsonNode> field = fields.next(); Phenomenon phenomenon = phenomenonDao.getByName(field.getKey()); JsonNode valueNode = field.getValue().get(JSONConstants.VALUE_KEY); if (valueNode.isValueNode()) { Object value = null; if (valueNode.isNumber()) { value = valueNode.asDouble(); } else if (valueNode.isBoolean()) { value = valueNode.booleanValue(); } else if (valueNode.isTextual()) { value = valueNode.textValue(); } MeasurementValue v = getEntityFactory().createMeasurementValue(); v.setValue(value); v.setPhenomenon(phenomenon); measurement.addValue(v); } } } } return measurement; }
From source file:io.fabric8.collector.git.GitBuildConfigProcessor.java
protected String findFirstId(final SearchDTO search) { return WebClients.handle404ByReturningNull(new Callable<String>() { @Override/*from www . j ava 2 s .co m*/ public String call() throws Exception { ObjectNode results = elasticsearchClient.search(esIndex, esType, search); JsonNode hitsArray = results.path("hits").path("hits"); JsonNode idNode = hitsArray.path(0).path("_id"); String latestSha = null; if (idNode.isTextual()) { latestSha = idNode.textValue(); } if (LOG.isDebugEnabled()) { LOG.debug("Searching for " + JsonHelper.toJson(search) + " => " + latestSha); LOG.debug("Found hits " + hitsArray.size()); /* LOG.debug("JSON: " + JsonHelper.toJson(results)); */ } return latestSha; } }); }
From source file:eu.europa.ec.fisheries.uvms.reporting.service.util.ReportDeserializer.java
private void addAssetFilterDTO(List<FilterDTO> filterDTOList, Long reportId, JsonNode next) { AssetFilterDTO asset = new AssetFilterDTO(); asset.setReportId(reportId);/* ww w .j a va 2 s . co m*/ JsonNode idNode = next.get(FilterDTO.ID); if (idNode != null) { long id = idNode.longValue(); asset.setId(id); } JsonNode guidNode = next.get(GUID); if (guidNode != null) { String guidValue = guidNode.textValue(); asset.setGuid(guidValue); } JsonNode nameNode = next.get(NAME); if (nameNode != null) { String nameValue = nameNode.textValue(); asset.setName(nameValue); } filterDTOList.add(asset); }
From source file:ru.histone.deparser.Deparser.java
protected String processSelector(ArrayNode ast) { JsonNode selector = ast.get(1);/* ww w . jav a 2 s .com*/ List<String> result = new ArrayList<String>(); for (JsonNode partOfSelector : selector) { if (partOfSelector.isArray()) { result.add(processAstNode(partOfSelector)); } else { result.add(partOfSelector.textValue()); } } return StringUtils.join(result, "."); }
From source file:com.sitewhere.wso2.identity.scim.Wso2ScimAssetModule.java
/** * Parse role information./*from w ww .j a va 2 s . com*/ * * @param resource * @param asset */ protected void parseRoles(JsonNode resource, PersonAsset asset) { JsonNode groups = resource.get(IScimFields.GROUPS); if (groups != null) { Iterator<JsonNode> it = groups.elements(); while (it.hasNext()) { JsonNode fields = it.next(); JsonNode role = fields.get(IScimFields.DISPLAY); if (role != null) { asset.getRoles().add(role.textValue()); } } } }
From source file:com.sitewhere.wso2.identity.scim.Wso2ScimAssetModule.java
/** * Parse name fields.// w w w.j a va2 s . c om * * @param resource * @param asset */ protected void parseName(JsonNode resource, PersonAsset asset) { JsonNode name = resource.get(IScimFields.NAME); if (name != null) { String full = ""; JsonNode given = name.get(IScimFields.GIVEN_NAME); if (given != null) { String givenValue = given.textValue(); full += givenValue + " "; asset.getProperties().put(IScimFields.GIVEN_NAME, givenValue); } JsonNode family = name.get(IScimFields.FAMILY_NAME); if (family != null) { String familyValue = family.textValue(); full += familyValue; asset.getProperties().put(IScimFields.FAMILY_NAME, familyValue); } asset.getProperties().put(IWso2ScimFields.PROP_NAME, full.trim()); asset.setName(full.trim()); } }
From source file:org.apache.taverna.activities.dependencyactivity.AbstractAsynchronousDependencyActivity.java
/** * Finds dependencies for a nested workflow. *//*from w w w. j a v a2 s . co m*/ private HashSet<URL> findNestedDependencies(String dependencyType, JsonNode json, Dataflow nestedWorkflow) { ClassLoaderSharing classLoaderSharing; if (json.has("classLoaderSharing")) { classLoaderSharing = ClassLoaderSharing.fromString(json.get("classLoaderSharing").textValue()); } else { classLoaderSharing = ClassLoaderSharing.workflow; } // Files of dependencies for all activities in the nested workflow that share the classloading policy HashSet<File> dependencies = new HashSet<File>(); // Urls of all dependencies HashSet<URL> dependenciesURLs = new HashSet<URL>(); for (Processor proc : nestedWorkflow.getProcessors()) { // Another nested workflow if (!proc.getActivityList().isEmpty() && proc.getActivityList().get(0) instanceof NestedDataflow) { // Get the nested workflow Dataflow nestedNestedWorkflow = ((NestedDataflow) proc.getActivityList().get(0)) .getNestedDataflow(); dependenciesURLs.addAll(findNestedDependencies(dependencyType, json, nestedNestedWorkflow)); } else { // Not nested - go through all of the processor's activities Activity<?> activity = proc.getActivityList().get(0); if (activity instanceof AbstractAsynchronousDependencyActivity) { AbstractAsynchronousDependencyActivity dependencyActivity = (AbstractAsynchronousDependencyActivity) activity; // if (dependencyType.equals(LOCAL_JARS)){ // Collect the files of all found local dependencies if (dependencyActivity.getConfiguration().has("localDependency")) { for (JsonNode jar : dependencyActivity.getConfiguration().get("localDependency")) { try { dependencies.add(new File(libDir, jar.textValue())); } catch (Exception ex) { logger.warn("Invalid URL for " + jar, ex); continue; } } } // } else if (dependencyType.equals(ARTIFACTS) && this.getClass().getClassLoader() instanceof LocalArtifactClassLoader){ // LocalArtifactClassLoader cl = (LocalArtifactClassLoader) this.getClass().getClassLoader(); // this class is always loaded with LocalArtifactClassLoader // LocalRepository rep = (LocalRepository) cl.getRepository(); // for (BasicArtifact art : ((DependencyActivityConfigurationBean) activity // .getConfiguration()) // .getArtifactDependencies()){ // dependencies.add(rep.jarFile(art)); // } // } } } } // Collect the URLs of all found dependencies for (File file : dependencies) { try { dependenciesURLs.add(file.toURI().toURL()); } catch (Exception ex) { logger.warn("Invalid URL for " + file.getAbsolutePath(), ex); continue; } } return dependenciesURLs; }
From source file:com.unboundid.scim2.common.utils.FilterEvaluator.java
/** * Evaluate a substring match filter./*from ww w .j ava2s . c o m*/ * * @param filter The filter to operate on. * @param object The object to evaluate. * @return The return value from the operation. * @throws ScimException If an exception occurs during the operation. */ private boolean substringMatch(final Filter filter, final JsonNode object) throws ScimException { Iterable<JsonNode> nodes = getCandidateNodes(filter.getAttributePath(), object); for (JsonNode node : nodes) { if (node.isTextual() && filter.getComparisonValue().isTextual()) { AttributeDefinition attributeDefinition = getAttributeDefinition(filter.getAttributePath()); String nodeValue = node.textValue(); String comparisonValue = filter.getComparisonValue().textValue(); if (attributeDefinition == null || !attributeDefinition.isCaseExact()) { nodeValue = StaticUtils.toLowerCase(nodeValue); comparisonValue = StaticUtils.toLowerCase(comparisonValue); } switch (filter.getFilterType()) { case CONTAINS: if (nodeValue.contains(comparisonValue)) { return true; } break; case STARTS_WITH: if (nodeValue.startsWith(comparisonValue)) { return true; } break; case ENDS_WITH: if (nodeValue.endsWith(comparisonValue)) { return true; } break; } } else if (node.equals(filter.getComparisonValue())) { return true; } } return false; }
From source file:com.sitewhere.wso2.identity.scim.Wso2ScimAssetModule.java
/** * Parse the JSON branch that holds a SCIM resource. * /*from w ww .j a v a2 s . c o m*/ * @param resource * @return */ protected PersonAsset parse(JsonNode resource) throws SiteWhereException { PersonAsset asset = new PersonAsset(); JsonNode id = resource.get(IScimFields.ID); if (id != null) { asset.getProperties().put(IWso2ScimFields.PROP_ASSET_ID, id.textValue()); } JsonNode username = resource.get(IScimFields.USERNAME); if (username != null) { asset.getProperties().put(IWso2ScimFields.PROP_USERNAME, username.textValue()); asset.setUserName(username.textValue()); asset.setId(username.textValue()); } JsonNode profileUrl = resource.get(IScimFields.PROFILE_URL); if (profileUrl != null) { asset.getProperties().put(IWso2ScimFields.PROP_PROFILE_URL, profileUrl.textValue()); asset.setImageUrl(profileUrl.textValue()); } else { asset.getProperties().put(IWso2ScimFields.PROP_PROFILE_URL, NO_PHOTO_URL); asset.setImageUrl(NO_PHOTO_URL); } parseName(resource, asset); parseEmail(resource, asset); parseRoles(resource, asset); return asset; }
From source file:com.collaborne.jsonschema.generator.pojo.PojoClassGenerator.java
@Override public void generateType(PojoCodeGenerationContext context, SchemaTree schema, JavaWriter writer) throws IOException, CodeGenerationException { Mapping mapping = context.getMapping(); // Process the properties into PropertyGenerators List<PojoPropertyGenerator> propertyGenerators = new ArrayList<>(); visitProperties(schema, new PropertyVisitor<CodeGenerationException>() { @Override/* w w w . j a va 2s . co m*/ public void visitProperty(String propertyName, URI type, SchemaTree schema) throws CodeGenerationException { String defaultValue; JsonNode defaultValueNode = schema.getNode().path("default"); if (defaultValueNode.isMissingNode() || defaultValueNode.isNull()) { defaultValue = null; } else if (defaultValueNode.isTextual()) { defaultValue = '"' + defaultValueNode.textValue() + '"'; } else { defaultValue = defaultValueNode.asText(); } PojoPropertyGenerator propertyGenerator = context.createPropertyGenerator(type, propertyName, defaultValue); propertyGenerators.add(propertyGenerator); } @Override public void visitProperty(String propertyName, URI type) throws CodeGenerationException { propertyGenerators.add(context.createPropertyGenerator(type, propertyName, null)); } }); for (PojoPropertyGenerator propertyGenerator : propertyGenerators) { propertyGenerator.generateImports(writer); } // check whether we need to work with additionalProperties: // - schema can say "yes", or "yes-with-this-type" // - mapping can say "yes", or "ignore" // Ultimately if we have to handle them we let the generated class extend AbstractMap<String, TYPE>, // where TYPE is either the one from the schema, or Object (if the schema didn't specify anything. // XXX: "Object" should probably be "whatever our factory/reader would produce" // XXX: Instead an AbstractMap, should we have a standard class in our support library? ClassName additionalPropertiesValueClassName = null; ClassName extendedClass = mapping.getExtends(); JsonNode additionalPropertiesNode = schema.getNode().path("additionalProperties"); if (!additionalPropertiesNode.isMissingNode() && !additionalPropertiesNode.isNull() && !mapping.isIgnoreAdditionalProperties()) { if (additionalPropertiesNode.isBoolean()) { if (additionalPropertiesNode.booleanValue()) { additionalPropertiesValueClassName = ClassName.create(Object.class); } } else { assert additionalPropertiesNode.isContainerNode(); AtomicReference<ClassName> ref = new AtomicReference<>(); SchemaTree additionalPropertiesSchema = schema.append(JsonPointer.of("additionalProperties")); URI additionalPropertiesUri = additionalPropertiesSchema.getLoadingRef().toURI() .resolve("#" + additionalPropertiesSchema.getPointer().toString()); visitSchema(additionalPropertiesUri, additionalPropertiesSchema, new SchemaVisitor<CodeGenerationException>() { @Override public void visitSchema(URI type, SchemaTree schema) throws CodeGenerationException { visitSchema(type); } @Override public void visitSchema(URI type) throws CodeGenerationException { ref.set(context.getGenerator().generate(type)); } }); additionalPropertiesValueClassName = ref.get(); } if (additionalPropertiesValueClassName != null) { if (extendedClass != null) { // FIXME: handle this by using an interface instead throw new CodeGenerationException(context.getType(), "additionalProperties is incompatible with 'extends'"); } extendedClass = ClassName.create(AbstractMap.class, ClassName.create(String.class), additionalPropertiesValueClassName); writer.writeImport(extendedClass); ClassName mapClass = ClassName.create(Map.class, ClassName.create(String.class), additionalPropertiesValueClassName); writer.writeImport(mapClass); ClassName hashMapClass = ClassName.create(HashMap.class, ClassName.create(String.class), additionalPropertiesValueClassName); writer.writeImport(hashMapClass); ClassName mapEntryClass = ClassName.create(Map.Entry.class, ClassName.create(String.class), additionalPropertiesValueClassName); writer.writeImport(mapEntryClass); ClassName setMapEntryClass = ClassName.create(Set.class, mapEntryClass); writer.writeImport(setMapEntryClass); } } if (mapping.getImplements() != null) { for (ClassName implementedInterface : mapping.getImplements()) { writer.writeImport(implementedInterface); } } writeSchemaDocumentation(schema, writer); writer.writeClassStart(mapping.getGeneratedClassName(), extendedClass, mapping.getImplements(), Kind.CLASS, Visibility.PUBLIC, mapping.getModifiers()); try { // Write properties for (PojoPropertyGenerator propertyGenerator : propertyGenerators) { propertyGenerator.generateFields(writer); } if (additionalPropertiesValueClassName != null) { ClassName mapClass = ClassName.create(Map.class, ClassName.create(String.class), additionalPropertiesValueClassName); ClassName hashMapClass = ClassName.create(HashMap.class, ClassName.create(String.class), additionalPropertiesValueClassName); writer.writeField(Visibility.PRIVATE, mapClass, "additionalPropertiesMap", () -> { writer.write(" = new "); // XXX: If code generation would know about java 7/8, we could use diamond here writer.writeClassName(hashMapClass); writer.write("()"); }); } // Write accessors // TODO: style to create them: pairs, or ordered? // TODO: whether to generate setters in the first place, or just getters for (PojoPropertyGenerator propertyGenerator : propertyGenerators) { propertyGenerator.generateGetter(writer); propertyGenerator.generateSetter(writer); } if (additionalPropertiesValueClassName != null) { ClassName mapEntryClass = ClassName.create(Map.Entry.class, ClassName.create(String.class), additionalPropertiesValueClassName); ClassName setMapEntryClass = ClassName.create(Set.class, mapEntryClass); writer.writeAnnotation(ClassName.create(Override.class)); writer.writeMethodBodyStart(Visibility.PUBLIC, setMapEntryClass, "entrySet"); writer.writeCode("return additionalPropertiesMap.entrySet();"); writer.writeMethodBodyEnd(); } } finally { writer.writeClassEnd(); } }