Search in sources :

Example 1 with ArchiveBuilder

use of io.automatiko.engine.api.workflow.ArchiveBuilder 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 ArchiveBuilder

use of io.automatiko.engine.api.workflow.ArchiveBuilder 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)

Aggregations

ArchiveBuilder (io.automatiko.engine.api.workflow.ArchiveBuilder)2 ArchivedProcessInstance (io.automatiko.engine.api.workflow.ArchivedProcessInstance)2 Application (io.automatiko.engine.api.Application)1 Model (io.automatiko.engine.api.Model)1 ArchivedVariable (io.automatiko.engine.api.workflow.ArchivedVariable)1 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 JsonArchiveBuilder (io.automatiko.engine.workflow.json.JsonArchiveBuilder)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1