use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class ParticipantsAccessPolicy method whenInitiatorNotSetOrAsIdentity.
@SuppressWarnings("unchecked")
protected boolean whenInitiatorNotSetOrAsIdentity(IdentityProvider identityProvider, ProcessInstance<T> instance) {
if (identityProvider.isAdmin()) {
return true;
}
WorkflowProcessInstance pi = (WorkflowProcessInstance) ((AbstractProcessInstance<?>) instance).processInstance();
if (pi.getInitiator() == null || pi.getInitiator().isEmpty() || pi.getInitiator().equals(identityProvider.getName())) {
return true;
}
// next check if the user/group is assigned to any of the active user tasks that
// can make it eligible to access the instance
boolean result = ((WorkflowProcessInstanceImpl) pi).getNodeInstances(true).stream().filter(ni -> ni instanceof HumanTaskNodeInstance).anyMatch(ni -> {
HumanTaskWorkItem workitem = (HumanTaskWorkItem) ((HumanTaskNodeInstance) ni).getWorkItem();
return workitem.enforce(SecurityPolicy.of(identityProvider));
});
if (!result) {
result = instance.subprocesses().stream().anyMatch(spi -> whenInitiatorNotSetOrAsIdentity(identityProvider, (ProcessInstance<T>) spi));
}
return result;
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class ProcessMetricsEventListener method afterProcessCompleted.
@Override
public void afterProcessCompleted(ProcessCompletedEvent event) {
final WorkflowProcessInstanceImpl processInstance = (WorkflowProcessInstanceImpl) event.getProcessInstance();
Counter counter;
if (processInstance.getState() == ProcessInstance.STATE_COMPLETED) {
// Displays total count of completed process instances
counter = registry.counter("automatiko.process.completed.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
} else {
// Displays total count of aborted process instances
counter = registry.counter("automatiko.process.aborted.count", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
}
counter.increment();
if (processInstance.getStartDate() != null) {
// Displays duration of process instances - from start to completion
Timer instanceDuration = registry.timer("automatiko.process.instances.duration", Arrays.asList(Tag.of("application", application.orElse("")), Tag.of("version", version.orElse("")), Tag.of("processId", processInstance.getProcessId()), Tag.of("processVersion", processInstance.getProcess().getVersion() == null ? "unknown" : processInstance.getProcess().getVersion())));
final long duration = millisToSeconds(processInstance.getEndDate().getTime() - processInstance.getStartDate().getTime());
instanceDuration.record(Duration.ofSeconds(duration));
}
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class EndNodeInstance method internalTrigger.
public void internalTrigger(final NodeInstance from, String type) {
super.internalTrigger(from, type);
if (!io.automatiko.engine.workflow.process.core.Node.CONNECTION_DEFAULT_TYPE.equals(type)) {
throw new IllegalArgumentException("An EndNode only accepts default incoming connections!");
}
leaveTime = new Date();
boolean hidden = false;
if (getNode().getMetaData().get(HIDDEN) != null) {
hidden = true;
}
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;
});
}
InternalProcessRuntime runtime = getProcessInstance().getProcessRuntime();
if (!hidden) {
runtime.getProcessEventSupport().fireBeforeNodeLeft(this, runtime);
}
((NodeInstanceContainer) getNodeInstanceContainer()).removeNodeInstance(this);
if (getEndNode().isTerminate()) {
if (getNodeInstanceContainer() instanceof CompositeNodeInstance) {
if (getEndNode().getScope() == PROCESS_SCOPE) {
getProcessInstance().setState(STATE_COMPLETED);
} else {
while (!getNodeInstanceContainer().getNodeInstances().isEmpty()) {
((io.automatiko.engine.workflow.process.instance.NodeInstance) getNodeInstanceContainer().getNodeInstances().iterator().next()).cancel();
}
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).setState(STATE_COMPLETED);
}
} else {
((NodeInstanceContainer) getNodeInstanceContainer()).nodeInstanceCompleted(this, null);
}
if (!hidden) {
runtime.getProcessEventSupport().fireAfterNodeLeft(this, runtime);
}
String uniqueId = (String) getNode().getMetaData().get(UNIQUE_ID);
if (uniqueId == null) {
uniqueId = ((NodeImpl) getNode()).getUniqueId();
}
((WorkflowProcessInstanceImpl) getProcessInstance()).addCompletedNodeId(uniqueId);
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class AbstractProcessInstance method buildTags.
protected Tags buildTags() {
return new Tags() {
Collection<String> values = ((WorkflowProcessInstanceImpl) processInstance()).getTags().stream().map(t -> t.getValue()).collect(Collectors.toList());
@Override
public Collection<String> values() {
return values;
}
@Override
public boolean remove(String id) {
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
boolean removed = pi.removedTag(id);
removeOnFinish();
return removed;
}
@Override
public Tag get(String id) {
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
return pi.getTags().stream().filter(t -> t.getId().equals(id)).findFirst().orElse(null);
}
@Override
public void add(String value) {
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
pi.addTag(value);
removeOnFinish();
}
@Override
public Collection<Tag> get() {
WorkflowProcessInstanceImpl pi = (WorkflowProcessInstanceImpl) processInstance();
return pi.getTags();
}
};
}
use of io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl in project automatiko-engine by automatiko-io.
the class AbstractProcessInstance method populateChildProcesses.
@SuppressWarnings("unchecked")
protected void populateChildProcesses(Process<?> process, Collection<ProcessInstance<? extends Model>> collection, ProcessInstanceReadMode mode) {
WorkflowProcessInstanceImpl instance = (WorkflowProcessInstanceImpl) processInstance();
List<String> children = instance.getChildren().get(process.id());
if (children != null && !children.isEmpty()) {
for (String id : children) {
process.instances().findById(id, mode).ifPresent(pi -> collection.add((ProcessInstance<? extends Model>) pi));
}
}
}
Aggregations