use of org.activiti.bpmn.model.AdhocSubProcess 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.AdhocSubProcess in project Activiti by Activiti.
the class SubProcessParser method parse.
public void parse(XMLStreamReader xtr, List<SubProcess> activeSubProcessList, Process activeProcess) {
SubProcess subProcess = null;
if (ELEMENT_TRANSACTION.equalsIgnoreCase(xtr.getLocalName())) {
subProcess = new Transaction();
} else if (ELEMENT_ADHOC_SUBPROCESS.equalsIgnoreCase(xtr.getLocalName())) {
AdhocSubProcess adhocSubProcess = new AdhocSubProcess();
String orderingAttributeValue = xtr.getAttributeValue(null, ATTRIBUTE_ORDERING);
if (StringUtils.isNotEmpty(orderingAttributeValue)) {
adhocSubProcess.setOrdering(orderingAttributeValue);
}
if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_CANCEL_REMAINING_INSTANCES))) {
adhocSubProcess.setCancelRemainingInstances(false);
}
subProcess = adhocSubProcess;
} else if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(xtr.getAttributeValue(null, ATTRIBUTE_TRIGGERED_BY))) {
subProcess = new EventSubProcess();
} else {
subProcess = new SubProcess();
}
BpmnXMLUtil.addXMLLocation(subProcess, xtr);
activeSubProcessList.add(subProcess);
subProcess.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
subProcess.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
boolean async = false;
String asyncString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_ASYNCHRONOUS);
if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(asyncString)) {
async = true;
}
boolean notExclusive = false;
String exclusiveString = xtr.getAttributeValue(ACTIVITI_EXTENSIONS_NAMESPACE, ATTRIBUTE_ACTIVITY_EXCLUSIVE);
if (ATTRIBUTE_VALUE_FALSE.equalsIgnoreCase(exclusiveString)) {
notExclusive = true;
}
boolean forCompensation = false;
String compensationString = xtr.getAttributeValue(null, ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION);
if (ATTRIBUTE_VALUE_TRUE.equalsIgnoreCase(compensationString)) {
forCompensation = true;
}
subProcess.setAsynchronous(async);
subProcess.setNotExclusive(notExclusive);
subProcess.setForCompensation(forCompensation);
if (StringUtils.isNotEmpty(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT))) {
subProcess.setDefaultFlow(xtr.getAttributeValue(null, ATTRIBUTE_DEFAULT));
}
if (activeSubProcessList.size() > 1) {
SubProcess parentSubProcess = activeSubProcessList.get(activeSubProcessList.size() - 2);
parentSubProcess.addFlowElement(subProcess);
} else {
activeProcess.addFlowElement(subProcess);
}
}
use of org.activiti.bpmn.model.AdhocSubProcess in project Activiti by Activiti.
the class ExecuteActivityForAdhocSubProcessCmd method execute.
public Execution execute(CommandContext commandContext) {
ExecutionEntity execution = commandContext.getExecutionEntityManager().findById(executionId);
if (execution == null) {
throw new ActivitiObjectNotFoundException("No execution found for id '" + executionId + "'", ExecutionEntity.class);
}
if (!(execution.getCurrentFlowElement() instanceof AdhocSubProcess)) {
throw new ActivitiException("The current flow element of the requested execution is not an ad-hoc sub process");
}
FlowNode foundNode = null;
AdhocSubProcess adhocSubProcess = (AdhocSubProcess) execution.getCurrentFlowElement();
// if sequential ordering, only one child execution can be active
if (adhocSubProcess.hasSequentialOrdering()) {
if (execution.getExecutions().size() > 0) {
throw new ActivitiException("Sequential ad-hoc sub process already has an active execution");
}
}
for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {
if (activityId.equals(flowElement.getId()) && flowElement instanceof FlowNode) {
FlowNode flowNode = (FlowNode) flowElement;
if (flowNode.getIncomingFlows().size() == 0) {
foundNode = flowNode;
}
}
}
if (foundNode == null) {
throw new ActivitiException("The requested activity with id " + activityId + " can not be enabled");
}
ExecutionEntity activityExecution = Context.getCommandContext().getExecutionEntityManager().createChildExecution(execution);
activityExecution.setCurrentFlowElement(foundNode);
Context.getAgenda().planContinueProcessOperation(activityExecution);
return activityExecution;
}
use of org.activiti.bpmn.model.AdhocSubProcess in project Activiti by Activiti.
the class BpmnXMLConverter method createXML.
protected void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {
if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
if (flowElement instanceof Transaction) {
xtw.writeStartElement(ELEMENT_TRANSACTION);
} else if (flowElement instanceof AdhocSubProcess) {
xtw.writeStartElement(ELEMENT_ADHOC_SUBPROCESS);
} else {
xtw.writeStartElement(BPMN2_PREFIX, ELEMENT_SUBPROCESS, BPMN2_NAMESPACE);
}
xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
if (StringUtils.isNotEmpty(subProcess.getName())) {
xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
} else {
xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
}
if (subProcess instanceof EventSubProcess) {
xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
} else if (!(subProcess instanceof Transaction)) {
if (subProcess.isAsynchronous()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
if (subProcess.isNotExclusive()) {
BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
}
}
} else if (subProcess instanceof AdhocSubProcess) {
AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_CANCEL_REMAINING_INSTANCES, String.valueOf(adhocSubProcess.isCancelRemainingInstances()), xtw);
if (StringUtils.isNotEmpty(adhocSubProcess.getOrdering())) {
BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_ORDERING, adhocSubProcess.getOrdering(), xtw);
}
}
if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {
xtw.writeStartElement(BPMN2_PREFIX, ELEMENT_DOCUMENTATION, BPMN2_NAMESPACE);
xtw.writeCharacters(subProcess.getDocumentation());
xtw.writeEndElement();
}
boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);
didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess, didWriteExtensionStartElement, model.getNamespaces(), xtw);
if (didWriteExtensionStartElement) {
// closing extensions element
xtw.writeEndElement();
}
MultiInstanceExport.writeMultiInstance(subProcess, xtw);
if (subProcess instanceof AdhocSubProcess) {
AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
if (StringUtils.isNotEmpty(adhocSubProcess.getCompletionCondition())) {
xtw.writeStartElement(ELEMENT_COMPLETION_CONDITION);
xtw.writeCData(adhocSubProcess.getCompletionCondition());
xtw.writeEndElement();
}
}
for (FlowElement subElement : subProcess.getFlowElements()) {
createXML(subElement, model, xtw);
}
for (Artifact artifact : subProcess.getArtifacts()) {
createXML(artifact, model, xtw);
}
xtw.writeEndElement();
} else {
BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());
if (converter == null) {
throw new XMLException("No converter for " + flowElement.getClass() + " found");
}
converter.convertToXML(xtw, flowElement, model);
}
}
use of org.activiti.bpmn.model.AdhocSubProcess in project Activiti by Activiti.
the class TakeOutgoingSequenceFlowsOperation method handleAdhocSubProcess.
protected void handleAdhocSubProcess(FlowNode flowNode) {
boolean completeAdhocSubProcess = false;
AdhocSubProcess adhocSubProcess = (AdhocSubProcess) flowNode.getParentContainer();
if (adhocSubProcess.getCompletionCondition() != null) {
Expression expression = Context.getProcessEngineConfiguration().getExpressionManager().createExpression(adhocSubProcess.getCompletionCondition());
Condition condition = new UelExpressionCondition(expression);
if (condition.evaluate(adhocSubProcess.getId(), execution)) {
completeAdhocSubProcess = true;
}
}
if (flowNode.getOutgoingFlows().size() > 0) {
leaveFlowNode(flowNode);
} else {
commandContext.getExecutionEntityManager().deleteExecutionAndRelatedData(execution, null);
}
if (completeAdhocSubProcess) {
boolean endAdhocSubProcess = true;
if (!adhocSubProcess.isCancelRemainingInstances()) {
List<ExecutionEntity> childExecutions = commandContext.getExecutionEntityManager().findChildExecutionsByParentExecutionId(execution.getParentId());
for (ExecutionEntity executionEntity : childExecutions) {
if (!executionEntity.getId().equals(execution.getId())) {
endAdhocSubProcess = false;
break;
}
}
}
if (endAdhocSubProcess) {
Context.getAgenda().planEndExecutionOperation(execution.getParent());
}
}
}
Aggregations