use of org.jbpm.marshalling.impl.ProtobufRuleFlowProcessInstanceMarshaller in project jbpm by kiegroup.
the class ProcessInstanceInfo method transform.
public void transform() {
// if (processInstance == null) {
// return;
// }
ByteArrayOutputStream baos = new ByteArrayOutputStream();
boolean variablesChanged = false;
try {
ProcessMarshallerWriteContext context = new ProcessMarshallerWriteContext(baos, null, null, null, null, this.env);
context.setProcessInstanceId(processInstance.getId());
context.setState(processInstance.getState() == ProcessInstance.STATE_ACTIVE ? ProcessMarshallerWriteContext.STATE_ACTIVE : ProcessMarshallerWriteContext.STATE_COMPLETED);
String processType = ((ProcessInstanceImpl) processInstance).getProcess().getType();
saveProcessInstanceType(context, processInstance, processType);
ProcessInstanceMarshaller marshaller = ProcessMarshallerRegistry.INSTANCE.getMarshaller(processType);
Object result = marshaller.writeProcessInstance(context, processInstance);
if (marshaller instanceof ProtobufRuleFlowProcessInstanceMarshaller && result != null) {
JBPMMessages.ProcessInstance _instance = (JBPMMessages.ProcessInstance) result;
PersisterHelper.writeToStreamWithHeader(context, _instance);
}
context.close();
} catch (IOException e) {
throw new IllegalArgumentException("IOException while storing process instance " + processInstance.getId() + ": " + e.getMessage(), e);
}
byte[] newByteArray = baos.toByteArray();
if (variablesChanged || !Arrays.equals(newByteArray, processInstanceByteArray)) {
this.state = processInstance.getState();
this.lastModificationDate = new Date();
this.processInstanceByteArray = newByteArray;
this.eventTypes.clear();
for (String type : processInstance.getEventTypes()) {
eventTypes.add(type);
}
}
if (!processInstance.getProcessId().equals(this.processId)) {
this.processId = processInstance.getProcessId();
}
((WorkflowProcessInstanceImpl) processInstance).setPersisted(true);
}
Aggregations