use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.
the class ProcessInstanceMarshaller method unmarshallWorkflowProcessInstance.
public WorkflowProcessInstance unmarshallWorkflowProcessInstance(byte[] data, Process<?> process) {
Map<String, io.automatiko.engine.api.definition.process.Process> processes = new HashMap<String, io.automatiko.engine.api.definition.process.Process>();
io.automatiko.engine.api.definition.process.Process p = ((AbstractProcess<?>) process).process();
// this can include version number in the id
processes.put(process.id(), p);
// this is raw process id as defined in bpmn or so
processes.put(p.getId(), p);
try (ByteArrayInputStream bais = new ByteArrayInputStream(data)) {
MarshallerReaderContext context = new MarshallerReaderContext(bais, null, processes, this.env);
ObjectInputStream stream = context.stream;
String processInstanceType = stream.readUTF();
io.automatiko.engine.workflow.marshalling.impl.ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processInstanceType);
WorkflowProcessInstance pi = (WorkflowProcessInstance) marshaller.readProcessInstance(context);
context.close();
return pi;
} catch (Exception e) {
throw new RuntimeException("Error while unmarshalling process instance", e);
}
}
use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.
the class TestJobService method triggerProcessJob.
@SuppressWarnings({ "unchecked", "rawtypes" })
public void triggerProcessJob(String jobId) {
ProcessJobDescription job = (ProcessJobDescription) jobs.remove(jobId);
if (job == null) {
throw new IllegalArgumentException("Job with id " + jobId + " not found");
}
int limit = job.expirationTime().repeatLimit();
try {
LOGGER.debug("Job {} started", job.id());
Process process = mappedProcesses.get(job.processId());
if (process == null) {
LOGGER.warn("No process found for process id {}", job.processId());
return;
}
IdentityProvider.set(new TrustedIdentityProvider("System<timer>"));
UnitOfWorkExecutor.executeInUnitOfWork(unitOfWorkManager, () -> {
ProcessInstance<?> pi = process.createInstance(process.createModel());
if (pi != null) {
pi.start(TRIGGER, null, null);
}
return null;
});
limit--;
if (limit == 0) {
jobs.remove(jobId);
}
LOGGER.debug("Job {} completed", job.id());
} finally {
if (job.expirationTime().next() != null) {
jobs.remove(jobId);
scheduleProcessJob(job);
} else {
jobs.remove(jobId);
}
}
}
use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.
the class DynamoDBProcessInstances method values.
@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
LOGGER.debug("values() called");
Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
StringBuilder condition = new StringBuilder();
attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
condition.append(STATUS_FIELD + " = :status ");
ScanRequest request = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).limit(page * size).build();
return dynamodb.scanPaginator(request).items().stream().map(item -> {
try {
byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.
the class CassandraProcessInstances method values.
@Override
public Collection values(ProcessInstanceReadMode mode, int status, int page, int size) {
LOGGER.debug("values() called");
Select select = selectFrom(config.keyspace().orElse("automatiko"), tableName).column(CONTENT_FIELD).column(VERSION_FIELD).whereColumn(STATUS_FIELD).isEqualTo(literal(status));
ResultSet rs = cqlSession.execute(select.build());
return rs.all().stream().map(item -> {
try {
byte[] content = ByteUtils.getArray(item.getByteBuffer(CONTENT_FIELD));
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, item.getLong(VERSION_FIELD)) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).skip(calculatePage(page, size)).limit(size).collect(Collectors.toList());
}
use of io.automatiko.engine.api.workflow.Process in project automatiko-engine by automatiko-io.
the class DynamoDBProcessInstances method findByIdOrTag.
@Override
public Collection findByIdOrTag(ProcessInstanceReadMode mode, int status, String... values) {
LOGGER.debug("findByIdOrTag() called for values {}", values);
Map<String, AttributeValue> attrValues = new HashMap<String, AttributeValue>();
int counter = 0;
StringBuilder condition = new StringBuilder();
attrValues.put(":status", AttributeValue.builder().n(String.valueOf(status)).build());
condition.append(STATUS_FIELD + "= :status AND ");
for (String value : values) {
attrValues.put(":value" + counter, AttributeValue.builder().s(value).build());
condition.append("contains(" + TAGS_FIELD + ", :value" + counter + ") OR ");
counter++;
}
condition.delete(condition.length() - 4, condition.length());
ScanRequest query = ScanRequest.builder().tableName(tableName).filterExpression(condition.toString()).expressionAttributeValues(attrValues).build();
return dynamodb.scan(query).items().stream().map(item -> {
try {
byte[] content = item.get(CONTENT_FIELD).b().asByteArray();
return mode == MUTABLE ? marshaller.unmarshallProcessInstance(codec.decode(content), process, Long.parseLong(item.get(VERSION_FIELD).n())) : marshaller.unmarshallReadOnlyProcessInstance(codec.decode(content), process);
} catch (AccessDeniedException e) {
return null;
}
}).filter(pi -> pi != null).collect(Collectors.toList());
}
Aggregations