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

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

Introduction

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

Prototype

public int size() 

Source Link

Usage

From source file:fr.gouv.vitam.mdbes.QueryBench.java

private TypeField getField(JsonNode bfield, int level) throws InvalidParseOperationException {
    String name = bfield.get(FIELD_ARGS.__name.name()).asText();
    String type = bfield.get(FIELD_ARGS.__type.name()).asText();
    String sftype = bfield.path(FIELD_ARGS.__ftype.name()).asText();
    if (type == null || type.isEmpty()) {
        LOGGER.warn("Unknown empty type: {}", type);
        throw new InvalidParseOperationException("Unknown empty type: " + type);
    }// www  .  ja  va 2s .  c o m
    TypeField field = new TypeField();
    FIELD fieldType = null;
    try {
        fieldType = FIELD.valueOf(type);
    } catch (IllegalArgumentException e) {
        LOGGER.warn("Unknown type: {}", bfield);
        throw new InvalidParseOperationException("Unknown type: " + bfield);
    }
    field.name = name;
    field.type = fieldType;
    FIELD_TYPE ftype = FIELD_TYPE.chaine;
    if (sftype != null && !sftype.isEmpty()) {
        try {
            ftype = FIELD_TYPE.valueOf(sftype);
        } catch (final IllegalArgumentException e) {
            LOGGER.error("Unknown ftype: " + bfield);
            ftype = FIELD_TYPE.chaine;
        }
    }
    field.ftype = ftype;
    switch (fieldType) {
    case setdistrib: {
        // no field but CPT level
        distribCpt = context.cpts.get(CPTLEVEL + level);
        return null;
    }
    case save: {
        break;
    }
    case liste:
    case listeorder: {
        ArrayNode liste = (ArrayNode) bfield.get("__" + fieldType.name());
        if (liste == null || !liste.has(0)) {
            LOGGER.warn("Empty List: {}", liste);
            throw new InvalidParseOperationException("Empty List: " + bfield);
        }
        field.listeValeurs = new String[liste.size()];
        for (int i = 0; i < liste.size(); i++) {
            field.listeValeurs[i] = liste.get(i).asText();
        }
        break;
    }
    case serie: {
        JsonNode bson = bfield.get(FIELD_ARGS.__serie.name());
        if (bson == null) {
            LOGGER.warn("Empty serie: {}", bfield);
            throw new InvalidParseOperationException("Empty serie: " + bfield);
        }
        if (bson.has(FIELD_ARGS.__prefix.name())) {
            String prefix = bson.get(FIELD_ARGS.__prefix.name()).asText();
            if (prefix == null) {
                prefix = "";
            }
            field.prefix = prefix;
        }
        if (bson.has(FIELD_ARGS.__idcpt.name())) {
            String idcpt = bson.get(FIELD_ARGS.__idcpt.name()).asText();
            if (idcpt != null && !idcpt.isEmpty()) {
                field.idcpt = idcpt;
                context.cpts.put(idcpt, new AtomicLong(0));
            }
        }
        field.modulo = -1;
        if (bson.has(FIELD_ARGS.__modulo.name())) {
            int modulo = bson.get(FIELD_ARGS.__modulo.name()).asInt();
            if (modulo > 0) {
                field.modulo = modulo;
            }
        }
        break;
    }
    case interval: {
        Integer low = bfield.get(FIELD_ARGS.__low.name()).asInt();
        if (low == null) {
            LOGGER.warn("Empty interval: {}", bfield);
            throw new InvalidParseOperationException("Empty interval: " + bfield);
        }
        Integer high = bfield.get(FIELD_ARGS.__high.name()).asInt();
        if (high == null) {
            LOGGER.warn("Empty interval: {}", bfield);
            throw new InvalidParseOperationException("Empty interval: " + bfield);
        }
        field.low = low;
        field.high = high;
        break;
    }
    default:
        LOGGER.warn("Incorrect type: {}", bfield);
        throw new InvalidParseOperationException("Incorrect type: " + bfield);
    }
    if (bfield.has(FIELD_ARGS.__save.name())) {
        String savename = bfield.get(FIELD_ARGS.__save.name()).asText();
        if (savename != null && !savename.isEmpty()) {
            field.saveName = savename;
        }
    }
    if (bfield.has(FIELD_ARGS.__subprefix.name())) {
        ArrayNode liste = (ArrayNode) bfield.get(FIELD_ARGS.__subprefix.name());
        if (liste == null || !liste.has(0)) {
            LOGGER.warn("Empty SubPrefix List: {}", liste);
            throw new InvalidParseOperationException("Empty SubPrefix List: " + bfield);
        }
        field.subprefixes = new String[liste.size()];
        for (int i = 0; i < liste.size(); i++) {
            field.subprefixes[i] = liste.get(i).asText();
        }
    }
    return field;
}

From source file:org.activiti.kickstart.service.alfresco.AlfrescoKickstartServiceImpl.java

protected List<String> retrieveWorkflowInstanceIds(String workflowName) {
    String url = ALFRESCO_BASE_URL + "api/workflow-instances?state=active";
    JsonNode json = executeGet(url);/*from w  ww.j a v  a 2s  .c  o m*/
    ArrayNode data = (ArrayNode) json.get("data");

    ArrayList<String> workflowInstanceIds = new ArrayList<String>();
    for (int i = 0; i < data.size(); i++) {
        String title = data.get(i).get("title").asText();
        if (title.equalsIgnoreCase(workflowName)) {
            workflowInstanceIds.add(data.get(i).get("id").asText());
        }
    }

    return workflowInstanceIds;
}

From source file:fr.gouv.vitam.query.parser.EsQueryParser.java

/**
 * $flt : { $fields : [ name1, name2 ], $like : like_text }
 *
 * @param refCommand/*  w  w  w.  j  a v  a  2s  . c om*/
 * @param command
 * @param tr0
 * @param req
 * @throws InvalidParseOperationException
 */
@Override
protected final void analyzeXlt(final String refCommand, final JsonNode command, final TypeRequest tr0,
        final REQUEST req) throws InvalidParseOperationException {
    if (command == null) {
        throw new InvalidParseOperationException("Not correctly parsed: " + refCommand);
    }
    tr0.isOnlyES = true;
    LOGGER.debug("ES only: {}", refCommand);
    final ArrayNode fields = (ArrayNode) command.get(REQUESTARGS.fields.exactToken());
    final JsonNode like = command.get(REQUESTARGS.like.exactToken());
    if (fields == null || like == null) {
        throw new InvalidParseOperationException("Incorrect command: " + refCommand + " : " + command);
    }
    String[] names = new String[fields.size()];
    int i = 0;
    for (JsonNode name : fields) {
        names[i++] = name.toString();
    }
    switch (req) {
    case flt:
        tr0.query = QueryBuilders.fuzzyLikeThisQuery(names).likeText(like.toString());
        break;
    case mlt:
        tr0.query = QueryBuilders.moreLikeThisQuery(names).likeText(like.toString());
        break;
    default:
        throw new InvalidParseOperationException("Not correctly parsed: " + req);
    }
}

From source file:com.googlecode.jsonrpc4j.JsonRpcServer.java

/**
 * Handles the given {@link ArrayNode} and writes the
 * responses to the given {@link OutputStream}.
 *
 * @param node the {@link JsonNode}//  w  w w.  j a v  a 2 s  . co  m
 * @param ops the {@link OutputStream}
 * @throws IOException on error
 */
public void handleArray(ArrayNode node, OutputStream ops) throws IOException {
    if (LOGGER.isLoggable(Level.FINE)) {
        LOGGER.log(Level.FINE, "Handing " + node.size() + " requests");
    }

    // loop through each array element
    ops.write('[');
    for (int i = 0; i < node.size(); i++) {
        handleNode(node.get(i), ops);
        if (i != node.size() - 1)
            ops.write(',');
    }
    ops.write(']');
}

From source file:com.googlecode.jsonrpc4j.JsonRpcServer.java

/**
 * Finds the {@link Method} from the supplied {@link Set} that
 * best matches the rest of the arguments supplied and returns
 * it as a {@link MethodAndArgs} class.//w w  w  . j  a  v a2  s. c  o m
 *
 * @param methods the {@link Method}s
 * @param paramCount the number of expect parameters
 * @param paramNodes the parameters for matching types
 * @return the {@link MethodAndArgs}
 */
private MethodAndArgs findBestMethodUsingParamIndexes(Set<Method> methods, int paramCount,
        ArrayNode paramNodes) {

    // get param count
    int numParams = paramNodes != null && !paramNodes.isNull() ? paramNodes.size() : 0;

    // determine param count
    int bestParamNumDiff = Integer.MAX_VALUE;
    Set<Method> matchedMethods = new HashSet<Method>();

    // check every method
    for (Method method : methods) {

        // get parameter types
        Class<?>[] paramTypes = method.getParameterTypes();
        int paramNumDiff = paramTypes.length - paramCount;

        // we've already found a better match
        if (Math.abs(paramNumDiff) > Math.abs(bestParamNumDiff)) {
            continue;

            // we don't allow extra params
        } else if (!allowExtraParams && paramNumDiff < 0 || !allowLessParams && paramNumDiff > 0) {
            continue;

            // check the parameters
        } else {
            if (Math.abs(paramNumDiff) < Math.abs(bestParamNumDiff)) {
                matchedMethods.clear();
            }
            matchedMethods.add(method);
            bestParamNumDiff = paramNumDiff;
            continue;
        }
    }

    // bail early
    if (matchedMethods.isEmpty()) {
        return null;
    }

    // now narrow it down to the best method
    // based on argument types
    Method bestMethod = null;
    if (matchedMethods.size() == 1 || numParams == 0) {
        bestMethod = matchedMethods.iterator().next();

    } else {

        // check the matching methods for
        // matching parameter types
        int mostMatches = -1;
        for (Method method : matchedMethods) {
            List<Class<?>> parameterTypes = getParameterTypes(method);
            int numMatches = 0;
            for (int i = 0; i < parameterTypes.size() && i < numParams; i++) {
                if (isMatchingType(paramNodes.get(i), parameterTypes.get(i))) {
                    numMatches++;
                }
            }
            if (numMatches > mostMatches) {
                mostMatches = numMatches;
                bestMethod = method;
            }
        }
    }

    // create return
    MethodAndArgs ret = new MethodAndArgs();
    ret.method = bestMethod;

    // now fill arguments
    int numParameters = bestMethod.getParameterTypes().length;
    for (int i = 0; i < numParameters; i++) {
        if (i < numParams) {
            ret.arguments.add(paramNodes.get(i));
        } else {
            ret.arguments.add(NullNode.getInstance());
        }
    }

    // return the method
    return ret;
}

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  . j ava2  s  .  c om
                        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:org.activiti.editor.language.json.converter.BaseBpmnJsonConverter.java

protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
    ObjectNode formPropertiesNode = objectMapper.createObjectNode();
    ArrayNode itemsNode = objectMapper.createArrayNode();
    for (FormProperty property : formProperties) {
        ObjectNode propertyItemNode = objectMapper.createObjectNode();
        propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
        propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
        propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
        if (StringUtils.isNotEmpty(property.getExpression())) {
            propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
        } else {//  w  ww  .  ja  v  a 2s .  c  o  m
            propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
        }
        if (StringUtils.isNotEmpty(property.getVariable())) {
            propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
        } else {
            propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
        }

        propertyItemNode.put(PROPERTY_FORM_REQUIRED,
                property.isRequired() ? PROPERTY_VALUE_YES : PROPERTY_VALUE_NO);
        propertyItemNode.put(PROPERTY_FORM_READABLE,
                property.isReadable() ? PROPERTY_VALUE_YES : PROPERTY_VALUE_NO);
        propertyItemNode.put(PROPERTY_FORM_WRITEABLE,
                property.isWriteable() ? PROPERTY_VALUE_YES : PROPERTY_VALUE_NO);

        ObjectNode formValueNode = objectMapper.createObjectNode();
        ArrayNode formValueItemNode = objectMapper.createArrayNode();

        for (FormValue formValue : property.getFormValues()) {
            ObjectNode propertyFormValueNode = objectMapper.createObjectNode();
            propertyFormValueNode.put(PROPERTY_FORM_FORM_VALUE_ID, formValue.getId());
            propertyFormValueNode.put(PROPERTY_FORM_FORM_VALUE_NAME, formValue.getName());
            formValueItemNode.add(propertyFormValueNode);
        }
        formValueNode.put("totalCount", formValueItemNode.size());
        formValueNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, formValueItemNode);
        propertyItemNode.put(PROPERTY_FORM_FORM_VALUES, formValueNode.toString());

        itemsNode.add(propertyItemNode);
    }

    formPropertiesNode.put("totalCount", itemsNode.size());
    formPropertiesNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
    propertiesNode.put("formproperties", formPropertiesNode);
}

From source file:org.activiti.editor.language.json.converter.CallActivityJsonConverter.java

private void addJsonParameters(String propertyName, List<IOParameter> parameterList,
        ObjectNode propertiesNode) {//from  ww  w.ja va 2s  .  c o m
    ObjectNode parametersNode = objectMapper.createObjectNode();
    ArrayNode itemsNode = objectMapper.createArrayNode();
    for (IOParameter parameter : parameterList) {
        ObjectNode parameterItemNode = objectMapper.createObjectNode();
        if (StringUtils.isNotEmpty(parameter.getSource())) {
            parameterItemNode.put(PROPERTY_IOPARAMETER_SOURCE, parameter.getSource());
        } else {
            parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE);
        }
        if (StringUtils.isNotEmpty(parameter.getTarget())) {
            parameterItemNode.put(PROPERTY_IOPARAMETER_TARGET, parameter.getTarget());
        } else {
            parameterItemNode.putNull(PROPERTY_IOPARAMETER_TARGET);
        }
        if (StringUtils.isNotEmpty(parameter.getSourceExpression())) {
            parameterItemNode.put(PROPERTY_IOPARAMETER_SOURCE_EXPRESSION, parameter.getSourceExpression());
        } else {
            parameterItemNode.putNull(PROPERTY_IOPARAMETER_SOURCE_EXPRESSION);
        }

        itemsNode.add(parameterItemNode);
    }

    parametersNode.put("totalCount", itemsNode.size());
    parametersNode.put(EDITOR_PROPERTIES_GENERAL_ITEMS, itemsNode);
    propertiesNode.put(propertyName, parametersNode);
}

From source file:org.flowable.editor.language.json.converter.BpmnJsonConverter.java

public BpmnModel convertToBpmnModel(JsonNode modelNode, Map<String, String> formKeyMap,
        Map<String, String> decisionTableKeyMap) {

    BpmnModel bpmnModel = new BpmnModel();

    bpmnModel.setTargetNamespace("http://activiti.org/test");
    Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
    Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
    Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();

    readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
    filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
    readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);

    ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);

    if (shapesArrayNode == null || shapesArrayNode.size() == 0)
        return bpmnModel;

    boolean nonEmptyPoolFound = false;
    Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
    // first create the pool structure
    for (JsonNode shapeNode : shapesArrayNode) {
        String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
        if (STENCIL_POOL.equals(stencilId)) {
            Pool pool = new Pool();
            pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
            pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
            pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
            pool.setExecutable(// w w w. jav  a  2  s .c om
                    JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
            bpmnModel.getPools().add(pool);

            Process process = new Process();
            process.setId(pool.getProcessRef());
            process.setName(pool.getName());
            process.setExecutable(pool.isExecutable());
            bpmnModel.addProcess(process);

            ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
            for (JsonNode laneNode : laneArrayNode) {
                // should be a lane, but just check to be certain
                String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
                if (STENCIL_LANE.equals(laneStencilId)) {
                    nonEmptyPoolFound = true;
                    Lane lane = new Lane();
                    lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
                    lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
                    lane.setParentProcess(process);
                    process.getLanes().add(lane);

                    processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap,
                            formKeyMap, decisionTableKeyMap, bpmnModel);
                    if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
                        for (String elementRef : lane.getFlowReferences()) {
                            elementInLaneMap.put(elementRef, lane);
                        }
                    }
                }
            }
        }
    }

    // Signal Definitions exist on the root level
    JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
    signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode); // no idea why this needs to be done twice ..
    if (signalDefinitionNode != null) {
        if (signalDefinitionNode instanceof ArrayNode) {
            ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
            Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
            while (signalDefinitionIterator.hasNext()) {
                JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
                String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
                String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
                String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();

                if (StringUtils.isNotEmpty(signalId) && StringUtils.isNotEmpty(signalName)) {
                    Signal signal = new Signal();
                    signal.setId(signalId);
                    signal.setName(signalName);
                    signal.setScope((signalScope.toLowerCase().equals("processinstance"))
                            ? Signal.SCOPE_PROCESS_INSTANCE
                            : Signal.SCOPE_GLOBAL);
                    bpmnModel.addSignal(signal);
                }
            }
        }
    }

    if (nonEmptyPoolFound == false) {
        Process process = new Process();
        bpmnModel.getProcesses().add(process);
        process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
        process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
        String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE,
                modelNode);
        if (StringUtils.isNotEmpty(namespace)) {
            bpmnModel.setTargetNamespace(namespace);
        }
        process.setDocumentation(
                BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
        JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
        if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
            process.setExecutable(
                    JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
        }

        BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);

        BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
        JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
        if (eventListenersNode != null) {
            eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
            BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE),
                    process);
        }

        JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES)
                .get(PROPERTY_DATA_PROPERTIES);

        if (processDataPropertiesNode != null) {
            List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil
                    .convertJsonToDataProperties(processDataPropertiesNode, process);
            process.setDataObjects(dataObjects);
            process.getFlowElements().addAll(dataObjects);
        }

        processJsonElements(shapesArrayNode, modelNode, process, shapeMap, formKeyMap, decisionTableKeyMap,
                bpmnModel);

    } else {
        // sequence flows are on root level so need additional parsing for pools
        for (JsonNode shapeNode : shapesArrayNode) {
            if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))
                    || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {

                String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(
                        shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
                if (sourceRef != null) {
                    Lane lane = elementInLaneMap.get(sourceRef);
                    SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
                    if (lane != null) {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
                    } else {
                        flowConverter.convertToBpmnModel(shapeNode, modelNode, this,
                                bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
                    }
                }
            }
        }
    }

    // sequence flows are now all on root level
    Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
    for (Process process : bpmnModel.getProcesses()) {
        for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
            SubProcess subProcess = (SubProcess) flowElement;
            fillSubShapes(subShapesMap, subProcess);
        }

        if (subShapesMap.size() > 0) {
            List<String> removeSubFlowsList = new ArrayList<String>();
            for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
                SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
                if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
                    SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
                    if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
                        subProcess.addFlowElement(sequenceFlow);
                        removeSubFlowsList.add(sequenceFlow.getId());
                    }
                }
            }
            for (String flowId : removeSubFlowsList) {
                process.removeFlowElement(flowId);
            }
        }
    }

    Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
    List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
    // post handling of process elements
    for (Process process : bpmnModel.getProcesses()) {
        postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap,
                gatewayWithOrderList);
    }

    // sort the sequence flows
    for (Gateway gateway : gatewayWithOrderList) {
        List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
        if (CollectionUtils.isNotEmpty(orderList)) {
            for (ExtensionElement orderElement : orderList) {
                String flowValue = orderElement.getElementText();
                if (StringUtils.isNotEmpty(flowValue)) {
                    if (allFlowMap.containsKey(flowValue)) {
                        FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
                        flowWithContainer.getFlowContainer()
                                .removeFlowElement(flowWithContainer.getSequenceFlow().getId());
                        flowWithContainer.getFlowContainer()
                                .addFlowElement(flowWithContainer.getSequenceFlow());
                    }
                }
            }
        }
        gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
    }

    return bpmnModel;
}

From source file:net.sf.jasperreports.engine.json.expression.member.evaluation.AbstractMemberExpressionEvaluator.java

protected List<JRJsonNode> filterArrayNode(JRJsonNode parent, ArrayNode childArray, String deeperKey,
        boolean keepArrayContainment) {
    if (log.isDebugEnabled()) {
        log.debug("filtering array: " + childArray + "; deeperKey: " + deeperKey + "; keepArrayContainment: "
                + keepArrayContainment);
    }/*from   w w  w .  j  av  a 2 s  .  c o m*/

    List<JRJsonNode> result = new ArrayList<>();
    ArrayNode container = null;

    if (keepArrayContainment) {
        container = evaluationContext.getObjectMapper().createArrayNode();
    }

    for (JsonNode current : childArray) {
        if (deeperKey != null) {
            JsonNode deeperNode = current.get(deeperKey);

            if (deeperNode != null) {
                JRJsonNode currentParent = parent.createChild(current);
                JRJsonNode currentChild = currentParent.createChild(deeperNode);

                if (applyFilter(currentChild)) {
                    if (keepArrayContainment) {
                        container.add(deeperNode);
                    } else {
                        result.add(currentChild);
                    }
                }
            }
        } else {
            JRJsonNode currentChild = parent.createChild(current);

            if (applyFilter(currentChild)) {
                if (keepArrayContainment) {
                    container.add(current);
                } else {
                    result.add(currentChild);
                }
            }
        }
    }

    if (keepArrayContainment && container.size() > 0) {
        result.add(parent.createChild(container));
    }

    return result;
}