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);
}
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());
}
}
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;
}
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;
}
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);
}
}
Aggregations