use of org.activiti.bpmn.model.Association in project Activiti by Activiti.
the class AssociationXMLConverter method writeAdditionalAttributes.
@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw) throws Exception {
Association association = (Association) element;
writeDefaultAttribute(ATTRIBUTE_FLOW_SOURCE_REF, association.getSourceRef(), xtw);
writeDefaultAttribute(ATTRIBUTE_FLOW_TARGET_REF, association.getTargetRef(), xtw);
AssociationDirection associationDirection = association.getAssociationDirection();
if (associationDirection != null) {
writeDefaultAttribute(ATTRIBUTE_ASSOCIATION_DIRECTION, associationDirection.getValue(), xtw);
}
}
use of org.activiti.bpmn.model.Association 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()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName()))) {
activeSubProcessList.remove(activeSubProcessList.size() - 1);
}
if (!xtr.isStartElement()) {
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_NAME), 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()) || ELEMENT_TRANSACTION.equals(xtr.getLocalName()) || ELEMENT_ADHOC_SUBPROCESS.equals(xtr.getLocalName())) {
subProcessParser.parse(xtr, activeSubProcessList, activeProcess);
} else if (ELEMENT_COMPLETION_CONDITION.equals(xtr.getLocalName())) {
if (!activeSubProcessList.isEmpty()) {
SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
if (subProcess instanceof AdhocSubProcess) {
AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
adhocSubProcess.setCompletionCondition(xtr.getElementText());
}
}
} 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.Association in project Activiti by Activiti.
the class BpmnAutoLayout method layout.
protected void layout(FlowElementsContainer flowElementsContainer) {
graph = new mxGraph();
cellParent = graph.getDefaultParent();
graph.getModel().beginUpdate();
// Subprocesses are handled in a new instance of BpmnAutoLayout, hence they instantiations of new maps here.
handledFlowElements = new HashMap<String, FlowElement>();
handledArtifacts = new HashMap<String, Artifact>();
generatedVertices = new HashMap<String, Object>();
generatedSequenceFlowEdges = new HashMap<String, Object>();
generatedAssociationEdges = new HashMap<String, Object>();
// Associations are gathered and processed afterwards, because we must be sure we already found source and target
associations = new HashMap<String, Association>();
// Text Annotations are gathered and processed afterwards, because we must be sure we already found the parent.
textAnnotations = new HashMap<String, TextAnnotation>();
// Sequence flow are gathered and processed afterwards,because we mustbe sure we already found source and target
sequenceFlows = new HashMap<String, SequenceFlow>();
// Boundary events are gathered and processed afterwards, because we must be sure we have its parent
boundaryEvents = new ArrayList<BoundaryEvent>();
// Process all elements
for (FlowElement flowElement : flowElementsContainer.getFlowElements()) {
if (flowElement instanceof SequenceFlow) {
handleSequenceFlow((SequenceFlow) flowElement);
} else if (flowElement instanceof Event) {
handleEvent(flowElement);
} else if (flowElement instanceof Gateway) {
createGatewayVertex(flowElement);
} else if (flowElement instanceof Task || flowElement instanceof CallActivity) {
handleActivity(flowElement);
} else if (flowElement instanceof SubProcess) {
handleSubProcess(flowElement);
}
handledFlowElements.put(flowElement.getId(), flowElement);
}
// process artifacts
for (Artifact artifact : flowElementsContainer.getArtifacts()) {
if (artifact instanceof Association) {
handleAssociation((Association) artifact);
} else if (artifact instanceof TextAnnotation) {
handleTextAnnotation((TextAnnotation) artifact);
}
handledArtifacts.put(artifact.getId(), artifact);
}
// Process gathered elements
handleBoundaryEvents();
handleSequenceFlow();
handleAssociations();
// All elements are now put in the graph. Let's layout them!
CustomLayout layout = new CustomLayout(graph, SwingConstants.WEST);
layout.setIntraCellSpacing(100.0);
layout.setResizeParent(true);
layout.setFineTuning(true);
layout.setParentBorder(20);
layout.setMoveParent(true);
layout.setDisableEdgeStyle(false);
layout.setUseBoundingBox(true);
layout.execute(graph.getDefaultParent());
graph.getModel().endUpdate();
generateDiagramInterchangeElements();
}
use of org.activiti.bpmn.model.Association in project Activiti by Activiti.
the class BoundaryCompensateEventActivityBehavior method execute.
@Override
public void execute(DelegateExecution execution) {
ExecutionEntity executionEntity = (ExecutionEntity) execution;
BoundaryEvent boundaryEvent = (BoundaryEvent) execution.getCurrentFlowElement();
Process process = ProcessDefinitionUtil.getProcess(execution.getProcessDefinitionId());
if (process == null) {
throw new ActivitiException("Process model (id = " + execution.getId() + ") could not be found");
}
Activity compensationActivity = null;
List<Association> associations = process.findAssociationsWithSourceRefRecursive(boundaryEvent.getId());
for (Association association : associations) {
FlowElement targetElement = process.getFlowElement(association.getTargetRef(), true);
if (targetElement instanceof Activity) {
Activity activity = (Activity) targetElement;
if (activity.isForCompensation()) {
compensationActivity = activity;
break;
}
}
}
if (compensationActivity == null) {
throw new ActivitiException("Compensation activity could not be found (or it is missing 'isForCompensation=\"true\"'");
}
// find SubProcess or Process instance execution
ExecutionEntity scopeExecution = null;
ExecutionEntity parentExecution = executionEntity.getParent();
while (scopeExecution == null && parentExecution != null) {
if (parentExecution.getCurrentFlowElement() instanceof SubProcess) {
scopeExecution = parentExecution;
} else if (parentExecution.isProcessInstanceType()) {
scopeExecution = parentExecution;
} else {
parentExecution = parentExecution.getParent();
}
}
if (scopeExecution == null) {
throw new ActivitiException("Could not find a scope execution for compensation boundary event " + boundaryEvent.getId());
}
Context.getCommandContext().getEventSubscriptionEntityManager().insertCompensationEvent(scopeExecution, compensationActivity.getId());
}
use of org.activiti.bpmn.model.Association in project Activiti by Activiti.
the class BpmnAutoLayout method handleAssociations.
protected void handleAssociations() {
Hashtable<String, Object> edgeStyle = new Hashtable<String, Object>();
edgeStyle.put(mxConstants.STYLE_ORTHOGONAL, true);
edgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.ElbowConnector);
edgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.0);
edgeStyle.put(mxConstants.STYLE_ENTRY_Y, 0.5);
graph.getStylesheet().putCellStyle(STYLE_SEQUENCEFLOW, edgeStyle);
Hashtable<String, Object> boundaryEdgeStyle = new Hashtable<String, Object>();
boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_X, 0.5);
boundaryEdgeStyle.put(mxConstants.STYLE_EXIT_Y, 1.0);
boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_X, 0.5);
boundaryEdgeStyle.put(mxConstants.STYLE_ENTRY_Y, 1.0);
boundaryEdgeStyle.put(mxConstants.STYLE_EDGE, mxEdgeStyle.OrthConnector);
graph.getStylesheet().putCellStyle(STYLE_BOUNDARY_SEQUENCEFLOW, boundaryEdgeStyle);
for (Association association : associations.values()) {
Object sourceVertex = generatedVertices.get(association.getSourceRef());
Object targetVertex = generatedVertices.get(association.getTargetRef());
String style = null;
if (handledFlowElements.get(association.getSourceRef()) instanceof BoundaryEvent) {
// Sequence flow out of boundary events are handled in a different way,
// to make them visually appealing for the eye of the dear end user.
style = STYLE_BOUNDARY_SEQUENCEFLOW;
} else {
style = STYLE_SEQUENCEFLOW;
}
Object associationEdge = graph.insertEdge(cellParent, association.getId(), "", sourceVertex, targetVertex, style);
generatedAssociationEdges.put(association.getId(), associationEdge);
}
}
Aggregations