Search in sources :

Example 16 with Process

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

the class ProcessInstanceManagementResource method importInstance.

@APIResponses(value = { @APIResponse(responseCode = "404", description = "In case of instance with given process id was not found", content = @Content(mediaType = "application/json")), @APIResponse(responseCode = "200", description = "Exported process instance", content = @Content(mediaType = "application/json")) })
@Operation(summary = "Imports exported process instance and returns its details after the import")
@POST
@Path("/{processId}/instances")
@Produces(MediaType.APPLICATION_JSON)
public ProcessInstanceDetailsDTO importInstance(@Context UriInfo uriInfo, @Parameter(description = "Unique identifier of the process", required = true) @PathParam("processId") String processId, @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, @Parameter(description = "The input model for orders instance", schema = @Schema(type = SchemaType.OBJECT, implementation = Map.class)) JsonExportedProcessInstance instance) {
    identitySupplier.buildIdentityProvider(user, groups);
    return UnitOfWorkExecutor.executeInUnitOfWork(application.unitOfWorkManager(), () -> {
        ProcessInstance<?> pi = exporter.importInstance(instance);
        ProcessInstanceDetailsDTO details = new ProcessInstanceDetailsDTO();
        details.setId(pi.id());
        details.setProcessId(processId);
        details.setBusinessKey(pi.businessKey());
        details.setDescription(pi.description());
        details.setFailed(pi.errors().isPresent());
        if (pi.errors().isPresent()) {
            details.setErrors(pi.errors().get().errors().stream().map(e -> new ErrorInfoDTO(e.failedNodeId(), e.errorId(), e.errorMessage(), e.errorDetails())).collect(Collectors.toList()));
        }
        details.setImage(uriInfo.getBaseUri().toString() + "management/processes/" + processId + "/instances/" + pi.id() + "/image");
        details.setTags(pi.tags().values());
        details.setVariables(pi.variables());
        VariableScope variableScope = (VariableScope) ((ContextContainer) ((AbstractProcess<?>) pi.process()).process()).getDefaultContext(VariableScope.VARIABLE_SCOPE);
        details.setVersionedVariables(variableScope.getVariables().stream().filter(v -> v.hasTag(Variable.VERSIONED_TAG)).map(v -> v.getName()).collect(Collectors.toList()));
        return details;
    });
}
Also used : Produces(javax.ws.rs.Produces) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) ProcessInstanceExporter(io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter) MediaType(javax.ws.rs.core.MediaType) Application(io.automatiko.engine.api.Application) QueryParam(javax.ws.rs.QueryParam) ProcessImageNotFoundException(io.automatiko.engine.api.workflow.ProcessImageNotFoundException) ContextContainer(io.automatiko.engine.workflow.base.core.ContextContainer) SchemaType(org.eclipse.microprofile.openapi.annotations.enums.SchemaType) VariableNotFoundException(io.automatiko.engine.api.workflow.VariableNotFoundException) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APIResponse(org.eclipse.microprofile.openapi.annotations.responses.APIResponse) Instance(javax.enterprise.inject.Instance) DELETE(javax.ws.rs.DELETE) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) IoUtils(io.automatiko.engine.services.utils.IoUtils) Context(javax.ws.rs.core.Context) Model(io.automatiko.engine.api.Model) IdentityProvider(io.automatiko.engine.api.auth.IdentityProvider) Operation(org.eclipse.microprofile.openapi.annotations.Operation) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) Parameter(org.eclipse.microprofile.openapi.annotations.parameters.Parameter) ProcessInstanceDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO) ProcessInstanceReadMode(io.automatiko.engine.api.workflow.ProcessInstanceReadMode) Optional(java.util.Optional) Tag(org.eclipse.microprofile.openapi.annotations.tags.Tag) Variable(io.automatiko.engine.workflow.base.core.context.variable.Variable) UriInfo(javax.ws.rs.core.UriInfo) ProcessInstanceNotFoundException(io.automatiko.engine.api.workflow.ProcessInstanceNotFoundException) PathParam(javax.ws.rs.PathParam) AbstractProcessInstance(io.automatiko.engine.workflow.AbstractProcessInstance) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) ArchivedProcessInstance(io.automatiko.engine.api.workflow.ArchivedProcessInstance) JsonArchiveBuilder(io.automatiko.engine.workflow.json.JsonArchiveBuilder) IdentitySupplier(io.automatiko.engine.api.auth.IdentitySupplier) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) WorkflowProcess(io.automatiko.engine.workflow.process.core.WorkflowProcess) Process(io.automatiko.engine.api.workflow.Process) ProcessDTO(io.automatiko.engine.addons.process.management.model.ProcessDTO) Content(org.eclipse.microprofile.openapi.annotations.media.Content) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) Status(javax.ws.rs.core.Response.Status) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) UnitOfWorkExecutor(io.automatiko.engine.services.uow.UnitOfWorkExecutor) POST(javax.ws.rs.POST) Logger(org.slf4j.Logger) Schema(org.eclipse.microprofile.openapi.annotations.media.Schema) IOException(java.io.IOException) ExternalDocumentation(org.eclipse.microprofile.openapi.annotations.ExternalDocumentation) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Collections(java.util.Collections) ProcessInstanceDetailsDTO(io.automatiko.engine.addons.process.management.model.ProcessInstanceDetailsDTO) ErrorInfoDTO(io.automatiko.engine.addons.process.management.model.ErrorInfoDTO) AbstractProcess(io.automatiko.engine.workflow.AbstractProcess) VariableScope(io.automatiko.engine.workflow.base.core.context.variable.VariableScope) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 17 with Process

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

the class ProcessInstanceExporter method importInstance.

public ProcessInstance<?> importInstance(JsonExportedProcessInstance instance) {
    if (!instance.getSubInstances().isEmpty()) {
        for (JsonExportedProcessInstance subinstance : instance.getSubInstances()) {
            importInstance(subinstance);
        }
    }
    String processId = instance.getInstance().get("processId").asText();
    String processVersion = instance.getInstance().has("processVersion") ? instance.getInstance().get("processVersion").asText() : null;
    if (processVersion != null) {
        processId += "_" + processVersion.replaceAll("\\.", "_");
    }
    Process<?> process = processData.get(processId);
    return process.importInstance(StringExportedProcessInstance.of(instance.getHeader().toString(), instance.getInstance().toString(), instance.getTimers().toString(), s -> {
        return instance.convertTimers();
    }));
}
Also used : JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) JsonExportedProcessInstance(io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance) StringExportedProcessInstance(io.automatiko.engine.workflow.StringExportedProcessInstance) List(java.util.List) Model(io.automatiko.engine.api.Model) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) Collection(java.util.Collection) Map(java.util.Map) Process(io.automatiko.engine.api.workflow.Process) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) ArrayList(java.util.ArrayList)

Example 18 with Process

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

Aggregations

Process (io.automatiko.engine.api.workflow.Process)18 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)15 Model (io.automatiko.engine.api.Model)13 List (java.util.List)11 Map (java.util.Map)11 ArrayList (java.util.ArrayList)10 HashMap (java.util.HashMap)10 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 Collection (java.util.Collection)9 Application (io.automatiko.engine.api.Application)8 Optional (java.util.Optional)8 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)7 Collectors (java.util.stream.Collectors)7 ProcessInstanceReadMode (io.automatiko.engine.api.workflow.ProcessInstanceReadMode)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 WorkItem (io.automatiko.engine.api.workflow.WorkItem)5 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)5 AbstractProcess (io.automatiko.engine.workflow.AbstractProcess)5 IOException (java.io.IOException)5