From 5253404cac988d416fb93d01bc6f614ff08c3534 Mon Sep 17 00:00:00 2001 From: William Welling Date: Tue, 17 Sep 2024 08:10:17 -0500 Subject: [PATCH] Get node inherited property values --- .../rest/camunda/service/BpmnModelFactory.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java b/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java index fbd9094a..f3d656db 100644 --- a/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java +++ b/src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java @@ -1,13 +1,14 @@ package org.folio.rest.camunda.service; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Objects; import java.util.Optional; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.commons.lang3.reflect.FieldUtils; import org.camunda.bpm.engine.delegate.Expression; import org.camunda.bpm.model.bpmn.Bpmn; @@ -150,8 +151,8 @@ private void eventSubprocess(ProcessBuilder processBuilder, Node node) throws Sc String expression = ((StartEvent) node).getExpression(); if (type != StartEventType.NONE && expression == null) { - // TODO: implement and ensure validation - throw new RuntimeException(String.format("%s start event requests an expression", type)); + // TODO: create custom exception and controller advice to handle better + throw new RuntimeException(String.format("%s start event requires an expression", type)); } builder = ((StartEventBuilder) builder).id(node.getIdentifier()).name(node.getName()); @@ -406,9 +407,11 @@ private void expressions(BpmnModelInstance model, List nodes) { FieldUtils.getAllFieldsList(delegate.get().getClass()).stream() .filter(df -> Expression.class.isAssignableFrom(df.getType())) - .map(df -> FieldUtils.getDeclaredField(node.getClass(), df.getName(), true)).forEach(f -> { + .map(df -> FieldUtils.getField(node.getClass(), df.getName(), true)) + .filter(f -> Objects.nonNull(f)) + .forEach(f -> { try { - Object value = f == null ? null : f.get(node); + Object value = f.get(node); if (Objects.nonNull(value)) { CamundaField field = model.newInstance(CamundaField.class); field.setCamundaName(f.getName()); @@ -432,7 +435,6 @@ private void expressions(BpmnModelInstance model, List nodes) { // TODO: create custom exception and controller advice to handle better throw new RuntimeException("Task must have delegate representation!"); } - } }); }