Example usage for com.liferay.portal.kernel.workflow WorkflowTaskManagerUtil getPooledActorsIds

List of usage examples for com.liferay.portal.kernel.workflow WorkflowTaskManagerUtil getPooledActorsIds

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.workflow WorkflowTaskManagerUtil getPooledActorsIds.

Prototype

@Deprecated
public static long[] getPooledActorsIds(long companyId, long workflowTaskId) throws WorkflowException 

Source Link

Usage

From source file:org.activiti.engine.impl.bpmn.behavior.UserTaskActivityBehavior.java

License:Apache License

@SuppressWarnings({ "unchecked", "rawtypes" })
protected void handleAssignments(TaskEntity task, ActivityExecution execution) {

    // to send SO notification we need to extract workflow context, get
    // users to send to..
    Map<String, Object> workflowContext = ActivitiUtil.getRuntimeService().getVariables(execution.getId());
    _log.debug("User task for companyId = " + (String) workflowContext.get("companyId"));
    long companyId = Long.valueOf((String) workflowContext.get("companyId"));

    if (taskDefinition.getAssigneeExpression() != null) {
        String userId = (String) taskDefinition.getAssigneeExpression().getValue(execution);
        task.setAssignee(userId);/*ww  w  .  ja  v  a  2s  .  c om*/
        try {
            List<Long> receiverUserIds = new ArrayList<Long>();
            receiverUserIds.add(Long.valueOf(userId));
            sendPortalNotification(task, receiverUserIds, workflowContext, false);
        } catch (ChannelException e) {
            _log.error("Could not send portal notification to user", e);
        }
    }

    if (!taskDefinition.getCandidateGroupIdExpressions().isEmpty()) {
        List<User> users = new ArrayList<User>();
        for (Expression groupIdExpr : taskDefinition.getCandidateGroupIdExpressions()) {
            Object value = groupIdExpr.getValue(execution);
            if (value instanceof String) {
                List<String> candiates = extractCandidates((String) value);
                task.addCandidateGroups(candiates);
                users.addAll(resolveUsersForGroups(companyId, candiates));
            } else if (value instanceof Collection) {
                task.addCandidateGroups((Collection) value);
                users.addAll(resolveUsersForGroups(companyId, (Collection) value));
            } else {
                throw new ActivitiIllegalArgumentException(
                        "Expression did not resolve to a string or collection of strings");
            }
        }
        try {
            long[] pooledActorsIds = WorkflowTaskManagerUtil.getPooledActorsIds(companyId,
                    Long.valueOf(task.getId()));
            List<Long> receiverUserIds = null;
            if (pooledActorsIds == null || pooledActorsIds.length == 0) {
                //try to use users list
                receiverUserIds = new ArrayList<Long>(users.size());
                for (User user : users) {
                    receiverUserIds.add(Long.valueOf(user.getId()));
                }
            } else {
                receiverUserIds = new ArrayList<Long>(Arrays.asList(ArrayUtils.toObject(pooledActorsIds)));
            }
            try {
                sendPortalNotification(task, receiverUserIds, workflowContext, true);
            } catch (ChannelException e) {
                _log.error("Could not send portal notification to group", e);
            }
        } catch (Exception e) {
            _log.error("Could not send portal notification to group", e);
        }

    }

    if (!taskDefinition.getCandidateUserIdExpressions().isEmpty()) {
        for (Expression userIdExpr : taskDefinition.getCandidateUserIdExpressions()) {
            Object value = userIdExpr.getValue(execution);
            if (value instanceof String) {
                List<String> candiates = extractCandidates((String) value);
                task.addCandidateUsers(candiates);
            } else if (value instanceof Collection) {
                task.addCandidateUsers((Collection) value);
            } else {
                throw new ActivitiException("Expression did not resolve to a string or collection of strings");
            }
        }
    }
}