Java Code Examples for org.activiti.engine.history.HistoricTaskInstance#getEndTime()

The following examples show how to use org.activiti.engine.history.HistoricTaskInstance#getEndTime() . 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: LocalTaskService.java    From maven-framework-project with MIT License 6 votes vote down vote up
/**
 * Returns a list of <strong>completed</strong> Doc Approval Tasks.
 *
 * @param businessKey
 * @return
 */
public List<HistoricTask> getDocApprovalHistory(String businessKey) {
    log.debug("getting historic tasks for doc: " + businessKey);
    HistoricProcessInstance pi = historyService.createHistoricProcessInstanceQuery().
            includeProcessVariables().processInstanceBusinessKey(businessKey).singleResult();

    if (pi == null) {
        return Collections.emptyList();
    }
    log.debug("Duration time in millis: " + pi.getDurationInMillis());
    List<HistoricTaskInstance> hTasks;
    hTasks = historyService.createHistoricTaskInstanceQuery().includeTaskLocalVariables().processInstanceBusinessKey(businessKey).list();
    List<HistoricTask> historicTasks = Lists.newArrayList();
    for (HistoricTaskInstance hti : hTasks) {
        if (StringUtils.startsWith(hti.getProcessDefinitionId(), Workflow.PROCESS_ID_DOC_APPROVAL)
                && hti.getEndTime() != null) {
            historicTasks.add(fromActiviti(hti));
        }
    }
    Collections.sort(historicTasks);
    return historicTasks;
}
 
Example 2
Source File: Task.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Task(HistoricTaskInstance taskInstance)
{
    this.id = taskInstance.getId();
    this.processId = taskInstance.getProcessInstanceId();
    this.processDefinitionId = taskInstance.getProcessDefinitionId();
    this.activityDefinitionId = taskInstance.getTaskDefinitionKey();
    this.name = taskInstance.getName();
    this.description = taskInstance.getDescription();
    this.dueAt = taskInstance.getDueDate();
    this.startedAt = taskInstance.getStartTime();
    this.endedAt = taskInstance.getEndTime();
    this.durationInMs = taskInstance.getDurationInMillis();
    this.priority = taskInstance.getPriority();
    this.owner = taskInstance.getOwner();
    this.assignee = taskInstance.getAssignee();
    this.formResourceKey = taskInstance.getFormKey();
    if (taskInstance.getEndTime() != null)
    {
    	this.state = TaskStateTransition.COMPLETED.name().toLowerCase();
    }
    else if (taskInstance.getAssignee() != null)
    {
    	this.state = TaskStateTransition.CLAIMED.name().toLowerCase();
    }
    else
    {
    	this.state = TaskStateTransition.UNCLAIMED.name().toLowerCase();
    }
}
 
Example 3
Source File: ActivitiTaskFormService.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public FormDefinition getTaskForm(String taskId) {
  HistoricTaskInstance task = permissionService.validateReadPermissionOnTask(SecurityUtils.getCurrentUserObject(), taskId);
  
  Map<String, Object> variables = new HashMap<String, Object>();
  if (task.getProcessInstanceId() != null) {
    List<HistoricVariableInstance> variableInstances = historyService.createHistoricVariableInstanceQuery()
        .processInstanceId(task.getProcessInstanceId())
        .list();
    
    for (HistoricVariableInstance historicVariableInstance : variableInstances) {
      variables.put(historicVariableInstance.getVariableName(), historicVariableInstance.getValue());
    }
  }
  
  String parentDeploymentId = null;
  if (StringUtils.isNotEmpty(task.getProcessDefinitionId())) {
    try {
      ProcessDefinition processDefinition = repositoryService.getProcessDefinition(task.getProcessDefinitionId());
      parentDeploymentId = processDefinition.getDeploymentId();
      
    } catch (ActivitiException e) {
      logger.error("Error getting process definition " + task.getProcessDefinitionId(), e);
    }
  }
  
  FormDefinition formDefinition = null;
  if (task.getEndTime() != null) {
    formDefinition = formService.getCompletedTaskFormDefinitionByKeyAndParentDeploymentId(task.getFormKey(), parentDeploymentId, 
        taskId, task.getProcessInstanceId(), variables, task.getTenantId());
    
  } else {
    formDefinition = formService.getTaskFormDefinitionByKeyAndParentDeploymentId(task.getFormKey(), parentDeploymentId, 
        task.getProcessInstanceId(), variables, task.getTenantId());
  }

  // If form does not exists, we don't want to leak out this info to just anyone
  if (formDefinition == null) {
    throw new NotFoundException("Form definition for task " + task.getTaskDefinitionKey() + " cannot be found for form key " + task.getFormKey());
  }

  return formDefinition;
}
 
Example 4
Source File: TasksImpl.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Get a valid {@link HistoricTaskInstance} based on the given task id. Checks if current logged
 * in user is assignee/owner/involved with the task. In case true was passed for "validIfClaimable", 
 * the task is also valid if the current logged in user is a candidate for claiming the task.
 *  
 * @throws EntityNotFoundException when the task was not found
 * @throws PermissionDeniedException when the current logged in user isn't allowed to access task.
 */
protected HistoricTaskInstance getValidHistoricTask(String taskId)
{
    HistoricTaskInstanceQuery query = activitiProcessEngine.getHistoryService()
        .createHistoricTaskInstanceQuery()
        .taskId(taskId);
    
    if (authorityService.isAdminAuthority(AuthenticationUtil.getRunAsUser())) 
    {
        // Admin is allowed to read all tasks in the current tenant
        if (tenantService.isEnabled()) 
        {
            query.processVariableValueEquals(ActivitiConstants.VAR_TENANT_DOMAIN, TenantUtil.getCurrentDomain());
        }
    }
    else
    {
        // If non-admin user, involvement in the task is required (either owner, assignee or externally involved).
        query.taskInvolvedUser(AuthenticationUtil.getRunAsUser());
    }
    
    HistoricTaskInstance taskInstance = query.singleResult();
    
    if (taskInstance == null) 
    {
        // Either the task doesn't exist or the user is not involved directly. We can differentiate by
        // checking if the task exists without applying the additional filtering
        taskInstance =  activitiProcessEngine.getHistoryService()
            .createHistoricTaskInstanceQuery()
            .taskId(taskId)
            .singleResult();
        
        if (taskInstance == null) 
        {
            // Full error message will be "Task with id: 'id' was not found" 
            throw new EntityNotFoundException(taskId); 
        }
        else
        {
            boolean isTaskClaimable = false;
            if (taskInstance.getEndTime() == null) 
            {
                // Task is not yet finished, so potentially claimable. If user is part of a "candidateGroup", the task is accessible to the
                // user regardless of not being involved/owner/assignee
                isTaskClaimable = activitiProcessEngine.getTaskService()
                        .createTaskQuery()
                        .taskCandidateGroupIn(new ArrayList<String>(authorityService.getAuthoritiesForUser(AuthenticationUtil.getRunAsUser())))
                        .taskId(taskId)
                        .count() == 1;
            }
            
            if (isTaskClaimable == false)
            {
                throw new PermissionDeniedException();
            }
        }
    }
    return taskInstance;
}