Hey everyone,
I wrote 2 functions to retrieve extensions properties from a process model instance and user tasks. They look as follow:
private String getProcessModelExtensionProperty(DelegateTask delegateTask, String propertyKey) {
String propertyValue = null;
BpmnModelInstance model = delegateTask.getExecution().getBpmnModelInstance();
try {
List<CamundaProperty> processModelExtensionProperties =
model.getModelElementsByType(CamundaProperty.class)
.stream()
.filter(camundaProperty ->
camundaProperty.getCamundaName()
.equals(propertyKey))
.collect(Collectors.toList());
if (processModelExtensionProperties.isEmpty()) {
return propertyValue;
} else {
propertyValue = processModelExtensionProperties.get(0).getCamundaValue();
}
} catch (Exception e) {
LOGGER.warn("Caught {} while trying to retrieve the " + propertyKey + " property from a process model", e);
}
return propertyValue;
}
private String getUserTaskExtensionProperty(DelegateTask delegateTask, String propertyKey) {
String propertyValue = null;
try {
CamundaProperties camundaProperties = delegateTask.getExecution()
.getBpmnModelElementInstance()
.getExtensionElements()
.getElementsQuery()
.filterByType(CamundaProperties.class).singleResult();
List<CamundaProperty> userTaskExtensionProperties = camundaProperties.getCamundaProperties()
.stream()
.filter(camundaProperty ->
camundaProperty.getCamundaName()
.equals(propertyKey))
.collect(Collectors.toList());
if (userTaskExtensionProperties.isEmpty()) {
return propertyValue;
} else {
propertyValue = userTaskExtensionProperties.get(0).getCamundaValue();
}
} catch (Exception e) {
LOGGER.warn("Caught {} while trying to retrieve the " + propertyKey + " property of a user task", e);
}
return propertyValue;
}
But now i realized, that the method that was supposed to retrieve process model extensions properties only also retrieves extension properties from user tasks.
Is there a better way to just exclusively get process model extension properties?
Also, currently this property is retireved in every single user task through a task listener. What would be a good approach to maybe only look it up once and kinda cache it? Since it would be the same value for every user task, I don’t know how performant the Camunda API performs these lookups and always retireving all extension properties and filtering them seems very overkill
Cheers,
Dirk