提交 265d8348 编写于 作者: J Joram Barrez

Porting 'terminateAll' to v6: cherry pick of...

Porting 'terminateAll' to v6: cherry pick of https://github.com/Activiti/Activiti/commit/a67374d65b93b22590da9e45e149e5433c35408e
上级 a54386e3
......@@ -492,6 +492,70 @@ public class TerminateEndEventTest extends PluggableActivitiTestCase {
assertProcessEnded(pi.getId());
}
@Deployment
public void testMiCallActivityParallel() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testMiCallActivity");
List<Task> aTasks = taskService.createTaskQuery().taskName("A").list();
assertEquals(5, aTasks.size());
List<Task> bTasks = taskService.createTaskQuery().taskName("B").list();
assertEquals(5, bTasks.size());
// Completing B should terminate one instance (it goes to a terminate end event)
int bTasksCompleted = 0;
for (Task bTask : bTasks) {
taskService.complete(bTask.getId());
bTasksCompleted++;
aTasks = taskService.createTaskQuery().taskName("A").list();
assertEquals(5-bTasksCompleted, aTasks.size());
}
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals("After call activity", task.getName());
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}
@Deployment
public void testMiCallActivitySequential() {
ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("testMiCallActivity");
List<Task> aTasks = taskService.createTaskQuery().taskName("A").list();
assertEquals(1, aTasks.size());
List<Task> bTasks = taskService.createTaskQuery().taskName("B").list();
assertEquals(1, bTasks.size());
// Completing B should terminate one instance (it goes to a terminate end event)
for (int i=0; i<9; i++) {
Task bTask = taskService.createTaskQuery().taskName("B").singleResult();
taskService.complete(bTask.getId());
if (i != 8) {
aTasks = taskService.createTaskQuery().taskName("A").list();
assertEquals(1, aTasks.size());
bTasks = taskService.createTaskQuery().taskName("B").list();
assertEquals(1, bTasks.size());
}
}
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
assertEquals("After call activity", task.getName());
taskService.complete(task.getId());
assertProcessEnded(processInstance.getId());
}
@Deployment(resources={
"org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.testTerminateInCallActivityConcurrent.bpmn",
"org/activiti/engine/test/bpmn/event/end/TerminateEndEventTest.subProcessConcurrentTerminateTerminateAll.bpmn20.xml"
......
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0en" modeler:exportDateTime="20151105122624969" modeler:modelId="4000" modeler:modelVersion="1" modeler:modelLastUpdated="1446722783163">
<process id="testMiCallActivity" name="testMiCallActivity" isExecutable="true">
<startEvent id="startEvent1"/>
<callActivity id="sid-45436C99-B809-4449-A773-E3DCDA74F253" name="Call activity" calledElement="parallel_tasks">
<multiInstanceLoopCharacteristics isSequential="false">
<loopCardinality>5</loopCardinality>
</multiInstanceLoopCharacteristics>
</callActivity>
<sequenceFlow id="sid-309D0F1D-AA7E-4331-AA94-A16400848DC0" sourceRef="startEvent1" targetRef="sid-45436C99-B809-4449-A773-E3DCDA74F253"/>
<userTask id="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B" name="After call activity" activiti:assignee="$INITIATOR">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
<modeler:activiti-idm-initiator>true</modeler:activiti-idm-initiator>
</extensionElements>
</userTask>
<sequenceFlow id="sid-0ABF8EBD-4104-42C1-B5EE-BC8DD5D0C2DA" sourceRef="sid-45436C99-B809-4449-A773-E3DCDA74F253" targetRef="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B"/>
<endEvent id="sid-ED852A9C-4DA6-4A47-88B9-835857B44E6A"/>
<sequenceFlow id="sid-9F03602D-75DE-4E34-9438-402F7A7B200E" sourceRef="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B" targetRef="sid-ED852A9C-4DA6-4A47-88B9-835857B44E6A"/>
</process>
<process id="parallel_tasks" name="parallel_tasks" isExecutable="true">
<startEvent id="startEvent1_sub"/>
<sequenceFlow id="sid-62A7653D-4888-43DC-A137-DC4E867A26CD" sourceRef="startEvent1_sub" targetRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6"/>
<parallelGateway id="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6"/>
<userTask id="sid-363E5425-6005-4D44-B2D3-87F8B56950DD" name="A">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
</extensionElements>
</userTask>
<sequenceFlow id="sid-1D38EE85-8F49-4E28-A336-0EC41AE2ADD5" sourceRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6" targetRef="sid-363E5425-6005-4D44-B2D3-87F8B56950DD"/>
<userTask id="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D" name="B">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
</extensionElements>
</userTask>
<sequenceFlow id="sid-3D311008-D9F9-40F3-AD3E-D91910D814AD" sourceRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6" targetRef="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D"/>
<endEvent id="a_end"/>
<sequenceFlow id="sid-B10CF0D5-03B6-4C17-A2E9-25D4DB34BCBF" sourceRef="sid-363E5425-6005-4D44-B2D3-87F8B56950DD" targetRef="a_end"/>
<sequenceFlow id="sid-8951E7EA-0ECB-4954-AD4A-74E6BF6A02E9" sourceRef="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D" targetRef="b_end"/>
<endEvent id="b_end">
<terminateEventDefinition/>
</endEvent>
</process>
</definitions>
\ No newline at end of file
<?xml version='1.0' encoding='UTF-8'?>
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.activiti.org/processdef" xmlns:modeler="http://activiti.com/modeler" modeler:version="1.0en" modeler:exportDateTime="20151105122624969" modeler:modelId="4000" modeler:modelVersion="1" modeler:modelLastUpdated="1446722783163">
<process id="testMiCallActivity" name="testMiCallActivity" isExecutable="true">
<startEvent id="startEvent1"/>
<callActivity id="sid-45436C99-B809-4449-A773-E3DCDA74F253" name="Call activity" calledElement="parallel_tasks">
<multiInstanceLoopCharacteristics isSequential="true">
<loopCardinality>9</loopCardinality>
</multiInstanceLoopCharacteristics>
</callActivity>
<sequenceFlow id="sid-309D0F1D-AA7E-4331-AA94-A16400848DC0" sourceRef="startEvent1" targetRef="sid-45436C99-B809-4449-A773-E3DCDA74F253"/>
<userTask id="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B" name="After call activity" activiti:assignee="$INITIATOR">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
<modeler:activiti-idm-initiator>true</modeler:activiti-idm-initiator>
</extensionElements>
</userTask>
<sequenceFlow id="sid-0ABF8EBD-4104-42C1-B5EE-BC8DD5D0C2DA" sourceRef="sid-45436C99-B809-4449-A773-E3DCDA74F253" targetRef="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B"/>
<endEvent id="sid-ED852A9C-4DA6-4A47-88B9-835857B44E6A"/>
<sequenceFlow id="sid-9F03602D-75DE-4E34-9438-402F7A7B200E" sourceRef="sid-50A98D4E-06A5-4481-B8A1-64DDFFEC3E2B" targetRef="sid-ED852A9C-4DA6-4A47-88B9-835857B44E6A"/>
</process>
<process id="parallel_tasks" name="parallel_tasks" isExecutable="true">
<startEvent id="startEvent1_sub"/>
<sequenceFlow id="sid-62A7653D-4888-43DC-A137-DC4E867A26CD" sourceRef="startEvent1_sub" targetRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6"/>
<parallelGateway id="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6"/>
<userTask id="sid-363E5425-6005-4D44-B2D3-87F8B56950DD" name="A">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
</extensionElements>
</userTask>
<sequenceFlow id="sid-1D38EE85-8F49-4E28-A336-0EC41AE2ADD5" sourceRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6" targetRef="sid-363E5425-6005-4D44-B2D3-87F8B56950DD"/>
<userTask id="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D" name="B">
<extensionElements>
<modeler:allow-send-email>true</modeler:allow-send-email>
</extensionElements>
</userTask>
<sequenceFlow id="sid-3D311008-D9F9-40F3-AD3E-D91910D814AD" sourceRef="sid-90FE0F4A-623F-40EC-A916-150BE2964BD6" targetRef="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D"/>
<endEvent id="a_end"/>
<sequenceFlow id="sid-B10CF0D5-03B6-4C17-A2E9-25D4DB34BCBF" sourceRef="sid-363E5425-6005-4D44-B2D3-87F8B56950DD" targetRef="a_end"/>
<sequenceFlow id="sid-8951E7EA-0ECB-4954-AD4A-74E6BF6A02E9" sourceRef="sid-327D8D79-540C-4D70-90F3-6D3B3863F77D" targetRef="b_end"/>
<endEvent id="b_end">
<terminateEventDefinition/>
</endEvent>
</process>
</definitions>
\ No newline at end of file
......@@ -232,5 +232,5 @@ public interface StencilConstants {
final String PROPERTY_SIGNAL_DEFINITION_NAME = "name";
final String PROPERTY_SIGNAL_DEFINITION_SCOPE = "scope";
final String PROPERTY_TERMINATE_ALL = "terminateAll";
final String PROPERTY_TERMINATE_ALL = "terminateall";
}
......@@ -46,6 +46,7 @@ import org.activiti.bpmn.model.ServiceTask;
import org.activiti.bpmn.model.SignalEventDefinition;
import org.activiti.bpmn.model.StartEvent;
import org.activiti.bpmn.model.SubProcess;
import org.activiti.bpmn.model.TerminateEventDefinition;
import org.activiti.bpmn.model.TimerEventDefinition;
import org.activiti.bpmn.model.UserTask;
import org.activiti.editor.constants.EditorJsonConstants;
......@@ -66,616 +67,620 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
*/
public abstract class BaseBpmnJsonConverter implements EditorJsonConstants, StencilConstants {
protected static final Logger LOGGER = LoggerFactory.getLogger(BaseBpmnJsonConverter.class);
public static final String NAMESPACE = "http://activiti.com/modeler";
protected ObjectMapper objectMapper = new ObjectMapper();
protected ActivityProcessor processor;
protected BpmnModel model;
protected ObjectNode flowElementNode;
protected double subProcessX;
protected double subProcessY;
protected ArrayNode shapesArrayNode;
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
this.model = model;
this.processor = processor;
this.subProcessX = subProcessX;
this.subProcessY = subProcessY;
this.shapesArrayNode = shapesArrayNode;
GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
String stencilId = null;
if (baseElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) baseElement;
if ("mail".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MAIL;
} else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_CAMEL;
} else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MULE;
} else {
stencilId = getStencilId(baseElement);
}
} else {
stencilId = getStencilId(baseElement);
}
flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(),
graphicInfo.getY() - subProcessY + graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
shapesArrayNode.add(flowElementNode);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getName())) {
propertiesNode.put(PROPERTY_NAME, flowElement.getName());
}
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
}
}
convertElementToJson(propertiesNode, baseElement);
protected static final Logger LOGGER = LoggerFactory.getLogger(BaseBpmnJsonConverter.class);
public static final String NAMESPACE = "http://activiti.com/modeler";
protected ObjectMapper objectMapper = new ObjectMapper();
protected ActivityProcessor processor;
protected BpmnModel model;
protected ObjectNode flowElementNode;
protected double subProcessX;
protected double subProcessY;
protected ArrayNode shapesArrayNode;
public void convertToJson(BaseElement baseElement, ActivityProcessor processor, BpmnModel model, FlowElementsContainer container, ArrayNode shapesArrayNode, double subProcessX, double subProcessY) {
this.model = model;
this.processor = processor;
this.subProcessX = subProcessX;
this.subProcessY = subProcessY;
this.shapesArrayNode = shapesArrayNode;
GraphicInfo graphicInfo = model.getGraphicInfo(baseElement.getId());
String stencilId = null;
if (baseElement instanceof ServiceTask) {
ServiceTask serviceTask = (ServiceTask) baseElement;
if ("mail".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MAIL;
} else if ("camel".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_CAMEL;
} else if ("mule".equalsIgnoreCase(serviceTask.getType())) {
stencilId = STENCIL_TASK_MULE;
} else {
stencilId = getStencilId(baseElement);
}
} else {
stencilId = getStencilId(baseElement);
}
flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
flowElementNode = BpmnJsonConverterUtil.createChildShape(baseElement.getId(), stencilId, graphicInfo.getX() - subProcessX + graphicInfo.getWidth(), graphicInfo.getY() - subProcessY
+ graphicInfo.getHeight(), graphicInfo.getX() - subProcessX, graphicInfo.getY() - subProcessY);
shapesArrayNode.add(flowElementNode);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, baseElement.getId());
if (baseElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) baseElement;
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
}
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getName())) {
propertiesNode.put(PROPERTY_NAME, flowElement.getName());
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(flowNode.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
propertiesNode.put(PROPERTY_DOCUMENTATION, flowElement.getDocumentation());
}
}
}
}
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
}
convertElementToJson(propertiesNode, baseElement);
propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
flowElementNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
if (activity.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
if (baseElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) baseElement;
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(sequenceFlow.getId()));
}
for (MessageFlow messageFlow : model.getMessageFlows().values()) {
if (messageFlow.getSourceRef().equals(flowNode.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(messageFlow.getId()));
}
}
}
if (loopDef.isSequential() == false) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
} else {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
}
if (baseElement instanceof Activity) {
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
}
if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
}
if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
}
if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
}
}
}
Activity activity = (Activity) baseElement;
for (BoundaryEvent boundaryEvent : activity.getBoundaryEvents()) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(boundaryEvent.getId()));
}
if (activity instanceof UserTask) {
BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
}
propertiesNode.put(PROPERTY_ASYNCHRONOUS, activity.isAsynchronous());
propertiesNode.put(PROPERTY_EXCLUSIVE, !activity.isNotExclusive());
if (activity.getLoopCharacteristics() != null) {
MultiInstanceLoopCharacteristics loopDef = activity.getLoopCharacteristics();
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality()) || StringUtils.isNotEmpty(loopDef.getInputDataItem()) || StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
if (loopDef.isSequential() == false) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Parallel");
} else {
propertiesNode.put(PROPERTY_MULTIINSTANCE_TYPE, "Sequential");
}
if (StringUtils.isNotEmpty(loopDef.getLoopCardinality())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CARDINALITY, loopDef.getLoopCardinality());
}
if (StringUtils.isNotEmpty(loopDef.getInputDataItem())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_COLLECTION, loopDef.getInputDataItem());
}
if (StringUtils.isNotEmpty(loopDef.getElementVariable())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_VARIABLE, loopDef.getElementVariable());
}
if (StringUtils.isNotEmpty(loopDef.getCompletionCondition())) {
propertiesNode.put(PROPERTY_MULTIINSTANCE_CONDITION, loopDef.getCompletionCondition());
}
}
}
BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, propertiesNode);
if (activity instanceof UserTask) {
BpmnJsonConverterUtil.convertListenersToJson(((UserTask) activity).getTaskListeners(), false, propertiesNode);
}
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
createDataAssociation(dataAssociation, true, activity);
}
BpmnJsonConverterUtil.convertListenersToJson(activity.getExecutionListeners(), true, propertiesNode);
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (model.getFlowElement(dataAssociation.getSourceRef()) != null) {
createDataAssociation(dataAssociation, true, activity);
}
}
}
if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
createDataAssociation(dataAssociation, false, activity);
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
}
}
}
}
if (CollectionUtils.isNotEmpty(activity.getDataOutputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataOutputAssociations()) {
if (model.getFlowElement(dataAssociation.getTargetRef()) != null) {
createDataAssociation(dataAssociation, false, activity);
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
for (Artifact artifact : container.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
}
}
}
}
}
for (Artifact artifact : container.getArtifacts()) {
if (artifact instanceof Association) {
Association association = (Association) artifact;
if (StringUtils.isNotEmpty(association.getSourceRef()) && association.getSourceRef().equals(baseElement.getId())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(association.getId()));
if (baseElement instanceof DataStoreReference) {
for (Process process : model.getProcesses()) {
processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
}
}
}
}
if (baseElement instanceof DataStoreReference) {
for (Process process : model.getProcesses()) {
processDataStoreReferences(process, baseElement.getId(), outgoingArrayNode);
}
flowElementNode.put("outgoing", outgoingArrayNode);
}
flowElementNode.put("outgoing", outgoingArrayNode);
}
protected void processDataStoreReferences(FlowElementsContainer container, String dataStoreReferenceId, ArrayNode outgoingArrayNode) {
for (FlowElement flowElement : container.getFlowElements()) {
if (flowElement instanceof Activity) {
Activity activity = (Activity) flowElement;
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (dataStoreReferenceId.equals(dataAssociation.getSourceRef())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
protected void processDataStoreReferences(FlowElementsContainer container, String dataStoreReferenceId, ArrayNode outgoingArrayNode) {
for (FlowElement flowElement : container.getFlowElements()) {
if (flowElement instanceof Activity) {
Activity activity = (Activity) flowElement;
if (CollectionUtils.isNotEmpty(activity.getDataInputAssociations())) {
for (DataAssociation dataAssociation : activity.getDataInputAssociations()) {
if (dataStoreReferenceId.equals(dataAssociation.getSourceRef())) {
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(dataAssociation.getId()));
}
}
}
} else if (flowElement instanceof SubProcess) {
processDataStoreReferences((SubProcess) flowElement, dataStoreReferenceId, outgoingArrayNode);
}
}
}
} else if (flowElement instanceof SubProcess) {
processDataStoreReferences((SubProcess) flowElement, dataStoreReferenceId, outgoingArrayNode);
}
}
}
protected void createDataAssociation(DataAssociation dataAssociation, boolean incoming, Activity activity) {
String sourceRef = null;
String targetRef = null;
if (incoming) {
sourceRef = dataAssociation.getSourceRef();
targetRef = activity.getId();
} else {
sourceRef = activity.getId();
targetRef = dataAssociation.getTargetRef();
protected void createDataAssociation(DataAssociation dataAssociation, boolean incoming, Activity activity) {
String sourceRef = null;
String targetRef = null;
if (incoming) {
sourceRef = dataAssociation.getSourceRef();
targetRef = activity.getId();
} else {
sourceRef = activity.getId();
targetRef = dataAssociation.getTargetRef();
}
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(dataAssociation.getId(), STENCIL_DATA_ASSOCIATION, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sourceRef).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sourceRef).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
if (model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() > 2) {
for (int i = 1; i < model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() - 1; i++) {
GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(dataAssociation.getId()).get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
}
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(targetRef).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(targetRef).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
flowNode.put("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(targetRef));
flowNode.put("outgoing", outgoingArrayNode);
flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(targetRef));
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, dataAssociation.getId());
flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
ObjectNode flowNode = BpmnJsonConverterUtil.createChildShape(dataAssociation.getId(), STENCIL_DATA_ASSOCIATION, 172, 212, 128, 212);
ArrayNode dockersArrayNode = objectMapper.createArrayNode();
ObjectNode dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(sourceRef).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(sourceRef).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement,
Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
this.processor = processor;
this.model = bpmnModel;
BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
if (StringUtils.isNotEmpty(multiInstanceType) && "none".equalsIgnoreCase(multiInstanceType) == false) {
String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
if ("sequential".equalsIgnoreCase(multiInstanceType)) {
multiInstanceObject.setSequential(true);
} else {
multiInstanceObject.setSequential(false);
}
multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
multiInstanceObject.setInputDataItem(multiInstanceCollection);
multiInstanceObject.setElementVariable(multiInstanceVariable);
multiInstanceObject.setCompletionCondition(multiInstanceCondition);
activity.setLoopCharacteristics(multiInstanceObject);
}
} else if (baseElement instanceof Gateway) {
JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
if (flowOrderNode != null) {
flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
if (orderArray != null && orderArray.size() > 0) {
for (JsonNode orderNode : orderArray) {
ExtensionElement orderElement = new ExtensionElement();
orderElement.setName("EDITOR_FLOW_ORDER");
orderElement.setElementText(orderNode.asText());
flowElement.addExtensionElement(orderElement);
}
}
}
}
}
if (model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() > 2) {
for (int i = 1; i < model.getFlowLocationGraphicInfo(dataAssociation.getId()).size() - 1; i++) {
GraphicInfo graphicInfo = model.getFlowLocationGraphicInfo(dataAssociation.getId()).get(i);
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, graphicInfo.getX());
dockNode.put(EDITOR_BOUNDS_Y, graphicInfo.getY());
dockersArrayNode.add(dockNode);
}
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (flowElement instanceof SequenceFlow) {
ExtensionElement idExtensionElement = new ExtensionElement();
idExtensionElement.setName("EDITOR_RESOURCEID");
idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
flowElement.addExtensionElement(idExtensionElement);
}
if (parentElement instanceof Process) {
((Process) parentElement).addFlowElement(flowElement);
} else if (parentElement instanceof SubProcess) {
((SubProcess) parentElement).addFlowElement(flowElement);
} else if (parentElement instanceof Lane) {
Lane lane = (Lane) parentElement;
lane.getFlowReferences().add(flowElement.getId());
lane.getParentProcess().addFlowElement(flowElement);
}
} else if (baseElement instanceof Artifact) {
Artifact artifact = (Artifact) baseElement;
if (parentElement instanceof Process) {
((Process) parentElement).addArtifact(artifact);
} else if (parentElement instanceof SubProcess) {
((SubProcess) parentElement).addArtifact(artifact);
} else if (parentElement instanceof Lane) {
Lane lane = (Lane) parentElement;
lane.getFlowReferences().add(artifact.getId());
lane.getParentProcess().addArtifact(artifact);
}
}
}
dockNode = objectMapper.createObjectNode();
dockNode.put(EDITOR_BOUNDS_X, model.getGraphicInfo(targetRef).getWidth() / 2.0);
dockNode.put(EDITOR_BOUNDS_Y, model.getGraphicInfo(targetRef).getHeight() / 2.0);
dockersArrayNode.add(dockNode);
flowNode.put("dockers", dockersArrayNode);
ArrayNode outgoingArrayNode = objectMapper.createArrayNode();
outgoingArrayNode.add(BpmnJsonConverterUtil.createResourceNode(targetRef));
flowNode.put("outgoing", outgoingArrayNode);
flowNode.put("target", BpmnJsonConverterUtil.createResourceNode(targetRef));
protected abstract void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement);
ObjectNode propertiesNode = objectMapper.createObjectNode();
propertiesNode.put(PROPERTY_OVERRIDE_ID, dataAssociation.getId());
protected abstract BaseElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap);
flowNode.put(EDITOR_SHAPE_PROPERTIES, propertiesNode);
shapesArrayNode.add(flowNode);
}
protected abstract String getStencilId(BaseElement baseElement);
public void convertToBpmnModel(JsonNode elementNode, JsonNode modelNode, ActivityProcessor processor, BaseElement parentElement, Map<String, JsonNode> shapeMap, BpmnModel bpmnModel) {
protected void setPropertyValue(String name, String value, ObjectNode propertiesNode) {
if (StringUtils.isNotEmpty(value)) {
propertiesNode.put(name, value);
}
}
this.processor = processor;
this.model = bpmnModel;
protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
if (CollectionUtils.isEmpty(formProperties))
return;
ObjectNode formPropertiesNode = objectMapper.createObjectNode();
ArrayNode propertiesArrayNode = objectMapper.createArrayNode();
for (FormProperty property : formProperties) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
if (StringUtils.isNotEmpty(property.getExpression())) {
propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
} else {
propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
}
if (StringUtils.isNotEmpty(property.getVariable())) {
propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
} else {
propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
}
if (StringUtils.isNotEmpty(property.getDatePattern())) {
propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern());
}
if (CollectionUtils.isNotEmpty(property.getFormValues())) {
ArrayNode valuesNode = objectMapper.createArrayNode();
for (FormValue formValue : property.getFormValues()) {
ObjectNode valueNode = objectMapper.createObjectNode();
valueNode.put("value", formValue.getName());
valuesNode.add(valueNode);
}
propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
}
propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired());
propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable());
propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable());
BaseElement baseElement = convertJsonToElement(elementNode, modelNode, shapeMap);
baseElement.setId(BpmnJsonConverterUtil.getElementId(elementNode));
propertiesArrayNode.add(propertyItemNode);
}
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
flowElement.setName(getPropertyValueAsString(PROPERTY_NAME, elementNode));
flowElement.setDocumentation(getPropertyValueAsString(PROPERTY_DOCUMENTATION, elementNode));
formPropertiesNode.put("formProperties", propertiesArrayNode);
propertiesNode.put(PROPERTY_FORM_PROPERTIES, formPropertiesNode);
}
BpmnJsonConverterUtil.convertJsonToListeners(elementNode, flowElement);
protected void addFieldExtensions(List<FieldExtension> extensions, ObjectNode propertiesNode) {
ObjectNode fieldExtensionsNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
for (FieldExtension extension : extensions) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_NAME, extension.getFieldName());
if (StringUtils.isNotEmpty(extension.getStringValue())) {
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_STRING_VALUE, extension.getStringValue());
}
if (StringUtils.isNotEmpty(extension.getExpression())) {
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_EXPRESSION, extension.getExpression());
}
itemsNode.add(propertyItemNode);
}
if (baseElement instanceof Activity) {
Activity activity = (Activity) baseElement;
activity.setAsynchronous(getPropertyValueAsBoolean(PROPERTY_ASYNCHRONOUS, elementNode));
activity.setNotExclusive(!getPropertyValueAsBoolean(PROPERTY_EXCLUSIVE, elementNode));
fieldExtensionsNode.put("fields", itemsNode);
propertiesNode.put(PROPERTY_SERVICETASK_FIELDS, fieldExtensionsNode);
}
String multiInstanceType = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_TYPE, elementNode);
String multiInstanceCardinality = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CARDINALITY, elementNode);
String multiInstanceCollection = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_COLLECTION, elementNode);
String multiInstanceCondition = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_CONDITION, elementNode);
protected void addEventProperties(Event event, ObjectNode propertiesNode) {
List<EventDefinition> eventDefinitions = event.getEventDefinitions();
if (eventDefinitions.size() == 1) {
if (StringUtils.isNotEmpty(multiInstanceType) && "none".equalsIgnoreCase(multiInstanceType) == false) {
EventDefinition eventDefinition = eventDefinitions.get(0);
if (eventDefinition instanceof ErrorEventDefinition) {
ErrorEventDefinition errorDefinition = (ErrorEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(errorDefinition.getErrorCode())) {
propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorCode());
}
String multiInstanceVariable = getPropertyValueAsString(PROPERTY_MULTIINSTANCE_VARIABLE, elementNode);
} else if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalDefinition = (SignalEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(signalDefinition.getSignalRef())) {
propertiesNode.put(PROPERTY_SIGNALREF, signalDefinition.getSignalRef());
}
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) {
propertiesNode.put(PROPERTY_MESSAGEREF, messageDefinition.getMessageRef());
}
MultiInstanceLoopCharacteristics multiInstanceObject = new MultiInstanceLoopCharacteristics();
if ("sequential".equalsIgnoreCase(multiInstanceType)) {
multiInstanceObject.setSequential(true);
} else {
multiInstanceObject.setSequential(false);
}
multiInstanceObject.setLoopCardinality(multiInstanceCardinality);
multiInstanceObject.setInputDataItem(multiInstanceCollection);
multiInstanceObject.setElementVariable(multiInstanceVariable);
multiInstanceObject.setCompletionCondition(multiInstanceCondition);
activity.setLoopCharacteristics(multiInstanceObject);
} else if (eventDefinition instanceof TimerEventDefinition) {
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) {
propertiesNode.put(PROPERTY_TIMER_DURATON, timerDefinition.getTimeDuration());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE, timerDefinition.getTimeCycle());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) {
propertiesNode.put(PROPERTY_TIMER_DATE, timerDefinition.getTimeDate());
}
if (StringUtils.isNotEmpty(timerDefinition.getEndDate())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE_END_DATE, timerDefinition.getEndDate());
}
} else if (eventDefinition instanceof TerminateEventDefinition) {
TerminateEventDefinition terminateEventDefinition = (TerminateEventDefinition) eventDefinition;
propertiesNode.put(PROPERTY_TERMINATE_ALL, terminateEventDefinition.isTerminateAll());
}
}
}
} else if (baseElement instanceof Gateway) {
JsonNode flowOrderNode = getProperty(PROPERTY_SEQUENCEFLOW_ORDER, elementNode);
if (flowOrderNode != null) {
flowOrderNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(flowOrderNode);
JsonNode orderArray = flowOrderNode.get("sequenceFlowOrder");
if (orderArray != null && orderArray.size() > 0) {
for (JsonNode orderNode : orderArray) {
ExtensionElement orderElement = new ExtensionElement();
orderElement.setName("EDITOR_FLOW_ORDER");
orderElement.setElementText(orderNode.asText());
flowElement.addExtensionElement(orderElement);
protected void convertJsonToFormProperties(JsonNode objectNode, BaseElement element) {
JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
if (formPropertiesNode != null) {
formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
JsonNode propertiesArray = formPropertiesNode.get("formProperties");
if (propertiesArray != null) {
for (JsonNode formNode : propertiesArray) {
JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
FormProperty formProperty = new FormProperty();
formProperty.setId(formIdNode.asText());
formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
if ("date".equalsIgnoreCase(formProperty.getType())) {
formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
} else if ("enum".equalsIgnoreCase(formProperty.getType())) {
JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
if (enumValuesNode != null) {
List<FormValue> formValueList = new ArrayList<FormValue>();
for (JsonNode enumNode : enumValuesNode) {
if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);
}
}
formProperty.setFormValues(formValueList);
}
}
formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
if (element instanceof StartEvent) {
((StartEvent) element).getFormProperties().add(formProperty);
} else if (element instanceof UserTask) {
((UserTask) element).getFormProperties().add(formProperty);
}
}
}
}
}
}
}
}
if (baseElement instanceof FlowElement) {
FlowElement flowElement = (FlowElement) baseElement;
if (flowElement instanceof SequenceFlow) {
ExtensionElement idExtensionElement = new ExtensionElement();
idExtensionElement.setName("EDITOR_RESOURCEID");
idExtensionElement.setElementText(elementNode.get(EDITOR_SHAPE_ID).asText());
flowElement.addExtensionElement(idExtensionElement);
}
if (parentElement instanceof Process) {
((Process) parentElement).addFlowElement(flowElement);
} else if (parentElement instanceof SubProcess) {
((SubProcess) parentElement).addFlowElement(flowElement);
} else if (parentElement instanceof Lane) {
Lane lane = (Lane) parentElement;
lane.getFlowReferences().add(flowElement.getId());
lane.getParentProcess().addFlowElement(flowElement);
}
} else if (baseElement instanceof Artifact) {
Artifact artifact = (Artifact) baseElement;
if (parentElement instanceof Process) {
((Process) parentElement).addArtifact(artifact);
} else if (parentElement instanceof SubProcess) {
((SubProcess) parentElement).addArtifact(artifact);
} else if (parentElement instanceof Lane) {
Lane lane = (Lane) parentElement;
lane.getFlowReferences().add(artifact.getId());
lane.getParentProcess().addArtifact(artifact);
}
}
}
protected void convertJsonToTimerDefinition(JsonNode objectNode, Event event) {
protected abstract void convertElementToJson(ObjectNode propertiesNode, BaseElement baseElement);
String timeDate = getPropertyValueAsString(PROPERTY_TIMER_DATE, objectNode);
String timeCycle = getPropertyValueAsString(PROPERTY_TIMER_CYCLE, objectNode);
String timeDuration = getPropertyValueAsString(PROPERTY_TIMER_DURATON, objectNode);
String endDate = getPropertyValueAsString(PROPERTY_TIMER_CYCLE_END_DATE, objectNode);
protected abstract BaseElement convertJsonToElement(JsonNode elementNode, JsonNode modelNode, Map<String, JsonNode> shapeMap);
TimerEventDefinition eventDefinition = new TimerEventDefinition();
if (StringUtils.isNotEmpty(timeDate)) {
eventDefinition.setTimeDate(timeDate);
protected abstract String getStencilId(BaseElement baseElement);
} else if (StringUtils.isNotEmpty(timeCycle)) {
eventDefinition.setTimeCycle(timeCycle);
protected void setPropertyValue(String name, String value, ObjectNode propertiesNode) {
if (StringUtils.isNotEmpty(value)) {
propertiesNode.put(name, value);
}
}
protected void addFormProperties(List<FormProperty> formProperties, ObjectNode propertiesNode) {
if (CollectionUtils.isEmpty(formProperties))
return;
ObjectNode formPropertiesNode = objectMapper.createObjectNode();
ArrayNode propertiesArrayNode = objectMapper.createArrayNode();
for (FormProperty property : formProperties) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_FORM_ID, property.getId());
propertyItemNode.put(PROPERTY_FORM_NAME, property.getName());
propertyItemNode.put(PROPERTY_FORM_TYPE, property.getType());
if (StringUtils.isNotEmpty(property.getExpression())) {
propertyItemNode.put(PROPERTY_FORM_EXPRESSION, property.getExpression());
} else {
propertyItemNode.putNull(PROPERTY_FORM_EXPRESSION);
}
if (StringUtils.isNotEmpty(property.getVariable())) {
propertyItemNode.put(PROPERTY_FORM_VARIABLE, property.getVariable());
} else {
propertyItemNode.putNull(PROPERTY_FORM_VARIABLE);
}
if (StringUtils.isNotEmpty(property.getDatePattern())) {
propertyItemNode.put(PROPERTY_FORM_DATE_PATTERN, property.getDatePattern());
}
if (CollectionUtils.isNotEmpty(property.getFormValues())) {
ArrayNode valuesNode = objectMapper.createArrayNode();
for (FormValue formValue : property.getFormValues()) {
ObjectNode valueNode = objectMapper.createObjectNode();
valueNode.put("value", formValue.getName());
valuesNode.add(valueNode);
} else if (StringUtils.isNotEmpty(timeDuration)) {
eventDefinition.setTimeDuration(timeDuration);
}
if (StringUtils.isNotEmpty(endDate)) {
eventDefinition.setEndDate(endDate);
}
propertyItemNode.put(PROPERTY_FORM_ENUM_VALUES, valuesNode);
}
propertyItemNode.put(PROPERTY_FORM_REQUIRED, property.isRequired());
propertyItemNode.put(PROPERTY_FORM_READABLE, property.isReadable());
propertyItemNode.put(PROPERTY_FORM_WRITABLE, property.isWriteable());
propertiesArrayNode.add(propertyItemNode);
event.getEventDefinitions().add(eventDefinition);
}
formPropertiesNode.put("formProperties", propertiesArrayNode);
propertiesNode.put(PROPERTY_FORM_PROPERTIES, formPropertiesNode);
}
protected void addFieldExtensions(List<FieldExtension> extensions, ObjectNode propertiesNode) {
ObjectNode fieldExtensionsNode = objectMapper.createObjectNode();
ArrayNode itemsNode = objectMapper.createArrayNode();
for (FieldExtension extension : extensions) {
ObjectNode propertyItemNode = objectMapper.createObjectNode();
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_NAME, extension.getFieldName());
if (StringUtils.isNotEmpty(extension.getStringValue())) {
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_STRING_VALUE, extension.getStringValue());
}
if (StringUtils.isNotEmpty(extension.getExpression())) {
propertyItemNode.put(PROPERTY_SERVICETASK_FIELD_EXPRESSION, extension.getExpression());
}
itemsNode.add(propertyItemNode);
protected void convertJsonToSignalDefinition(JsonNode objectNode, Event event) {
String signalRef = getPropertyValueAsString(PROPERTY_SIGNALREF, objectNode);
SignalEventDefinition eventDefinition = new SignalEventDefinition();
eventDefinition.setSignalRef(signalRef);
event.getEventDefinitions().add(eventDefinition);
}
fieldExtensionsNode.put("fields", itemsNode);
propertiesNode.put(PROPERTY_SERVICETASK_FIELDS, fieldExtensionsNode);
}
protected void convertJsonToMessageDefinition(JsonNode objectNode, Event event) {
String messageRef = getPropertyValueAsString(PROPERTY_MESSAGEREF, objectNode);
MessageEventDefinition eventDefinition = new MessageEventDefinition();
eventDefinition.setMessageRef(messageRef);
event.getEventDefinitions().add(eventDefinition);
}
protected void addEventProperties(Event event, ObjectNode propertiesNode) {
List<EventDefinition> eventDefinitions = event.getEventDefinitions();
if (eventDefinitions.size() == 1) {
protected void convertJsonToErrorDefinition(JsonNode objectNode, Event event) {
String errorRef = getPropertyValueAsString(PROPERTY_ERRORREF, objectNode);
ErrorEventDefinition eventDefinition = new ErrorEventDefinition();
eventDefinition.setErrorCode(errorRef);
event.getEventDefinitions().add(eventDefinition);
}
EventDefinition eventDefinition = eventDefinitions.get(0);
if (eventDefinition instanceof ErrorEventDefinition) {
ErrorEventDefinition errorDefinition = (ErrorEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(errorDefinition.getErrorCode())) {
propertiesNode.put(PROPERTY_ERRORREF, errorDefinition.getErrorCode());
protected String getValueAsString(String name, JsonNode objectNode) {
String propertyValue = null;
JsonNode propertyNode = objectNode.get(name);
if (propertyNode != null && propertyNode.isNull() == false) {
propertyValue = propertyNode.asText();
}
return propertyValue;
}
} else if (eventDefinition instanceof SignalEventDefinition) {
SignalEventDefinition signalDefinition = (SignalEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(signalDefinition.getSignalRef())) {
propertiesNode.put(PROPERTY_SIGNALREF, signalDefinition.getSignalRef());
protected boolean getValueAsBoolean(String name, JsonNode objectNode) {
boolean propertyValue = false;
JsonNode propertyNode = objectNode.get(name);
if (propertyNode != null && propertyNode.isNull() == false) {
propertyValue = propertyNode.asBoolean();
}
return propertyValue;
}
} else if (eventDefinition instanceof MessageEventDefinition) {
MessageEventDefinition messageDefinition = (MessageEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(messageDefinition.getMessageRef())) {
propertiesNode.put(PROPERTY_MESSAGEREF, messageDefinition.getMessageRef());
protected List<String> getValueAsList(String name, JsonNode objectNode) {
List<String> resultList = new ArrayList<String>();
JsonNode valuesNode = objectNode.get(name);
if (valuesNode != null) {
for (JsonNode valueNode : valuesNode) {
if (valueNode.get("value") != null && valueNode.get("value").isNull() == false) {
resultList.add(valueNode.get("value").asText());
}
}
}
return resultList;
}
} else if (eventDefinition instanceof TimerEventDefinition) {
TimerEventDefinition timerDefinition = (TimerEventDefinition) eventDefinition;
if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) {
propertiesNode.put(PROPERTY_TIMER_DURATON, timerDefinition.getTimeDuration());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE, timerDefinition.getTimeCycle());
}
if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) {
propertiesNode.put(PROPERTY_TIMER_DATE, timerDefinition.getTimeDate());
}
if (StringUtils.isNotEmpty(timerDefinition.getEndDate())) {
propertiesNode.put(PROPERTY_TIMER_CYCLE_END_DATE, timerDefinition.getEndDate());
protected void addField(String name, JsonNode elementNode, ServiceTask task) {
FieldExtension field = new FieldExtension();
field.setFieldName(name.substring(8));
String value = getPropertyValueAsString(name, elementNode);
if (StringUtils.isNotEmpty(value)) {
if ((value.contains("${") || value.contains("#{")) && value.contains("}")) {
field.setExpression(value);
} else {
field.setStringValue(value);
}
task.getFieldExtensions().add(field);
}
}
}
}
protected void convertJsonToFormProperties(JsonNode objectNode, BaseElement element) {
JsonNode formPropertiesNode = getProperty(PROPERTY_FORM_PROPERTIES, objectNode);
if (formPropertiesNode != null) {
formPropertiesNode = BpmnJsonConverterUtil.validateIfNodeIsTextual(formPropertiesNode);
JsonNode propertiesArray = formPropertiesNode.get("formProperties");
if (propertiesArray != null) {
for (JsonNode formNode : propertiesArray) {
JsonNode formIdNode = formNode.get(PROPERTY_FORM_ID);
if (formIdNode != null && StringUtils.isNotEmpty(formIdNode.asText())) {
FormProperty formProperty = new FormProperty();
formProperty.setId(formIdNode.asText());
formProperty.setName(getValueAsString(PROPERTY_FORM_NAME, formNode));
formProperty.setType(getValueAsString(PROPERTY_FORM_TYPE, formNode));
formProperty.setExpression(getValueAsString(PROPERTY_FORM_EXPRESSION, formNode));
formProperty.setVariable(getValueAsString(PROPERTY_FORM_VARIABLE, formNode));
if ("date".equalsIgnoreCase(formProperty.getType())) {
formProperty.setDatePattern(getValueAsString(PROPERTY_FORM_DATE_PATTERN, formNode));
} else if ("enum".equalsIgnoreCase(formProperty.getType())) {
JsonNode enumValuesNode = formNode.get(PROPERTY_FORM_ENUM_VALUES);
if (enumValuesNode != null) {
List<FormValue> formValueList = new ArrayList<FormValue>();
for (JsonNode enumNode : enumValuesNode) {
if (enumNode.get("value") != null && enumNode.get("value").isNull() == false) {
FormValue formValue = new FormValue();
formValue.setId(enumNode.get("value").asText());
formValue.setName(enumNode.get("value").asText());
formValueList.add(formValue);
}
}
formProperty.setFormValues(formValueList);
}
protected void addField(String name, String propertyName, JsonNode elementNode, ServiceTask task) {
FieldExtension field = new FieldExtension();
field.setFieldName(name);
String value = getPropertyValueAsString(propertyName, elementNode);
if (StringUtils.isNotEmpty(value)) {
if ((value.contains("${") || value.contains("#{")) && value.contains("}")) {
field.setExpression(value);
} else {
field.setStringValue(value);
}
formProperty.setRequired(getValueAsBoolean(PROPERTY_FORM_REQUIRED, formNode));
formProperty.setReadable(getValueAsBoolean(PROPERTY_FORM_READABLE, formNode));
formProperty.setWriteable(getValueAsBoolean(PROPERTY_FORM_WRITABLE, formNode));
if (element instanceof StartEvent) {
((StartEvent) element).getFormProperties().add(formProperty);
} else if (element instanceof UserTask) {
((UserTask) element).getFormProperties().add(formProperty);
}
}
task.getFieldExtensions().add(field);
}
}
}
}
protected void convertJsonToTimerDefinition(JsonNode objectNode, Event event) {
String timeDate = getPropertyValueAsString(PROPERTY_TIMER_DATE, objectNode);
String timeCycle = getPropertyValueAsString(PROPERTY_TIMER_CYCLE, objectNode);
String timeDuration = getPropertyValueAsString(PROPERTY_TIMER_DURATON, objectNode);
String endDate = getPropertyValueAsString(PROPERTY_TIMER_CYCLE_END_DATE, objectNode);
TimerEventDefinition eventDefinition = new TimerEventDefinition();
if (StringUtils.isNotEmpty(timeDate)) {
eventDefinition.setTimeDate(timeDate);
} else if (StringUtils.isNotEmpty(timeCycle)) {
eventDefinition.setTimeCycle(timeCycle);
} else if (StringUtils.isNotEmpty(timeDuration)) {
eventDefinition.setTimeDuration(timeDuration);
protected String getPropertyValueAsString(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsString(name, objectNode);
}
if (StringUtils.isNotEmpty(endDate)) {
eventDefinition.setEndDate(endDate);
protected boolean getPropertyValueAsBoolean(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsBoolean(name, objectNode);
}
event.getEventDefinitions().add(eventDefinition);
}
protected void convertJsonToSignalDefinition(JsonNode objectNode, Event event) {
String signalRef = getPropertyValueAsString(PROPERTY_SIGNALREF, objectNode);
SignalEventDefinition eventDefinition = new SignalEventDefinition();
eventDefinition.setSignalRef(signalRef);
event.getEventDefinitions().add(eventDefinition);
}
protected void convertJsonToMessageDefinition(JsonNode objectNode, Event event) {
String messageRef = getPropertyValueAsString(PROPERTY_MESSAGEREF, objectNode);
MessageEventDefinition eventDefinition = new MessageEventDefinition();
eventDefinition.setMessageRef(messageRef);
event.getEventDefinitions().add(eventDefinition);
}
protected void convertJsonToErrorDefinition(JsonNode objectNode, Event event) {
String errorRef = getPropertyValueAsString(PROPERTY_ERRORREF, objectNode);
ErrorEventDefinition eventDefinition = new ErrorEventDefinition();
eventDefinition.setErrorCode(errorRef);
event.getEventDefinitions().add(eventDefinition);
}
protected String getValueAsString(String name, JsonNode objectNode) {
String propertyValue = null;
JsonNode propertyNode = objectNode.get(name);
if (propertyNode != null && propertyNode.isNull() == false) {
propertyValue = propertyNode.asText();
}
return propertyValue;
}
protected boolean getValueAsBoolean(String name, JsonNode objectNode) {
boolean propertyValue = false;
JsonNode propertyNode = objectNode.get(name);
if (propertyNode != null && propertyNode.isNull() == false) {
propertyValue = propertyNode.asBoolean();
protected List<String> getPropertyValueAsList(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsList(name, objectNode);
}
return propertyValue;
}
protected List<String> getValueAsList(String name, JsonNode objectNode) {
List<String> resultList = new ArrayList<String>();
JsonNode valuesNode = objectNode.get(name);
if (valuesNode != null) {
for (JsonNode valueNode : valuesNode) {
if (valueNode.get("value") != null && valueNode.get("value").isNull() == false) {
resultList.add(valueNode.get("value").asText());
}
}
}
return resultList;
}
protected void addField(String name, JsonNode elementNode, ServiceTask task) {
FieldExtension field = new FieldExtension();
field.setFieldName(name.substring(8));
String value = getPropertyValueAsString(name, elementNode);
if (StringUtils.isNotEmpty(value)) {
if ((value.contains("${") || value.contains("#{")) && value.contains("}")) {
field.setExpression(value);
} else {
field.setStringValue(value);
}
task.getFieldExtensions().add(field);
}
}
protected void addField(String name, String propertyName, JsonNode elementNode, ServiceTask task) {
FieldExtension field = new FieldExtension();
field.setFieldName(name);
String value = getPropertyValueAsString(propertyName, elementNode);
if (StringUtils.isNotEmpty(value)) {
if ((value.contains("${") || value.contains("#{")) && value.contains("}")) {
field.setExpression(value);
} else {
field.setStringValue(value);
}
task.getFieldExtensions().add(field);
protected JsonNode getProperty(String name, JsonNode objectNode) {
return JsonConverterUtil.getProperty(name, objectNode);
}
}
protected String getPropertyValueAsString(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsString(name, objectNode);
}
protected boolean getPropertyValueAsBoolean(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsBoolean(name, objectNode);
}
protected List<String> getPropertyValueAsList(String name, JsonNode objectNode) {
return JsonConverterUtil.getPropertyValueAsList(name, objectNode);
}
protected JsonNode getProperty(String name, JsonNode objectNode) {
return JsonConverterUtil.getProperty(name, objectNode);
}
protected String convertListToCommaSeparatedString(List<String> stringList) {
String resultString = null;
if (stringList != null && stringList.size() > 0) {
StringBuilder expressionBuilder = new StringBuilder();
for (String singleItem : stringList) {
if (expressionBuilder.length() > 0) {
expressionBuilder.append(",");
protected String convertListToCommaSeparatedString(List<String> stringList) {
String resultString = null;
if (stringList != null && stringList.size() > 0) {
StringBuilder expressionBuilder = new StringBuilder();
for (String singleItem : stringList) {
if (expressionBuilder.length() > 0) {
expressionBuilder.append(",");
}
expressionBuilder.append(singleItem);
}
resultString = expressionBuilder.toString();
}
expressionBuilder.append(singleItem);
}
resultString = expressionBuilder.toString();
return resultString;
}
return resultString;
}
}
......@@ -831,6 +831,34 @@ Note that the _errorRef_ must comply with the BPMN 2.0 schema, and must be a val
[[bpmnCancelEndEvent]]
==== Terminate End Event
===== Description
When a _terminate end event_ is reached, the current process instance or sub-process will be terminated. Conceptually, when an execution arrives in a terminate end event, the first _scope_ (process or sub-process) will be determined and ended. Note that in BPMN 2.0, a sub-process can be an embedded sub-process, call activity, event sub-process or transaction sub-process. This rule applies in general: when for example there is a multi-instance call activity or embedded subprocess, only that instance will be ended, the other instances and the process instance are not affected.
There is an optional attribute _terminateAll_ that can be added. When _true_, regardless of the placement of the terminate end event in the process definition and regardless of being in a sub-process (even nested), the (root) process instance will be terminated.
===== Graphical notation
A cancel end event visualized as a typical end event (circle with thick outline), with a full black circle inside.
image::images/bpmn.terminate.end.event.png[align="center"]
===== XML representation
A terminate end event is represented as an end event, with a _terminateEventDefinition_ child element.
Note that the _terminateAll_ attribute is optional (and _false_ by default).
[source,xml,linenums]
----
<endEvent id="myEndEvent >
<terminateEventDefinition activiti:terminateAll="true"></terminateEventDefinition>
</endEvent>
----
==== Cancel End Event
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册