List of usage examples for com.fasterxml.jackson.databind.node ObjectNode putNull
public ObjectNode putNull(String paramString)
From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java
String getKeyStrokesJSON() { ObjectNode keyStrokesNode = JsonNodeFactory.instance.objectNode(); for (Entry<String, KeyStroke> entry : getKeyStrokeMap().entrySet()) { if (entry.getValue() != null) { ArrayNode arrayNode = keyStrokesNode.putArray(entry.getKey()); arrayNode.add(entry.getValue().getKeyCode()); arrayNode.add(entry.getValue().getModifiers()); } else {//from ww w . j a v a 2s. co m keyStrokesNode.putNull(entry.getKey()); } } return keyStrokesNode.toString(); }
From source file:com.unboundid.scim2.common.DiffTestCase.java
/** * Test comparison of objects removing all attributes. * * @throws Exception//from www .j a v a 2s . co m * if an error occurs. */ @Test public void testRemoveAll() throws Exception { // *** singular *** ObjectNode source = JsonUtils.getJsonNodeFactory().objectNode(); ObjectNode target = JsonUtils.getJsonNodeFactory().objectNode(); // - unchanged source.put("userName", "bjensen"); target.putNull("userName"); source.put("nickName", "bjj3"); target.putNull("nickName"); source.put("title", "hot shot"); target.putNull("title"); source.put("userType", "employee"); target.putArray("userType"); List<PatchOperation> d = JsonUtils.diff(source, target, false); assertEquals(d.size(), 4); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("userName")))); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("nickName")))); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("title")))); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("userType")))); target = JsonUtils.getJsonNodeFactory().objectNode(); List<PatchOperation> d2 = JsonUtils.diff(source, target, true); for (PatchOperation op : d2) { op.apply(source); } removeNullNodes(target); assertEquals(source, target); }
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 ww w . j a v 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.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.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"; }// www . ja v 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.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: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 w w .j a v 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.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.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addField(String dbName, String fieldName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("field-name", fieldName); childNodeObject.put("include-root", true); childNodeObject.putNull("included-elements"); childNodeObject.putNull("excluded-elements"); childNodeObject.putNull("tokenizer-overrides"); arrNode.add(childNodeObject);//from w ww .jav a 2 s .c o m childNode.putArray("field").addAll(arrNode); // mainNode.put("fields", childNode); // System.out.println("Entered field to make it true"); setDatabaseProperties(dbName, "field", childNode); }
From source file:com.marklogic.jena.functionaltests.ConnectedRESTQA.java
public static void addFieldExcludeRoot(String dbName, String fieldName) throws Exception { ObjectMapper mapper = new ObjectMapper(); // ObjectNode mainNode = mapper.createObjectNode(); ObjectNode childNode = mapper.createObjectNode(); ArrayNode arrNode = mapper.createArrayNode(); ObjectNode childNodeObject = mapper.createObjectNode(); childNodeObject.put("field-name", fieldName); childNodeObject.put("include-root", false); childNodeObject.putNull("included-elements"); childNodeObject.putNull("excluded-elements"); childNodeObject.putNull("tokenizer-overrides"); arrNode.add(childNodeObject);/* ww w .j a v a 2s.c om*/ childNode.putArray("field").addAll(arrNode); // mainNode.put("fields", childNode); // System.out.println( childNode.toString()); setDatabaseProperties(dbName, "field", childNode); }
From source file:com.unboundid.scim2.common.DiffTestCase.java
/** * Test comparison of multi-valued complex attributes. * * @throws Exception if an error occurs. *//*from w w w.j a va 2s . c o m*/ @Test public void testDiffMultiValuedComplexAttribute() throws Exception { // *** multi-valued *** ObjectNode source = JsonUtils.getJsonNodeFactory().objectNode(); ObjectNode target = JsonUtils.getJsonNodeFactory().objectNode(); // - unchanged ObjectNode email1 = JsonUtils .valueToNode(new Email().setValue("bjensen@example.com").setType("work").setPrimary(true)); ObjectNode email2 = JsonUtils .valueToNode(new Email().setValue("babs@jensen.org").setType("home").setPrimary(false)); source.putArray("emails").add(email1).add(email2); target.putArray("emails").add(email1).add(email2); // - added ObjectNode phone1 = JsonUtils .valueToNode(new PhoneNumber().setValue("1234567890").setType("work").setPrimary(true)); ObjectNode phone2 = JsonUtils .valueToNode(new PhoneNumber().setValue("0987654321").setType("home").setPrimary(false)); target.putArray("phones").add(phone1).add(phone2); // - removed ObjectNode im1 = JsonUtils .valueToNode(new InstantMessagingAddress().setValue("babs").setType("aim").setPrimary(true)); ObjectNode im2 = JsonUtils .valueToNode(new InstantMessagingAddress().setValue("bjensen").setType("gtalk").setPrimary(false)); source.putArray("ims").add(im1).add(im2); target.putArray("ims"); // - updated // -- unchanged ObjectNode photo0 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo0")).setType("photo0").setPrimary(false)); ObjectNode photo1 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo1")).setType("photo1").setPrimary(false)); // -- non-asserted ObjectNode photo2 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo2")).setType("photo2").setPrimary(false)); ObjectNode photo2a = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo2")).setType("photo2")); // -- add a new value ObjectNode photo3 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo3")).setType("photo3").setPrimary(true)); // -- update an existing value ObjectNode photo4 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo4")).setType("photo4").setPrimary(true)); ObjectNode photo4a = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo4")).setType("photo4").setPrimary(false)); // -- add a new value ObjectNode photo5 = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo5")).setType("photo5").setPrimary(false)); ObjectNode photo5a = JsonUtils.valueToNode(new Photo().setValue(new URI("http://photo5")).setType("photo5") .setPrimary(false).setDisplay("Photo 5")); // -- remove an existing value ObjectNode photo6 = JsonUtils.valueToNode(new Photo().setValue(new URI("http://photo6")).setType("photo6") .setPrimary(false).setDisplay("Photo 6")); ObjectNode photo6a = JsonUtils .valueToNode(new Photo().setValue(new URI("http://photo6")).setType("photo6").setPrimary(false)); photo6a.putNull("display"); // -- remove a value ObjectNode thumbnail = JsonUtils.valueToNode( new Photo().setValue(new URI("http://thumbnail1")).setType("thumbnail").setPrimary(true)); source.putArray("photos").add(photo0).add(photo1).add(photo2).add(photo4).add(photo5).add(photo6) .add(thumbnail); target.putArray("photos").add(photo0).add(photo1).add(photo2a).add(photo4a).add(photo5a).add(photo6a) .add(photo3); // -- updated with all new values ObjectNode entitlement1 = JsonUtils.valueToNode(new Entitlement().setValue("admin").setPrimary(false)); ObjectNode entitlement2 = JsonUtils.valueToNode(new Entitlement().setValue("user").setPrimary(false)); ObjectNode entitlement3 = JsonUtils.valueToNode(new Entitlement().setValue("inactive").setPrimary(true)); source.putArray("entitlements").add(entitlement1).add(entitlement2); target.putArray("entitlements").add(entitlement3); List<PatchOperation> d = JsonUtils.diff(source, target, false); assertEquals(d.size(), 7); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("ims")))); assertTrue(d.contains(PatchOperation.remove(Path.root() .attribute("photos", Filter.fromString("value eq \"http://photo6\" and " + "display eq \"Photo 6\" and " + "type eq \"photo6\" and " + "primary eq false")) .attribute("display")))); assertTrue( d.contains(PatchOperation.replace( Path.root().attribute("photos", Filter.fromString("value eq \"http://photo4\" and " + "type eq \"photo4\" and " + "primary eq true")), JsonUtils.getJsonNodeFactory().objectNode().put("primary", false)))); assertTrue(d.contains(PatchOperation.replace( Path.root().attribute("photos", Filter.fromString("value eq \"http://photo5\" and " + "type eq \"photo5\" and " + "primary eq false")), JsonUtils.getJsonNodeFactory().objectNode().put("display", "Photo 5")))); assertTrue(d.contains(PatchOperation.remove(Path.root().attribute("photos", Filter.fromString( "value eq \"http://thumbnail1\" and " + "type eq \"thumbnail\" and " + "primary eq true"))))); ObjectNode replaceValue = JsonUtils.getJsonNodeFactory().objectNode(); replaceValue.putArray("entitlements").add(entitlement3); replaceValue.putArray("phones").add(phone1).add(phone2); assertTrue(d.contains(PatchOperation.replace(replaceValue))); ObjectNode addValue = JsonUtils.getJsonNodeFactory().objectNode(); addValue.putArray("photos").add(photo3); assertTrue(d.contains(PatchOperation.add(addValue))); List<PatchOperation> d2 = JsonUtils.diff(source, target, true); for (PatchOperation op : d2) { op.apply(source); } removeNullNodes(target); assertEquals(source, target); }
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"; }/*from w ww.ja va 2s . 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); // 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); } }
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"; }/*from www . ja v a2s .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); } }