List of usage examples for com.fasterxml.jackson.databind.node ArrayNode size
public int size()
From source file:com.randstad.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
@SuppressWarnings("unchecked") 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 ww.j a v a2 s .co 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.glaf.activiti.web.rest.ActivitiResource.java
@SuppressWarnings("unchecked") private void getActivity(ActivityImpl activity, ArrayNode activityArray, ArrayNode sequenceFlowArray) { 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 . ja v a 2 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) { 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)) { List<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); } } 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); } } 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()); 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(); 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(nestedActivity, activityArray, sequenceFlowArray); } }
From source file:io.swagger.parser.util.SwaggerDeserializer.java
public Operation operation(ObjectNode obj, String location, ParseResult result) { if (obj == null) { return null; }/* ww w. j ava 2s. c o m*/ Operation output = new Operation(); ArrayNode array = getArray("tags", obj, false, location, result); List<String> tags = tagStrings(array, location, result); if (tags != null) { output.tags(tags); } String value = getString("summary", obj, false, location, result); output.summary(value); value = getString("description", obj, false, location, result); output.description(value); ObjectNode externalDocs = getObject("externalDocs", obj, false, location, result); ExternalDocs docs = externalDocs(externalDocs, location, result); output.setExternalDocs(docs); value = getString("operationId", obj, false, location, result); output.operationId(value); array = getArray("consumes", obj, false, location, result); if (array != null) { if (array.size() == 0) { output.consumes(Collections.<String>emptyList()); } else { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".consumes", result); if (s != null) { output.consumes(s); } } } } array = getArray("produces", obj, false, location, result); if (array != null) { if (array.size() == 0) { output.produces(Collections.<String>emptyList()); } else { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".produces", result); if (s != null) { output.produces(s); } } } } ArrayNode parameters = getArray("parameters", obj, false, location, result); output.setParameters(parameters(parameters, location, result)); ObjectNode responses = getObject("responses", obj, true, location, result); output.setResponses(responses(responses, location, result)); array = getArray("schemes", obj, false, location, result); if (array != null) { Iterator<JsonNode> it = array.iterator(); while (it.hasNext()) { JsonNode n = it.next(); String s = getString(n, location + ".schemes", result); if (s != null) { Scheme scheme = Scheme.forValue(s); if (scheme != null) { output.scheme(scheme); } } } } Boolean deprecated = getBoolean("deprecated", obj, false, location, result); if (deprecated != null) { output.setDeprecated(deprecated); } array = getArray("security", obj, false, location, result); List<SecurityRequirement> security = securityRequirements(array, location, result); if (security != null) { List<Map<String, List<String>>> ss = new ArrayList<>(); for (SecurityRequirement s : security) { if (s.getRequirements() != null && s.getRequirements().size() > 0) { ss.add(s.getRequirements()); } } output.setSecurity(ss); } // extra keys Set<String> keys = getKeys(obj); for (String key : keys) { if (key.startsWith("x-")) { output.setVendorExtension(key, extension(obj.get(key))); } else if (!OPERATION_KEYS.contains(key)) { result.extra(location, key, obj.get(key)); } } return output; }
From source file:com.redhat.lightblue.eval.ForEachExpressionEvaluator.java
private boolean update(JsonDoc doc, Path contextPath, UpdateInfo updateInfo) { boolean ret = false; // Get a reference to the array field, and iterate all elements in the array ArrayNode arrayNode = (ArrayNode) doc.get(new Path(contextPath, updateInfo.field)); LOGGER.debug("Array node {}={}", updateInfo.field, arrayNode); ArrayElement elementMd = updateInfo.fieldMd.getElement(); if (arrayNode != null) { int index = 0; MutablePath itrPath = new MutablePath(contextPath); itrPath.push(updateInfo.field);/* w w w.ja v a 2s . c om*/ MutablePath arrSizePath = itrPath.copy(); arrSizePath.setLast(arrSizePath.getLast() + "#"); arrSizePath.rewriteIndexes(contextPath); itrPath.push(index); // Copy the nodes to a separate list, so we iterate on the // new copy, and modify the original ArrayList<JsonNode> nodes = new ArrayList<>(); for (Iterator<JsonNode> itr = arrayNode.elements(); itr.hasNext();) { nodes.add(itr.next()); } for (JsonNode elementNode : nodes) { itrPath.setLast(index); Path elementPath = itrPath.immutableCopy(); LOGGER.debug("itr:{}", elementPath); QueryEvaluationContext ctx = new QueryEvaluationContext(elementNode, elementPath); if (updateInfo.queryEvaluator.evaluate(ctx)) { LOGGER.debug("query matches {}", elementPath); LOGGER.debug("Calling updater {}", updateInfo.updater); if (updateInfo.updater.update(doc, elementMd, elementPath)) { LOGGER.debug("Updater {} returns {}", updateInfo.updater, true); ret = true; // Removal shifts nodes down if (updateInfo.updater instanceof RemoveEvaluator) { index--; } } else { LOGGER.debug("Updater {} return false", updateInfo.updater); } } else { LOGGER.debug("query does not match {}", elementPath); } index++; } if (ret) { doc.modify(arrSizePath, factory.numberNode(arrayNode.size()), false); } } return ret; }
From source file:com.appdynamics.analytics.processor.event.ElasticSearchEventService.java
private String[] arrayOfStringsFromNode(ArrayNode sourceNode) { /* 1595 */ String[] ary = new String[sourceNode.size()]; /* 1596 */ Iterator<JsonNode> elements = sourceNode.elements(); /* 1597 */ int i = 0; /* 1598 */ while (elements.hasNext()) { /* 1599 */ JsonNode elem = (JsonNode) elements.next(); /* 1600 */ ary[(i++)] = (elem.isTextual() ? elem.asText() : elem.toString()); /* */ } /* 1602 */ return ary; /* */ }/*from w w w .j av a 2 s. co m*/
From source file:org.pf9.pangu.app.act.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
public ObjectNode getDiagramNode(String processInstanceId, String processDefinitionId) { List<String> highLightedFlows = Collections.<String>emptyList(); List<String> highLightedActivities = Collections.<String>emptyList(); Map<String, ObjectNode> subProcessInstanceMap = new HashMap<String, ObjectNode>(); ProcessInstance processInstance = null; if (processInstanceId != null) { processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult();/* w w w .j ava2 s . c o m*/ if (processInstance == null) { throw new ActivitiObjectNotFoundException("Process instance could not be found"); } processDefinitionId = processInstance.getProcessDefinitionId(); List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).list(); for (ProcessInstance subProcessInstance : subProcessInstances) { String subDefId = subProcessInstance.getProcessDefinitionId(); String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId(); ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(subDefId); ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode(); processInstanceJSON.put("processInstanceId", subProcessInstance.getId()); processInstanceJSON.put("superExecutionId", superExecutionId); processInstanceJSON.put("processDefinitionId", subDef.getId()); processInstanceJSON.put("processDefinitionKey", subDef.getKey()); processInstanceJSON.put("processDefinitionName", subDef.getName()); subProcessInstanceMap.put(superExecutionId, processInstanceJSON); } } if (processDefinitionId == null) { throw new ActivitiObjectNotFoundException("No process definition id provided"); } ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiException("Process definition " + processDefinitionId + " could not be found"); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); // Process definition JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition); if (pdrJSON != null) { responseJSON.put("processDefinition", pdrJSON); } // Highlighted activities if (processInstance != null) { ArrayNode activityArray = new ObjectMapper().createArrayNode(); ArrayNode flowsArray = new ObjectMapper().createArrayNode(); highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId); highLightedFlows = getHighLightedFlows(processInstanceId, processDefinition); for (String activityName : highLightedActivities) { activityArray.add(activityName); } for (String flow : highLightedFlows) flowsArray.add(flow); responseJSON.put("highLightedActivities", activityArray); responseJSON.put("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.put("participantProcess", participantProcessJSON); } // Draw lanes if (processDefinition.getLaneSets() != null && !processDefinition.getLaneSets().isEmpty()) { ArrayNode laneSetArray = new ObjectMapper().createArrayNode(); for (LaneSet laneSet : processDefinition.getLaneSets()) { ArrayNode laneArray = new ObjectMapper().createArrayNode(); if (laneSet.getLanes() != null && !laneSet.getLanes().isEmpty()) { 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.put("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.put("lanes", laneArray); laneSetArray.add(laneSetJSON); } if (laneSetArray.size() > 0) responseJSON.put("laneSets", laneSetArray); } ArrayNode sequenceFlowArray = new ObjectMapper().createArrayNode(); ArrayNode activityArray = new ObjectMapper().createArrayNode(); // Activities and their sequence-flows for (ActivityImpl activity : processDefinition.getActivities()) { getActivity(processInstanceId, activity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap); } responseJSON.put("activities", activityArray); responseJSON.put("sequenceFlows", sequenceFlowArray); return responseJSON; }
From source file:com.xyz.activiti.bussiness.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
public ObjectNode getDiagramNode(String processInstanceId, String processDefinitionId) { List<String> highLightedFlows = Collections.<String>emptyList(); List<String> highLightedActivities = Collections.<String>emptyList(); Map<String, ObjectNode> subProcessInstanceMap = new HashMap<String, ObjectNode>(); ProcessInstance processInstance = null; if (processInstanceId != null) { processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult();//from w w w . ja v a 2 s .c o m if (processInstance == null) { throw new ActivitiObjectNotFoundException("Process instance could not be found"); } processDefinitionId = processInstance.getProcessDefinitionId(); List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).list(); for (ProcessInstance subProcessInstance : subProcessInstances) { String subDefId = subProcessInstance.getProcessDefinitionId(); String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId(); ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(subDefId); ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode(); processInstanceJSON.put("processInstanceId", subProcessInstance.getId()); processInstanceJSON.put("superExecutionId", superExecutionId); processInstanceJSON.put("processDefinitionId", subDef.getId()); processInstanceJSON.put("processDefinitionKey", subDef.getKey()); processInstanceJSON.put("processDefinitionName", subDef.getName()); subProcessInstanceMap.put(superExecutionId, processInstanceJSON); } } if (processDefinitionId == null) { throw new ActivitiObjectNotFoundException("No process definition id provided"); } ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiException("Process definition " + processDefinitionId + " could not be found"); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); // Process definition JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition); if (pdrJSON != null) { 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(processInstanceId, processDefinition); 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().isEmpty()) { ArrayNode laneSetArray = new ObjectMapper().createArrayNode(); for (LaneSet laneSet : processDefinition.getLaneSets()) { ArrayNode laneArray = new ObjectMapper().createArrayNode(); if (laneSet.getLanes() != null && !laneSet.getLanes().isEmpty()) { 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(processInstanceId, activity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap); } responseJSON.set("activities", activityArray); responseJSON.set("sequenceFlows", sequenceFlowArray); return responseJSON; }
From source file:com.randstad.rest.diagram.services.BaseProcessDefinitionDiagramLayoutResource.java
public ObjectNode getDiagramNode(String processInstanceId, String processDefinitionId) { List<String> highLightedFlows = Collections.<String>emptyList(); List<String> highLightedActivities = Collections.<String>emptyList(); Map<String, ObjectNode> subProcessInstanceMap = new HashMap<String, ObjectNode>(); ProcessInstance processInstance = null; if (processInstanceId != null) { processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult();/*from w w w. j a v a 2 s . c o m*/ if (processInstance == null) { throw new ActivitiObjectNotFoundException("Process instance could not be found"); } processDefinitionId = processInstance.getProcessDefinitionId(); List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).list(); for (ProcessInstance subProcessInstance : subProcessInstances) { String subDefId = subProcessInstance.getProcessDefinitionId(); String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId(); ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(subDefId); ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode(); processInstanceJSON.put("processInstanceId", subProcessInstance.getId()); processInstanceJSON.put("superExecutionId", superExecutionId); processInstanceJSON.put("processDefinitionId", subDef.getId()); processInstanceJSON.put("processDefinitionKey", subDef.getKey()); processInstanceJSON.put("processDefinitionName", subDef.getName()); subProcessInstanceMap.put(superExecutionId, processInstanceJSON); } } if (processDefinitionId == null) { throw new ActivitiObjectNotFoundException("No process definition id provided"); } ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService .getProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiException("Process definition " + processDefinitionId + " could not be found"); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); // Process definition JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition); if (pdrJSON != null) { responseJSON.put("processDefinition", pdrJSON); } // Highlighted activities if (processInstance != null) { ArrayNode activityArray = new ObjectMapper().createArrayNode(); ArrayNode flowsArray = new ObjectMapper().createArrayNode(); highLightedActivities = runtimeService.getActiveActivityIds(processInstanceId); highLightedFlows = getHighLightedFlows(processInstanceId, processDefinition); for (String activityName : highLightedActivities) { activityArray.add(activityName); } for (String flow : highLightedFlows) { flowsArray.add(flow); } responseJSON.put("highLightedActivities", activityArray); responseJSON.put("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.put("participantProcess", participantProcessJSON); } // Draw lanes if (processDefinition.getLaneSets() != null && !processDefinition.getLaneSets().isEmpty()) { ArrayNode laneSetArray = new ObjectMapper().createArrayNode(); for (LaneSet laneSet : processDefinition.getLaneSets()) { ArrayNode laneArray = new ObjectMapper().createArrayNode(); if (laneSet.getLanes() != null && !laneSet.getLanes().isEmpty()) { 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.put("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.put("lanes", laneArray); laneSetArray.add(laneSetJSON); } if (laneSetArray.size() > 0) { responseJSON.put("laneSets", laneSetArray); } } ArrayNode sequenceFlowArray = new ObjectMapper().createArrayNode(); ArrayNode activityArray = new ObjectMapper().createArrayNode(); // Activities and their sequence-flows for (ActivityImpl activity : processDefinition.getActivities()) { getActivity(processInstanceId, activity, activityArray, sequenceFlowArray, processInstance, highLightedFlows, subProcessInstanceMap); } responseJSON.put("activities", activityArray); responseJSON.put("sequenceFlows", sequenceFlowArray); return responseJSON; }
From source file:com.glaf.activiti.web.rest.ActivitiResource.java
public ObjectNode getDiagram() { if (processInstanceId != null) { processInstance = runtimeService.createProcessInstanceQuery().processInstanceId(processInstanceId) .singleResult();/*from w w w. j a v a2 s . c om*/ if (processInstance == null) { ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode(); return processInstanceJSON; } processDefinitionId = processInstance.getProcessDefinitionId(); List<ProcessInstance> subProcessInstances = runtimeService.createProcessInstanceQuery() .superProcessInstanceId(processInstanceId).list(); for (ProcessInstance subProcessInstance : subProcessInstances) { String subDefId = subProcessInstance.getProcessDefinitionId(); String superExecutionId = ((ExecutionEntity) subProcessInstance).getSuperExecutionId(); ProcessDefinitionEntity subDef = (ProcessDefinitionEntity) repositoryService .getDeployedProcessDefinition(subDefId); ObjectNode processInstanceJSON = new ObjectMapper().createObjectNode(); processInstanceJSON.put("processInstanceId", subProcessInstance.getId()); processInstanceJSON.put("superExecutionId", superExecutionId); processInstanceJSON.put("processDefinitionId", subDef.getId()); processInstanceJSON.put("processDefinitionKey", subDef.getKey()); processInstanceJSON.put("processDefinitionName", subDef.getName()); subProcessInstanceMap.put(superExecutionId, processInstanceJSON); } } if (processDefinitionId == null) { throw new ActivitiException("No process definition id provided"); } processDefinition = (ProcessDefinitionEntity) repositoryService .getDeployedProcessDefinition(processDefinitionId); if (processDefinition == null) { throw new ActivitiException("Process definition " + processDefinitionId + " could not be found"); } ObjectNode responseJSON = new ObjectMapper().createObjectNode(); // Process definition JsonNode pdrJSON = getProcessDefinitionResponse(processDefinition); if (pdrJSON != null) { 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); } responseJSON.set("activities", activityArray); responseJSON.set("sequenceFlows", sequenceFlowArray); return responseJSON; }