Search in sources :

Example 1 with ArchivedProcessInstance

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

the class ArchiveEndOfInstanceStrategy method perform.

@Override
public void perform(ProcessInstance<?> instance) {
    ArchiveBuilder builder = new JsonArchiveBuilder();
    ArchivedProcessInstance archived = instance.archive(builder);
    storage.store(archived);
}
Also used : JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) ArchiveBuilder(io.automatiko.engine.api.workflow.ArchiveBuilder) JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance)

Example 2 with ArchivedProcessInstance

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

the class ExportProcessInstanceTest method testBasicUserTaskProcessArchive.

@Test
public void testBasicUserTaskProcessArchive() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "John");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    // archive active process instance
    ArchivedProcessInstance archived = processInstance.archive(new ArchiveBuilder() {

        @Override
        public ArchivedVariable variable(String name, Object value) {
            return new ArchivedVariable(name, value) {

                @Override
                public byte[] data() {
                    return getValue().toString().getBytes();
                }
            };
        }

        @Override
        public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
            return new ArchivedProcessInstance(id, processId, exported);
        }
    });
    assertThat(archived).isNotNull();
    assertThat(archived.getExport()).isNotNull();
    assertThat(archived.getVariables()).isNotNull();
    assertThat(archived.getSubInstances()).isNotNull();
    assertThat(archived.getVariables()).hasSize(1);
    assertThat(archived.getSubInstances()).hasSize(0);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    // and now let's export completed instance
    archived = processInstance.archive(new ArchiveBuilder() {

        @Override
        public ArchivedVariable variable(String name, Object value) {
            return new ArchivedVariable(name, value) {

                @Override
                public byte[] data() {
                    return getValue().toString().getBytes();
                }
            };
        }

        @Override
        public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
            return new ArchivedProcessInstance(id, processId, exported);
        }
    });
    assertThat(archived).isNotNull();
    assertThat(archived.getExport()).isNotNull();
    assertThat(archived.getVariables()).isNotNull();
    assertThat(archived.getSubInstances()).isNotNull();
    assertThat(archived.getVariables()).hasSize(1);
    assertThat(archived.getSubInstances()).hasSize(0);
}
Also used : HashMap(java.util.HashMap) ArchivedVariable(io.automatiko.engine.api.workflow.ArchivedVariable) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) ArchiveBuilder(io.automatiko.engine.api.workflow.ArchiveBuilder) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 3 with ArchivedProcessInstance

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

the class AbstractProcessInstance method archive.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public ArchivedProcessInstance archive(ArchiveBuilder builder) {
    ArchivedProcessInstance archived = builder.instance(id, process.id(), ((MutableProcessInstances) process().instances()).exportInstance(this, false));
    Map<String, Object> variables = processInstance().getVariables();
    for (Entry<String, Object> var : variables.entrySet()) {
        archived.addVariable(builder.variable(var.getKey(), var.getValue()));
    }
    Collection<ProcessInstance<? extends Model>> subInstances = subprocesses(ProcessInstanceReadMode.MUTABLE);
    List<ArchivedProcessInstance> subinstances = new ArrayList<ArchivedProcessInstance>();
    if (!subInstances.isEmpty()) {
        for (ProcessInstance<? extends Model> si : subInstances) {
            ArchivedProcessInstance subArchived = si.archive(builder);
            subinstances.add(subArchived);
        }
    }
    archived.setSubInstances(subinstances);
    return archived;
}
Also used : Model(io.automatiko.engine.api.Model) ArrayList(java.util.ArrayList) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) WorkflowProcessInstance(io.automatiko.engine.api.runtime.process.WorkflowProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance)

Example 4 with ArchivedProcessInstance

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

the class AbstractProcess method archiveInstance.

public ArchivedProcessInstance archiveInstance(String id, ArchiveBuilder builder) {
    ExportedProcessInstance<?> exported = exportInstance(id, false);
    ArchivedProcessInstance archived = builder.instance(id, this.id(), exported);
    ProcessInstance<?> instance = instances().findById(id, ProcessInstanceReadMode.READ_ONLY).get();
    Map<String, Object> variables = ((AbstractProcessInstance<?>) instance).processInstance().getVariables();
    for (Entry<String, Object> entry : variables.entrySet()) {
        archived.addVariable(builder.variable(entry.getKey(), entry.getValue()));
    }
    return archived;
}
Also used : ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance)

Example 5 with ArchivedProcessInstance

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

the class ProcessInstanceManagementResource method archiveInstance.

@SuppressWarnings("unchecked")
@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given id was not found", content = @Content(mediaType = "application/json", schema = @Schema(type = SchemaType.OBJECT))), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Returns archived process instance for given instance id as zip")
@GET()
@Path("/{processId}/instances/{instanceId}/archive")
@Produces("application/zip")
public Response archiveInstance(@Context UriInfo uriInfo, @Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @Parameter(description = "Unique identifier of the instance", required = true) @PathParam("instanceId") String instanceId, @Parameter(description = "Indicates if the instance should be aborted after export, defaults to false", required = false) @QueryParam("abort") @DefaultValue("false") final boolean abort, @Parameter(description = "User identifier as alternative autroization info", required = false, hidden = true) @QueryParam("user") final String user, @Parameter(description = "Groups as alternative autroization info", required = false, hidden = true) @QueryParam("group") final List<String> groups) {
    identitySupplier.buildIdentityProvider(user, groups);
    ArchivedProcessInstance archived = UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
        Process<?> process = processData.get(processId);
        if (process == null) {
            throw new ProcessInstanceNotFoundException(instanceId);
        }
        Optional<ProcessInstance<?>> instance = (Optional<ProcessInstance<?>>) process.instances().findById(instanceId);
        if (instance.isEmpty()) {
            throw new ProcessInstanceNotFoundException(instanceId);
        }
        ProcessInstance<?> pi = instance.get();
        return pi.archive(new JsonArchiveBuilder());
    });
    try {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        archived.writeAsZip(output);
        ResponseBuilder builder = Response.ok().entity(output.toByteArray());
        if (abort) {
            cancelProcessInstanceId(processId, instanceId, "active", user, groups);
        }
        return builder.header("Content-Type", "application/zip").header("Content-Disposition", "attachment; filename=" + archived.getId() + ".zip").build();
    } catch (Exception e) {
        LOGGER.error("Error generating process instance archive", e);
        return Response.serverError().entity("Error generating process instance archive").build();
    }
}
Also used : JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) Optional(java.util.Optional) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) VariableNotFoundException(io.automatiko.engine.api.workflow.VariableNotFoundException) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Aggregations

ArchivedProcessInstance (io.automatiko.engine.api.workflow.ArchivedProcessInstance)5 Model (io.automatiko.engine.api.Model)2 ArchiveBuilder (io.automatiko.engine.api.workflow.ArchiveBuilder)2 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)2 JsonArchiveBuilder (io.automatiko.engine.workflow.json.JsonArchiveBuilder)2 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)1 Application (io.automatiko.engine.api.Application)1 WorkflowProcessInstance (io.automatiko.engine.api.runtime.process.WorkflowProcessInstance)1 ArchivedVariable (io.automatiko.engine.api.workflow.ArchivedVariable)1 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)1 ProcessImageNotFoundException (io.automatiko.engine.api.workflow.ProcessImageNotFoundException)1 ProcessInstanceNotFoundException (io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException)1 VariableNotFoundException (io.automatiko.engine.api.workflow.VariableNotFoundException)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1