use of org.kie.kogito.jobs.api.event.JobCloudEvent in project kogito-runtimes by kiegroup.
the class JobCloudEventDeserializer method deserialize.
public JobCloudEvent<?> deserialize(byte[] data) {
try {
CloudEvent cloudEvent = objectMapper.readValue(data, CloudEvent.class);
CloudEventData cloudEventData = Objects.requireNonNull(cloudEvent.getData(), "JobCloudEvent data field must not be null");
if (cloudEvent.getType().equals(CreateProcessInstanceJobRequestEvent.CREATE_PROCESS_INSTANCE_JOB_REQUEST)) {
Job job = objectMapper.readValue(cloudEventData.toBytes(), Job.class);
return CreateProcessInstanceJobRequestEvent.builder().withValuesFrom(cloudEvent).withContextFrom(cloudEvent).job(job).build();
} else if (cloudEvent.getType().equals(CancelJobRequestEvent.CANCEL_JOB_REQUEST)) {
CancelJobRequestEvent.JobId jobId = objectMapper.readValue(cloudEventData.toBytes(), CancelJobRequestEvent.JobId.class);
return CancelJobRequestEvent.builder().withValuesFrom(cloudEvent).withContextFrom(cloudEvent).jobId(jobId.getId()).build();
}
throw new DeserializationException("Unknown JobCloudEvent event type: " + cloudEvent.getType());
} catch (IOException e) {
throw new DeserializationException("An error was produced during a JobCloudEvent deserialization: " + e.getMessage(), e);
}
}
Aggregations