Search in sources :

Example 11 with Process

use of io.automatiko.engine.api.definition.process.Process in project automatiko-engine by automatiko-io.

the class ProcessCodegen method ofJar.

public static ProcessCodegen ofJar(List<String> dependencies, Path... jarPaths) {
    List<Process> processes = new ArrayList<>();
    for (Path jarPath : jarPaths) {
        try (ZipFile zipFile = new ZipFile(jarPath.toFile())) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    for (String dependency : dependencies) {
        try (ZipFile zipFile = new ZipFile(dependency)) {
            Enumeration<? extends ZipEntry> entries = zipFile.entries();
            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();
                ResourceType resourceType = determineResourceType(entry.getName());
                if (SUPPORTED_BPMN_EXTENSIONS.stream().anyMatch(entry.getName()::endsWith)) {
                    InternalResource resource = new ByteArrayResource(readBytesFromInputStream(zipFile.getInputStream(entry)));
                    resource.setResourceType(resourceType);
                    resource.setSourcePath(entry.getName());
                    processes.addAll(parseProcessFile(resource));
                }
            }
        } catch (IOException e) {
        }
    }
    return ofProcesses(processes);
}
Also used : Path(java.nio.file.Path) InternalResource(io.automatiko.engine.services.io.InternalResource) ZipEntry(java.util.zip.ZipEntry) ArrayList(java.util.ArrayList) Process(io.automatiko.engine.api.definition.process.Process) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) ResourceType.determineResourceType(io.automatiko.engine.api.io.ResourceType.determineResourceType) ResourceType(io.automatiko.engine.api.io.ResourceType) UncheckedIOException(java.io.UncheckedIOException) ByteArrayResource(io.automatiko.engine.services.io.ByteArrayResource) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ZipFile(java.util.zip.ZipFile)

Example 12 with Process

use of io.automatiko.engine.api.definition.process.Process in project automatiko-engine by automatiko-io.

the class FaultNodeInstance method internalTrigger.

public void internalTrigger(final NodeInstance from, String type) {
    if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
        throw new IllegalArgumentException("A FaultNode only accepts default incoming connections!");
    }
    triggerTime = new Date();
    if (getProcessInstance().isFunctionFlow(this) && getNodeInstanceContainer() instanceof ProcessInstance) {
        // only when running as function flow and node is in the top level node container meaning process instance
        // and not subprocesses
        getProcessInstance().getMetaData().compute("ATK_FUNC_FLOW_NEXT", (k, v) -> {
            if (v == null) {
                v = new ArrayList<String>();
            }
            Process process = getProcessInstance().getProcess();
            String version = "";
            if (process.getVersion() != null && !process.getVersion().trim().isEmpty()) {
                version = ".v" + process.getVersion().replaceAll("\\.", "_");
            }
            String defaultNextNode = process.getPackageName() + "." + process.getId() + version + "." + getNodeName().toLowerCase();
            ((List<String>) v).add((String) getNode().getMetaData().getOrDefault("functionType", defaultNextNode));
            return v;
        });
    }
    String faultName = getFaultName();
    ExceptionScopeInstance exceptionScopeInstance = getExceptionScopeInstance(faultName);
    NodeInstanceContainer nodeInstanceContainer = (NodeInstanceContainer) getNodeInstanceContainer();
    nodeInstanceContainer.removeNodeInstance(this);
    boolean exceptionHandled = false;
    if (getFaultNode().isTerminateParent()) {
        // events
        if (exceptionScopeInstance != null) {
            exceptionHandled = true;
            handleException(faultName, exceptionScopeInstance);
        }
        if (nodeInstanceContainer instanceof CompositeNodeInstance) {
            ((CompositeNodeInstance) nodeInstanceContainer).cancel();
        } else if (nodeInstanceContainer instanceof WorkflowProcessInstance) {
            Collection<NodeInstance> nodeInstances = ((WorkflowProcessInstance) nodeInstanceContainer).getNodeInstances();
            for (NodeInstance nodeInstance : nodeInstances) {
                ((io.automatiko.engine.workflow.process.instance.NodeInstance) nodeInstance).cancel();
            }
        }
    }
    String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
    if (uniqueId == null) {
        uniqueId = ((NodeImpl) getNode()).getUniqueId();
    }
    ((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
    if (exceptionScopeInstance != null) {
        if (!exceptionHandled) {
            handleException(faultName, exceptionScopeInstance);
        }
        boolean hidden = false;
        if (getNode().getMetaData().get("hidden") != null) {
            hidden = true;
        }
        if (!hidden) {
            InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
            runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
        }
        ((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
        if (!hidden) {
            InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
            runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
        }
    } else {
        ((ProcessInstance) getProcessInstance()).setState(ProcessInstance.STATE_ABORTED, faultName, getFaultData());
    }
}
Also used : NodeInstanceContainer(io.automatiko.engine.workflow.process.instance.NodeInstanceContainer) WorkflowProcessInstanceImpl(io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl) Process(io.automatiko.engine.api.definition.process.Process) Date(java.util.Date) Collection(java.util.Collection) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ProcessInstance(io.automatiko.engine.workflow.base.instance.ProcessInstance) ArrayList(java.util.ArrayList) List(java.util.List) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) NodeInstance(io.automatiko.engine.api.runtime.process.NodeInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ExceptionScopeInstance(io.automatiko.engine.workflow.base.instance.context.exception.ExceptionScopeInstance)

Example 13 with Process

use of io.automatiko.engine.api.definition.process.Process in project automatiko-engine by automatiko-io.

the class AbstractBaseTest method createProcessRuntime.

public InternalProcessRuntime createProcessRuntime(Process... process) {
    Map<String, Process> mappedProcesses = Stream.of(process).collect(Collectors.toMap(Process::getId, p -> p));
    InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(mappedProcesses);
    return processRuntime;
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) TestProcessEventListener(io.automatiko.engine.workflow.process.test.TestProcessEventListener) IOException(java.io.IOException) LoggingPrintStream(io.automatiko.engine.workflow.base.instance.impl.util.LoggingPrintStream) Collectors(java.util.stream.Collectors) TestInfo(org.junit.jupiter.api.TestInfo) AfterAll(org.junit.jupiter.api.AfterAll) List(java.util.List) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Process(io.automatiko.engine.api.definition.process.Process) InputStream(java.io.InputStream) ProcessRuntimeImpl(io.automatiko.engine.workflow.base.instance.ProcessRuntimeImpl) Process(io.automatiko.engine.api.definition.process.Process) InternalProcessRuntime(io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)

Example 14 with Process

use of io.automatiko.engine.api.definition.process.Process in project automatiko-engine by automatiko-io.

the class AssociationHandler method start.

public Object start(final String uri, final String localName, final Attributes attrs, final ExtensibleXmlParser parser) throws SAXException {
    parser.startElementBuilder(localName, attrs);
    Association association = new Association();
    association.setId(attrs.getValue("id"));
    association.setSourceRef(attrs.getValue("sourceRef"));
    association.setTargetRef(attrs.getValue("targetRef"));
    String direction = attrs.getValue("associationDirection");
    if (direction != null) {
        boolean acceptableDirection = false;
        direction = direction.toLowerCase();
        String[] possibleDirections = { "none", "one", "both" };
        for (String acceptable : possibleDirections) {
            if (acceptable.equals(direction)) {
                acceptableDirection = true;
                break;
            }
        }
        if (!acceptableDirection) {
            throw new IllegalArgumentException("Unknown direction '" + direction + "' used in Association " + association.getId());
        }
    }
    association.setDirection(direction);
    /**
     * BPMN2 spec, p. 66: "At this point, BPMN provides three standard Artifacts:
     * Associations, Groups, and Text Annotations. ... When an Artifact is defined
     * it is contained within a Collaboration or a FlowElementsContainer (a Process
     * or Choreography)."
     *
     * (In other words: associations must be defined within a process, not outside)
     */
    List<Association> associations = null;
    NodeContainer nodeContainer = (NodeContainer) parser.getParent();
    if (nodeContainer instanceof Process) {
        ExecutableProcess process = (ExecutableProcess) nodeContainer;
        associations = (List<Association>) process.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            process.setMetaData(ASSOCIATIONS, associations);
        }
    } else if (nodeContainer instanceof CompositeNode) {
        CompositeContextNode compositeNode = (CompositeContextNode) nodeContainer;
        associations = (List<Association>) compositeNode.getMetaData(ASSOCIATIONS);
        if (associations == null) {
            associations = new ArrayList<>();
            compositeNode.setMetaData(ProcessHandler.ASSOCIATIONS, associations);
        }
    } else {
        associations = new ArrayList<>();
    }
    associations.add(association);
    return association;
}
Also used : CompositeContextNode(io.automatiko.engine.workflow.process.core.node.CompositeContextNode) ArrayList(java.util.ArrayList) NodeContainer(io.automatiko.engine.workflow.process.core.NodeContainer) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) Process(io.automatiko.engine.api.definition.process.Process) CompositeNode(io.automatiko.engine.workflow.process.core.node.CompositeNode) Association(io.automatiko.engine.workflow.bpmn2.core.Association) ExecutableProcess(io.automatiko.engine.workflow.process.executable.core.ExecutableProcess) ArrayList(java.util.ArrayList) List(java.util.List)

Example 15 with Process

use of io.automatiko.engine.api.definition.process.Process in project automatiko-engine by automatiko-io.

the class BpmnProcessCompiler method parse.

public List<Process> parse(ProcessConfig config, Resource... resources) {
    try {
        List<Process> processes = new ArrayList<>();
        XmlProcessReader xmlReader = new XmlProcessReader(getSemanticModules(), Thread.currentThread().getContextClassLoader());
        configureProcessReader(xmlReader, config);
        for (Resource resource : resources) {
            processes.addAll(xmlReader.read(resource.getReader()));
        }
        return processes;
    } catch (Exception e) {
        throw new BpmnProcessReaderException(e);
    }
}
Also used : XmlProcessReader(io.automatiko.engine.workflow.compiler.xml.XmlProcessReader) ArrayList(java.util.ArrayList) Resource(io.automatiko.engine.api.io.Resource) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.definition.process.Process)

Aggregations

Process (io.automatiko.engine.api.definition.process.Process)28 ArrayList (java.util.ArrayList)15 List (java.util.List)12 ExecutableProcess (io.automatiko.engine.workflow.process.executable.core.ExecutableProcess)11 Map (java.util.Map)10 WorkflowProcess (io.automatiko.engine.api.definition.process.WorkflowProcess)8 IOException (java.io.IOException)8 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)7 WorkflowProcess (io.automatiko.engine.workflow.process.core.WorkflowProcess)7 StartNode (io.automatiko.engine.workflow.process.core.node.StartNode)6 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)6 UncheckedIOException (java.io.UncheckedIOException)6 HashMap (java.util.HashMap)5 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)4 Variable (io.automatiko.engine.workflow.base.core.context.variable.Variable)4 VariableScope (io.automatiko.engine.workflow.base.core.context.variable.VariableScope)4 ProcessInstance (io.automatiko.engine.workflow.base.instance.ProcessInstance)4 XmlProcessReader (io.automatiko.engine.workflow.compiler.xml.XmlProcessReader)4 Connection (io.automatiko.engine.api.definition.process.Connection)3 Resource (io.automatiko.engine.api.io.Resource)3