Esempio n. 1
0
  /*
   * Helper methods
   */
  public static Activity activity(Process process, ProcessInstance instance, Task task)
      throws StatusCodeError {
    Activity activity = null;
    if (process.isAllowPerInstanceActivities()
        && task != null
        && task.getTaskDefinitionKey() != null
        && instance != null) {
      Map<String, Activity> activityMap = instance.getActivityMap();
      if (activityMap != null) activity = activityMap.get(task.getTaskDefinitionKey());

      if (activity != null) return activity;
    }

    ProcessDeployment deployment = process.getDeployment();
    if (deployment == null)
      throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured);

    String activityKey = deployment.getStartActivityKey();
    if (task != null) activityKey = task.getTaskDefinitionKey();

    if (activityKey != null) activity = deployment.getActivity(activityKey);

    if (activity != null) return activity;

    throw new InternalServerError(Constants.ExceptionCodes.process_is_misconfigured);
  }
Esempio n. 2
0
  public FormRequest create(
      RequestDetails requestDetails,
      Process process,
      ProcessInstance processInstance,
      Task task,
      ActionType actionType,
      FormValidation validation)
      throws StatusCodeError {
    Activity activity = activity(process, processInstance, task);

    // Don't allow anyone to issue a create request for a task that's not open
    if (actionType == ActionType.CREATE
        && task != null
        && task.getTaskStatus() != null
        && !task.getTaskStatus().equals(Constants.TaskStatuses.OPEN)) actionType = ActionType.VIEW;

    FormRequest.Builder formRequestBuilder =
        new FormRequest.Builder()
            .processDefinitionKey(process.getProcessDefinitionKey())
            .instance(processInstance)
            .task(task)
            .activity(activity)
            .action(actionType);

    if (requestDetails != null) {
      String contentType =
          requestDetails.getContentType() != null
              ? requestDetails.getContentType().toString()
              : null;

      formRequestBuilder
          .remoteAddr(requestDetails.getRemoteAddr())
          .remoteHost(requestDetails.getRemoteHost())
          .remotePort(requestDetails.getRemotePort())
          .remoteUser(requestDetails.getRemoteUser())
          .actAsUser(requestDetails.getActAsUser())
          .certificateIssuer(requestDetails.getCertificateIssuer())
          .certificateSubject(requestDetails.getCertificateSubject())
          .contentType(contentType)
          .referrer(requestDetails.getReferrer())
          .userAgent(requestDetails.getUserAgent());

      List<MediaType> acceptableMediaTypes = requestDetails.getAcceptableMediaTypes();
      if (acceptableMediaTypes != null) {
        for (MediaType acceptableMediaType : acceptableMediaTypes) {
          formRequestBuilder.acceptableMediaType(acceptableMediaType.toString());
        }
      }
    }

    if (validation != null) {
      formRequestBuilder.messages(validation.getResults());
    }

    return requestRepository.save(formRequestBuilder.build());
  }
  @Cacheable("processDefinitionIdMap")
  public ManyMap<String, Process> getProcessDefinitionIdMap(Set<Process> processes) {
    ManyMap<String, Process> processDefinitionKeyMap = new ManyMap<String, Process>();
    for (Process process : processes) {
      ProcessDeployment deployment = process.getDeployment();
      if (deployment != null
          && deployment.getEngine() != null
          && getKey() != null
          && deployment.getEngine().equals(getKey()))
        processDefinitionKeyMap.putOne(deployment.getEngineProcessDefinitionKey(), process);
    }

    ManyMap<String, Process> map = new ManyMap<String, Process>();
    for (ProcessDefinition processDefinition :
        processEngine.getRepositoryService().createProcessDefinitionQuery().list()) {
      List<Process> matchingProcesses = processDefinitionKeyMap.get(processDefinition.getKey());
      if (matchingProcesses != null && !matchingProcesses.isEmpty())
        map.put(processDefinition.getId(), matchingProcesses);
    }

    return map;
  }
Esempio n. 4
0
  public FormRequest create(
      RequestDetails requestDetails,
      Process process,
      String taskId,
      FormRequest previousFormRequest)
      throws StatusCodeError {
    ProcessInstance instance = processInstanceService.findByTaskId(process, taskId);
    if (instance == null) {
      LOG.warn(
          "Forbidden: No instance found for the task id passed "
              + process.getProcessDefinitionKey()
              + " task: "
              + taskId);
      throw new ForbiddenError(Constants.ExceptionCodes.insufficient_permission);
    }
    Task task = taskService.read(instance, taskId);
    verifyCurrentUserIsAuthorized(process, task);

    ActionType actionType = ActionType.CREATE;

    return create(requestDetails, process, instance, task, actionType);
  }