Search in sources :

Example 21 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class ResetPasswordServiceImpl method initiateResetPassword.

@Override
public void initiateResetPassword(ResetPasswordDetails resetDetails) {
    ParameterCheck.mandatory("resetDetails", resetDetails);
    validateIdAndKey(resetDetails.getWorkflowId(), resetDetails.getWorkflowKey(), resetDetails.getUserId());
    if (StringUtils.isBlank(resetDetails.getPassword())) {
        throw new IllegalArgumentException("Invalid password value [" + resetDetails.getPassword() + ']');
    }
    // So now we know that the workflow instance exists, is active and has the correct key. We can proceed.
    WorkflowTaskQuery processTaskQuery = new WorkflowTaskQuery();
    processTaskQuery.setProcessId(resetDetails.getWorkflowId());
    List<WorkflowTask> tasks = workflowService.queryTasks(processTaskQuery, false);
    if (tasks.isEmpty()) {
        throw new InvalidResetPasswordWorkflowException("Invalid workflow identifier: " + resetDetails.getWorkflowId() + ", " + resetDetails.getWorkflowKey());
    }
    WorkflowTask task = tasks.get(0);
    // Set the provided password into the task. We will remove this after we have updated the user's authentication details.
    Map<QName, Serializable> props = Collections.singletonMap(WorkflowModelResetPassword.WF_PROP_PASSWORD, resetDetails.getPassword());
    // Note the taskId as taken from the WorkflowService will include a "activiti$" prefix.
    final String taskId = task.getId();
    workflowService.updateTask(taskId, props, null, null);
    workflowService.endTask(taskId, null);
    // Remove the previous task from Activiti's history - so that the password will not be in the database.
    // See http://www.activiti.org/userguide/index.html#history for a description of how Activiti stores historical records of
    // processes, tasks and properties.
    // The activitiHistoryService does not expect the activiti$ prefix.
    final String activitiTaskId = taskId.replace("activiti$", "");
    activitiHistoryService.deleteHistoricTaskInstance(activitiTaskId);
    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("Deleting historical task for security reasons " + activitiTaskId);
    }
}
Also used : Serializable(java.io.Serializable) QName(org.alfresco.service.namespace.QName) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 22 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method queryRuntimeTasks.

private List<WorkflowTask> queryRuntimeTasks(WorkflowTaskQuery query) {
    // so no use in querying runtime tasks if not active
    if (!Boolean.FALSE.equals(query.isActive())) {
        TaskQuery taskQuery = createRuntimeTaskQuery(query);
        List<Task> results;
        int limit = query.getLimit();
        if (limit > 0) {
            results = taskQuery.listPage(0, limit);
        } else {
            results = taskQuery.list();
        }
        return getValidWorkflowTasks(results);
    }
    return new ArrayList<WorkflowTask>();
}
Also used : WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) LazyActivitiWorkflowTask(org.alfresco.service.cmr.workflow.LazyActivitiWorkflowTask) Task(org.activiti.engine.task.Task) TaskQuery(org.activiti.engine.task.TaskQuery) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery) ArrayList(java.util.ArrayList)

Example 23 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class ActivitiWorkflowEngine method createRuntimeTaskQuery.

private TaskQuery createRuntimeTaskQuery(WorkflowTaskQuery query) {
    // Add task name
    TaskQuery taskQuery = taskService.createTaskQuery();
    if (!activitiUtil.isMultiTenantWorkflowDeploymentEnabled()) {
        // Filter by tenant domain.
        taskQuery.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
    } else if (tenantService.isEnabled() && !TenantUtil.isCurrentDomainDefault() && !StringUtils.isEmpty(TenantUtil.getCurrentDomain())) {
        // Process definition keys are prefixed with the tenant ID, in case MT is enabled and
        // deployments are done in tenant-context
        taskQuery.processDefinitionKeyLike("@" + TenantUtil.getCurrentDomain() + "@%");
    }
    if (query.getTaskName() != null) {
        // Task 'key' is stored as variable on task
        String formKey = query.getTaskName().toPrefixString(namespaceService);
        taskQuery.taskVariableValueEquals(ActivitiConstants.PROP_TASK_FORM_KEY, formKey);
    }
    if (query.getProcessId() != null) {
        String processInstanceId = createLocalId(query.getProcessId());
        taskQuery.processInstanceId(processInstanceId);
    }
    if (query.getProcessName() != null) {
        String processName = getProcessNameMTSafe(query.getProcessName());
        taskQuery.processDefinitionKey(processName);
    }
    if (query.getWorkflowDefinitionName() != null) {
        String processName = factory.getProcessKey(query.getWorkflowDefinitionName());
        taskQuery.processDefinitionKey(processName);
    }
    if (query.getActorId() != null) {
        taskQuery.taskAssignee(query.getActorId());
    }
    if (query.getTaskId() != null) {
        String taskId = createLocalId(query.getTaskId());
        taskQuery.taskId(taskId);
    }
    // Custom task properties
    if (query.getTaskCustomProps() != null) {
        addTaskPropertiesToQuery(query.getTaskCustomProps(), taskQuery);
    }
    if (query.getProcessCustomProps() != null) {
        addProcessPropertiesToQuery(query.getProcessCustomProps(), taskQuery);
    }
    // Add ordering
    if (query.getOrderBy() != null) {
        WorkflowTaskQuery.OrderBy[] orderBy = query.getOrderBy();
        orderQuery(taskQuery, orderBy);
    }
    return taskQuery;
}
Also used : OrderBy(org.alfresco.service.cmr.workflow.WorkflowTaskQuery.OrderBy) TaskQuery(org.activiti.engine.task.TaskQuery) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 24 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class InvitationServiceImpl method searchModeratedInvitations.

/**
 * @param criteria criteria to search by
 * @param limit maximum number of IDs to return. If less than 1, there is no limit.
 * @return list of WorkflowTask representing moderated invitations
 */
private List<WorkflowTask> searchModeratedInvitations(InvitationSearchCriteria criteria, int limit) {
    long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
    WorkflowTaskQuery query = new WorkflowTaskQuery();
    query.setTaskState(WorkflowTaskState.IN_PROGRESS);
    if (limit > 0) {
        query.setLimit(limit);
    }
    Map<QName, Object> properties = new HashMap<QName, Object>();
    String invitee = criteria.getInvitee();
    if (invitee != null) {
        properties.put(WorkflowModelModeratedInvitation.WF_PROP_INVITEE_USER_NAME, invitee);
    }
    // TODO Uncomment if more than one ResourceType added.
    // ResourceType resourceType = criteria.getResourceType();
    // if (resourceType != null)
    // {
    // properties.put(WorkflowModelModeratedInvitation.WF_PROP_RESOURCE_TYPE, resourceType.toString());
    // }
    String resourceName = criteria.getResourceName();
    if (resourceName != null) {
        properties.put(WorkflowModelModeratedInvitation.WF_PROP_RESOURCE_NAME, resourceName);
    }
    query.setProcessCustomProps(properties);
    query.setTaskName(WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK);
    // query for invite workflow tasks
    List<WorkflowTask> results = new ArrayList<WorkflowTask>();
    if (workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID)) {
        query.setTaskName(WorkflowModelModeratedInvitation.WF_ACTIVITI_REVIEW_TASK);
        List<WorkflowTask> activitiTasks = this.workflowService.queryTasks(query, true);
        if (activitiTasks != null) {
            results.addAll(activitiTasks);
            if (logger.isTraceEnabled()) {
                logger.trace("Found " + activitiTasks.size() + " Activiti moderated invitation tasks.");
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("  searchModeratedInvitations in " + (System.currentTimeMillis() - start) + " ms");
    }
    return results;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Example 25 with WorkflowTaskQuery

use of org.alfresco.service.cmr.workflow.WorkflowTaskQuery in project alfresco-repository by Alfresco.

the class InvitationServiceImpl method searchNominatedInvitations.

/**
 * @param criteria
 * @param limit maximum number of IDs to return. If less than 1, there is no limit.
 * @return list of WorkflowTask representing nominated invitations
 */
private List<WorkflowTask> searchNominatedInvitations(InvitationSearchCriteria criteria, int limit) {
    long start = (logger.isDebugEnabled()) ? System.currentTimeMillis() : 0;
    WorkflowTaskQuery query = new WorkflowTaskQuery();
    query.setTaskState(WorkflowTaskState.IN_PROGRESS);
    if (limit > 0) {
        query.setLimit(limit);
    }
    String invitee = criteria.getInvitee();
    if (invitee != null) {
        query.setActorId(invitee);
    }
    Map<QName, Object> queryProps = new HashMap<QName, Object>();
    String inviter = criteria.getInviter();
    if (inviter != null) {
        queryProps.put(WorkflowModelNominatedInvitation.WF_PROP_INVITER_USER_NAME, inviter);
    }
    String resourceName = criteria.getResourceName();
    if (resourceName != null) {
        queryProps.put(WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_NAME, resourceName);
    }
    // TODO uncomment if more ResourceTypes are created.
    // ResourceType resourceType = criteria.getResourceType();
    // if (resourceType != null)
    // {
    // wfNominatedQueryProps.put(WorkflowModelNominatedInvitation.WF_PROP_RESOURCE_TYPE,
    // resourceType.name());
    // }
    // set workflow task query parameters
    query.setProcessCustomProps(queryProps);
    List<WorkflowTask> results = new ArrayList<WorkflowTask>();
    if (workflowAdminService.isEngineEnabled(ActivitiConstants.ENGINE_ID)) {
        query.setTaskName(WorkflowModelNominatedInvitation.WF_TASK_ACTIVIT_INVITE_PENDING);
        List<WorkflowTask> activitiTasks = this.workflowService.queryTasks(query, true);
        if (activitiTasks != null) {
            results.addAll(activitiTasks);
            if (logger.isTraceEnabled()) {
                logger.trace("Found " + activitiTasks.size() + " Activiti nominated invitation tasks.");
            }
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("  searchNominatedInvitations in " + (System.currentTimeMillis() - start) + " ms");
    }
    return results;
}
Also used : HashMap(java.util.HashMap) QName(org.alfresco.service.namespace.QName) ArrayList(java.util.ArrayList) WorkflowTask(org.alfresco.service.cmr.workflow.WorkflowTask) WorkflowTaskQuery(org.alfresco.service.cmr.workflow.WorkflowTaskQuery)

Aggregations

WorkflowTaskQuery (org.alfresco.service.cmr.workflow.WorkflowTaskQuery)34 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)20 HashMap (java.util.HashMap)14 QName (org.alfresco.service.namespace.QName)14 Serializable (java.io.Serializable)9 ArrayList (java.util.ArrayList)6 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)5 Test (org.junit.Test)5 NodeRef (org.alfresco.service.cmr.repository.NodeRef)4 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)4 Map (java.util.Map)3 Task (org.activiti.engine.task.Task)3 Date (java.util.Date)2 List (java.util.List)2 FacesContext (javax.faces.context.FacesContext)2 UserTransaction (javax.transaction.UserTransaction)2 TaskQuery (org.activiti.engine.task.TaskQuery)2 WorkflowInstance (org.alfresco.service.cmr.workflow.WorkflowInstance)2 WorkflowTaskState (org.alfresco.service.cmr.workflow.WorkflowTaskState)2 WorkflowTransition (org.alfresco.service.cmr.workflow.WorkflowTransition)2