cancel
Showing results for 
Search instead for 
Did you mean: 

MultiInstance UserTask - add/remove executor while running

bpmn
Champ in-the-making
Champ in-the-making
Hi. I need to implement votes with ability of adding/removing voters while usertask is still running. How is it possible? Can i use multiinstance usertask for this by doing some interventions in it?
1 REPLY 1

bpmn
Champ in-the-making
Champ in-the-making
I took <java>createInstances</java> from ParallelMultiInstanceBehavior.java as a starting point and got this dirty solution:

<java>
public static void addChildConcurrentExecutionToCurrentExecution(String processId, final String uuid, final String assigneeVarName)
{
final ExecutionEntity execution = ActivitiUtil.getCurrentExecution(processId);
getCommandExecutor().execute(new Command<Object>() {
      public Object execute(CommandContext commandContext) {
       Integer numInstances = (Integer) execution.getVariableLocal(NUMBER_OF_INSTANCES);
       execution.setVariableLocal(NUMBER_OF_INSTANCES, numInstances + 1);
       execution.setVariableLocal(NUMBER_OF_ACTIVE_INSTANCES, numInstances + 1);

       ExecutionEntity newExecution = execution.createExecution();
       newExecution.setActive(true);
       newExecution.setConcurrent(true);
       newExecution.setScope(false);
       newExecution.setVariableLocal(LOOP_COUNTER, numInstances + 1);
       newExecution.setVariableLocal(assigneeVarName, uuid);
//     executeOriginalBehavior(newExecution, numInstances + 1);
//     newExecution.setVariableLocal(behavior.getCollectionElementVariable(), "corebofs002080000ldurpmdvigvgcu0");
//     ee.setActive(false);
       newExecution.executeActivity(newExecution.getActivity());
       return null;
      }
});
}

public static void delecteConcurrentExecutionByAssignee(String processId, String uuid)
{
final String executionId = getExecutionIdByAssignee(processId, uuid);
if ( null == executionId ) return;

getCommandExecutor().execute(new Command<Object>() {
      public Object execute(CommandContext commandContext)
      {
       ExecutionEntity execution = Context
            .getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(executionId);
       execution.deleteCascade("User manual");
       return null;
      }
});
}

public static CommandExecutor getCommandExecutor()
{
ProcessEngine processEngine = ActivitiEngineServiceImpl.getInstance().getProcessEngine();
ProcessEngineConfigurationImpl processEngineConfiguration = ((ProcessEngineImpl) processEngine).getProcessEngineConfiguration();
return processEngineConfiguration.getCommandExecutorTxRequired();
}

public static ExecutionEntity getCurrentExecution(String processInstanceId)
{
    RuntimeService runtimeService = ActivitiEngineServiceImpl.getInstance().getRuntimeService();
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).list();
    for ( Execution exec: executions )
    {
     ExecutionEntity ee = (ExecutionEntity)exec;
     if ( ee.isActive() )
         if ( ee.isConcurrent() )
          return (ExecutionEntity)runtimeService.createExecutionQuery().executionId(ee.getParentId()).singleResult();
         else
          return ee;
    }
    return null;
}

public static String getExecutionIdByAssignee(String processInstanceId, String assignee)
{
return ActivitiEngineServiceImpl
   .getInstance()
   .getTaskService()
   .createTaskQuery()
   .processInstanceId(processInstanceId)
   .taskAssignee(assignee)
   .singleResult()
   .getExecutionId();
}

public static List<ExecutionEntity> getCurrentChildConcurrentExecutions(String processInstanceId)
{
    RuntimeService runtimeService = ActivitiEngineServiceImpl.getInstance().getRuntimeService();
    List<Execution> executions = runtimeService.createExecutionQuery().processInstanceId(processInstanceId).list();
    List<ExecutionEntity> parallelExecutions = new ArrayList<ExecutionEntity>();
    for ( Execution exec: executions )
    {
     ExecutionEntity ee = (ExecutionEntity)exec;
     if ( ee.isActive() && ee.isConcurrent() )
      parallelExecutions.add(ee);
    }
    return parallelExecutions;
}

public static ExecutionEntity getExecutionInitialized(final ExecutionEntity execution)
{
return getCommandExecutor().execute(new Command<ExecutionEntity>() {
  public ExecutionEntity execute(CommandContext commandContext)
  {
   execution.initialize();
   return execution;
  }
});
}

public static TaskEntity getTaskByExecution(String executionId)
{
    return (TaskEntity) ActivitiEngineServiceImpl.getInstance().getTaskService().createTaskQuery()
            .executionId(executionId).singleResult();
}

public static ExecutionEntity getExecutionById(final String executionId)
{
return getCommandExecutor().execute(new Command<ExecutionEntity>() {
      public ExecutionEntity execute(CommandContext commandContext)
      {
       return Context
            .getCommandContext()
            .getExecutionEntityManager()
            .findExecutionById(executionId);
      }
});
}
</java>
Getting started

Tags


Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.