Example usage for com.fasterxml.jackson.databind.node ArrayNode add

List of usage examples for com.fasterxml.jackson.databind.node ArrayNode add

Introduction

In this page you can find the example usage for com.fasterxml.jackson.databind.node ArrayNode add.

Prototype

public ArrayNode add(JsonNode paramJsonNode) 

Source Link

Usage

From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java

/**
 * Sets vRouters to the config./*from   ww  w .  j a va 2  s  . c  om*/
 *
 * @param vRouterMacs a set of vRouter MAC addresses
 * @return this {@link SegmentRoutingAppConfig}
 */
public SegmentRoutingAppConfig setVRouterMacs(Set<MacAddress> vRouterMacs) {
    if (vRouterMacs == null) {
        object.remove(VROUTER_MACS);
    } else {
        ArrayNode arrayNode = mapper.createArrayNode();

        vRouterMacs.forEach(mac -> {
            arrayNode.add(mac.toString());
        });

        object.set(VROUTER_MACS, arrayNode);
    }
    return this;
}

From source file:org.onosproject.segmentrouting.config.SegmentRoutingDeviceConfig.java

/**
 * Sets the adjacency SIDs of the router.
 *
 * @param adjacencySids adjacency SIDs of the router.
 * @return the config of the router.//from   w  w  w . j av  a 2 s.  co  m
 */
public SegmentRoutingDeviceConfig setAdjacencySids(Map<Integer, Set<Integer>> adjacencySids) {
    if (adjacencySids == null) {
        object.remove(ADJSIDS);
    } else {
        ArrayNode adjacencySidsNode = mapper.createArrayNode();

        adjacencySids.forEach((sid, ports) -> {
            ObjectNode adjacencySidNode = mapper.createObjectNode();

            adjacencySidNode.put(ADJSID, sid);

            ArrayNode portsNode = mapper.createArrayNode();
            ports.forEach(port -> {
                portsNode.add(port.toString());
            });
            adjacencySidNode.set(PORTS, portsNode);

            adjacencySidsNode.add(adjacencySidNode);
        });

        object.set(ADJSIDS, adjacencySidsNode);
    }

    return this;
}

From source file:com.almende.eve.transport.Router.java

@Override
public ObjectNode getParams() {
    final ArrayNode transportConfs = JOM.createArrayNode();
    for (final Transport transport : transports.values()) {
        transportConfs.add(transport.getParams());
    }//from ww  w.j a  v a 2  s. c o m
    final ObjectNode result = JOM.createObjectNode();
    result.set("transports", transportConfs);
    return result;
}

From source file:com.rusticisoftware.tincan.internal.StatementBase.java

@Override
public ObjectNode toJSONNode(TCAPIVersion version) {
    ObjectNode node = Mapper.getInstance().createObjectNode();
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime().withZoneUTC();

    node.put("actor", this.getActor().toJSONNode(version));
    node.put("verb", this.getVerb().toJSONNode(version));
    node.put("object", this.getObject().toJSONNode(version));

    if (this.result != null) {
        node.put("result", this.getResult().toJSONNode(version));
    }/*ww  w .java  2 s .  co  m*/
    if (this.context != null) {
        node.put("context", this.getContext().toJSONNode(version));
    }
    if (this.timestamp != null) {
        node.put("timestamp", fmt.print(this.getTimestamp()));
    }

    //Include 1.0.x specific fields if asking for 1.0.x version
    if (version.ordinal() <= TCAPIVersion.V100.ordinal()) {
        if (this.getAttachments() != null && this.getAttachments().size() > 0) {
            ArrayNode attachmentsNode = Mapper.getInstance().createArrayNode();
            for (Attachment attachment : this.getAttachments()) {
                attachmentsNode.add(attachment.toJSONNode(version));
            }
            node.put("attachments", attachmentsNode);
        }
    }

    return node;
}

From source file:org.apache.taverna.scufl2.translator.t2flow.defaultactivities.BeanshellActivityParser.java

@Override
public Configuration parseConfiguration(T2FlowParser t2FlowParser, ConfigBean configBean,
        ParserState parserState) throws ReaderException {
    BeanshellConfig beanshellConfig = unmarshallConfig(t2FlowParser, configBean, "xstream",
            BeanshellConfig.class);

    Configuration configuration = new Configuration();
    configuration.setParent(parserState.getCurrentProfile());

    ObjectNode json = (ObjectNode) configuration.getJson();
    configuration.setType(ACTIVITY_URI.resolve("#Config"));

    if (beanshellConfig.getLocalworkerName() != null) {
        URI localWorkerURI = LOCAL_WORKER_URI
                .resolve(uriTools.validFilename(beanshellConfig.getLocalworkerName()));
        /*/*  w  w w.  j a va 2  s . co m*/
         * FIXME: As we can't read the annotation chain yet, we can't tell
         * whether this local worker has been edited or not, and so can't
         * use #definedBy
         */
        json.put("derivedFrom", localWorkerURI.toString());
    }

    String script = beanshellConfig.getScript();
    json.put("script", script);

    ClassLoaderSharing classLoaderSharing = beanshellConfig.getClassLoaderSharing();
    if (classLoaderSharing == ClassLoaderSharing.SYSTEM)
        json.put("classLoaderSharing", "system");
    else {
        // default is "workflow" but don't need to be expressed
        //          json.put("classLoaderSharing", "workflow");
    }

    if (beanshellConfig.getLocalDependencies() != null) {
        ArrayNode dependencies = json.arrayNode();
        for (String localDep : beanshellConfig.getLocalDependencies().getString())
            dependencies.add(localDep);
        if (dependencies.size() > 0)
            json.put("localDependency", dependencies);
    }

    /*
     * Note: Maven Dependencies are not supported by Taverna 3 - only here
     * for informational purposes and potential t2flow->t2flow scenarios
     */
    if (beanshellConfig.getArtifactDependencies() != null) {
        ArrayNode dependencies = json.arrayNode();
        for (BasicArtifact mavenDep : beanshellConfig.getArtifactDependencies()
                .getNetSfTavernaRavenRepositoryBasicArtifact()) {
            ObjectNode mavenDependency = json.objectNode();
            dependencies.add(mavenDependency);
            mavenDependency.put("groupId", mavenDep.getGroupId());
            mavenDependency.put("artifactId", mavenDep.getArtifactId());
            mavenDependency.put("version", mavenDep.getVersion());
        }
        if (dependencies.size() > 0)
            json.put("mavenDependency", dependencies);
    }

    Activity activity = parserState.getCurrentActivity();
    activity.getInputPorts().clear();
    activity.getOutputPorts().clear();
    for (ActivityPortDefinitionBean portBean : beanshellConfig.getInputs()
            .getNetSfTavernaT2WorkflowmodelProcessorActivityConfigActivityInputPortDefinitionBean())
        parseAndAddInputPortDefinition(portBean, configuration, activity);
    for (ActivityPortDefinitionBean portBean : beanshellConfig.getOutputs()
            .getNetSfTavernaT2WorkflowmodelProcessorActivityConfigActivityOutputPortDefinitionBean())
        parseAndAddOutputPortDefinition(portBean, configuration, activity);
    return configuration;
}

From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java

/**
 * Sets names of ports to which SegmentRouting does not push host rules.
 *
 * @param suppressHost names of ports to which SegmentRouting does not push
 *                     host rules//from  w w w . ja va 2 s  .co  m
 * @return this {@link SegmentRoutingAppConfig}
 */
public SegmentRoutingAppConfig setSuppressHost(Set<ConnectPoint> suppressHost) {
    if (suppressHost == null) {
        object.remove(SUPPRESS_HOST);
    } else {
        ArrayNode arrayNode = mapper.createArrayNode();
        suppressHost.forEach(connectPoint -> {
            arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port());
        });
        object.set(SUPPRESS_HOST, arrayNode);
    }
    return this;
}

From source file:org.onosproject.segmentrouting.config.SegmentRoutingAppConfig.java

/**
 * Sets names of ports to which SegmentRouting does not push subnet rules.
 *
 * @param suppressSubnet names of ports to which SegmentRouting does not push
 *                     subnet rules/*from  w  ww.  java2 s  .  c  o  m*/
 * @return this {@link SegmentRoutingAppConfig}
 */
public SegmentRoutingAppConfig setSuppressSubnet(Set<ConnectPoint> suppressSubnet) {
    if (suppressSubnet == null) {
        object.remove(SUPPRESS_SUBNET);
    } else {
        ArrayNode arrayNode = mapper.createArrayNode();
        suppressSubnet.forEach(connectPoint -> {
            arrayNode.add(connectPoint.deviceId() + "/" + connectPoint.port());
        });
        object.set(SUPPRESS_SUBNET, arrayNode);
    }
    return this;
}

From source file:com.redhat.lightblue.eval.ArrayProjector.java

/**
 * Sorts the given array node using the sort criteria given in this ArrayProjector
 *
 * @param array The array node to sort//  w w  w  .ja va 2s.  c  om
 * @param factory Json node factory
 *
 * If there is a sort criteria defined in <code>this</code>, the array elements are
 * sorted using that.
 *
 * @return A new ArrayNode containing the sorted elements, or if
 * there is no sort defined, the <code>array</code> itself
 */
public ArrayNode sortArray(ArrayNode array, JsonNodeFactory factory) {
    if (sort == null) {
        return array;
    } else {
        List<SortableElement> list = new ArrayList<>(array.size());
        for (Iterator<JsonNode> itr = array.elements(); itr.hasNext();) {
            list.add(new SortableElement(itr.next(), sortFields));
        }
        Collections.sort(list);
        ArrayNode newNode = factory.arrayNode();
        for (SortableElement x : list)
            newNode.add(x.node);
        return newNode;
    }
}

From source file:org.activiti.designer.eclipse.navigator.cloudrepo.ProcessModelContentProvider.java

public Object[] getChildren(Object parentElement) {
    if (parentElement instanceof ActivitiCloudEditorRoot) {
        if (modelsNode == null) {
            try {
                initializeRootElements();
            } catch (final ActivitiCloudEditorException e) {
                String detailMessage = null;
                if (e.getExceptionNode() != null) {
                    detailMessage = e.getExceptionNode().get("message").asText();
                } else {
                    detailMessage = e.getMessage();
                }//from   ww  w . ja  va2s .  co  m
                // creating fake entry
                ObjectMapper objectMapper = new ObjectMapper();
                modelsNode = objectMapper.createObjectNode();
                ArrayNode modelArrayNode = objectMapper.createArrayNode();
                ((ObjectNode) modelsNode).put("data", modelArrayNode);
                ObjectNode errorNode = objectMapper.createObjectNode();
                modelArrayNode.add(errorNode);
                errorNode.put("name", "Process models could not be retrieved: " + detailMessage);
            }
        }

        if (modelsNode != null) {
            ArrayNode modelArrayNode = (ArrayNode) modelsNode.get("data");
            Object[] objectArray = new Object[modelArrayNode.size()];
            for (int i = 0; i < modelArrayNode.size(); i++) {
                JsonNode modelNode = modelArrayNode.get(i);
                objectArray[i] = modelNode;
            }
            return objectArray;
        } else {
            return EMPTY_ARRAY;
        }

    } else {
        return EMPTY_ARRAY;
    }
}

From source file:org.lendingclub.mercator.aws.Route53Scanner.java

ObjectNode toJson(GetHostedZoneResult hzResult) {
    HostedZone hz = hzResult.getHostedZone();

    ObjectNode n = mapper.createObjectNode();
    n.put("aws_account", getAccountId());
    n.put("aws_id", hz.getId());
    n.put("aws_name", hz.getName());
    n.put("aws_callerReference", hz.getCallerReference());
    n.put("aws_resourceRecordSetCount", hz.getResourceRecordSetCount());
    n.put("aws_comment", hz.getConfig().getComment());
    n.put("aws_privateZone", hz.getConfig().getPrivateZone());
    n.put("aws_arn", "arn:aws:route53:::hostedzone/" + hz.getId());

    ArrayNode an = mapper.createArrayNode();
    if (hzResult.getDelegationSet() != null) {
        hzResult.getDelegationSet().getNameServers().forEach(ns -> {
            an.add(ns);
        });/*  www .ja  va  2s  . c  o  m*/
    }
    n.set("aws_nameServers", an);
    return n;

}