Java Code Examples for org.activiti.engine.history.HistoricProcessInstance#getStartUserId()

The following examples show how to use org.activiti.engine.history.HistoricProcessInstance#getStartUserId() . 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: PermissionService.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
public boolean validateIfUserIsInitiatorAndCanCompleteTask(User user, Task task) {
  boolean canCompleteTask = false;
  if (task.getProcessInstanceId() != null) {
    HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(task.getProcessInstanceId()).singleResult();
    if (historicProcessInstance != null && StringUtils.isNotEmpty(historicProcessInstance.getStartUserId())) {
      String processInstanceStartUserId = historicProcessInstance.getStartUserId();
      if (String.valueOf(user.getId()).equals(processInstanceStartUserId)) {
        BpmnModel bpmnModel = repositoryService.getBpmnModel(task.getProcessDefinitionId());
        FlowElement flowElement = bpmnModel.getFlowElement(task.getTaskDefinitionKey());
        if (flowElement != null && flowElement instanceof UserTask) {
          UserTask userTask = (UserTask) flowElement;
          List<ExtensionElement> extensionElements = userTask.getExtensionElements().get("initiator-can-complete");
          if (CollectionUtils.isNotEmpty(extensionElements)) {
            String value = extensionElements.get(0).getElementText();
            if (StringUtils.isNotEmpty(value) && Boolean.valueOf(value)) {
              canCompleteTask = true;
            }
          }
        }
      }
    }
  }
  return canCompleteTask;
}
 
Example 2
Source File: AbstractProcessInstanceQueryResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<ProcessInstanceRepresentation> convertInstanceList(List<HistoricProcessInstance> instances) {
  List<ProcessInstanceRepresentation> result = new ArrayList<ProcessInstanceRepresentation>();
  if (CollectionUtils.isNotEmpty(instances)) {

    for (HistoricProcessInstance processInstance : instances) {
      User userRep = null;
      if (processInstance.getStartUserId() != null) {
        CachedUser user = userCache.getUser(processInstance.getStartUserId());
        if (user != null && user.getUser() != null) {
          userRep = user.getUser();
        }
      }

      ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
      ProcessInstanceRepresentation instanceRepresentation = new ProcessInstanceRepresentation(processInstance, procDef, procDef.isGraphicalNotationDefined(), userRep);
      result.add(instanceRepresentation);
    }

  }
  return result;
}
 
Example 3
Source File: AbstractRelatedContentResource.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
protected List<ProcessInstanceRepresentation> convertInstanceList(List<HistoricProcessInstance> instances) {
    List<ProcessInstanceRepresentation> result = new ArrayList<ProcessInstanceRepresentation>();
    if (CollectionUtils.isNotEmpty(instances)) {

        for (HistoricProcessInstance processInstance : instances) {
            User userRep = null;
            if(processInstance.getStartUserId() != null) {
                UserCache.CachedUser user = userCache.getUser(processInstance.getStartUserId());
                if(user != null && user.getUser() != null) {
                    userRep = user.getUser();
                }
            }

            ProcessDefinitionEntity procDef = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());
            ProcessInstanceRepresentation instanceRepresentation = new ProcessInstanceRepresentation(
                    processInstance, procDef, procDef.isGraphicalNotationDefined(), userRep);
            result.add(instanceRepresentation);
        }

    }
    return result;
}
 
Example 4
Source File: PermissionService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the given user is allowed to read the process instance.
 */
public boolean hasReadPermissionOnProcessInstance(User user, HistoricProcessInstance historicProcessInstance, String processInstanceId) {
  if (historicProcessInstance == null) {
    throw new NotFoundException("Process instance not found for id " + processInstanceId);
  }

  // Start user check
  if (historicProcessInstance.getStartUserId() != null && historicProcessInstance.getStartUserId().equals(user.getId())) {
    return true;
  }

  // check if the user is involved in the task
  HistoricProcessInstanceQuery historicProcessInstanceQuery = historyService.createHistoricProcessInstanceQuery();
  historicProcessInstanceQuery.processInstanceId(processInstanceId);
  historicProcessInstanceQuery.involvedUser(user.getId());
  if (historicProcessInstanceQuery.count() > 0) {
    return true;
  }

  // Visibility: check if there are any tasks for the current user
  HistoricTaskInstanceQuery historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
  historicTaskInstanceQuery.processInstanceId(processInstanceId);
  historicTaskInstanceQuery.taskInvolvedUser(user.getId());
  if (historicTaskInstanceQuery.count() > 0) {
    return true;
  }

  List<String> groupIds = getGroupIdsForUser(user);
  if (!groupIds.isEmpty()) {
    historicTaskInstanceQuery = historyService.createHistoricTaskInstanceQuery();
    historicTaskInstanceQuery.processInstanceId(processInstanceId).taskCandidateGroupIn(groupIds);
    return historicTaskInstanceQuery.count() > 0;
  }

  return false;
}
 
Example 5
Source File: PermissionService.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public boolean canDeleteProcessInstance(User currentUser, HistoricProcessInstance processInstance) {
  boolean canDelete = false;
  if (processInstance.getStartUserId() != null) {

     canDelete = processInstance.getStartUserId().equals(currentUser.getId());
  }

  return canDelete;
}
 
Example 6
Source File: AbstractProcessInstanceResource.java    From activiti6-boot2 with Apache License 2.0 5 votes vote down vote up
public ProcessInstanceRepresentation getProcessInstance(String processInstanceId, HttpServletResponse response) {

    HistoricProcessInstance processInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).singleResult();

    if (!permissionService.hasReadPermissionOnProcessInstance(SecurityUtils.getCurrentUserObject(), processInstance, processInstanceId)) {
      throw new NotFoundException("Process with id: " + processInstanceId + " does not exist or is not available for this user");
    }

    ProcessDefinitionEntity processDefinition = (ProcessDefinitionEntity) repositoryService.getProcessDefinition(processInstance.getProcessDefinitionId());

    User userRep = null;
    if (processInstance.getStartUserId() != null) {
      CachedUser user = userCache.getUser(processInstance.getStartUserId());
      if (user != null && user.getUser() != null) {
        userRep = user.getUser();
      }
    }

    ProcessInstanceRepresentation processInstanceResult = new ProcessInstanceRepresentation(processInstance, processDefinition, processDefinition.isGraphicalNotationDefined(), userRep);

    FormDefinition formDefinition = getStartFormDefinition(processInstance.getProcessDefinitionId(), processDefinition, processInstance.getId());
    if (formDefinition != null) {
      processInstanceResult.setStartFormDefined(true);
    }

    return processInstanceResult;
  }
 
Example 7
Source File: ProcessInfo.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ProcessInfo(HistoricProcessInstance processInstance)
{
    this.id = processInstance.getId();
    this.processDefinitionId = processInstance.getProcessDefinitionId();
    this.startedAt = processInstance.getStartTime();
    this.endedAt = processInstance.getEndTime();
    this.durationInMs = processInstance.getDurationInMillis();
    this.deleteReason = processInstance.getDeleteReason();
    this.startUserId = processInstance.getStartUserId();
    this.startActivityId = processInstance.getStartActivityId();
    this.endActivityId = processInstance.getEndActivityId();
    this.businessKey = processInstance.getBusinessKey();
    this.superProcessInstanceId = processInstance.getSuperProcessInstanceId();
    this.completed = (processInstance.getEndTime() != null);
}
 
Example 8
Source File: AbstractProcessInstancesResource.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
public ProcessInstanceRepresentation startNewProcessInstance(CreateProcessInstanceRepresentation startRequest) {
  if (StringUtils.isEmpty(startRequest.getProcessDefinitionId())) {
    throw new BadRequestException("Process definition id is required");
  }
  
  FormDefinition formDefinition = null;
  Map<String, Object> variables = null;

  ProcessDefinition processDefinition = permissionService.getProcessDefinitionById(startRequest.getProcessDefinitionId());

  if (startRequest.getValues() != null || startRequest.getOutcome() != null) {
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());
    Process process = bpmnModel.getProcessById(processDefinition.getKey());
    FlowElement startElement = process.getInitialFlowElement();
    if (startElement instanceof StartEvent) {
      StartEvent startEvent = (StartEvent) startElement;
      if (StringUtils.isNotEmpty(startEvent.getFormKey())) {
        formDefinition = formRepositoryService.getFormDefinitionByKey(startEvent.getFormKey());
        if (formDefinition != null) {
          variables = formService.getVariablesFromFormSubmission(formDefinition, startRequest.getValues(), startRequest.getOutcome());
        }
      }
    }
  }
  
  ProcessInstance processInstance = activitiService.startProcessInstance(startRequest.getProcessDefinitionId(), variables, startRequest.getName());

  // Mark any content created as part of the form-submission connected to the process instance
  /*if (formSubmission != null) {
    if (formSubmission.hasContent()) {
      ObjectNode contentNode = objectMapper.createObjectNode();
      submittedFormValuesJson.put("content", contentNode);
      for (Entry<String, List<RelatedContent>> entry : formSubmission.getVariableContent().entrySet()) {
        ArrayNode contentArray = objectMapper.createArrayNode();
        for (RelatedContent content : entry.getValue()) {
          relatedContentService.setContentField(content.getId(), entry.getKey(), processInstance.getId(), null);
          contentArray.add(content.getId());
        }
        contentNode.put(entry.getKey(), contentArray);
      }
    }*/

  HistoricProcessInstance historicProcess = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstance.getId()).singleResult();

  if (formDefinition != null) {
    formService.storeSubmittedForm(variables, formDefinition, null, historicProcess.getId());
  }
  
  User user = null;
  if (historicProcess.getStartUserId() != null) {
    CachedUser cachedUser = userCache.getUser(historicProcess.getStartUserId());
    if (cachedUser != null && cachedUser.getUser() != null) {
      user = cachedUser.getUser();
    }
  }
  return new ProcessInstanceRepresentation(historicProcess, processDefinition, ((ProcessDefinitionEntity) processDefinition).isGraphicalNotationDefined(), user);

}