Question

work flow

I am designing a workflow in activiti so far i have been able to design it like above. My problem is

  1. i start a work flow.
  2. present user option to execute one of the two possible action(Archive and complete in diagram)
  3. i also need to have authorization on whether he can archive or complete or both.
  4. user can take one of these options.
  5. based on one of the action taken workflow proceeds.

So far to achieve this i introduced user task new before complete and archive and added two form variables named archive and complete as boolean.

Depending on which form variable he chooses to fill i proceed further.

But in this case i can't restrict user based on whether it has permission of archive and complete and all users will be shown both options.

is there any other way to achieve this i am very new to activiti and workflow and bpmn in general. Any help will be appreciated thanks in advance

Was it helpful?

Solution

1. How to presents possible transitions to user:

Set transitions directly to task and set transition id according this pattern: <task_id>_<transition_id> that means in this case: newTask_archive and newTask_complete. Then you can read all transitions from task definition and parse the postfix from id and send to user list of possible transitions (complete, archive). Your bussines layer can remove any transition according user permissions.

// Source: http://forums.activiti.org/content/how-get-all-possible-flows-current-activity
public List<String> getPossibleTransitionIds(long processInstanceId, String taskId) {
     RepositoryServiceImpl repoServiceImpl = (RepositoryServiceImpl) repositoryService;

     List<String> possibleTransitionIds = new ArrayList<String>();

     ReadOnlyProcessDefinition processDef = repoServiceImpl.getDeployedProcessDefinition(processInstance.getProcessDefinitionId());
     PvmActivity activity = processDef.findActivity(taskId);

     for (PvmTransition pvmTransition : activity.getOutgoingTransitions()) {
          String transitionId = extractTransitionId(pvmTransition);
          if (transitionId != null) {
              possibleTransitionIds.add(transitionId);
          }
      }

      return possibleTransitionIds;
 }

2. How to move process by selected transition:

User selects one of presented transition ids. Bussines layer checks user's permissions and move process. Set selected transition to process variables and resolve task.

Map<String, Object> variableMap = new HashMap<String, Object>();
variableMap.put("selectedTransition", selectedTransition);
taskService.resolveTask(taskId, variableMap);

In every transition has to be set a condition expression ${selectedTransition == '<transition_id>'}. In this case ${selectedTransition == 'complete'} and ${selectedTransition == 'archive'}

<sequenceFlow id="newTask_complete" name="Complete" sourceRef="newTask" targetRef="completeTask">
      <conditionExpression xsi:type="tFormalExpression"><![CDATA[${selectedTransition == 'complete'}]]></conditionExpression>
</sequenceFlow>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top