BPMN Parse listener for call activity

I have created a parse listener where I am able to read all activities within a bpmn. Is there a way to parse the call-activity or sub-process during parsing the parent bpmn?

I get the callactivity name like this:
String bpmnFileName = elem.attributeMap.get("calledElement").value;

I don’t think it’s possible in general since the called process model might not be a part of this application. It could be in another application working with the same process DB.

What problem are you trying to solve?

@mns you can read any bpmn model using this api:

BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(stream);

(or)

@Autowired
private RepositoryService repositoryService;

BpmnModelInstance bpmnModelInstance = repositoryService.getBpmnModelInstance(execution.getProcessDefinitionId());
//or
BpmnModelInstance bpmnModelInstance = repositoryService.getResourceAsStream(deploymentId, resourceName);

Dependency:

<dependency>
    <groupId>org.camunda.bpm.model</groupId>
    <artifactId>camunda-bpmn-model</artifactId>
    <version>7.13.0</version>
</dependency>

Reference: https://docs.camunda.org/manual/7.13/user-guide/model-api/bpmn-model-api/read-a-model/

@aravindhrs Looks like repositoryService is not available during process parsing. I see that it is available during event listeners of process instance though.

@mns All the process engine services are available once process engine is bootstrapped.

Below api’s will accept bpmn file or input stream also.

BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromFile(file);
BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(stream);

I would like to read from repositoryService dynamically the bpmn and not directly from the file. Here is what I have to register the process parseListener :

@Component
public class pluginRegisterer extends AbstractProcessEnginePlugin {
@Override
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) {
List preParseListeners = processEngineConfiguration.getCustomPreBPMNParseListeners();
if(preParseListeners == null) {
preParseListeners = new ArrayList();
processEngineConfiguration.setCustomPreBPMNParseListeners(preParseListeners);
}
preParseListeners.add(new deployedProcessParseListener());
}

}

Here is the deployedProcessParseListener.java. repositoryService is null though.

@Slf4j
@Component
public class deployedProcessParseListener extends AbstractBpmnParseListener {

@Autowired private RepositoryService repositoryService;
@Autowired private RuntimeService runtimeService;

 @Override
public void parseProcess(Element processElement, ProcessDefinitionEntity processDefinition) {
  InputStream modelInstance = repositoryService.getResourceAsStream(processDefinition.getDeploymentId(), processDefinition.getResourceName());
    BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(modelInstance);
    log.info("process=bpmnModelInstance event={}", bpmnModelInstance);

}
}