コード例 #1
0
  @Post
  public ProcessInstanceResponse createProcessInstance(ProcessInstanceCreateRequest request) {

    if (request.getProcessDefinitionId() == null
        && request.getProcessDefinitionKey() == null
        && request.getMessage() == null) {
      throw new ActivitiIllegalArgumentException(
          "Either processDefinitionId, processDefinitionKey or message is required.");
    }

    int paramsSet =
        ((request.getProcessDefinitionId() != null) ? 1 : 0)
            + ((request.getProcessDefinitionKey() != null) ? 1 : 0)
            + ((request.getMessage() != null) ? 1 : 0);

    if (paramsSet > 1) {
      throw new ActivitiIllegalArgumentException(
          "Only one of processDefinitionId, processDefinitionKey or message should be set.");
    }

    RestResponseFactory factory =
        getApplication(ActivitiRestServicesApplication.class).getRestResponseFactory();

    Map<String, Object> startVariables = null;
    if (request.getVariables() != null) {
      startVariables = new HashMap<String, Object>();
      for (RestVariable variable : request.getVariables()) {
        startVariables.put(variable.getName(), factory.getVariableValue(variable));
      }
    }

    // Actually start the instance based on key or id
    try {
      ProcessInstance instance = null;
      if (request.getProcessDefinitionId() != null) {
        instance =
            ActivitiUtil.getRuntimeService()
                .startProcessInstanceById(
                    request.getProcessDefinitionId(), request.getBusinessKey(), startVariables);
      } else if (request.getProcessDefinitionKey() != null) {
        instance =
            ActivitiUtil.getRuntimeService()
                .startProcessInstanceByKey(
                    request.getProcessDefinitionKey(), request.getBusinessKey(), startVariables);
      } else {
        instance =
            ActivitiUtil.getRuntimeService()
                .startProcessInstanceByMessage(
                    request.getMessage(), request.getBusinessKey(), startVariables);
      }

      setStatus(Status.SUCCESS_CREATED);
      return factory.createProcessInstanceResponse(this, instance);
    } catch (ActivitiObjectNotFoundException aonfe) {
      throw new ActivitiIllegalArgumentException(aonfe.getMessage(), aonfe);
    }
  }
コード例 #2
0
  @Get
  public List<AttachmentResponse> getAttachments() {
    if (!authenticate()) return null;

    List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
    RestResponseFactory responseFactory =
        getApplication(ActivitiRestServicesApplication.class).getRestResponseFactory();
    Task task = getTaskFromRequest();

    for (Attachment attachment : ActivitiUtil.getTaskService().getTaskAttachments(task.getId())) {
      result.add(responseFactory.createAttachmentResponse(this, attachment));
    }

    return result;
  }