Package com.fasterxml.jackson.databind.node

Examples of com.fasterxml.jackson.databind.node.ArrayNode


                PagingResult<T> result = new PagingResult<>();
                JsonNode node = mapper.readTree(response.getEntity().getContent());
                if (node.get("total_rows") != null) {
                    result.setTotalRows(node.get("total_rows").asInt());
                }
                ArrayNode rowsNode = (ArrayNode) node.get("rows");
                return rowsNode.size();
            }
        }, SC_OK, SC_NOT_FOUND);
    }
View Full Code Here


            responseJSON.set("processDefinition", pdrJSON);
        }

        // Highlighted activities
        if (processInstance != null) {
            ArrayNode activityArray = new ObjectMapper().createArrayNode();
            ArrayNode flowsArray = new ObjectMapper().createArrayNode();

            highLightedActivities = runtimeService
                    .getActiveActivityIds(processInstanceId);
            highLightedFlows = getHighLightedFlows();

            for (String activityName : highLightedActivities) {
                activityArray.add(activityName);
            }

            for (String flow : highLightedFlows) {
                flowsArray.add(flow);
            }

            responseJSON.set("highLightedActivities", activityArray);
            responseJSON.set("highLightedFlows", flowsArray);
        }

        // Pool shape, if process is participant in collaboration
        if (processDefinition.getParticipantProcess() != null) {
            ParticipantProcess pProc = processDefinition
                    .getParticipantProcess();

            ObjectNode participantProcessJSON = new ObjectMapper()
                    .createObjectNode();
            participantProcessJSON.put("id", pProc.getId());

            if (StringUtils.isNotEmpty(pProc.getName())) {
                participantProcessJSON.put("name", pProc.getName());
            } else {
                participantProcessJSON.put("name", "");
            }

            participantProcessJSON.put("x", pProc.getX());
            participantProcessJSON.put("y", pProc.getY());
            participantProcessJSON.put("width", pProc.getWidth());
            participantProcessJSON.put("height", pProc.getHeight());

            responseJSON.set("participantProcess", participantProcessJSON);
        }

        // Draw lanes
        if ((processDefinition.getLaneSets() != null)
                && (processDefinition.getLaneSets().size() > 0)) {
            ArrayNode laneSetArray = new ObjectMapper().createArrayNode();

            for (LaneSet laneSet : processDefinition.getLaneSets()) {
                ArrayNode laneArray = new ObjectMapper().createArrayNode();

                if ((laneSet.getLanes() != null)
                        && (laneSet.getLanes().size() > 0)) {
                    for (Lane lane : laneSet.getLanes()) {
                        ObjectNode laneJSON = new ObjectMapper()
                                .createObjectNode();
                        laneJSON.put("id", lane.getId());

                        if (StringUtils.isNotEmpty(lane.getName())) {
                            laneJSON.put("name", lane.getName());
                        } else {
                            laneJSON.put("name", "");
                        }

                        laneJSON.put("x", lane.getX());
                        laneJSON.put("y", lane.getY());
                        laneJSON.put("width", lane.getWidth());
                        laneJSON.put("height", lane.getHeight());

                        List<String> flowNodeIds = lane.getFlowNodeIds();
                        ArrayNode flowNodeIdsArray = new ObjectMapper()
                                .createArrayNode();

                        for (String flowNodeId : flowNodeIds) {
                            flowNodeIdsArray.add(flowNodeId);
                        }

                        laneJSON.set("flowNodeIds", flowNodeIdsArray);

                        laneArray.add(laneJSON);
                    }
                }

                ObjectNode laneSetJSON = new ObjectMapper().createObjectNode();
                laneSetJSON.put("id", laneSet.getId());

                if (StringUtils.isNotEmpty(laneSet.getName())) {
                    laneSetJSON.put("name", laneSet.getName());
                } else {
                    laneSetJSON.put("name", "");
                }

                laneSetJSON.set("lanes", laneArray);

                laneSetArray.add(laneSetJSON);
            }

            if (laneSetArray.size() > 0) {
                responseJSON.set("laneSets", laneSetArray);
            }
        }

        ArrayNode sequenceFlowArray = new ObjectMapper().createArrayNode();
        ArrayNode activityArray = new ObjectMapper().createArrayNode();

        // Activities and their sequence-flows
        for (ActivityImpl activity : processDefinition.getActivities()) {
            getActivity(activity, activityArray, sequenceFlowArray);
        }
View Full Code Here

                    && ((String) activity.getProperty("type")).toLowerCase()
                            .contains("gateway");

            List<Integer> waypoints = ((TransitionImpl) sequenceFlow)
                    .getWaypoints();
            ArrayNode xPointArray = new ObjectMapper().createArrayNode();
            ArrayNode yPointArray = new ObjectMapper().createArrayNode();

            for (int i = 0; i < waypoints.size(); i += 2) { // waypoints.size()
                                                            // minimally 4: x1, y1,
                                                            // x2, y2
                xPointArray.add(waypoints.get(i));
                yPointArray.add(waypoints.get(i + 1));
            }

            ObjectNode flowJSON = new ObjectMapper().createObjectNode();
            flowJSON.put("id", sequenceFlow.getId());
            flowJSON.put("name", flowName);
            flowJSON.put("flow", "(" + sequenceFlow.getSource().getId() + ")--"
                    + sequenceFlow.getId() + "-->("
                    + sequenceFlow.getDestination().getId() + ")");

            if (isConditional) {
                flowJSON.put("isConditional", isConditional);
            }

            if (isDefault) {
                flowJSON.put("isDefault", isDefault);
            }

            if (isHighLighted) {
                flowJSON.put("isHighLighted", isHighLighted);
            }

            flowJSON.set("xPointArray", xPointArray);
            flowJSON.set("yPointArray", yPointArray);

            sequenceFlowArray.add(flowJSON);
        }

        // Nested activities (boundary events)
        ArrayNode nestedActivityArray = new ObjectMapper().createArrayNode();

        for (ActivityImpl nestedActivity : activity.getActivities()) {
            nestedActivityArray.add(nestedActivity.getId());
        }

        Map<String, Object> properties = activity.getProperties();
        ObjectNode propertiesJSON = new ObjectMapper().createObjectNode();

        for (Map.Entry<String, Object> entry : properties.entrySet()) {
            String key = entry.getKey();
            Object prop = entry.getValue();

            if (prop instanceof String) {
                propertiesJSON.put(key, (String) properties.get(key));
            } else if (prop instanceof Integer) {
                propertiesJSON.put(key, (Integer) properties.get(key));
            } else if (prop instanceof Boolean) {
                propertiesJSON.put(key, (Boolean) properties.get(key));
            } else if ("initial".equals(key)) {
                ActivityImpl act = (ActivityImpl) properties.get(key);
                propertiesJSON.put(key, act.getId());
            } else if ("timerDeclarations".equals(key)) {
                ArrayList<TimerDeclarationImpl> timerDeclarations = (ArrayList<TimerDeclarationImpl>) properties
                        .get(key);
                ArrayNode timerDeclarationArray = new ObjectMapper()
                        .createArrayNode();

                if (timerDeclarations != null) {
                    for (TimerDeclarationImpl timerDeclaration : timerDeclarations) {
                        ObjectNode timerDeclarationJSON = new ObjectMapper()
                                .createObjectNode();

                        timerDeclarationJSON.put("isExclusive",
                                timerDeclaration.isExclusive());

                        if (timerDeclaration.getRepeat() != null) {
                            timerDeclarationJSON.put("repeat",
                                    timerDeclaration.getRepeat());
                        }

                        timerDeclarationJSON.put("retries",
                                String.valueOf(timerDeclaration.getRetries()));
                        timerDeclarationJSON.put("type",
                                timerDeclaration.getJobHandlerType());
                        timerDeclarationJSON.put("configuration",
                                timerDeclaration.getJobHandlerConfiguration());

                        timerDeclarationArray.add(timerDeclarationJSON);
                    }
                }

                if (timerDeclarationArray.size() > 0) {
                    propertiesJSON.set(key, timerDeclarationArray);
                }

                // TODO: implement getting description
            } else if ("eventDefinitions".equals(key)) {
                ArrayList<EventSubscriptionDeclaration> eventDefinitions = (ArrayList<EventSubscriptionDeclaration>) properties
                        .get(key);
                ArrayNode eventDefinitionsArray = new ObjectMapper()
                        .createArrayNode();

                if (eventDefinitions != null) {
                    for (EventSubscriptionDeclaration eventDefinition : eventDefinitions) {
                        ObjectNode eventDefinitionJSON = new ObjectMapper()
                                .createObjectNode();

                        if (eventDefinition.getActivityId() != null) {
                            eventDefinitionJSON.put("activityId",
                                    eventDefinition.getActivityId());
                        }

                        eventDefinitionJSON.put("eventName",
                                eventDefinition.getEventName());
                        eventDefinitionJSON.put("eventType",
                                eventDefinition.getEventType());
                        eventDefinitionJSON.put("isAsync",
                                eventDefinition.isAsync());
                        eventDefinitionJSON.put("isStartEvent",
                                eventDefinition.isStartEvent());
                        eventDefinitionsArray.add(eventDefinitionJSON);
                    }
                }

                if (eventDefinitionsArray.size() > 0) {
                    propertiesJSON.set(key, eventDefinitionsArray);
                }

                // TODO: implement it
            } else if ("errorEventDefinitions".equals(key)) {
                ArrayList<ErrorEventDefinition> errorEventDefinitions = (ArrayList<ErrorEventDefinition>) properties
                        .get(key);
                ArrayNode errorEventDefinitionsArray = new ObjectMapper()
                        .createArrayNode();

                if (errorEventDefinitions != null) {
                    for (ErrorEventDefinition errorEventDefinition : errorEventDefinitions) {
                        ObjectNode errorEventDefinitionJSON = new ObjectMapper()
                                .createObjectNode();

                        if (errorEventDefinition.getErrorCode() != null) {
                            errorEventDefinitionJSON.put("errorCode",
                                    errorEventDefinition.getErrorCode());
                        } else {
                            errorEventDefinitionJSON.putNull("errorCode");
                        }

                        errorEventDefinitionJSON.put("handlerActivityId",
                                errorEventDefinition.getHandlerActivityId());

                        errorEventDefinitionsArray
                                .add(errorEventDefinitionJSON);
                    }
                }

                if (errorEventDefinitionsArray.size() > 0) {
                    propertiesJSON.set(key, errorEventDefinitionsArray);
                }
            }
        }

        if ("callActivity".equals(properties.get("type"))) {
            CallActivityBehavior callActivityBehavior = null;

            if (activityBehavior instanceof CallActivityBehavior) {
                callActivityBehavior = (CallActivityBehavior) activityBehavior;
            }

            if (callActivityBehavior != null) {
                propertiesJSON.put("processDefinitonKey",
                        callActivityBehavior.getProcessDefinitonKey());

                // get processDefinitonId from execution or get last processDefinitonId
                // by key
                ArrayNode processInstanceArray = new ObjectMapper()
                        .createArrayNode();

                if (processInstance != null) {
                    List<Execution> executionList = runtimeService
                            .createExecutionQuery()
                            .processInstanceId(processInstanceId)
                            .activityId(activity.getId()).list();

                    if (executionList.size() > 0) {
                        for (Execution execution : executionList) {
                            ObjectNode processInstanceJSON = subProcessInstanceMap
                                    .get(execution.getId());
                            processInstanceArray.add(processInstanceJSON);
                        }
                    }
                }

                // If active activities nas no instance of this callActivity then add
                // last definition
                if (processInstanceArray.size() == 0) {
                    // Get last definition by key
                    ProcessDefinition lastProcessDefinition = repositoryService
                            .createProcessDefinitionQuery()
                            .processDefinitionKey(
                                    callActivityBehavior
                                            .getProcessDefinitonKey())
                            .latestVersion().singleResult();

                    // TODO: unuseful fields there are processDefinitionName,
                    // processDefinitionKey
                    ObjectNode processInstanceJSON = new ObjectMapper()
                            .createObjectNode();
                    processInstanceJSON.put("processDefinitionId",
                            lastProcessDefinition.getId());
                    processInstanceJSON.put("processDefinitionKey",
                            lastProcessDefinition.getKey());
                    processInstanceJSON.put("processDefinitionName",
                            lastProcessDefinition.getName());
                    processInstanceArray.add(processInstanceJSON);
                }

                if (processInstanceArray.size() > 0) {
                    propertiesJSON.set("processDefinitons",
                            processInstanceArray);
                }
            }
        }
View Full Code Here

        ObjectNode responseJSON = new ObjectMapper().createObjectNode();

        responseJSON.put("processInstanceId", processInstanceId);

        ArrayNode activitiesArray = new ObjectMapper().createArrayNode();
        ArrayNode flowsArray = new ObjectMapper().createArrayNode();

        try {
            processInstance = runtimeService.createProcessInstanceQuery()
                    .processInstanceId(processInstanceId).singleResult();
            processDefinition = (ProcessDefinitionEntity) repositoryService
                    .getDeployedProcessDefinition(processInstance
                            .getProcessDefinitionId());

            responseJSON.put("processDefinitionId",
                    processInstance.getProcessDefinitionId());

            highLightedActivities = runtimeService
                    .getActiveActivityIds(processInstanceId);

            List<String> highLightedFlows = getHighLightedFlows(
                    processDefinition, processInstanceId);

            for (String activityId : highLightedActivities) {
                activitiesArray.add(activityId);
            }

            for (String flow : highLightedFlows) {
                flowsArray.add(flow);
            }

            for (String activityId : highLightedActivities) {
                Execution execution = runtimeService
                        .createExecutionQuery()
View Full Code Here

        Assert.assertTrue(rootNode.has(GraphSONTokens.MODE));
        Assert.assertEquals("NORMAL", rootNode.get(GraphSONTokens.MODE).asText());

        Assert.assertTrue(rootNode.has(GraphSONTokens.VERTICES));

        ArrayNode vertices = (ArrayNode) rootNode.get(GraphSONTokens.VERTICES);
        Assert.assertEquals(6, vertices.size());

        Assert.assertTrue(rootNode.has(GraphSONTokens.EDGES));

        ArrayNode edges = (ArrayNode) rootNode.get(GraphSONTokens.EDGES);
        Assert.assertEquals(6, edges.size());
    }
View Full Code Here

        Assert.assertTrue(rootNode.has(GraphSONTokens.MODE));
        Assert.assertEquals("EXTENDED", rootNode.get(GraphSONTokens.MODE).asText());

        Assert.assertTrue(rootNode.has(GraphSONTokens.VERTICES));

        ArrayNode vertices = (ArrayNode) rootNode.get(GraphSONTokens.VERTICES);
        Assert.assertEquals(6, vertices.size());

        Assert.assertTrue(rootNode.has(GraphSONTokens.EDGES));

        ArrayNode edges = (ArrayNode) rootNode.get(GraphSONTokens.EDGES);
        Assert.assertEquals(6, edges.size());
    }
View Full Code Here

        Assert.assertTrue(rootNode.has(GraphSONTokens.MODE));
        Assert.assertEquals("COMPACT", rootNode.get(GraphSONTokens.MODE).asText());

        Assert.assertTrue(rootNode.has(GraphSONTokens.VERTICES));

        ArrayNode vertices = (ArrayNode) rootNode.get(GraphSONTokens.VERTICES);
        Assert.assertEquals(6, vertices.size());

        Assert.assertTrue(rootNode.has(GraphSONTokens.EDGES));

        ArrayNode edges = (ArrayNode) rootNode.get(GraphSONTokens.EDGES);
        Assert.assertEquals(6, edges.size());
    }
View Full Code Here

        }
        if( !inputNode.isArray() )
        {
            throw new ValueSerializationException( "Expected an array but got " + inputNode );
        }
        ArrayNode array = (ArrayNode) inputNode;
        for( JsonNode item : array )
        {
            T value = deserializer.map( item );
            collection.add( value );
        }
View Full Code Here

        }
        if( !inputNode.isArray() )
        {
            throw new ValueSerializationException( "Expected an array but got " + inputNode );
        }
        ArrayNode array = (ArrayNode) inputNode;
        for( JsonNode item : array )
        {
            if( !item.isObject() )
            {
                throw new ValueSerializationException( "Expected an object but got " + inputNode );
View Full Code Here

    public void matcherShouldPassWhenMatcherPasses() {
        assertThat(matcher.matches(array("foo")), is(true));
    }
   
    private ArrayNode array(String... items) {
        ArrayNode array = MAPPER.createArrayNode();
        for (String item : items) {
            array.add(item);
        }
        return array;
    }
View Full Code Here

TOP

Related Classes of com.fasterxml.jackson.databind.node.ArrayNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.