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:org.wisdom.wamp.WampController.java

private void handleCallMessage(String id, Map.Entry<String, WampClient> entry, ArrayNode message) {
    if (entry == null) {
        LOGGER.error("Invalid CALL message, cannot identify the client {}", id);
        return;/*from  ww  w.  j a v a2 s. co  m*/
    }
    if (message.get(1) == null || message.get(1).asText() == null) {
        LOGGER.error("Invalid CALL message, callId not defined in the CALL message {}", message.toString());
        sendOnWebSocket(new RPCError("0", new IllegalArgumentException("callId not defined in CALL message"),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }
    String callId = message.get(1).asText();

    if (message.get(2) == null || message.get(2).asText() == null) {
        LOGGER.error("Invalid CALL message, procId not defined in the CALL message {}", message.toString());
        sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("procId not defined in CALL message"),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }
    String procId = message.get(2).asText();

    List<JsonNode> args = new ArrayList<>();
    for (int i = 3; i < message.size(); i++) {
        args.add(message.get(i));
    }

    // Get full url from the potential compacted url (prefixed)
    String url = entry.getValue().getUri(procId);
    // Extract the service object identifier
    int index = url.indexOf("#");
    if (index == -1) {
        LOGGER.error("Invalid CALL message, malformed procId in the CALL message {}", message.toString());
        sendOnWebSocket(
                new RPCError(callId, new IllegalArgumentException("Malformed procId " + procId), errorPrefix)
                        .toJson(json),
                entry.getValue());
        return;
    }
    String regId = url.substring(0, index);
    String method = url.substring(index + 1);

    ExportedService service;
    synchronized (this) {
        service = registry.get(regId);
    }
    if (service == null) {
        LOGGER.error("Invalid CALL message, cannot find service {} from message {}", regId, message.toString());
        sendOnWebSocket(
                new RPCError(callId, new IllegalArgumentException("Service object " + regId + " not found"),
                        errorPrefix).toJson(json),
                entry.getValue());
        return;
    }
    if (method.isEmpty()) {
        LOGGER.error("Invalid CALL message, broken method name in message {}", message.toString());
        sendOnWebSocket(new RPCError(callId, new IllegalArgumentException("Malformed method name in " + procId),
                errorPrefix).toJson(json), entry.getValue());
        return;
    }

    // invocation
    handleRPCInvocation(entry.getValue(), callId, service, method, args);

}

From source file:org.pf9.pangu.app.act.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray,
        ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows,
        Map<String, ObjectNode> subProcessInstanceMap) {

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

    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }//from   www  .  j  a  va  2s. c  o m
    }

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }

    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }

    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null
                && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default"))
                && ((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.put("xPointArray", xPointArray);
        flowJSON.put("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 (String key : properties.keySet()) {
        Object prop = properties.get(key);
        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());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());

                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.put(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.put(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.put(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.isEmpty()) {
                    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
                    && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery()
                        .processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion()
                        .singleResult();

                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    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.put("processDefinitons", processInstanceArray);
            }
        }
    }

    activityJSON.put("activityId", activity.getId());
    activityJSON.put("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.put("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);

    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());

    activityArray.add(activityJSON);

    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance,
                highLightedFlows, subProcessInstanceMap);
    }
}

From source file:org.activiti.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray,
        ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows,
        Map<String, ObjectNode> subProcessInstanceMap) {

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

    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }//from w w w  .j a va2  s. c  o m
    }

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }

    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }

    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null
                && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default"))
                && ((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.put("xPointArray", xPointArray);
        flowJSON.put("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 (String key : properties.keySet()) {
        Object prop = properties.get(key);
        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());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());

                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.put(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.put(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.put(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.isEmpty()) {
                    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.put("processDefinitons", processInstanceArray);
            }
        }
    }

    activityJSON.put("activityId", activity.getId());
    activityJSON.put("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.put("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);

    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());

    activityArray.add(activityJSON);

    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance,
                highLightedFlows, subProcessInstanceMap);
    }
}

From source file:com.almende.eve.agent.MeetingAgent.java

/**
 * Retrieve the busy intervals of a calendar agent
 * //w w w.  j  a  va2s .c  o  m
 * @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:com.xyz.activiti.bussiness.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray,
        ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows,
        Map<String, ObjectNode> subProcessInstanceMap) {

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

    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }/*from  w ww  .  ja v a2  s  .com*/
    }

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }

    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }

    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null
                && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default"))
                && ((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 (String key : properties.keySet()) {
        Object prop = properties.get(key);
        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());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());

                    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.isEmpty()) {
                    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
                    && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery()
                        .processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion()
                        .singleResult();

                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    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);
            }
        }
    }

    activityJSON.put("activityId", activity.getId());
    activityJSON.set("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.set("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);

    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());

    activityArray.add(activityJSON);

    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance,
                highLightedFlows, subProcessInstanceMap);
    }
}

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

private JRJsonNode goDeeperIntoObjectNode(JRJsonNode jrJsonNode, boolean keepMissingNode) {
    ObjectNode dataNode = (ObjectNode) jrJsonNode.getDataNode();
    ArrayNode container = getEvaluationContext().getObjectMapper().createArrayNode();

    // A complex expression allows an object key to treated as a REGEX
    if (expression.isComplex()) {
        Iterator<String> fieldNamesIterator = dataNode.fieldNames();
        while (fieldNamesIterator.hasNext()) {
            String fieldName = fieldNamesIterator.next();
            Matcher fieldNameMatcher = fieldNamePattern.matcher(fieldName);

            if (fieldNameMatcher.matches()) {
                JsonNode deeperNode = dataNode.path(fieldName);

                // if the deeper node is object/value => filter and add it
                if (deeperNode.isObject() || deeperNode.isValueNode() || deeperNode.isArray()) {

                    JRJsonNode child = jrJsonNode.createChild(deeperNode);
                    if (applyFilter(child)) {
                        container.add(deeperNode);
                    }/*  ww w  . j av a  2 s .c  om*/
                }
            }
        }
    } else {
        JsonNode deeperNode = dataNode.path(expression.getObjectKey());

        // if the deeper node is object/value => filter and add it
        if (deeperNode.isObject() || deeperNode.isValueNode() || deeperNode.isArray()) {

            JRJsonNode child = jrJsonNode.createChild(deeperNode);
            if (applyFilter(child)) {
                container.add(deeperNode);
            }
        }
    }

    if (container.size() > 1) {
        return jrJsonNode.createChild(container);
    } else if (container.size() == 1) {
        return jrJsonNode.createChild(container.get(0));
    }
    // Filtering expressions need the missing node to check for null
    else if (keepMissingNode) {
        return jrJsonNode.createChild(MissingNode.getInstance());
    }

    return null;
}

From source file:com.admin.bpm.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray,
        ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows,
        Map<String, ObjectNode> subProcessInstanceMap) {

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

    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }/*from w  ww  .  jav a  2s  .c  o  m*/
    }

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }

    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }

    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null
                && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default"))
                && ((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.put("xPointArray", xPointArray);
        flowJSON.put("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 (String key : properties.keySet()) {
        Object prop = properties.get(key);
        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());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());

                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.put(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.put(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.put(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.isEmpty()) {
                    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
                    && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery()
                        .processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion()
                        .singleResult();

                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    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.put("processDefinitons", processInstanceArray);
            }
        }
    }

    activityJSON.put("activityId", activity.getId());
    activityJSON.put("properties", propertiesJSON);
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.put("nestedActivities", nestedActivityArray);
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);

    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());

    activityArray.add(activityJSON);

    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance,
                highLightedFlows, subProcessInstanceMap);
    }
}

From source file:com.funtl.framework.smoke.core.modules.act.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java

private void getActivity(String processInstanceId, ActivityImpl activity, ArrayNode activityArray,
        ArrayNode sequenceFlowArray, ProcessInstance processInstance, List<String> highLightedFlows,
        Map<String, ObjectNode> subProcessInstanceMap) {

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

    // Gather info on the multi instance marker
    String multiInstance = (String) activity.getProperty("multiInstance");
    if (multiInstance != null) {
        if (!"sequential".equals(multiInstance)) {
            multiInstance = "parallel";
        }//w  w w  . jav  a2  s.c  o m
    }

    ActivityBehavior activityBehavior = activity.getActivityBehavior();
    // Gather info on the collapsed marker
    Boolean collapsed = (activityBehavior instanceof CallActivityBehavior);
    Boolean expanded = (Boolean) activity.getProperty(BpmnParse.PROPERTYNAME_ISEXPANDED);
    if (expanded != null) {
        collapsed = !expanded;
    }

    Boolean isInterrupting = null;
    if (activityBehavior instanceof BoundaryEventActivityBehavior) {
        isInterrupting = ((BoundaryEventActivityBehavior) activityBehavior).isInterrupting();
    }

    // Outgoing transitions of activity
    for (PvmTransition sequenceFlow : activity.getOutgoingTransitions()) {
        String flowName = (String) sequenceFlow.getProperty("name");
        boolean isHighLighted = (highLightedFlows.contains(sequenceFlow.getId()));
        boolean isConditional = sequenceFlow.getProperty(BpmnParse.PROPERTYNAME_CONDITION) != null
                && !((String) activity.getProperty("type")).toLowerCase().contains("gateway");
        boolean isDefault = sequenceFlow.getId().equals(activity.getProperty("default"))
                && ((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);
        //         flowJSON.put("xPointArray", xPointArray); //  - 2016-09-03 by Lusifer
        //         flowJSON.put("yPointArray", yPointArray); //  - 2016-09-03 by Lusifer

        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 (String key : properties.keySet()) {
        Object prop = properties.get(key);
        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());
                    //timerDeclarationJSON.put("expression", timerDeclaration.getDescription());

                    timerDeclarationArray.add(timerDeclarationJSON);
                }
            if (timerDeclarationArray.size() > 0)
                propertiesJSON.set(key, timerDeclarationArray);
            //               propertiesJSON.put(key, timerDeclarationArray); //  - 2016-09-03 by Lusifer
            // 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);
            //               propertiesJSON.put(key, eventDefinitionsArray); //  - 2016-09-03 by Lusifer

            // 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);
            //               propertiesJSON.put(key, errorEventDefinitionsArray); //  - 2016-09-03 by Lusifer
        }

    }

    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.isEmpty()) {
                    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
                    && StringUtils.isNotEmpty(callActivityBehavior.getProcessDefinitonKey())) {
                // Get last definition by key
                ProcessDefinition lastProcessDefinition = repositoryService.createProcessDefinitionQuery()
                        .processDefinitionKey(callActivityBehavior.getProcessDefinitonKey()).latestVersion()
                        .singleResult();

                // TODO: unuseful fields there are processDefinitionName, processDefinitionKey
                if (lastProcessDefinition != null) {
                    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);
                //               propertiesJSON.put("processDefinitons", processInstanceArray); //  - 2016-09-03 by Lusifer
            }
        }
    }

    activityJSON.put("activityId", activity.getId());
    activityJSON.set("properties", propertiesJSON);
    //      activityJSON.put("properties", propertiesJSON); //  - 2016-09-03 by Lusifer
    if (multiInstance != null)
        activityJSON.put("multiInstance", multiInstance);
    if (collapsed)
        activityJSON.put("collapsed", collapsed);
    if (nestedActivityArray.size() > 0)
        activityJSON.set("nestedActivities", nestedActivityArray);
    //         activityJSON.put("nestedActivities", nestedActivityArray); //  - 2016-09-03 by Lusifer
    if (isInterrupting != null)
        activityJSON.put("isInterrupting", isInterrupting);

    activityJSON.put("x", activity.getX());
    activityJSON.put("y", activity.getY());
    activityJSON.put("width", activity.getWidth());
    activityJSON.put("height", activity.getHeight());

    activityArray.add(activityJSON);

    // Nested activities (boundary events)
    for (ActivityImpl nestedActivity : activity.getActivities()) {
        getActivity(processInstanceId, nestedActivity, activityArray, sequenceFlowArray, processInstance,
                highLightedFlows, subProcessInstanceMap);
    }
}