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;
}
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));
}
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));
}
Aggregations