use of org.activiti.bpmn.model.BaseElement in project Activiti by Activiti.
the class FeedbackStepDefinitionConverter method createProcessArtifact.
@Override
protected Map<String, BaseElement> createProcessArtifact(FeedbackStepDefinition feedbackStepDefinition, WorkflowDefinitionConversion conversion) {
// See feedback-step.png in the resource folder to get a graphical understanding of the conversion below
Map<String, BaseElement> processElements = new HashMap<String, BaseElement>();
// The first user task, responsible for configuring the feedback
UserTask selectPeopleUserTask = createSelectPeopleUserTask(feedbackStepDefinition, conversion, processElements);
// Parallel gateways (forking/joining)
ParallelGateway fork = createForkParallelGateway(conversion, processElements);
addSequenceFlow(conversion, selectPeopleUserTask, fork);
// Gather feedback user task for the initiator of the feedback step
UserTask gatherFeedbackUserTask = createGatherFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
addSequenceFlow(conversion, fork, gatherFeedbackUserTask);
// Global signal event
Signal signal = createSignalDeclaration(conversion);
// Signal throw event after the gather feedback task
ThrowEvent signalThrowEvent = createSignalThrow(conversion, signal);
addSequenceFlow(conversion, gatherFeedbackUserTask, signalThrowEvent);
// Povide feedback step
UserTask feedbackTask = createFeedbackUserTask(feedbackStepDefinition, conversion, processElements);
addSequenceFlow(conversion, fork, feedbackTask);
// Boundary signal catch to shut down all tasks if the 'gather feedback' task is completed
BoundaryEvent boundarySignalCatch = createBoundarySignalCatch(conversion, signal, feedbackTask);
// Exclusive gateway after the feedback task, needed to correctly merge the sequence flow
// such that the joining parallel gateway has exactly two incoming sequence flow
ExclusiveGateway mergingExclusiveGateway = createMergingExclusiveGateway(conversion);
addSequenceFlow(conversion, feedbackTask, mergingExclusiveGateway);
addSequenceFlow(conversion, boundarySignalCatch, mergingExclusiveGateway);
// Parallel gateway that will join it all together
ParallelGateway join = createJoinParallelGateway(conversion, processElements);
addSequenceFlow(conversion, signalThrowEvent, join);
addSequenceFlow(conversion, mergingExclusiveGateway, join);
// Set the last activity id, such that next steps can connect correctly
conversion.setLastActivityId(join.getId());
return processElements;
}
use of org.activiti.bpmn.model.BaseElement in project Activiti by Activiti.
the class BpmnXMLConverter method convertToBpmnModel.
public BpmnModel convertToBpmnModel(XMLStreamReader xtr) {
BpmnModel model = new BpmnModel();
model.setStartEventFormTypes(startEventFormTypes);
model.setUserTaskFormTypes(userTaskFormTypes);
try {
Process activeProcess = null;
List<SubProcess> activeSubProcessList = new ArrayList<SubProcess>();
while (xtr.hasNext()) {
try {
xtr.next();
} catch (Exception e) {
LOGGER.debug("Error reading XML document", e);
throw new XMLException("Error reading XML", e);
}
if (xtr.isEndElement() && ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
activeSubProcessList.remove(activeSubProcessList.size() - 1);
}
if (xtr.isEndElement() && ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
activeSubProcessList.remove(activeSubProcessList.size() - 1);
}
if (xtr.isStartElement() == false) {
continue;
}
if (ELEMENT_DEFINITIONS.equals(xtr.getLocalName())) {
definitionsParser.parse(xtr, model);
} else if (ELEMENT_RESOURCE.equals(xtr.getLocalName())) {
resourceParser.parse(xtr, model);
} else if (ELEMENT_SIGNAL.equals(xtr.getLocalName())) {
signalParser.parse(xtr, model);
} else if (ELEMENT_MESSAGE.equals(xtr.getLocalName())) {
messageParser.parse(xtr, model);
} else if (ELEMENT_ERROR.equals(xtr.getLocalName())) {
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_ID))) {
model.addError(xtr.getAttributeValue(null, ATTRIBUTE_ID), xtr.getAttributeValue(null, ATTRIBUTE_ERROR_CODE));
}
} else if (ELEMENT_IMPORT.equals(xtr.getLocalName())) {
importParser.parse(xtr, model);
} else if (ELEMENT_ITEM_DEFINITION.equals(xtr.getLocalName())) {
itemDefinitionParser.parse(xtr, model);
} else if (ELEMENT_DATA_STORE.equals(xtr.getLocalName())) {
dataStoreParser.parse(xtr, model);
} else if (ELEMENT_INTERFACE.equals(xtr.getLocalName())) {
interfaceParser.parse(xtr, model);
} else if (ELEMENT_IOSPECIFICATION.equals(xtr.getLocalName())) {
ioSpecificationParser.parseChildElement(xtr, activeProcess, model);
} else if (ELEMENT_PARTICIPANT.equals(xtr.getLocalName())) {
participantParser.parse(xtr, model);
} else if (ELEMENT_MESSAGE_FLOW.equals(xtr.getLocalName())) {
messageFlowParser.parse(xtr, model);
} else if (ELEMENT_PROCESS.equals(xtr.getLocalName())) {
Process process = processParser.parse(xtr, model);
if (process != null) {
activeProcess = process;
}
} else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
potentialStarterParser.parse(xtr, activeProcess);
} else if (ELEMENT_LANE.equals(xtr.getLocalName())) {
laneParser.parse(xtr, activeProcess, model);
} else if (ELEMENT_DOCUMENTATION.equals(xtr.getLocalName())) {
BaseElement parentElement = null;
if (!activeSubProcessList.isEmpty()) {
parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
} else if (activeProcess != null) {
parentElement = activeProcess;
}
documentationParser.parseChildElement(xtr, parentElement, model);
} else if (activeProcess == null && ELEMENT_TEXT_ANNOTATION.equals(xtr.getLocalName())) {
String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
TextAnnotation textAnnotation = (TextAnnotation) new TextAnnotationXMLConverter().convertXMLToElement(xtr, model);
textAnnotation.setId(elementId);
model.getGlobalArtifacts().add(textAnnotation);
} else if (activeProcess == null && ELEMENT_ASSOCIATION.equals(xtr.getLocalName())) {
String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
Association association = (Association) new AssociationXMLConverter().convertXMLToElement(xtr, model);
association.setId(elementId);
model.getGlobalArtifacts().add(association);
} else if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
extensionElementsParser.parse(xtr, activeSubProcessList, activeProcess, model);
} else if (ELEMENT_SUBPROCESS.equals(xtr.getLocalName())) {
subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
} else if (ELEMENT_TRANSACTION.equals(xtr.getLocalName())) {
subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
} else if (ELEMENT_DI_SHAPE.equals(xtr.getLocalName())) {
bpmnShapeParser.parse(xtr, model);
} else if (ELEMENT_DI_EDGE.equals(xtr.getLocalName())) {
bpmnEdgeParser.parse(xtr, model);
} else {
if (!activeSubProcessList.isEmpty() && ELEMENT_MULTIINSTANCE.equalsIgnoreCase(xtr.getLocalName())) {
multiInstanceParser.parseChildElement(xtr, activeSubProcessList.get(activeSubProcessList.size() - 1), model);
} else if (convertersToBpmnMap.containsKey(xtr.getLocalName())) {
if (activeProcess != null) {
BaseBpmnXMLConverter converter = convertersToBpmnMap.get(xtr.getLocalName());
converter.convertToBpmnModel(xtr, model, activeProcess, activeSubProcessList);
}
}
}
}
for (Process process : model.getProcesses()) {
for (Pool pool : model.getPools()) {
if (process.getId().equals(pool.getProcessRef())) {
pool.setExecutable(process.isExecutable());
}
}
processFlowElements(process.getFlowElements(), process);
}
} catch (XMLException e) {
throw e;
} catch (Exception e) {
LOGGER.error("Error processing BPMN document", e);
throw new XMLException("Error processing BPMN document", e);
}
return model;
}
use of org.activiti.bpmn.model.BaseElement in project Activiti by Activiti.
the class BaseBpmnXMLConverter method convertToBpmnModel.
public void convertToBpmnModel(XMLStreamReader xtr, BpmnModel model, Process activeProcess, List<SubProcess> activeSubProcessList) throws Exception {
String elementId = xtr.getAttributeValue(null, ATTRIBUTE_ID);
String elementName = xtr.getAttributeValue(null, ATTRIBUTE_NAME);
boolean async = parseAsync(xtr);
boolean notExclusive = parseNotExclusive(xtr);
String defaultFlow = xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT);
boolean isForCompensation = parseForCompensation(xtr);
BaseElement parsedElement = convertXMLToElement(xtr, model);
if (parsedElement instanceof Artifact) {
Artifact currentArtifact = (Artifact) parsedElement;
currentArtifact.setId(elementId);
if (!activeSubProcessList.isEmpty()) {
activeSubProcessList.get(activeSubProcessList.size() - 1).addArtifact(currentArtifact);
} else {
activeProcess.addArtifact(currentArtifact);
}
}
if (parsedElement instanceof FlowElement) {
FlowElement currentFlowElement = (FlowElement) parsedElement;
currentFlowElement.setId(elementId);
currentFlowElement.setName(elementName);
if (currentFlowElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) currentFlowElement;
flowNode.setAsynchronous(async);
flowNode.setNotExclusive(notExclusive);
if (currentFlowElement instanceof Activity) {
Activity activity = (Activity) currentFlowElement;
activity.setForCompensation(isForCompensation);
if (StringUtils.isNotEmpty(defaultFlow)) {
activity.setDefaultFlow(defaultFlow);
}
}
if (currentFlowElement instanceof Gateway) {
Gateway gateway = (Gateway) currentFlowElement;
if (StringUtils.isNotEmpty(defaultFlow)) {
gateway.setDefaultFlow(defaultFlow);
}
}
}
if (currentFlowElement instanceof DataObject) {
if (!activeSubProcessList.isEmpty()) {
activeSubProcessList.get(activeSubProcessList.size() - 1).getDataObjects().add((ValuedDataObject) parsedElement);
} else {
activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
}
}
if (!activeSubProcessList.isEmpty()) {
activeSubProcessList.get(activeSubProcessList.size() - 1).addFlowElement(currentFlowElement);
} else {
activeProcess.addFlowElement(currentFlowElement);
}
}
}
use of org.activiti.bpmn.model.BaseElement in project Activiti by Activiti.
the class ExtensionElementsParser method parse.
public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess, BpmnModel model) throws Exception {
BaseElement parentElement = null;
if (!activeSubProcessList.isEmpty()) {
parentElement = activeSubProcessList.get(activeSubProcessList.size() - 1);
} else {
parentElement = activeProcess;
}
boolean readyWithChildElements = false;
while (readyWithChildElements == false && xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement()) {
if (ELEMENT_EXECUTION_LISTENER.equals(xtr.getLocalName())) {
new ExecutionListenerParser().parseChildElement(xtr, parentElement, model);
} else if (ELEMENT_EVENT_LISTENER.equals(xtr.getLocalName())) {
new ActivitiEventListenerParser().parseChildElement(xtr, parentElement, model);
} else if (ELEMENT_POTENTIAL_STARTER.equals(xtr.getLocalName())) {
new PotentialStarterParser().parse(xtr, activeProcess);
} else {
ExtensionElement extensionElement = BpmnXMLUtil.parseExtensionElement(xtr);
parentElement.addExtensionElement(extensionElement);
}
} else if (xtr.isEndElement()) {
if (ELEMENT_EXTENSIONS.equals(xtr.getLocalName())) {
readyWithChildElements = true;
}
}
}
}
use of org.activiti.bpmn.model.BaseElement in project Activiti by Activiti.
the class BaseBpmnJsonConverter method convertToBpmnModel.
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 (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);
}
}
}
Aggregations