Search in sources :

Example 61 with ProcessInstance

use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessInstanceExporter method exportInstance.

@SuppressWarnings("unchecked")
public JsonExportedProcessInstance exportInstance(String id, ProcessInstance<?> processInstance) {
    Collection<ProcessInstance<? extends Model>> subInstances = processInstance.subprocesses();
    List<JsonExportedProcessInstance> subinstances = new ArrayList<JsonExportedProcessInstance>();
    if (!subInstances.isEmpty()) {
        for (ProcessInstance<? extends Model> si : subInstances) {
            JsonExportedProcessInstance subExported = exportInstance(id + ":" + si.id(), si);
            subinstances.add(subExported);
        }
    }
    ExportedProcessInstance<String> exported = processInstance.process().exportInstance(id, false);
    JsonExportedProcessInstance jsonExported = JsonExportedProcessInstance.of(exported);
    jsonExported.setSubInstances(subinstances);
    return jsonExported;
}
Also used : JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) Model(io.automatiko.engine.api.Model) ArrayList(java.util.ArrayList) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) StringExportedProcessInstance(io.automatiko.engine.workflow.StringExportedProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance)

Example 62 with ProcessInstance

use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.

the class ProcessInstanceManagementResourceTest method setup.

@SuppressWarnings({ "rawtypes", "unchecked" })
@BeforeEach
public void setup() {
    responseBuilder = mock(ResponseBuilder.class);
    Response response = mock(Response.class);
    when((runtimeDelegate).createResponseBuilder()).thenReturn(responseBuilder);
    lenient().when((responseBuilder).status(any(StatusType.class))).thenReturn(responseBuilder);
    lenient().when((responseBuilder).entity(any())).thenReturn(responseBuilder);
    lenient().when((responseBuilder).build()).thenReturn(response);
    application = mock(Application.class);
    Map<String, Process<?>> processes = Mockito.mock(Map.class);
    Process process = mock(Process.class);
    ProcessInstances instances = mock(ProcessInstances.class);
    processInstance = mock(ProcessInstance.class);
    errors = mock(ProcessErrors.class);
    lenient().when(processes.get(anyString())).thenReturn(process);
    lenient().when(process.instances()).thenReturn(instances);
    lenient().when(instances.findById(anyString())).thenReturn(Optional.of(processInstance));
    lenient().when(instances.findById(anyString(), eq(5), any())).thenReturn(Optional.of(processInstance));
    lenient().when(processInstance.errors()).thenReturn(Optional.of(errors));
    lenient().when(processInstance.id()).thenReturn("abc-def");
    lenient().when(processInstance.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    lenient().when(errors.failedNodeIds()).thenReturn("xxxxx");
    lenient().when(errors.errorMessages()).thenReturn("Test error message");
    lenient().when(application.unitOfWorkManager()).thenReturn(new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory()));
    IdentitySupplier identitySupplier = new IdentitySupplier() {

        @Override
        public IdentityProvider buildIdentityProvider(String user, List<String> roles) {
            return new StaticIdentityProvider("test");
        }
    };
    resource = spy(new ProcessInstanceManagementResource(processes, application, identitySupplier));
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Response(javax.ws.rs.core.Response) ProcessInstances(io.automatiko.engine.api.workflow.ProcessInstances) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) StatusType(javax.ws.rs.core.Response.StatusType) CollectingUnitOfWorkFactory(io.automatiko.engine.services.uow.CollectingUnitOfWorkFactory) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) List(java.util.List) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Application(io.automatiko.engine.api.Application) DefaultUnitOfWorkManager(io.automatiko.engine.services.uow.DefaultUnitOfWorkManager) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 63 with ProcessInstance

use of io.automatiko.engine.api.workflow.ProcessInstance in project automatiko-engine by automatiko-io.

the class FileSystemProcessInstances method findById.

@Override
public Optional findById(String id, int status, ProcessInstanceReadMode mode) {
    String resolvedId = resolveId(id);
    if (cachedInstances.containsKey(resolvedId)) {
        ProcessInstance pi = cachedInstances.get(resolvedId);
        if (pi.status() == status) {
            return Optional.of(pi);
        } else {
            return Optional.empty();
        }
    }
    if (resolvedId.contains(":")) {
        if (cachedInstances.containsKey(resolvedId.split(":")[1])) {
            ProcessInstance pi = cachedInstances.get(resolvedId.split(":")[1]);
            if (pi.status() == status) {
                return Optional.of(pi);
            } else {
                return Optional.empty();
            }
        }
    }
    Path processInstanceStorage = Paths.get(storage.toString(), resolvedId);
    if (Files.notExists(processInstanceStorage) || Integer.parseInt(getMetadata(processInstanceStorage, PI_STATUS)) != status) {
        return Optional.empty();
    }
    byte[] data = readBytesFromFile(processInstanceStorage);
    return Optional.of(mode == MUTABLE ? marshaller.unmarshallProcessInstance(data, process, getVersionTracker(processInstanceStorage)) : marshaller.unmarshallReadOnlyProcessInstance(data, process));
}
Also used : Path(java.nio.file.Path) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)63 Model (io.automatiko.engine.api.Model)29 Application (io.automatiko.engine.api.Application)26 HashMap (java.util.HashMap)23 Test (org.junit.jupiter.api.Test)23 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)22 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)21 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)16 List (java.util.List)15 WorkItem (io.automatiko.engine.api.workflow.WorkItem)14 Process (io.automatiko.engine.api.workflow.Process)13 Optional (java.util.Optional)13 Map (java.util.Map)12 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)10 Collections (java.util.Collections)10 ProcessInstanceDuplicatedException (io.automatiko.engine.api.workflow.ProcessInstanceDuplicatedException)9 ArrayList (java.util.ArrayList)9 Collection (java.util.Collection)9 Collectors (java.util.stream.Collectors)9 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)8