cancel
Showing results for 
Search instead for 
Did you mean: 

bpmnParse.getCurrentProcessDefinition().getId() returns null

lmazurk
Champ in-the-making
Champ in-the-making
I'm trying to hook into UserTaskBPMNParsePre to set some UserTask properties overriding bpmn.xml definition.
I store those custom properties in external db table and want to connect them with specific UserTask basing on processDefinitionId (it's very convenient in others part of application to use procDefId) and some  others (deploymentId, userTaskId,processDefinitionKey). But seems that bpmnParse.getCurrentProcessDefinition().getId() returns null.

public class CustomUserTaskParseHandlerBefore extends AbstractBpmnParseHandler<UserTask> {

@Override
   protected Class<? extends BaseElement> getHandledType() {
      return UserTask.class;
   }

@Override
   protected void executeParse(BpmnParse bpmnParse, UserTask element) {

                String deploymentId=bpmnParse.getDeployment().getId();//OK
      String processDefKey=bpmnParse.getCurrentProcessDefinition().getKey();//OK
      String processDefId=bpmnParse.getCurrentProcessDefinition().getId();//NOT OK - null
      String userTaskId=element.getId();//OK

                //getting stored custom information
      List<ExtUserTask> lista=service.getAllExtUserTask(deploymentId,processDefId,processDefKey, userTaskId);
                ….
                //setting some custom properties overriding original from bpmn.xml e.g.
                element.setCandidateGroups(overriding_group);
        }
}

I understand that processDefinitionId is generated by activity and that processDefinitionKey is proces id in bpmn.xml scope,
but I have to use rather that generated (and present in db table for process definition) Id cause of there is situation that many same bpmn.xml files are deployed and processDefinitionKey is not unique.

Same situation is if I hook PostParser.

Do you have any suggestion?
2 REPLIES 2

trademak
Star Contributor
Star Contributor
The process definition id is not yet known in the parsing phase of the deployment.
So that's why it still has a value of null.

Best regards,

lmazurk
Champ in-the-making
Champ in-the-making
But this is true only for first time deployment as I understand deployment process.

Later when given process definition is out of process definitions cache parsing is executed to put it back.
At this moment process definition id is perfectly known - look at org.activiti.engine.impl.bpmn.deployer.deploy:
if (deployment.isNew()) {
  …
}
else
{…
  persistedProcessDefinition = processDefinitionManager.findProcessDefinitionByDeploymentAndKey
  …
  processDefinition.setId(persistedProcessDefinition.getId());
  …
}

So, at first time deploy you are rigth - id is not known (maybe in next releases it can be generated before parsing).
But on following deploys (when procDef must be put back into cache) shouldn't be procDef.id set at start (from DB)  and passed to parser?

Understand it's not an option for now.
So I'm trying to hook in with custom deployer (public class CustomDeployerAfter implements Deployer{ …)
and something like:

@Override
public void deploy(DeploymentEntity deployment, Map<String, Object> deploymentSettings) {
  // TODO Auto-generated method stub
  System.out.println("DeployerAfter");
  List<ProcessDefinitionEntity> proc_defs=deployment.getDeployedArtifacts(ProcessDefinitionEntity.class);
 
 
  for(ProcessDefinitionEntity proc_def: proc_defs){
   System.out.println(proc_def.getId());
   Map<String,TaskDefinition> tasks=proc_def.getTaskDefinitions();
   Set<String> tasks_key=tasks.keySet();
   for(String key:tasks_key){
    TaskDefinition task=tasks.get(key);
    System.out.println(task.getKey());

   }
  }
}

I wonder if Map<String,TaskDefinition> tasks=proc_def.getTaskDefinitions(); returns only UserTasks
… or maybe it returns all kind of tasks (HumanTask, scriptTask, receiveTask, …)?

In such case how can I distinguish between task types?

Also - how to convert TaskDefinition to UserTask?

Regards
Luke