use of org.activiti.bpmn.model.SubProcess in project Activiti by Activiti.
the class ScopedConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("outerSubProcess");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
assertEquals("outerSubProcess", flowElement.getId());
SubProcess outerSubProcess = (SubProcess) flowElement;
List<BoundaryEvent> eventList = outerSubProcess.getBoundaryEvents();
assertEquals(1, eventList.size());
BoundaryEvent boundaryEvent = eventList.get(0);
assertEquals("outerBoundaryEvent", boundaryEvent.getId());
FlowElement subElement = outerSubProcess.getFlowElement("innerSubProcess");
assertNotNull(subElement);
assertTrue(subElement instanceof SubProcess);
assertEquals("innerSubProcess", subElement.getId());
SubProcess innerSubProcess = (SubProcess) subElement;
eventList = innerSubProcess.getBoundaryEvents();
assertEquals(1, eventList.size());
boundaryEvent = eventList.get(0);
assertEquals("innerBoundaryEvent", boundaryEvent.getId());
FlowElement taskElement = innerSubProcess.getFlowElement("usertask");
assertNotNull(taskElement);
assertTrue(taskElement instanceof UserTask);
UserTask userTask = (UserTask) taskElement;
assertEquals("usertask", userTask.getId());
eventList = userTask.getBoundaryEvents();
assertEquals(1, eventList.size());
boundaryEvent = eventList.get(0);
assertEquals("taskBoundaryEvent", boundaryEvent.getId());
}
use of org.activiti.bpmn.model.SubProcess in project Activiti by Activiti.
the class BpmnJsonConverter method convertToBpmnModel.
public BpmnModel convertToBpmnModel(JsonNode modelNode) {
BpmnModel bpmnModel = new BpmnModel();
bpmnModel.setTargetNamespace("http://activiti.org/test");
Map<String, JsonNode> shapeMap = new HashMap<String, JsonNode>();
Map<String, JsonNode> sourceRefMap = new HashMap<String, JsonNode>();
Map<String, JsonNode> edgeMap = new HashMap<String, JsonNode>();
Map<String, List<JsonNode>> sourceAndTargetMap = new HashMap<String, List<JsonNode>>();
readShapeDI(modelNode, 0, 0, shapeMap, sourceRefMap, bpmnModel);
filterAllEdges(modelNode, edgeMap, sourceAndTargetMap, shapeMap, sourceRefMap);
readEdgeDI(edgeMap, sourceAndTargetMap, bpmnModel);
ArrayNode shapesArrayNode = (ArrayNode) modelNode.get(EDITOR_CHILD_SHAPES);
if (shapesArrayNode == null || shapesArrayNode.size() == 0)
return bpmnModel;
boolean nonEmptyPoolFound = false;
Map<String, Lane> elementInLaneMap = new HashMap<String, Lane>();
// first create the pool structure
for (JsonNode shapeNode : shapesArrayNode) {
String stencilId = BpmnJsonConverterUtil.getStencilId(shapeNode);
if (STENCIL_POOL.equals(stencilId)) {
Pool pool = new Pool();
pool.setId(BpmnJsonConverterUtil.getElementId(shapeNode));
pool.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, shapeNode));
pool.setProcessRef(JsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, shapeNode));
pool.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, shapeNode, true));
bpmnModel.getPools().add(pool);
Process process = new Process();
process.setId(pool.getProcessRef());
process.setName(pool.getName());
process.setExecutable(pool.isExecutable());
bpmnModel.addProcess(process);
ArrayNode laneArrayNode = (ArrayNode) shapeNode.get(EDITOR_CHILD_SHAPES);
for (JsonNode laneNode : laneArrayNode) {
// should be a lane, but just check to be certain
String laneStencilId = BpmnJsonConverterUtil.getStencilId(laneNode);
if (STENCIL_LANE.equals(laneStencilId)) {
nonEmptyPoolFound = true;
Lane lane = new Lane();
lane.setId(BpmnJsonConverterUtil.getElementId(laneNode));
lane.setName(JsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, laneNode));
lane.setParentProcess(process);
process.getLanes().add(lane);
processJsonElements(laneNode.get(EDITOR_CHILD_SHAPES), modelNode, lane, shapeMap, bpmnModel);
if (CollectionUtils.isNotEmpty(lane.getFlowReferences())) {
for (String elementRef : lane.getFlowReferences()) {
elementInLaneMap.put(elementRef, lane);
}
}
}
}
}
}
// Signal Definitions exist on the root level
JsonNode signalDefinitionNode = BpmnJsonConverterUtil.getProperty(PROPERTY_SIGNAL_DEFINITIONS, modelNode);
signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
// no idea why this needs to be done twice ..
signalDefinitionNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(signalDefinitionNode);
if (signalDefinitionNode != null) {
if (signalDefinitionNode instanceof ArrayNode) {
ArrayNode signalDefinitionArrayNode = (ArrayNode) signalDefinitionNode;
Iterator<JsonNode> signalDefinitionIterator = signalDefinitionArrayNode.iterator();
while (signalDefinitionIterator.hasNext()) {
JsonNode signalDefinitionJsonNode = signalDefinitionIterator.next();
String signalId = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_ID).asText();
String signalName = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_NAME).asText();
String signalScope = signalDefinitionJsonNode.get(PROPERTY_SIGNAL_DEFINITION_SCOPE).asText();
Signal signal = new Signal();
signal.setId(signalId);
signal.setName(signalName);
signal.setScope((signalScope.toLowerCase().equals("processinstance")) ? Signal.SCOPE_PROCESS_INSTANCE : Signal.SCOPE_GLOBAL);
bpmnModel.addSignal(signal);
}
}
}
if (nonEmptyPoolFound == false) {
Process process = new Process();
bpmnModel.getProcesses().add(process);
process.setId(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_ID, modelNode));
process.setName(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_NAME, modelNode));
String namespace = BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_PROCESS_NAMESPACE, modelNode);
if (StringUtils.isNotEmpty(namespace)) {
bpmnModel.setTargetNamespace(namespace);
}
process.setDocumentation(BpmnJsonConverterUtil.getPropertyValueAsString(PROPERTY_DOCUMENTATION, modelNode));
JsonNode processExecutableNode = JsonConverterUtil.getProperty(PROPERTY_PROCESS_EXECUTABLE, modelNode);
if (processExecutableNode != null && StringUtils.isNotEmpty(processExecutableNode.asText())) {
process.setExecutable(JsonConverterUtil.getPropertyValueAsBoolean(PROPERTY_PROCESS_EXECUTABLE, modelNode));
}
BpmnJsonConverterUtil.convertJsonToMessages(modelNode, bpmnModel);
BpmnJsonConverterUtil.convertJsonToListeners(modelNode, process);
JsonNode eventListenersNode = BpmnJsonConverterUtil.getProperty(PROPERTY_EVENT_LISTENERS, modelNode);
if (eventListenersNode != null) {
eventListenersNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(eventListenersNode);
BpmnJsonConverterUtil.parseEventListeners(eventListenersNode.get(PROPERTY_EVENTLISTENER_VALUE), process);
}
JsonNode processDataPropertiesNode = modelNode.get(EDITOR_SHAPE_PROPERTIES).get(PROPERTY_DATA_PROPERTIES);
if (processDataPropertiesNode != null) {
List<ValuedDataObject> dataObjects = BpmnJsonConverterUtil.convertJsonToDataProperties(processDataPropertiesNode, process);
process.setDataObjects(dataObjects);
process.getFlowElements().addAll(dataObjects);
}
processJsonElements(shapesArrayNode, modelNode, process, shapeMap, bpmnModel);
} else {
// sequence flows are on root level so need additional parsing for pools
for (JsonNode shapeNode : shapesArrayNode) {
if (STENCIL_SEQUENCE_FLOW.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode)) || STENCIL_ASSOCIATION.equalsIgnoreCase(BpmnJsonConverterUtil.getStencilId(shapeNode))) {
String sourceRef = BpmnJsonConverterUtil.lookForSourceRef(shapeNode.get(EDITOR_SHAPE_ID).asText(), modelNode.get(EDITOR_CHILD_SHAPES));
if (sourceRef != null) {
Lane lane = elementInLaneMap.get(sourceRef);
SequenceFlowJsonConverter flowConverter = new SequenceFlowJsonConverter();
if (lane != null) {
flowConverter.convertToBpmnModel(shapeNode, modelNode, this, lane, shapeMap, bpmnModel);
} else {
flowConverter.convertToBpmnModel(shapeNode, modelNode, this, bpmnModel.getProcesses().get(0), shapeMap, bpmnModel);
}
}
}
}
}
// sequence flows are now all on root level
Map<String, SubProcess> subShapesMap = new HashMap<String, SubProcess>();
for (Process process : bpmnModel.getProcesses()) {
for (FlowElement flowElement : process.findFlowElementsOfType(SubProcess.class)) {
SubProcess subProcess = (SubProcess) flowElement;
fillSubShapes(subShapesMap, subProcess);
}
if (subShapesMap.size() > 0) {
List<String> removeSubFlowsList = new ArrayList<String>();
for (FlowElement flowElement : process.findFlowElementsOfType(SequenceFlow.class)) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
if (subShapesMap.containsKey(sequenceFlow.getSourceRef())) {
SubProcess subProcess = subShapesMap.get(sequenceFlow.getSourceRef());
if (subProcess.getFlowElement(sequenceFlow.getId()) == null) {
subProcess.addFlowElement(sequenceFlow);
removeSubFlowsList.add(sequenceFlow.getId());
}
}
}
for (String flowId : removeSubFlowsList) {
process.removeFlowElement(flowId);
}
}
}
Map<String, FlowWithContainer> allFlowMap = new HashMap<String, FlowWithContainer>();
List<Gateway> gatewayWithOrderList = new ArrayList<Gateway>();
// post handling of process elements
for (Process process : bpmnModel.getProcesses()) {
postProcessElements(process, process.getFlowElements(), edgeMap, bpmnModel, allFlowMap, gatewayWithOrderList);
}
// sort the sequence flows
for (Gateway gateway : gatewayWithOrderList) {
List<ExtensionElement> orderList = gateway.getExtensionElements().get("EDITOR_FLOW_ORDER");
if (CollectionUtils.isNotEmpty(orderList)) {
for (ExtensionElement orderElement : orderList) {
String flowValue = orderElement.getElementText();
if (StringUtils.isNotEmpty(flowValue)) {
if (allFlowMap.containsKey(flowValue)) {
FlowWithContainer flowWithContainer = allFlowMap.get(flowValue);
flowWithContainer.getFlowContainer().removeFlowElement(flowWithContainer.getSequenceFlow().getId());
flowWithContainer.getFlowContainer().addFlowElement(flowWithContainer.getSequenceFlow());
}
}
}
}
gateway.getExtensionElements().remove("EDITOR_FLOW_ORDER");
}
return bpmnModel;
}
use of org.activiti.bpmn.model.SubProcess in project Activiti by Activiti.
the class FlowNodeInSubProcessConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("subprocess1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
SubProcess subProcess = (SubProcess) flowElement;
ParallelGateway gateway = (ParallelGateway) subProcess.getFlowElement("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC");
assertNotNull(gateway);
List<SequenceFlow> sequenceFlows = gateway.getOutgoingFlows();
assertTrue(sequenceFlows.size() == 2);
assertTrue(sequenceFlows.get(0).getId().equals("sid-9C669980-C274-4A48-BF7F-B9C5CA577DD2") || sequenceFlows.get(0).getId().equals("sid-A299B987-396F-46CA-8D63-85991FBFCE6E"));
assertTrue(sequenceFlows.get(1).getId().equals("sid-9C669980-C274-4A48-BF7F-B9C5CA577DD2") || sequenceFlows.get(1).getId().equals("sid-A299B987-396F-46CA-8D63-85991FBFCE6E"));
assertTrue(sequenceFlows.get(0).getSourceRef().equals("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC"));
assertTrue(sequenceFlows.get(1).getSourceRef().equals("sid-A0E0B174-36DF-4C4F-A952-311CC3C031FC"));
}
use of org.activiti.bpmn.model.SubProcess in project Activiti by Activiti.
the class SubProcessJsonConverter method convertElementToJson.
protected void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement) {
SubProcess subProcess = (SubProcess) baseElement;
propertiesNode.put("activitytype", "Sub-Process");
propertiesNode.put("subprocesstype", "Embedded");
ArrayNode subProcessShapesArrayNode = objectMapper.createArrayNode();
GraphicInfo graphicInfo = model.getGraphicInfo(subProcess.getId());
processor.processFlowElements(subProcess, model, subProcessShapesArrayNode, graphicInfo.getX(), graphicInfo.getY());
flowElementNode.put("childShapes", subProcessShapesArrayNode);
if (subProcess instanceof Transaction) {
propertiesNode.put("istransaction", true);
}
BpmnJsonConverterUtil.convertDataPropertiesToJson(subProcess.getDataObjects(), propertiesNode);
}
use of org.activiti.bpmn.model.SubProcess in project Activiti by Activiti.
the class ValuedDataObjectConverterTest method validateModel.
private void validateModel(BpmnModel model) {
FlowElement flowElement = model.getMainProcess().getFlowElement("start1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof StartEvent);
assertEquals("start1", flowElement.getId());
// verify the main process data objects
List<ValuedDataObject> dataObjects = model.getProcess(null).getDataObjects();
assertEquals(7, dataObjects.size());
Map<String, ValuedDataObject> objectMap = new HashMap<String, ValuedDataObject>();
for (ValuedDataObject valueObj : dataObjects) {
objectMap.put(valueObj.getId(), valueObj);
}
ValuedDataObject dataObj = objectMap.get("dObj1");
assertEquals("dObj1", dataObj.getId());
assertEquals("StringTest", dataObj.getName());
assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof String);
assertEquals("Testing1&2&3", dataObj.getValue());
dataObj = objectMap.get("dObj2");
assertEquals("dObj2", dataObj.getId());
assertEquals("BooleanTest", dataObj.getName());
assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Boolean);
assertEquals(new Boolean(true), dataObj.getValue());
dataObj = objectMap.get("dObj3");
assertEquals("dObj3", dataObj.getId());
assertEquals("DateTest", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
assertEquals("2013-09-16T11:23:00", sdf.format(dataObj.getValue()));
dataObj = objectMap.get("dObj4");
assertEquals("dObj4", dataObj.getId());
assertEquals("DoubleTest", dataObj.getName());
assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Double);
assertEquals(new Double(123456789), dataObj.getValue());
dataObj = objectMap.get("dObj5");
assertEquals("dObj5", dataObj.getId());
assertEquals("IntegerTest", dataObj.getName());
assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Integer);
assertEquals(new Integer(123), dataObj.getValue());
dataObj = objectMap.get("dObj6");
assertEquals("dObj6", dataObj.getId());
assertEquals("LongTest", dataObj.getName());
assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Long);
assertEquals(new Long(-123456), dataObj.getValue());
assertEquals(1, dataObj.getExtensionElements().size());
List<ExtensionElement> testValues = dataObj.getExtensionElements().get("testvalue");
assertNotNull(testValues);
assertEquals(1, testValues.size());
assertEquals("testvalue", testValues.get(0).getName());
assertEquals("test", testValues.get(0).getElementText());
dataObj = objectMap.get("NoData");
assertEquals("NoData", dataObj.getId());
assertEquals("NoData", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertNull(dataObj.getValue());
flowElement = model.getMainProcess().getFlowElement("userTask1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof UserTask);
assertEquals("userTask1", flowElement.getId());
UserTask userTask = (UserTask) flowElement;
assertEquals("kermit", userTask.getAssignee());
flowElement = model.getMainProcess().getFlowElement("subprocess1");
assertNotNull(flowElement);
assertTrue(flowElement instanceof SubProcess);
assertEquals("subprocess1", flowElement.getId());
SubProcess subProcess = (SubProcess) flowElement;
assertEquals(11, subProcess.getFlowElements().size());
// verify the sub process data objects
dataObjects = subProcess.getDataObjects();
assertEquals(6, dataObjects.size());
objectMap = new HashMap<String, ValuedDataObject>();
for (ValuedDataObject valueObj : dataObjects) {
objectMap.put(valueObj.getId(), valueObj);
}
dataObj = objectMap.get("dObj7");
assertEquals("dObj7", dataObj.getId());
assertEquals("StringSubTest", dataObj.getName());
assertEquals("xsd:string", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof String);
assertEquals("Testing456", dataObj.getValue());
dataObj = objectMap.get("dObj8");
assertEquals("dObj8", dataObj.getId());
assertEquals("BooleanSubTest", dataObj.getName());
assertEquals("xsd:boolean", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Boolean);
assertEquals(new Boolean(false), dataObj.getValue());
dataObj = objectMap.get("dObj9");
assertEquals("dObj9", dataObj.getId());
assertEquals("DateSubTest", dataObj.getName());
assertEquals("xsd:datetime", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Date);
assertEquals("2013-11-11T22:00:00", sdf.format(dataObj.getValue()));
dataObj = objectMap.get("dObj10");
assertEquals("dObj10", dataObj.getId());
assertEquals("DoubleSubTest", dataObj.getName());
assertEquals("xsd:double", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Double);
assertEquals(new Double(678912345), dataObj.getValue());
dataObj = objectMap.get("dObj11");
assertEquals("dObj11", dataObj.getId());
assertEquals("IntegerSubTest", dataObj.getName());
assertEquals("xsd:int", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Integer);
assertEquals(new Integer(45), dataObj.getValue());
dataObj = objectMap.get("dObj12");
assertEquals("dObj12", dataObj.getId());
assertEquals("LongSubTest", dataObj.getName());
assertEquals("xsd:long", dataObj.getItemSubjectRef().getStructureRef());
assertTrue(dataObj.getValue() instanceof Long);
assertEquals(new Long(456123), dataObj.getValue());
}
Aggregations