use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project atlasmap by atlasmap.
the class InstanceInspector method handleObjectNode.
private void handleObjectNode(JsonDocument jsonDocument, JsonNode jsonNode, JsonComplexType parent, int index) throws IOException {
LOG.trace("HANDLING AN OBJECT NODE " + jsonNode.fields().next().getKey() + " WITH PARENT ---> " + parent.getName() + " WITH INDEX OF " + index);
Iterator<Map.Entry<String, JsonNode>> fields = jsonNode.fields();
while (fields.hasNext()) {
Map.Entry<String, JsonNode> next = fields.next();
String key = next.getKey();
JsonNode node = next.getValue();
if (node.isValueNode()) {
handleValueEntry(jsonDocument, next, parent, index);
} else if (node.isObject()) {
LOG.trace("FOUND AN OBJECT NODE THAT IS A CONTAINER WITH KEY --> " + key + " WITH A PARENT INDEX OF " + index);
JsonComplexType container = getJsonComplexType(parent, key, index);
// rest index to zero when dealing with containers (we don't need an index on
// containers)
handleObjectNode(jsonDocument, next.getValue(), container, 0);
} else if (node.isArray() && node.get(0).isObject()) {
ArrayNode arrayNode = (ArrayNode) node;
// index for children
int innerIndex = 0;
JsonComplexType deeperChild = getJsonComplexType(parent, key, index);
if (parent.getCollectionType() == null) {
deeperChild.setCollectionType(CollectionType.LIST);
} else {
deeperChild.setCollectionType(CollectionType.ARRAY);
}
for (JsonNode deeperJsonNode : arrayNode) {
handleObjectNode(jsonDocument, deeperJsonNode, deeperChild, innerIndex);
innerIndex++;
}
}
}
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project carbon-apimgt by wso2.
the class Publish method execute.
@Override
public BValue execute(Context context) {
log.info("publishing event to DAS");
BConnector bConnector = (BConnector) getRefArgument(context, 0);
BJSON json = (BJSON) getRefArgument(context, 1);
String streamName = json.value().get(Constants.STREAM_NAME).asText();
String streamVersion = json.value().get(Constants.STREAM_VERSION).asText();
ArrayNode metaData = (ArrayNode) json.value().get(Constants.META_DATA);
ArrayNode correlationData = (ArrayNode) json.value().get(Constants.CORRELATION_DATA);
ArrayNode payloadData = (ArrayNode) json.value().get(Constants.PAYLOAD_DATA);
Object[] metaDataArr = new Object[metaData.size()];
JSONArray jsonMetaData = new JSONArray(metaData.toString());
for (int i = 0; i < jsonMetaData.length(); i++) {
metaDataArr[i] = jsonMetaData.get(i);
}
Object[] correlationDataArr = new Object[correlationData.size()];
JSONArray jsonCorrelationData = new JSONArray(correlationData.toString());
for (int i = 0; i < jsonCorrelationData.length(); i++) {
correlationDataArr[i] = jsonCorrelationData.get(i);
}
Object[] payloadDataArr = new Object[payloadData.size()];
JSONArray jsonPayloadData = new JSONArray(payloadData.toString());
for (int i = 0; i < jsonPayloadData.length(); i++) {
payloadDataArr[i] = jsonPayloadData.get(i);
}
BMap sharedMap = (BMap) bConnector.getRefField(1);
EventPublisher pub = (EventPublisher) sharedMap.get(Constants.PUBLISHER_INSTANCE);
Event event = new Event();
event.setStreamId(DataBridgeCommonsUtils.generateStreamId(streamName, streamVersion));
event.setMetaData(metaDataArr);
event.setCorrelationData(correlationDataArr);
event.setPayloadData(payloadDataArr);
pub.publish(event);
return null;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project plumdo-work by wengwh.
the class ProcessDefinitionAuthorizeResource method getAuthorizes.
@RequestMapping(value = "/process-definition/{processDefinitionId}/authorize", method = RequestMethod.GET, produces = "application/json", name = "流程定义授权查询")
public ArrayNode getAuthorizes(@PathVariable String processDefinitionId) {
ProcessDefinition processDefinition = getProcessDefinitionFromRequest(processDefinitionId);
List<IdentityLink> identityLinks = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
ArrayNode arrayNode = objectMapper.createArrayNode();
for (IdentityLink identityLink : identityLinks) {
ObjectNode objectNode = objectMapper.createObjectNode();
if (identityLink.getGroupId() != null) {
objectNode.put("type", ProcessDefinitionAuthorizeRequest.AUTHORIZE_GROUP);
objectNode.put("identityId", identityLink.getGroupId());
} else if (identityLink.getUserId() != null) {
objectNode.put("type", ProcessDefinitionAuthorizeRequest.AUTHORIZE_USER);
objectNode.put("identityId", identityLink.getUserId());
}
arrayNode.add(objectNode);
}
return arrayNode;
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project ORCID-Source by ORCID.
the class LoadGridData method execute.
public void execute() {
Instant start = Instant.now();
JsonNode rootNode = JsonUtils.read(fileToLoad);
ArrayNode institutes = (ArrayNode) rootNode.get("institutes");
institutes.forEach(institute -> {
String sourceId = institute.get("id").isNull() ? null : institute.get("id").asText();
// Case that should never happen
if (PojoUtil.isEmpty(sourceId)) {
LOGGER.error("Invalid institute with null id found {}", institute.toString());
}
String status = institute.get("status").isNull() ? null : institute.get("status").asText();
if ("active".equals(status)) {
String name = institute.get("name").isNull() ? null : institute.get("name").asText();
StringJoiner sj = new StringJoiner(",");
String orgType = null;
if (!institute.get("types").isNull()) {
((ArrayNode) institute.get("types")).forEach(x -> sj.add(x.textValue()));
orgType = sj.toString();
}
ArrayNode addresses = institute.get("addresses").isNull() ? null : (ArrayNode) institute.get("addresses");
String city = null;
String region = null;
Iso3166Country country = null;
if (addresses != null) {
for (JsonNode address : addresses) {
if (addresses.size() == 1 || (address.get("primary") != null && address.get("primary").asBoolean())) {
city = address.get("city").isNull() ? null : address.get("city").asText();
region = address.get("state").isNull() ? null : address.get("state").asText();
String countryCode = address.get("country_code").isNull() ? null : address.get("country_code").asText();
country = StringUtils.isBlank(countryCode) ? null : Iso3166Country.fromValue(countryCode);
}
}
}
ArrayNode urls = institute.get("links").isNull() ? null : (ArrayNode) institute.get("links");
// Use the first URL
String url = (urls != null && urls.size() > 0) ? urls.get(0).asText() : null;
// Creates or updates an institute
OrgDisambiguatedEntity entity = processInstitute(sourceId, name, country, city, region, url, orgType);
// Creates external identifiers
processExternalIdentifiers(entity, institute);
} else if ("redirected".equals(status)) {
String primaryId = institute.get("redirect").isNull() ? null : institute.get("redirect").asText();
deprecateOrg(sourceId, primaryId);
} else if ("obsolete".equals(status)) {
obsoleteOrg(sourceId);
} else {
LOGGER.error("Illegal status '" + status + "' for institute " + sourceId);
}
});
LOGGER.info("Updated orgs: {}", updatedOrgs);
LOGGER.info("New orgs: {}", addedDisambiguatedOrgs);
LOGGER.info("New external identifiers: {}", addedExternalIdentifiers);
LOGGER.info("Updated external identifiers: {}", updatedExternalIdentifiers);
LOGGER.info("Deprecated orgs: {}", deprecatedOrgs);
LOGGER.info("Obsoleted orgs: {}", obsoletedOrgs);
LOGGER.info("Time taken to process the data: {}", Duration.between(start, Instant.now()).toString());
}
use of org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ArrayNode in project ksql by confluentinc.
the class JsonExtractStringKudf method evaluate.
@Override
public Object evaluate(Object... args) {
if (args.length != 2) {
throw new KsqlFunctionException("getStringFromJson udf should have two input arguments:" + " JSON document and JSON path.");
}
ensureInitialized(args);
JsonNode currentNode = parseJsonDoc(args[0]);
for (String token : tokens) {
if (currentNode instanceof ArrayNode) {
try {
final int index = Integer.parseInt(token);
currentNode = currentNode.get(index);
} catch (NumberFormatException e) {
return null;
}
} else {
currentNode = currentNode.get(token);
}
if (currentNode == null) {
return null;
}
}
if (currentNode.isTextual()) {
return currentNode.asText();
} else {
return currentNode.toString();
}
}
Aggregations