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 filterAllEdges(JsonNode objectNode, Map<String, JsonNode> edgeMap, Map<String, List<JsonNode>> sourceAndTargetMap, Map<String, JsonNode> shapeMap, Map<String, JsonNode> sourceRefMap) { if (objectNode.get(EDITOR_CHILD_SHAPES) != null) { for (JsonNode jsonChildNode : objectNode.get(EDITOR_CHILD_SHAPES)) { ObjectNode childNode = (ObjectNode) jsonChildNode; String stencilId = BpmnJsonConverterUtil.getStencilId(childNode); if (STENCIL_SUB_PROCESS.equals(stencilId)) { filterAllEdges(childNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap); } else if (STENCIL_SEQUENCE_FLOW.equals(stencilId) || STENCIL_ASSOCIATION.equals(stencilId)) { String childEdgeId = BpmnJsonConverterUtil.getElementId(childNode); JsonNode targetNode = childNode.get("target"); if ((targetNode != null) && (targetNode.isNull() == false)) { String targetRefId = targetNode.get(EDITOR_SHAPE_ID).asText(); List<JsonNode> sourceAndTargetList = new ArrayList<JsonNode>(); sourceAndTargetList.add(sourceRefMap.get(childNode.get(EDITOR_SHAPE_ID).asText())); sourceAndTargetList.add(shapeMap.get(targetRefId)); sourceAndTargetMap.put(childEdgeId, sourceAndTargetList); }/*from ww w . ja v a 2 s . co m*/ edgeMap.put(childEdgeId, childNode); } } } }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public RefModel refModel(ObjectNode node, String location, ParseResult result) { RefModel output = new RefModel(); if (node.getNodeType().equals(JsonNodeType.OBJECT)) { String refValue = ((TextNode) node.get("$ref")).textValue(); output.set$ref(refValue);/*from w ww .j a v a 2s . c o m*/ } else { result.invalidType(location, "$ref", "object", node); return null; } // extra keys Set<String> keys = getKeys(node); for (String key : keys) { if (!REF_MODEL_KEYS.contains(key)) { result.extra(location, key, node.get(key)); } } return output; }
From source file:org.apache.streams.lucene.LuceneSimpleTaggingProcessor.java
@Override public List<StreamsDatum> process(StreamsDatum entry) { LOGGER.debug("{} processing {}", STREAMS_ID, entry.getDocument().getClass()); List<StreamsDatum> result = Lists.newArrayList(); List<String> jsons = Lists.newLinkedList(); ObjectNode node; // first check for valid json if (this.metaDataKey == null) jsons.add(getJson(entry.getDocument())); else/*w w w. j av a2s . c om*/ getMetaDataJsons(entry, jsons); for (String json : jsons) { try { node = (ObjectNode) mapper.readTree(json); } catch (IOException e) { e.printStackTrace(); return result; } List<SimpleVerbatim> verbatimList = convertEntryToWorkUnit(json); Map<SimpleVerbatim, List<LanguageTag>> objectTags = taggingEngine.findMatches(verbatimList); Set<String> tagSet = Sets.newHashSet(); for (List<LanguageTag> fieldtags : objectTags.values()) { for (LanguageTag tag : fieldtags) { tagSet.add(tag.getTag()); } } ArrayNode tagArray = JsonNodeFactory.instance.arrayNode(); Set<String> tags = Sets.newHashSet(); for (String tag : tagSet) { if (tags.add(tag)) { tagArray.add(tag); } } // need utility methods for get / create specific node ObjectNode extensions = (ObjectNode) node.get("extensions"); if (extensions == null) { extensions = JsonNodeFactory.instance.objectNode(); node.put("extensions", extensions); } ObjectNode w2o = (ObjectNode) extensions.get("w2o"); if (w2o == null) { w2o = JsonNodeFactory.instance.objectNode(); extensions.put("w2o", w2o); } w2o.put("tags", tagArray); w2o.put("contentTags", tagArray); if (entry.getDocument() instanceof W2OActivity) { entry.setDocument(mapper.convertValue(node, W2OActivity.class)); } else if (entry.getDocument() instanceof Activity) { entry.setDocument(mapper.convertValue(node, Activity.class)); } else if (entry.getDocument() instanceof String) { try { entry.setDocument(mapper.writeValueAsString(node)); } catch (JsonProcessingException jpe) { LOGGER.error("Exception while converting ObjectNode to string. Outputing as ObjectNode. {}", jpe); entry.setDocument(node); } } else { entry.setDocument(node); } result.add(entry); } return result; }
From source file:com.almende.eve.agent.MeetingAgent.java
/** * Retrieve the busy intervals of a calendar agent * /*from ww w . j a v a2 s .com*/ * @param agent */ private void updateBusyInterval(@Name("agent") final String agent) { try { // create parameters with the boundaries of the interval to be // retrieved final ObjectNode params = JOM.createObjectNode(); final DateTime timeMin = DateTime.now(); final DateTime timeMax = timeMin.plusDays(LOOK_AHEAD_DAYS); params.put("timeMin", timeMin.toString()); params.put("timeMax", timeMax.toString()); // exclude the event managed by this agent from the busy intervals final String eventId = getAgentData(agent).eventId; if (eventId != null) { final ArrayNode excludeEventIds = JOM.createArrayNode(); excludeEventIds.add(eventId); params.put("excludeEventIds", excludeEventIds); } // get the busy intervals from the agent final ArrayNode array = send(URI.create(agent), "getBusy", params, ArrayNode.class); // convert from ArrayNode to List final List<Interval> busy = new ArrayList<Interval>(); for (int i = 0; i < array.size(); i++) { final ObjectNode obj = (ObjectNode) array.get(i); final String start = obj.has("start") ? obj.get("start").asText() : null; final String end = obj.has("end") ? obj.get("end").asText() : null; busy.add(new Interval(new DateTime(start), new DateTime(end))); } // store the interval in the state putAgentBusy(agent, busy); } catch (final JSONRPCException e) { addIssue(TYPE.warning, Issue.JSONRPCEXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } catch (final Exception e) { addIssue(TYPE.warning, Issue.EXCEPTION, e.getMessage()); LOG.log(Level.WARNING, "", e); } }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Model definition(ObjectNode node, String location, ParseResult result) { if (node == null) { result.missing(location, "empty schema"); }/*from w ww . j ava 2 s . com*/ if (node.get("$ref") != null) { return refModel(node, location, result); } if (node.get("allOf") != null) { return allOfModel(node, location, result); } Model model = null; String value = null; String type = getString("type", node, false, location, result); Model m = new ModelImpl(); if ("array".equals(type)) { ArrayModel am = new ArrayModel(); ObjectNode propertyNode = getObject("properties", node, false, location, result); Map<String, Property> properties = properties(propertyNode, location, result); am.setProperties(properties); ObjectNode itemsNode = getObject("items", node, false, location, result); Property items = property(itemsNode, location, result); if (items != null) { am.items(items); } model = am; } else { ModelImpl impl = new ModelImpl(); impl.setType(value); JsonNode ap = node.get("additionalProperties"); if (ap != null && ap.getNodeType().equals(JsonNodeType.OBJECT)) { impl.setAdditionalProperties(Json.mapper().convertValue(ap, Property.class)); } value = getString("default", node, false, location, result); impl.setDefaultValue(value); value = getString("format", node, false, location, result); impl.setFormat(value); value = getString("discriminator", node, false, location, result); impl.setDiscriminator(value); JsonNode xml = node.get("xml"); if (xml != null) { impl.setXml(Json.mapper().convertValue(xml, Xml.class)); } ObjectNode externalDocs = getObject("externalDocs", node, false, location, result); ExternalDocs docs = externalDocs(externalDocs, location, result); impl.setExternalDocs(docs); ObjectNode properties = getObject("properties", node, true, location, result); if (properties != null) { Set<String> propertyNames = getKeys(properties); for (String propertyName : propertyNames) { JsonNode propertyNode = properties.get(propertyName); if (propertyNode.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode on = (ObjectNode) propertyNode; Property property = property(on, location, result); impl.property(propertyName, property); } else { result.invalidType(location, "properties", "object", propertyNode); } } } // need to set properties first ArrayNode required = getArray("required", node, false, location, result); if (required != null) { List<String> requiredProperties = new ArrayList<String>(); for (JsonNode n : required) { if (n.getNodeType().equals(JsonNodeType.STRING)) { requiredProperties.add(((TextNode) n).textValue()); } else { result.invalidType(location, "required", "string", n); } } if (requiredProperties.size() > 0) { impl.setRequired(requiredProperties); } } // extra keys Set<String> keys = getKeys(node); for (String key : keys) { if (key.startsWith("x-")) { impl.setVendorExtension(key, extension(node.get(key))); } else if (!SCHEMA_KEYS.contains(key)) { result.extra(location, key, node.get(key)); } } if ("{ }".equals(Json.pretty(impl))) return null; model = impl; } JsonNode exampleNode = node.get("example"); if (exampleNode != null) { // we support text or object nodes if (exampleNode.getNodeType().equals(JsonNodeType.OBJECT)) { ObjectNode on = getObject("example", node, false, location, result); if (on != null) { model.setExample(on); } } else { model.setExample(exampleNode.asText()); } } if (model != null) { value = getString("description", node, false, location, result); model.setDescription(value); value = getString("title", node, false, location, result); model.setTitle(value); } return model; }
From source file:de.jlo.talendcomp.json.JsonDocument.java
public List<JsonNode> getAttributeNodes(ObjectNode objectNode) { List<JsonNode> listASttributes = new ArrayList<JsonNode>(); Iterator<String> it = objectNode.fieldNames(); while (it.hasNext()) { ObjectNode node = objectMapper.createObjectNode(); String attrName = it.next(); node.set(attrName, objectNode.get(attrName)); listASttributes.add(node);//from w w w.j a v a 2s .c om } return listASttributes; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Map<String, Path> paths(ObjectNode obj, String location, ParseResult result) { Map<String, Path> output = new LinkedHashMap<>(); if (obj == null) { return null; }//from w w w. j a va2s. co m Set<String> pathKeys = getKeys(obj); for (String pathName : pathKeys) { JsonNode pathValue = obj.get(pathName); if (!pathValue.getNodeType().equals(JsonNodeType.OBJECT)) { result.invalidType(location, pathName, "object", pathValue); } else { ObjectNode path = (ObjectNode) pathValue; Path pathObj = path(path, location + ".'" + pathName + "'", result); output.put(pathName, pathObj); } } return output; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Map<String, Model> definitions(ObjectNode node, String location, ParseResult result) { if (node == null) return null; Set<String> schemas = getKeys(node); Map<String, Model> output = new LinkedHashMap<String, Model>(); for (String schemaName : schemas) { JsonNode schema = node.get(schemaName); if (schema.getNodeType().equals(JsonNodeType.OBJECT)) { Model model = definition((ObjectNode) schema, location + "." + schemaName, result); if (model != null) { output.put(schemaName, model); }/* w ww. j av a2s . c o m*/ } else { result.invalidType(location, schemaName, "object", schema); } } return output; }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Parameter parameter(ObjectNode obj, String location, ParseResult result) { if (obj == null) { return null; }//from w w w . j a v a2s . c o m Parameter output = null; JsonNode ref = obj.get("$ref"); if (ref != null) { if (ref.getNodeType().equals(JsonNodeType.STRING)) { return refParameter((TextNode) ref, location, result); } else { result.invalidType(location, "$ref", "string", obj); return null; } } String l = null; JsonNode ln = obj.get("name"); if (ln != null) { l = ln.asText(); } else { l = "['unknown']"; } location += ".[" + l + "]"; String value = getString("in", obj, true, location, result); if (value != null) { String type = getString("type", obj, false, location, result); String format = getString("format", obj, false, location, result); AbstractSerializableParameter<?> sp = null; if ("query".equals(value)) { sp = new QueryParameter(); } else if ("header".equals(value)) { sp = new HeaderParameter(); } else if ("path".equals(value)) { sp = new PathParameter(); } else if ("formData".equals(value)) { sp = new FormParameter(); } if (sp != null) { // type is mandatory when sp != null getString("type", obj, true, location, result); Map<PropertyBuilder.PropertyId, Object> map = new HashMap<PropertyBuilder.PropertyId, Object>(); map.put(TYPE, type); map.put(FORMAT, format); String defaultValue = getString("default", obj, false, location, result); map.put(DEFAULT, defaultValue); sp.setDefault(defaultValue); Double dbl = getDouble("maximum", obj, false, location, result); if (dbl != null) { map.put(MAXIMUM, dbl); sp.setMaximum(dbl); } Boolean bl = getBoolean("exclusiveMaximum", obj, false, location, result); if (bl != null) { map.put(EXCLUSIVE_MAXIMUM, bl); sp.setExclusiveMaximum(bl); } dbl = getDouble("minimum", obj, false, location, result); if (dbl != null) { map.put(MINIMUM, dbl); sp.setMinimum(dbl); } bl = getBoolean("exclusiveMinimum", obj, false, location, result); if (bl != null) { map.put(EXCLUSIVE_MINIMUM, bl); sp.setExclusiveMinimum(bl); } map.put(MAX_LENGTH, getInteger("maxLength", obj, false, location, result)); map.put(MIN_LENGTH, getInteger("minLength", obj, false, location, result)); String pat = getString("pattern", obj, false, location, result); map.put(PATTERN, pat); sp.setPattern(pat); Integer iv = getInteger("maxItems", obj, false, location, result); map.put(MAX_ITEMS, iv); sp.setMaxItems(iv); iv = getInteger("minItems", obj, false, location, result); map.put(MIN_ITEMS, iv); sp.setMinItems(iv); map.put(UNIQUE_ITEMS, getBoolean("uniqueItems", obj, false, location, result)); ArrayNode an = getArray("enum", obj, false, location, result); if (an != null) { List<String> _enum = new ArrayList<String>(); for (JsonNode n : an) { _enum.add(n.textValue()); } sp.setEnum(_enum); map.put(ENUM, _enum); } Property prop = PropertyBuilder.build(type, format, map); if (prop != null) { sp.setProperty(prop); ObjectNode items = getObject("items", obj, false, location, result); if (items != null) { Property inner = schema(null, items, location, result); sp.setItems(inner); } } Set<String> keys = getKeys(obj); for (String key : keys) { if (key.startsWith("x-")) { sp.setVendorExtension(key, extension(obj.get(key))); } else if (!PARAMETER_KEYS.contains(key)) { result.extra(location, key, obj.get(key)); } } String collectionFormat = getString("collectionFormat", obj, false, location, result); sp.setCollectionFormat(collectionFormat); output = sp; } else if ("body".equals(value)) { output = Json.mapper().convertValue(obj, Parameter.class); } if (output != null) { value = getString("name", obj, true, location, result); output.setName(value); value = getString("description", obj, false, location, result); output.setDescription(value); Boolean required = getBoolean("required", obj, false, location, result); if (required != null) { output.setRequired(required); } } } return output; }
From source file:com.irccloud.android.fragment.UsersListFragment.java
private void refresh(ArrayList<UsersDataSource.User> users) { if (users == null) { if (adapter != null) { adapter.data.clear();/*w w w .ja v a 2 s .c o m*/ adapter.notifyDataSetInvalidated(); } return; } ArrayList<UserListAdapter.UserListEntry> entries = new ArrayList<UserListAdapter.UserListEntry>(); ArrayList<UsersDataSource.User> opers = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> owners = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> admins = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> ops = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> halfops = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> voiced = new ArrayList<UsersDataSource.User>(); ArrayList<UsersDataSource.User> members = new ArrayList<UsersDataSource.User>(); boolean showSymbol = false; try { if (conn != null && conn.getUserInfo() != null && conn.getUserInfo().prefs != null) showSymbol = conn.getUserInfo().prefs.getBoolean("mode-showsymbol"); } catch (JSONException e) { } ObjectNode PREFIX = null; ServersDataSource.Server s = ServersDataSource.getInstance().getServer(cid); if (s != null) PREFIX = s.PREFIX; if (PREFIX == null) { PREFIX = new ObjectMapper().createObjectNode(); PREFIX.put(s != null ? s.MODE_OPER : "Y", "!"); PREFIX.put(s != null ? s.MODE_OWNER : "q", "~"); PREFIX.put(s != null ? s.MODE_ADMIN : "a", "&"); PREFIX.put(s != null ? s.MODE_OP : "o", "@"); PREFIX.put(s != null ? s.MODE_HALFOP : "h", "%"); PREFIX.put(s != null ? s.MODE_VOICED : "v", "+"); } if (adapter == null) { adapter = new UserListAdapter(UsersListFragment.this); } for (int i = 0; i < users.size(); i++) { UsersDataSource.User user = users.get(i); if (user.mode.contains(s != null ? s.MODE_OPER : "Y") && PREFIX.has(s != null ? s.MODE_OPER : "Y")) { opers.add(user); } else if (user.mode.contains(s != null ? s.MODE_OWNER : "q") && PREFIX.has(s != null ? s.MODE_OWNER : "q")) { owners.add(user); } else if (user.mode.contains(s != null ? s.MODE_ADMIN : "a") && PREFIX.has(s != null ? s.MODE_ADMIN : "a")) { admins.add(user); } else if (user.mode.contains(s != null ? s.MODE_OP : "o") && PREFIX.has(s != null ? s.MODE_OP : "o")) { ops.add(user); } else if (user.mode.contains(s != null ? s.MODE_HALFOP : "h") && PREFIX.has(s != null ? s.MODE_HALFOP : "h")) { halfops.add(user); } else if (user.mode.contains(s != null ? s.MODE_VOICED : "v") && PREFIX.has(s != null ? s.MODE_VOICED : "v")) { voiced.add(user); } else { members.add(user); } } if (opers.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_OPER : "Y")) addUsersFromList(entries, opers, "OPER", PREFIX.get(s != null ? s.MODE_OPER : "Y").asText() + " ", R.color.heading_oper, R.drawable.row_opers_bg, R.drawable.oper_bg); else addUsersFromList(entries, opers, "OPER", "", R.color.heading_oper, R.drawable.row_opers_bg, R.drawable.oper_bg); } else { addUsersFromList(entries, opers, "OPER", " ", R.color.heading_oper, R.drawable.row_opers_bg, R.drawable.oper_bg); } } if (owners.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_OWNER : "q")) addUsersFromList(entries, owners, "OWNER", PREFIX.get(s != null ? s.MODE_OWNER : "q").asText() + " ", R.color.heading_owner, R.drawable.row_owners_bg, R.drawable.owner_bg); else addUsersFromList(entries, owners, "OWNER", "", R.color.heading_owner, R.drawable.row_owners_bg, R.drawable.owner_bg); } else { addUsersFromList(entries, owners, "OWNER", " ", R.color.heading_owner, R.drawable.row_owners_bg, R.drawable.owner_bg); } } if (admins.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_ADMIN : "a")) addUsersFromList(entries, admins, "ADMINS", PREFIX.get(s != null ? s.MODE_ADMIN : "a").asText() + " ", R.color.heading_admin, R.drawable.row_admins_bg, R.drawable.admin_bg); else addUsersFromList(entries, admins, "ADMINS", "", R.color.heading_admin, R.drawable.row_admins_bg, R.drawable.admin_bg); } else { addUsersFromList(entries, admins, "ADMINS", " ", R.color.heading_admin, R.drawable.row_admins_bg, R.drawable.admin_bg); } } if (ops.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_OP : "o")) addUsersFromList(entries, ops, "OPS", PREFIX.get(s != null ? s.MODE_OP : "o").asText() + " ", R.color.heading_operators, R.drawable.row_operator_bg, R.drawable.operator_bg); else addUsersFromList(entries, ops, "OPS", "", R.color.heading_operators, R.drawable.row_operator_bg, R.drawable.operator_bg); } else { addUsersFromList(entries, ops, "OPS", " ", R.color.heading_operators, R.drawable.row_operator_bg, R.drawable.operator_bg); } } if (halfops.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_HALFOP : "h")) addUsersFromList(entries, halfops, "HALF OPS", PREFIX.get(s != null ? s.MODE_HALFOP : "h").asText() + " ", R.color.heading_halfop, R.drawable.row_halfops_bg, R.drawable.halfop_bg); else addUsersFromList(entries, halfops, "HALF OPS", "", R.color.heading_halfop, R.drawable.row_halfops_bg, R.drawable.halfop_bg); } else { addUsersFromList(entries, halfops, "HALF OPS", " ", R.color.heading_halfop, R.drawable.row_halfops_bg, R.drawable.halfop_bg); } } if (voiced.size() > 0) { if (showSymbol) { if (PREFIX.has(s != null ? s.MODE_VOICED : "v")) addUsersFromList(entries, voiced, "VOICED", PREFIX.get(s != null ? s.MODE_VOICED : "v").asText() + " ", R.color.heading_voiced, R.drawable.row_voiced_bg, R.drawable.voiced_bg); else addUsersFromList(entries, voiced, "VOICED", "", R.color.heading_voiced, R.drawable.row_voiced_bg, R.drawable.voiced_bg); } else { addUsersFromList(entries, voiced, "VOICED", " ", R.color.heading_voiced, R.drawable.row_voiced_bg, R.drawable.voiced_bg); } } if (members.size() > 0) { addUsersFromList(entries, members, "MEMBERS", "", R.color.heading_members, R.drawable.row_members_bg, R.drawable.background_blue); } adapter.setItems(entries); if (getListAdapter() == null && entries.size() > 0) setListAdapter(adapter); else adapter.notifyDataSetChanged(); }