Java Code Examples for org.activiti.engine.delegate.DelegateTask#getAssignee()

The following examples show how to use org.activiti.engine.delegate.DelegateTask#getAssignee() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArrivalNotice.java    From lemon with Apache License 2.0 6 votes vote down vote up
public void process(DelegateTask delegateTask) {
    if (delegateTask.getAssignee() == null) {
        return;
    }

    String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
    String processDefinitionId = delegateTask.getProcessDefinitionId();

    List<BpmConfNotice> bpmConfNotices = ApplicationContextHelper
            .getBean(BpmConfNoticeManager.class)
            .find("from BpmConfNotice where bpmConfNode.bpmConfBase.processDefinitionId=? and bpmConfNode.code=?",
                    processDefinitionId, taskDefinitionKey);

    for (BpmConfNotice bpmConfNotice : bpmConfNotices) {
        if (TYPE_ARRIVAL == bpmConfNotice.getType()) {
            processArrival(delegateTask, bpmConfNotice);
        }
    }
}
 
Example 2
Source File: AssigneeOverwriteFromVariable.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void notify(DelegateTask delegateTask) {
  // get mapping table from variable
  DelegateExecution execution = delegateTask.getExecution();
  Map<String, String> assigneeMappingTable = (Map<String, String>) execution.getVariable("assigneeMappingTable");

  // get assignee from process
  String assigneeFromProcessDefinition = delegateTask.getAssignee();

  // overwrite assignee if there is an entry in the mapping table
  if (assigneeMappingTable.containsKey(assigneeFromProcessDefinition)) {
    String assigneeFromMappingTable = assigneeMappingTable.get(assigneeFromProcessDefinition);
    delegateTask.setAssignee(assigneeFromMappingTable);
  }
}
 
Example 3
Source File: AssigneeOverwriteFromVariable.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void notify(DelegateTask delegateTask) {
  // get mapping table from variable
  DelegateExecution execution = delegateTask.getExecution();
  Map<String, String> assigneeMappingTable = (Map<String, String>) execution.getVariable("assigneeMappingTable");
  
  // get assignee from process
  String assigneeFromProcessDefinition = delegateTask.getAssignee();
  
  // overwrite assignee if there is an entry in the mapping table
  if (assigneeMappingTable.containsKey(assigneeFromProcessDefinition)) {
    String assigneeFromMappingTable = assigneeMappingTable.get(assigneeFromProcessDefinition);
    delegateTask.setAssignee(assigneeFromMappingTable);
  }
}
 
Example 4
Source File: ActivitiOwnerPropertyHandler.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
* {@inheritDoc}
*/
@Override
protected Object handleDelegateTaskProperty(DelegateTask task, TypeDefinition type, QName key, Serializable value)
{
    checkType(key, value, String.class);
    String assignee = (String) value;
    String currentAssignee = task.getAssignee();
    // Only set the assignee if the value has changes to prevent
    // triggering assignementhandlers when not needed
    if (currentAssignee == null || !currentAssignee.equals(assignee))
    {
        task.setAssignee(assignee);
    }
    return DO_NOT_ADD;
}
 
Example 5
Source File: ScriptTaskListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Checks a valid Fully Authenticated User is set.
 * If none is set then attempts to set the task assignee as the Fully Authenticated User.
 * @param delegateTask the delegate task
 * @return <code>true</code> if the Fully Authenticated User was changed, otherwise <code>false</code>.
 */
private boolean checkFullyAuthenticatedUser(final DelegateTask delegateTask) 
{
    if (AuthenticationUtil.getFullyAuthenticatedUser() == null)
    {
        String userName = delegateTask.getAssignee();
        if (userName != null)
        {
            AuthenticationUtil.setFullyAuthenticatedUser(userName);
            return true;
        }
    }
    return false;
}
 
Example 6
Source File: TaskAutoRedirectListener.java    From activiti-in-action-codes with Apache License 2.0 5 votes vote down vote up
@Override
public void notify(DelegateTask delegateTask) {
    String originAssginee = delegateTask.getAssignee();
    String newUser = userMap.get(originAssginee);
    if (StringUtils.isNotBlank(newUser)) {
        delegateTask.setAssignee(newUser);
        EngineServices engineServices = delegateTask.getExecution().getEngineServices();
        TaskService taskService = engineServices.getTaskService();
        String message = getClass().getName() + "-> 任务[" + delegateTask.getName() + "]的办理人[" + originAssginee + "]自动转办给了用户[" + newUser + "]";
        taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "delegate", message);
    } else {
        System.out.println("任务[" + delegateTask.getName() + "]没有预设的代办人");
    }
}
 
Example 7
Source File: AssigneeAliasTaskListener.java    From lemon with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(DelegateTask delegateTask) throws Exception {
    String assignee = delegateTask.getAssignee();
    logger.debug("assignee : {}", assignee);

    if (assignee == null) {
        return;
    }

    for (Map.Entry<RuleMatcher, AssigneeRule> entry : assigneeRuleMap
            .entrySet()) {
        RuleMatcher ruleMatcher = entry.getKey();

        if (!ruleMatcher.matches(assignee)) {
            continue;
        }

        String value = ruleMatcher.getValue(assignee);
        AssigneeRule assigneeRule = entry.getValue();
        logger.debug("value : {}", value);
        logger.debug("assigneeRule : {}", assigneeRule);

        if (assigneeRule instanceof SuperiorAssigneeRule) {
            this.processSuperior(delegateTask, assigneeRule, value);
        } else if (assigneeRule instanceof PositionAssigneeRule) {
            this.processPosition(delegateTask, assigneeRule, value);
        }
    }
}
 
Example 8
Source File: TaskNotificationListener.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void notify(DelegateTask task)
{
    // Determine whether we need to send the workflow notification or not
    ExecutionEntity executionEntity = ((ExecutionEntity)task.getExecution()).getProcessInstance();
    Boolean value = (Boolean)executionEntity.getVariable(WorkflowNotificationUtils.PROP_SEND_EMAIL_NOTIFICATIONS);
    if (Boolean.TRUE.equals(value) == true)
    {    
        NodeRef workflowPackage = null;
        ActivitiScriptNode scriptNode = (ActivitiScriptNode)executionEntity.getVariable(WorkflowNotificationUtils.PROP_PACKAGE);
        if (scriptNode != null)
        {
            workflowPackage = scriptNode.getNodeRef();
        }
        
        // Determine whether the task is pooled or not
        String[] authorities = null;
        boolean isPooled = false;
        if (task.getAssignee() == null)
        {
            // Task is pooled
            isPooled = true;
            
            // Get the pool of user/groups for this task
            List<IdentityLinkEntity> identities = ((TaskEntity)task).getIdentityLinks();
            List<String> temp = new ArrayList<String>(identities.size());
            for (IdentityLinkEntity item : identities)
            {
                String group = item.getGroupId();
                if (group != null)
                {
                    temp.add(group);
                }
                String user = item.getUserId();
                if (user != null)
                {
                    temp.add(user);
                }
            }
            authorities = temp.toArray(new String[temp.size()]);
        }
        else
        {
            // Get the assigned user or group
            authorities = new String[]{task.getAssignee()};
        }
        
        String title = null;
        String taskFormKey = getFormKey(task);
        
        // Fetch definition and extract name again. Possible that the default is used if the provided is missing
        TypeDefinition typeDefinition = propertyConverter.getWorkflowObjectFactory().getTaskTypeDefinition(taskFormKey, false);
        taskFormKey = typeDefinition.getName().toPrefixString();
        
        if (taskFormKey != null) 
        {
            String processDefinitionKey = ((ProcessDefinition) ((TaskEntity)task).getExecution().getProcessDefinition()).getKey();
            String defName = propertyConverter.getWorkflowObjectFactory().buildGlobalId(processDefinitionKey);
            title = propertyConverter.getWorkflowObjectFactory().getTaskTitle(typeDefinition, defName, task.getName(), taskFormKey.replace(":", "_"));
        }
        
        if (title == null)
        {
            if (task.getName() != null)
            {
                title = task.getName();
            }
            else
            {
                title = taskFormKey.replace(":", "_");
            }
        }
        
        // Make sure a description is present
        String description = task.getDescription();
        if (description == null || description.length() == 0)
        {
        	// use the task title as the description
        	description = title;
        }

        // Send email notification
        workflowNotificationUtils.sendWorkflowAssignedNotificationEMail(
                ActivitiConstants.ENGINE_ID + "$" + task.getId(),
                title,
                description,
                task.getDueDate(),
                Integer.valueOf(task.getPriority()),
                workflowPackage,
                authorities,
                isPooled);
    }
}
 
Example 9
Source File: AutoCompleteFirstTaskListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(DelegateTask delegateTask) throws Exception {
    String initiatorId = Authentication.getAuthenticatedUserId();

    if (initiatorId == null) {
        return;
    }

    String assignee = delegateTask.getAssignee();

    if (assignee == null) {
        return;
    }

    PvmActivity targetActivity = this.findFirstActivity(delegateTask
            .getProcessDefinitionId());

    if (!targetActivity.getId().equals(
            delegateTask.getExecution().getCurrentActivityId())) {
        return;
    }

    if (!initiatorId.equals(assignee)) {
        return;
    }

    logger.debug("auto complete first task : {}", delegateTask);

    for (IdentityLink identityLink : delegateTask.getCandidates()) {
        String userId = identityLink.getUserId();
        String groupId = identityLink.getGroupId();

        if (userId != null) {
            delegateTask.deleteCandidateUser(userId);
        }

        if (groupId != null) {
            delegateTask.deleteCandidateGroup(groupId);
        }
    }

    // 对提交流程的任务进行特殊处理
    HumanTaskDTO humanTaskDto = humanTaskConnector
            .findHumanTaskByTaskId(delegateTask.getId());
    humanTaskDto.setCatalog(HumanTaskConstants.CATALOG_START);
    humanTaskConnector.saveHumanTask(humanTaskDto);

    // ((TaskEntity) delegateTask).complete();
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    new CompleteTaskWithCommentCmd(delegateTask.getId(), null, "发起流程")
            .execute(Context.getCommandContext());
}
 
Example 10
Source File: AutoCompleteFirstTaskEventListener.java    From lemon with Apache License 2.0 4 votes vote down vote up
public void onCreate(DelegateTask delegateTask) throws Exception {
    String initiatorId = Authentication.getAuthenticatedUserId();

    if (initiatorId == null) {
        return;
    }

    String assignee = delegateTask.getAssignee();

    if (assignee == null) {
        return;
    }

    if (!initiatorId.equals(assignee)) {
        return;
    }

    PvmActivity targetActivity = this.findFirstActivity(delegateTask
            .getProcessDefinitionId());
    logger.debug("targetActivity : {}", targetActivity);

    if (!targetActivity.getId().equals(
            delegateTask.getExecution().getCurrentActivityId())) {
        return;
    }

    logger.debug("auto complete first task : {}", delegateTask);

    for (IdentityLink identityLink : delegateTask.getCandidates()) {
        String userId = identityLink.getUserId();
        String groupId = identityLink.getGroupId();

        if (userId != null) {
            delegateTask.deleteCandidateUser(userId);
        }

        if (groupId != null) {
            delegateTask.deleteCandidateGroup(groupId);
        }
    }

    // 对提交流程的任务进行特殊处理
    HumanTaskDTO humanTaskDto = humanTaskConnector
            .findHumanTaskByTaskId(delegateTask.getId());
    humanTaskDto.setCatalog(HumanTaskConstants.CATALOG_START);
    humanTaskConnector.saveHumanTask(humanTaskDto);

    // ((TaskEntity) delegateTask).complete();
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    // Context.getCommandContext().getHistoryManager().recordTaskId((TaskEntity) delegateTask);
    // new CompleteTaskWithCommentCmd(delegateTask.getId(), null, "发起流程")
    // .execute(Context.getCommandContext());

    // 因为recordTaskId()会判断endTime,而complete以后会导致endTime!=null,
    // 所以才会出现record()放在complete后面导致taskId没记录到historyActivity里的情况
    delegateTask.getExecution().setVariableLocal(
            "_ACTIVITI_SKIP_EXPRESSION_ENABLED", true);

    TaskDefinition taskDefinition = ((TaskEntity) delegateTask)
            .getTaskDefinition();
    ExpressionManager expressionManager = Context
            .getProcessEngineConfiguration().getExpressionManager();
    Expression expression = expressionManager
            .createExpression("${_ACTIVITI_SKIP_EXPRESSION_ENABLED}");
    taskDefinition.setSkipExpression(expression);
}