use of io.automatiko.engine.workflow.marshalling.impl.MarshallerReaderContext in project automatiko-engine by automatiko-io.
the class ProcessInstanceMarshaller method importWorkflowProcessInstance.
public WorkflowProcessInstance importWorkflowProcessInstance(String header, String data, List<Map<String, String>> timers, 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(new byte[0])) {
Map<String, Object> localEnv = new HashMap<String, Object>(env);
localEnv.put("_import_", true);
localEnv.put("_services_", ((AbstractProcess<?>) process).services());
AutomatikoMessages.ProcessInstance.Builder builder = AutomatikoMessages.ProcessInstance.newBuilder();
JsonFormat.parser().merge(data, builder);
AutomatikoMessages.Header.Builder headerBuilder = AutomatikoMessages.Header.newBuilder();
JsonFormat.parser().merge(header, headerBuilder);
MarshallerReaderContext context = new MarshallerReaderContext(bais, null, processes, localEnv) {
@Override
protected void readStreamHeader() throws IOException, StreamCorruptedException {
}
};
context.parameterObject = builder.build();
PersisterHelper.loadStrategiesIndex(context, headerBuilder.build());
io.automatiko.engine.workflow.marshalling.impl.ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(builder.getProcessType());
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.workflow.marshalling.impl.MarshallerReaderContext 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);
}
}
Aggregations