use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testGeneratedWorkflowDefinitionId.
/**
* Check if all required artifacts are created when converting an empty workflow-definition.
*/
@Test
public void testGeneratedWorkflowDefinitionId() {
WorkflowDefinition definition = new WorkflowDefinition();
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
BpmnModel bpmnModel = conversion.getBpmnModel();
assertNotNull(bpmnModel);
Process process = bpmnModel.getMainProcess();
assertNotNull(process);
String generatedProcessId = process.getId();
assertNotNull(generatedProcessId);
}
use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class DefaultWorkflowDefinitionConversionListener method afterStepsConversion.
public void afterStepsConversion(WorkflowDefinitionConversion conversion) {
// Add end-event to process
Process process = conversion.getProcess();
EndEvent endEvent = new EndEvent();
endEvent.setId(END_EVENT_ID);
process.addFlowElement(endEvent);
// Sequence flow from last created activity to end
SequenceFlow sequenceFlow = new SequenceFlow();
sequenceFlow.setId(conversion.getUniqueNumberedId(ConversionConstants.DEFAULT_SEQUENCEFLOW_PREFIX));
sequenceFlow.setSourceRef(conversion.getLastActivityId());
sequenceFlow.setTargetRef(END_EVENT_ID);
process.addFlowElement(sequenceFlow);
// To make the generated workflow compatible with some tools (eg the
// Modeler, but also others),
// We must add the ingoing and outgoing sequence flow to each of the flow
// nodes
SequenceFlowMapping sequenceFlowMapping = generateSequenceflowMappings(process);
for (FlowNode flowNode : process.findFlowElementsOfType(FlowNode.class)) {
List<SequenceFlow> incomingSequenceFlow = sequenceFlowMapping.getIncomingSequenceFlowMapping().get(flowNode.getId());
if (incomingSequenceFlow != null) {
flowNode.setIncomingFlows(incomingSequenceFlow);
}
List<SequenceFlow> outgoingSequenceFlow = sequenceFlowMapping.getOutgoingSequenceFlowMapping().get(flowNode.getId());
if (outgoingSequenceFlow != null) {
flowNode.setOutgoingFlows(outgoingSequenceFlow);
}
}
}
use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class DefaultWorkflowDefinitionConversionListener method initializeProcess.
protected void initializeProcess(WorkflowDefinitionConversion conversion) {
WorkflowDefinition workflowDefinition = conversion.getWorkflowDefinition();
// Create new process
Process process = conversion.getProcess();
process.setId(generateProcessId(workflowDefinition));
process.setName(workflowDefinition.getName());
process.setDocumentation(workflowDefinition.getDescription());
if (workflowDefinition.getCategory() != null) {
conversion.getBpmnModel().setTargetNamespace(workflowDefinition.getCategory());
}
conversion.setProcess(process);
// Add start-event
StartEvent startEvent = new StartEvent();
startEvent.setId(START_EVENT_ID);
if (workflowDefinition.getStartFormDefinition() != null && workflowDefinition.getStartFormDefinition().getFormKey() != null) {
startEvent.setFormKey(workflowDefinition.getStartFormDefinition().getFormKey());
}
process.addFlowElement(startEvent);
conversion.setLastActivityId(startEvent.getId());
}
use of org.activiti.bpmn.model.Process in project Activiti by Activiti.
the class BpmnXMLConverter method convertToXML.
public byte[] convertToXML(BpmnModel model, String encoding) {
try {
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
XMLOutputFactory xof = XMLOutputFactory.newInstance();
OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);
XMLStreamWriter writer = xof.createXMLStreamWriter(out);
XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);
DefinitionsRootExport.writeRootElement(model, xtw, encoding);
CollaborationExport.writePools(model, xtw);
DataStoreExport.writeDataStores(model, xtw);
SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
for (Process process : model.getProcesses()) {
if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
// empty process, ignore it
continue;
}
ProcessExport.writeProcess(process, xtw);
for (FlowElement flowElement : process.getFlowElements()) {
createXML(flowElement, model, xtw);
}
for (Artifact artifact : process.getArtifacts()) {
createXML(artifact, model, xtw);
}
// end process element
xtw.writeEndElement();
}
BPMNDIExport.writeBPMNDI(model, xtw);
// end definitions root element
xtw.writeEndElement();
xtw.writeEndDocument();
xtw.flush();
outputStream.close();
xtw.close();
return outputStream.toByteArray();
} catch (Exception e) {
LOGGER.error("Error writing BPMN XML", e);
throw new XMLException("Error writing BPMN XML", e);
}
}
use of org.activiti.bpmn.model.Process 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;
}
Aggregations