Search in sources :

Example 11 with TrustedIdentityProvider

use of io.automatiko.engine.api.auth.TrustedIdentityProvider in project automatiko-engine by automatiko-io.

the class Controller method cleanup.

@Override
public DeleteControl cleanup($DataType$ resource, Context context) {
    try {
        String trigger = "deleted";
        IdentityProvider.set(new TrustedIdentityProvider("System<messaging>"));
        io.automatiko.engine.services.uow.UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
            String correlation = resource.getMetadata().getName();
            if (correlation != null) {
                LOGGER.debug("Correlation ({}) is set, attempting to find if there is matching instance already active", correlation);
                Optional<? extends ProcessInstance> possiblyFound = (Optional<? extends ProcessInstance>) process.instances().findById(correlation);
                if (possiblyFound.isEmpty()) {
                    possiblyFound = (Optional<? extends ProcessInstance>) process.instances().findById(correlation, ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.MUTABLE);
                }
                possiblyFound.ifPresent(pi -> {
                    ProcessInstance pInstance = (ProcessInstance) pi;
                    LOGGER.debug("Found process instance {} matching correlation {}, signaling deletion to allow cleanup", pInstance.id(), correlation);
                    pInstance.send(Sig.of("Message-" + trigger, resource));
                    if (pInstance.status() == ProcessInstance.STATE_ACTIVE) {
                        LOGGER.debug("Instance is still active after signal, aborting...");
                        pInstance.abort();
                    }
                });
                return null;
            }
            return null;
        });
    } catch (Throwable t) {
        LOGGER.error("Encountered problems while deleting instance", t);
    }
    return DeleteControl.defaultDelete();
}
Also used : Optional(java.util.Optional) TrustedIdentityProvider(io.automatiko.engine.api.auth.TrustedIdentityProvider) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance)

Aggregations

TrustedIdentityProvider (io.automatiko.engine.api.auth.TrustedIdentityProvider)11 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)7 Optional (java.util.Optional)5 ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)3 Model (io.automatiko.engine.api.Model)2 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)2 Collection (java.util.Collection)2 Application (io.automatiko.engine.api.Application)1 AccessDeniedException (io.automatiko.engine.api.auth.AccessDeniedException)1 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)1 ProcessInstanceJobDescription (io.automatiko.engine.api.jobs.ProcessInstanceJobDescription)1 ProcessJobDescription (io.automatiko.engine.api.jobs.ProcessJobDescription)1 EventListener (io.automatiko.engine.api.runtime.process.EventListener)1 Process (io.automatiko.engine.api.workflow.Process)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)1 InternalProcessRuntime (io.automatiko.engine.workflow.base.instance.InternalProcessRuntime)1 NodeInstance (io.automatiko.engine.workflow.process.instance.NodeInstance)1 WorkflowProcessInstanceImpl (io.automatiko.engine.workflow.process.instance.impl.WorkflowProcessInstanceImpl)1 CompositeNodeInstance (io.automatiko.engine.workflow.process.instance.node.CompositeNodeInstance)1