use of org.activiti.bpmn.model.Activity 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()) {
SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
subProcess.getDataObjects().add((ValuedDataObject) parsedElement);
} else {
activeProcess.getDataObjects().add((ValuedDataObject) parsedElement);
}
}
if (!activeSubProcessList.isEmpty()) {
SubProcess subProcess = activeSubProcessList.get(activeSubProcessList.size() - 1);
subProcess.addFlowElement(currentFlowElement);
} else {
activeProcess.addFlowElement(currentFlowElement);
}
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class BpmnXMLConverter method processFlowElements.
protected void processFlowElements(Collection<FlowElement> flowElementList, BaseElement parentScope) {
for (FlowElement flowElement : flowElementList) {
if (flowElement instanceof SequenceFlow) {
SequenceFlow sequenceFlow = (SequenceFlow) flowElement;
FlowNode sourceNode = getFlowNodeFromScope(sequenceFlow.getSourceRef(), parentScope);
if (sourceNode != null) {
sourceNode.getOutgoingFlows().add(sequenceFlow);
sequenceFlow.setSourceFlowElement(sourceNode);
}
FlowNode targetNode = getFlowNodeFromScope(sequenceFlow.getTargetRef(), parentScope);
if (targetNode != null) {
targetNode.getIncomingFlows().add(sequenceFlow);
sequenceFlow.setTargetFlowElement(targetNode);
}
} else if (flowElement instanceof BoundaryEvent) {
BoundaryEvent boundaryEvent = (BoundaryEvent) flowElement;
FlowElement attachedToElement = getFlowNodeFromScope(boundaryEvent.getAttachedToRefId(), parentScope);
if (attachedToElement instanceof Activity) {
Activity attachedActivity = (Activity) attachedToElement;
boundaryEvent.setAttachedToRef(attachedActivity);
attachedActivity.getBoundaryEvents().add(boundaryEvent);
}
} else if (flowElement instanceof SubProcess) {
SubProcess subProcess = (SubProcess) flowElement;
processFlowElements(subProcess.getFlowElements(), subProcess);
}
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class IOSpecificationParser method parseChildElement.
public void parseChildElement(XMLStreamReader xtr, BaseElement parentElement, BpmnModel model) throws Exception {
if (!(parentElement instanceof Activity) && !(parentElement instanceof Process))
return;
IOSpecification ioSpecification = new IOSpecification();
BpmnXMLUtil.addXMLLocation(ioSpecification, xtr);
boolean readyWithIOSpecification = false;
try {
while (!readyWithIOSpecification && xtr.hasNext()) {
xtr.next();
if (xtr.isStartElement() && ELEMENT_DATA_INPUT.equalsIgnoreCase(xtr.getLocalName())) {
DataSpec dataSpec = new DataSpec();
BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
dataSpec.setItemSubjectRef(parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
ioSpecification.getDataInputs().add(dataSpec);
} else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT.equalsIgnoreCase(xtr.getLocalName())) {
DataSpec dataSpec = new DataSpec();
BpmnXMLUtil.addXMLLocation(dataSpec, xtr);
dataSpec.setId(xtr.getAttributeValue(null, ATTRIBUTE_ID));
dataSpec.setName(xtr.getAttributeValue(null, ATTRIBUTE_NAME));
dataSpec.setItemSubjectRef(parseItemSubjectRef(xtr.getAttributeValue(null, ATTRIBUTE_ITEM_SUBJECT_REF), model));
ioSpecification.getDataOutputs().add(dataSpec);
} else if (xtr.isStartElement() && ELEMENT_DATA_INPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
String dataInputRefs = xtr.getElementText();
if (StringUtils.isNotEmpty(dataInputRefs)) {
ioSpecification.getDataInputRefs().add(dataInputRefs.trim());
}
} else if (xtr.isStartElement() && ELEMENT_DATA_OUTPUT_REFS.equalsIgnoreCase(xtr.getLocalName())) {
String dataOutputRefs = xtr.getElementText();
if (StringUtils.isNotEmpty(dataOutputRefs)) {
ioSpecification.getDataOutputRefs().add(dataOutputRefs.trim());
}
} else if (xtr.isEndElement() && getElementName().equalsIgnoreCase(xtr.getLocalName())) {
readyWithIOSpecification = true;
}
}
} catch (Exception e) {
LOGGER.warn("Error parsing ioSpecification child elements", e);
}
if (parentElement instanceof Process) {
((Process) parentElement).setIoSpecification(ioSpecification);
} else {
((Activity) parentElement).setIoSpecification(ioSpecification);
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class FlowElementValidator method executeValidation.
@Override
protected void executeValidation(BpmnModel bpmnModel, Process process, List<ValidationError> errors) {
for (FlowElement flowElement : process.getFlowElements()) {
if (flowElement instanceof Activity) {
Activity activity = (Activity) flowElement;
handleConstraints(process, activity, errors);
handleMultiInstanceLoopCharacteristics(process, activity, errors);
handleDataAssociations(process, activity, errors);
}
}
}
use of org.activiti.bpmn.model.Activity in project Activiti by Activiti.
the class TakeOutgoingSequenceFlowsOperation method leaveFlowNode.
protected void leaveFlowNode(FlowNode flowNode) {
logger.debug("Leaving flow node {} with id '{}' by following it's {} outgoing sequenceflow", flowNode.getClass(), flowNode.getId(), flowNode.getOutgoingFlows().size());
// Get default sequence flow (if set)
String defaultSequenceFlowId = null;
if (flowNode instanceof Activity) {
defaultSequenceFlowId = ((Activity) flowNode).getDefaultFlow();
} else if (flowNode instanceof Gateway) {
defaultSequenceFlowId = ((Gateway) flowNode).getDefaultFlow();
}
// Determine which sequence flows can be used for leaving
List<SequenceFlow> outgoingSequenceFlows = new ArrayList<SequenceFlow>();
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
String skipExpressionString = sequenceFlow.getSkipExpression();
if (!SkipExpressionUtil.isSkipExpressionEnabled(execution, skipExpressionString)) {
if (!evaluateConditions || (evaluateConditions && ConditionUtil.hasTrueCondition(sequenceFlow, execution) && (defaultSequenceFlowId == null || !defaultSequenceFlowId.equals(sequenceFlow.getId())))) {
outgoingSequenceFlows.add(sequenceFlow);
}
} else if (flowNode.getOutgoingFlows().size() == 1 || SkipExpressionUtil.shouldSkipFlowElement(commandContext, execution, skipExpressionString)) {
// The 'skip' for a sequence flow means that we skip the condition, not the sequence flow.
outgoingSequenceFlows.add(sequenceFlow);
}
}
// Check if there is a default sequence flow
if (outgoingSequenceFlows.size() == 0 && evaluateConditions) {
// The elements that set this to false also have no support for default sequence flow
if (defaultSequenceFlowId != null) {
for (SequenceFlow sequenceFlow : flowNode.getOutgoingFlows()) {
if (defaultSequenceFlowId.equals(sequenceFlow.getId())) {
outgoingSequenceFlows.add(sequenceFlow);
break;
}
}
}
}
// No outgoing found. Ending the execution
if (outgoingSequenceFlows.size() == 0) {
if (flowNode.getOutgoingFlows() == null || flowNode.getOutgoingFlows().size() == 0) {
logger.debug("No outgoing sequence flow found for flow node '{}'.", flowNode.getId());
Context.getAgenda().planEndExecutionOperation(execution);
} else {
throw new ActivitiException("No outgoing sequence flow of element '" + flowNode.getId() + "' could be selected for continuing the process");
}
} else {
// Leave, and reuse the incoming sequence flow, make executions for all the others (if applicable)
ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
List<ExecutionEntity> outgoingExecutions = new ArrayList<ExecutionEntity>(flowNode.getOutgoingFlows().size());
SequenceFlow sequenceFlow = outgoingSequenceFlows.get(0);
// Reuse existing one
execution.setCurrentFlowElement(sequenceFlow);
execution.setActive(true);
outgoingExecutions.add((ExecutionEntity) execution);
// Executions for all the other one
if (outgoingSequenceFlows.size() > 1) {
for (int i = 1; i < outgoingSequenceFlows.size(); i++) {
ExecutionEntity parent = execution.getParentId() != null ? execution.getParent() : execution;
ExecutionEntity outgoingExecutionEntity = commandContext.getExecutionEntityManager().createChildExecution(parent);
SequenceFlow outgoingSequenceFlow = outgoingSequenceFlows.get(i);
outgoingExecutionEntity.setCurrentFlowElement(outgoingSequenceFlow);
executionEntityManager.insert(outgoingExecutionEntity);
outgoingExecutions.add(outgoingExecutionEntity);
}
}
// Leave (only done when all executions have been made, since some queries depend on this)
for (ExecutionEntity outgoingExecution : outgoingExecutions) {
Context.getAgenda().planContinueProcessOperation(outgoingExecution);
}
}
}
Aggregations