Search in sources :

Example 6 with AdhocSubProcess

use of org.activiti.bpmn.model.AdhocSubProcess in project Activiti by Activiti.

the class GetEnabledActivitiesForAdhocSubProcessCmd method execute.

public List<FlowNode> 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");
    }
    List<FlowNode> enabledFlowNodes = new ArrayList<FlowNode>();
    AdhocSubProcess adhocSubProcess = (AdhocSubProcess) execution.getCurrentFlowElement();
    // if sequential ordering, only one child execution can be active, so no enabled activities
    if (adhocSubProcess.hasSequentialOrdering()) {
        if (execution.getExecutions().size() > 0) {
            return enabledFlowNodes;
        }
    }
    for (FlowElement flowElement : adhocSubProcess.getFlowElements()) {
        if (flowElement instanceof FlowNode) {
            FlowNode flowNode = (FlowNode) flowElement;
            if (flowNode.getIncomingFlows().size() == 0) {
                enabledFlowNodes.add(flowNode);
            }
        }
    }
    return enabledFlowNodes;
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) FlowElement(org.activiti.bpmn.model.FlowElement) ArrayList(java.util.ArrayList) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) FlowNode(org.activiti.bpmn.model.FlowNode)

Example 7 with AdhocSubProcess

use of org.activiti.bpmn.model.AdhocSubProcess in project Activiti by Activiti.

the class CompleteAdhocSubProcessCmd method execute.

public Void execute(CommandContext commandContext) {
    ExecutionEntityManager executionEntityManager = commandContext.getExecutionEntityManager();
    ExecutionEntity execution = executionEntityManager.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");
    }
    List<? extends ExecutionEntity> childExecutions = execution.getExecutions();
    if (childExecutions.size() > 0) {
        throw new ActivitiException("Ad-hoc sub process has running child executions that need to be completed first");
    }
    ExecutionEntity outgoingFlowExecution = executionEntityManager.createChildExecution(execution.getParent());
    outgoingFlowExecution.setCurrentFlowElement(execution.getCurrentFlowElement());
    executionEntityManager.deleteExecutionAndRelatedData(execution, null);
    Context.getAgenda().planTakeOutgoingSequenceFlowsOperation(outgoingFlowExecution, true);
    return null;
}
Also used : AdhocSubProcess(org.activiti.bpmn.model.AdhocSubProcess) ActivitiException(org.activiti.engine.ActivitiException) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ExecutionEntityManager(org.activiti.engine.impl.persistence.entity.ExecutionEntityManager)

Aggregations

AdhocSubProcess (org.activiti.bpmn.model.AdhocSubProcess)7 ExecutionEntity (org.activiti.engine.impl.persistence.entity.ExecutionEntity)4 EventSubProcess (org.activiti.bpmn.model.EventSubProcess)3 FlowElement (org.activiti.bpmn.model.FlowElement)3 SubProcess (org.activiti.bpmn.model.SubProcess)3 ActivitiException (org.activiti.engine.ActivitiException)3 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)3 ArrayList (java.util.ArrayList)2 XMLException (org.activiti.bpmn.exceptions.XMLException)2 FlowNode (org.activiti.bpmn.model.FlowNode)2 Transaction (org.activiti.bpmn.model.Transaction)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 Artifact (org.activiti.bpmn.model.Artifact)1 Association (org.activiti.bpmn.model.Association)1 BaseElement (org.activiti.bpmn.model.BaseElement)1 BpmnModel (org.activiti.bpmn.model.BpmnModel)1 Pool (org.activiti.bpmn.model.Pool)1 Process (org.activiti.bpmn.model.Process)1