use of org.activiti.bpmn.model.FlowElement 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.FlowElement in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testTaskListenerForOutgoingProperties.
@Test
public void testTaskListenerForOutgoingProperties() throws Exception {
WorkflowDefinition definition = new WorkflowDefinition();
definition.setId("process");
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setId("step1");
FormDefinition form = new FormDefinition();
humanStep.setForm(form);
TextPropertyDefinition text = new TextPropertyDefinition();
text.setName("my text");
text.getParameters().put(AlfrescoConversionConstants.PARAMETER_ADD_PROPERTY_TO_OUTPUT, true);
FormPropertyGroup group = new FormPropertyGroup();
group.setId("group");
form.getFormGroups().add(group);
group.getFormPropertyDefinitions().add(text);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
Process process = conversion.getProcess();
assertNotNull(process);
boolean listenerFound = false;
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof UserTask) {
UserTask task = (UserTask) flowElement;
assertNotNull(task.getTaskListeners());
assertEquals(2L, task.getTaskListeners().size());
assertEquals("create", task.getTaskListeners().get(0).getEvent());
assertEquals("complete", task.getTaskListeners().get(1).getEvent());
listenerFound = true;
}
}
assertTrue(listenerFound);
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class WorkflowDefinitionConversionTest method testTaskListenerForIncomingProperties.
@Test
public void testTaskListenerForIncomingProperties() throws Exception {
WorkflowDefinition definition = new WorkflowDefinition();
definition.setId("process");
HumanStepDefinition humanStep = new HumanStepDefinition();
humanStep.setId("step1");
FormDefinition form = new FormDefinition();
form.setFormKey("myform");
humanStep.setForm(form);
definition.addStep(humanStep);
WorkflowDefinitionConversion conversion = conversionFactory.createWorkflowDefinitionConversion(definition);
conversion.convert();
Process process = conversion.getProcess();
assertNotNull(process);
boolean listenerFound = false;
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof UserTask) {
UserTask task = (UserTask) flowElement;
assertNotNull(task.getTaskListeners());
assertEquals(1L, task.getTaskListeners().size());
assertEquals("create", task.getTaskListeners().get(0).getEvent());
listenerFound = true;
}
}
assertTrue(listenerFound);
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class ChoiceStepsDefinitionConverter method createProcessArtifact.
protected ExclusiveGateway createProcessArtifact(ChoiceStepsDefinition choiceStepsDefinition, WorkflowDefinitionConversion conversion) {
// First choice gateway
ExclusiveGateway forkGateway = createExclusiveGateway(conversion);
// Sequence flow from last activity to first gateway
addSequenceFlow(conversion, conversion.getLastActivityId(), forkGateway.getId());
conversion.setLastActivityId(forkGateway.getId());
// Convert all other steps, disabling activity id updates which makes all
// generated steps have a sequence flow to the first gateway
WorkflowDefinitionConversionFactory conversionFactory = conversion.getConversionFactory();
List<FlowElement> endElements = new ArrayList<FlowElement>();
List<SequenceFlow> bypassingFlows = new ArrayList<SequenceFlow>();
for (ListConditionStepDefinition<ChoiceStepsDefinition> stepListDefinition : choiceStepsDefinition.getStepList()) {
StringBuilder conditionBuilder = new StringBuilder();
for (ConditionDefinition conditionDefintion : stepListDefinition.getConditions()) {
if (conditionBuilder.length() > 0) {
conditionBuilder.append(" && ");
} else {
conditionBuilder.append("${");
}
conditionBuilder.append(conditionDefintion.getLeftOperand());
conditionBuilder.append(" ");
conditionBuilder.append(conditionDefintion.getOperator());
conditionBuilder.append(" ");
conditionBuilder.append(conditionDefintion.getRightOperand());
}
for (int i = 0; i < stepListDefinition.getSteps().size(); i++) {
if (i == 0) {
conversion.setSequenceflowGenerationEnabled(false);
} else {
conversion.setSequenceflowGenerationEnabled(true);
}
StepDefinition step = stepListDefinition.getSteps().get(i);
FlowElement flowElement = (FlowElement) conversionFactory.getStepConverterFor(step).convertStepDefinition(step, conversion);
if (i == 0) {
if (conditionBuilder.length() > 0) {
conditionBuilder.append("}");
SequenceFlow mainFlow = addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId(), conditionBuilder.toString());
if (stepListDefinition.getName() != null) {
mainFlow.setName(stepListDefinition.getName());
}
} else {
addSequenceFlow(conversion, forkGateway.getId(), flowElement.getId());
}
}
if ((i + 1) == stepListDefinition.getSteps().size()) {
endElements.add(flowElement);
}
}
if (stepListDefinition.getSteps().isEmpty()) {
// Special case for a "stepless" stepListDefinition, which should just create a sequence-flow from the fork to the join
SequenceFlow created = null;
if (conditionBuilder.length() > 0) {
conditionBuilder.append("}");
created = addSequenceFlow(conversion, forkGateway.getId(), null, conditionBuilder.toString());
} else {
created = addSequenceFlow(conversion, forkGateway.getId(), null);
}
if (stepListDefinition.getName() != null) {
created.setName(stepListDefinition.getName());
}
bypassingFlows.add(created);
}
}
conversion.setSequenceflowGenerationEnabled(false);
// Second choice gateway
ExclusiveGateway joinGateway = createExclusiveGateway(conversion);
conversion.setLastActivityId(joinGateway.getId());
conversion.setSequenceflowGenerationEnabled(true);
// Create sequenceflow from all generated steps to the second gateway
for (FlowElement endElement : endElements) {
if (!(endElement instanceof EndEvent)) {
addSequenceFlow(conversion, endElement.getId(), joinGateway.getId());
}
}
for (SequenceFlow bypassingFlow : bypassingFlows) {
bypassingFlow.setTargetRef(joinGateway.getId());
}
return forkGateway;
}
use of org.activiti.bpmn.model.FlowElement in project Activiti by Activiti.
the class BaseBpmnXMLConverter method convertToXML.
public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model) throws Exception {
xtw.writeStartElement(getXMLElementName());
boolean didWriteExtensionStartElement = false;
writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw);
if (baseElement instanceof FlowElement) {
writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw);
}
if (baseElement instanceof FlowNode) {
final FlowNode flowNode = (FlowNode) baseElement;
if (flowNode.isAsynchronous()) {
writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
if (flowNode.isNotExclusive()) {
writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
}
}
if (baseElement instanceof Activity) {
final Activity activity = (Activity) baseElement;
if (activity.isForCompensation()) {
writeDefaultAttribute(ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, ATTRIBUTE_VALUE_TRUE, xtw);
}
if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow());
if (defaultFlowElement instanceof SequenceFlow) {
writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw);
}
}
}
if (baseElement instanceof Gateway) {
final Gateway gateway = (Gateway) baseElement;
if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) {
FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow());
if (defaultFlowElement instanceof SequenceFlow) {
writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw);
}
}
}
}
writeAdditionalAttributes(baseElement, model, xtw);
if (baseElement instanceof FlowElement) {
final FlowElement flowElement = (FlowElement) baseElement;
if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {
xtw.writeStartElement(ELEMENT_DOCUMENTATION);
xtw.writeCharacters(flowElement.getDocumentation());
xtw.writeEndElement();
}
}
didWriteExtensionStartElement = writeExtensionChildElements(baseElement, didWriteExtensionStartElement, xtw);
didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw);
didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(baseElement, didWriteExtensionStartElement, model.getNamespaces(), xtw);
if (baseElement instanceof Activity) {
final Activity activity = (Activity) baseElement;
FailedJobRetryCountExport.writeFailedJobRetryCount(activity, xtw);
}
if (didWriteExtensionStartElement) {
xtw.writeEndElement();
}
if (baseElement instanceof Activity) {
final Activity activity = (Activity) baseElement;
MultiInstanceExport.writeMultiInstance(activity, xtw);
}
writeAdditionalChildElements(baseElement, model, xtw);
xtw.writeEndElement();
}
Aggregations