AnsweredAssumed Answered

Converting process instance from JSON to BpmnModel

Question asked by medovarszki on Oct 26, 2015
Latest reply on Nov 4, 2015 by medovarszki
Hi all,

I got a JSON representation of a process instance from the Activiti REST (see the attached 'process.json')
I want to create a diagram representation from this JSON with highlighted process history (tasks and flow elements), so I'd like to parse this JSON to a BpmnModel object (processDefJson contains the attached definition):

ObjectMapper mapper = new ObjectMapper();
BpmnJsonConverter converter = new BpmnJsonConverter();
JsonNode procDefJson = mapper.readTree(processDefJson.toString());
BpmnModel procDefModel = converter.convertToBpmnModel(procDefJson);

//getting the process instance history
JsonObject jsonRequest = new JsonObject();
jsonRequest.addProperty("processInstanceId", processInstanceId);
Representation requestBodyObject = new StringRepresentation(jsonRequest.toString(), MediaType.APPLICATION_JSON);
Representation resource = WorkflowUtils.getClientResource("query/historic-activity-instances").post(requestBodyObject);
JsonObject processHistoryJson = WorkflowUtils.getAsJsonElement(resource).getAsJsonObject();
JsonArray processHistory = processHistoryJson.get("data").getAsJsonArray();

List<String> highLightedActivities = Lists.newArrayList();
List<String> highLightedFlows = Lists.newArrayList();
            
for(JsonElement element : processHistory) {
    highLightedActivities.add(element.getAsJsonObject().get("id").getAsString());
}
            
ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
InputStream generatedDiagram = processDiagramGenerator.generateDiagram(procDefModel, "png", highLightedActivities, highLightedFlows);


The snippet above results an NPE at the diagram generation because of my procDefModel contains no processes, but the JSON does. If I'm right, something is wrong at the BpmnJsonConverter. The convertToBpmnModel(JsonNode modelNode) method returns at line 434 (shapesArrayNode is null), but I'm confused why.

I'm working with Activiti 5.18.0, Jackson-databind 2.2.3 for mapping and Restlet 2.1.1

Attachments

Outcomes