Skip to content

Commit

Permalink
Merge pull request #256 from TAMULib/sprint20-255-bpmn-node-to-delega…
Browse files Browse the repository at this point in the history
…te-values

Get node inherited property values
  • Loading branch information
wwtamu authored Sep 18, 2024
2 parents f82e3f7 + 5253404 commit 372e531
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/main/java/org/folio/rest/camunda/service/BpmnModelFactory.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -406,9 +407,11 @@ private void expressions(BpmnModelInstance model, List<Node> 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());
Expand All @@ -432,7 +435,6 @@ private void expressions(BpmnModelInstance model, List<Node> nodes) {
// TODO: create custom exception and controller advice to handle better
throw new RuntimeException("Task must have delegate representation!");
}

}
});
}
Expand Down

0 comments on commit 372e531

Please sign in to comment.