How to retrieve process extension properties?

Hello,

is there any way to retrieve the process extension properties through the java api? I thought you might get it through BpmnModelInstance, but wasn’t able to so far.

Would really appreciate some help.

@dirkw65 based on activity type, you can get extension properties from DelegateTask/Delegate Execution or by parsing the whole process definition xml itself.

Example to get extension properties from DelegateTask/DelegateExecution:

UserTask:

UserTaskImpl userTaskImpl = bpmnModelElementInstance.getModelInstance().getModelElementById(modelElementId);
ExtensionElements userTaskExtensionElements = userTaskImpl.getExtensionElements();
Collection<CamundaProperty> userTaskProperties = userTaskExtensionElements.getElementsQuery()
              .filterByType(CamundaProperties.class).singleResult().getCamundaProperties();

StartEvent:

StartEventImpl startEventImpl = bpmnModelElementInstance.getModelInstance().getModelElementById(modelElementId);
ExtensionElements startEventExtensionElements = startEventImpl.getExtensionElements();
Collection<CamundaProperty> startEventProperties = startEventExtensionElements.getElementsQuery()
          .filterByType(CamundaProperties.class).singleResult().getCamundaProperties();

Parsing whole bpmn file:

public Collection<CamundaProperty> parseBpmn(String xml) {
  try (InputStream bpmn20XMLStream = new ByteArrayInputStream(bpmn20XML.getBytes(StandardCharsets.UTF_8))) {
    BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(xml);
    Collection<UserTask> userTasks = bpmnModelInstance.getModelElementsByType(UserTask.class);
    userTasks.stream().forEach(userTask -> {
    if (userTask instanceof UserTask) {
      return userTask.getExtensionElements().getElementsQuery()
        .filterByType(CamundaProperties.class).singleResult().getCamundaProperties();
  });
 }}
2 Likes

@aravindhrs thank you, I’m able to retrieve the properties of a user task, but what I’m actually looking for is the properties that i marked in this picture of a sample .bpmn:

@dirkw65 you can try something like this.

public Collection<CamundaProperty> parseBpmn(String bpmnXML) throws IOException {
    try (InputStream bpmn20XMLStream = new ByteArrayInputStream(bpmnXML.getBytes(StandardCharsets.UTF_8))) {
      BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(bpmn20XMLStream);
      Collection<ProcessImpl> processImplList = bpmnModelInstance.getModelElementsByType(ProcessImpl.class);
      processImplList.stream().forEach(processImpl -> {
        if (processImpl instanceof ProcessImpl) {
          processImpl.getExtensionElements().getElementsQuery().filterByType(CamundaProperties.class).singleResult()
              .getCamundaProperties();
          //add more logic to extract properties
        }
      });
    }
    return null;
  }

Your element type should be ProcessImpl to get extension elements at the root process definition level.

1 Like

@aravindhrs This looks like a good solution, however i get a NullPointerException at

Collection<ProcessImpl> processImplList = bpmnModelInstance.getModelElementsByType(ProcessImpl.class);

Did you test this and get the process extension properties successfully?

@dirkw65
I tried the following code and it works fine.

public class LoggerDelegate implements JavaDelegate {
 
  private final Logger LOGGER = Logger.getLogger(LoggerDelegate.class.getName());
  
  public void execute(DelegateExecution execution) throws Exception {
    BpmnModelInstance modelInstance = execution.getBpmnModelInstance();
    Collection<CamundaProperty> elementInstances = modelInstance.getModelElementsByType(CamundaProperty.class);
    if (elementInstances == null) return;
	for (CamundaProperty camundaProperty : elementInstances) {
		CamundaProperty aa = camundaProperty;
		LOGGER.info("--->" + aa.getCamundaName() + "=" + aa.getCamundaValue());
	}
  }
}
3 Likes

@cheppin

this worked perfectly, thanks a lot!