Search in sources :

Example 76 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariableResource method deleteVariable.

@RequestMapping(value = "/runtime/tasks/{taskId}/variables/{variableName}", method = RequestMethod.DELETE)
public void deleteVariable(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scopeString, HttpServletResponse response) {
    Task task = getTaskFromRequest(taskId);
    // Determine scope
    RestVariableScope scope = RestVariableScope.LOCAL;
    if (scopeString != null) {
        scope = RestVariable.getScopeFromString(scopeString);
    }
    if (!hasVariableOnScope(task, variableName, scope)) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a variable '" + variableName + "' in scope " + scope.name().toLowerCase(), VariableInstanceEntity.class);
    }
    if (scope == RestVariableScope.LOCAL) {
        taskService.removeVariableLocal(task.getId(), variableName);
    } else {
        // Safe to use executionId, as the hasVariableOnScope whould have stopped a global-var update on standalone task
        runtimeService.removeVariable(task.getExecutionId(), variableName);
    }
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Task(org.activiti.engine.task.Task) RestVariableScope(org.activiti.rest.service.api.engine.variable.RestVariable.RestVariableScope) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 77 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskVariableResource method updateVariable.

@RequestMapping(value = "/runtime/tasks/{taskId}/variables/{variableName}", method = RequestMethod.PUT, produces = "application/json")
public RestVariable updateVariable(@PathVariable("taskId") String taskId, @PathVariable("variableName") String variableName, @RequestParam(value = "scope", required = false) String scope, HttpServletRequest request) {
    Task task = getTaskFromRequest(taskId);
    RestVariable result = null;
    if (request instanceof MultipartHttpServletRequest) {
        result = setBinaryVariable((MultipartHttpServletRequest) request, task, false);
        if (!result.getName().equals(variableName)) {
            throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
        }
    } else {
        RestVariable restVariable = null;
        try {
            restVariable = objectMapper.readValue(request.getInputStream(), RestVariable.class);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Error converting request body to RestVariable instance", e);
        }
        if (restVariable == null) {
            throw new ActivitiException("Invalid body was supplied");
        }
        if (!restVariable.getName().equals(variableName)) {
            throw new ActivitiIllegalArgumentException("Variable name in the body should be equal to the name used in the requested URL.");
        }
        result = setSimpleVariable(restVariable, task, false);
    }
    return result;
}
Also used : RestVariable(org.activiti.rest.service.api.engine.variable.RestVariable) Task(org.activiti.engine.task.Task) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ActivitiException(org.activiti.engine.ActivitiException) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 78 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskAttachmentCollectionResource method createAttachment.

@RequestMapping(value = "/runtime/tasks/{taskId}/attachments", method = RequestMethod.POST, produces = "application/json")
public AttachmentResponse createAttachment(@PathVariable String taskId, HttpServletRequest request, HttpServletResponse response) {
    AttachmentResponse result = null;
    Task task = getTaskFromRequest(taskId);
    if (request instanceof MultipartHttpServletRequest) {
        result = createBinaryAttachment((MultipartHttpServletRequest) request, task, response);
    } else {
        AttachmentRequest attachmentRequest = null;
        try {
            attachmentRequest = objectMapper.readValue(request.getInputStream(), AttachmentRequest.class);
        } catch (Exception e) {
            throw new ActivitiIllegalArgumentException("Failed to serialize to a AttachmentRequest instance", e);
        }
        if (attachmentRequest == null) {
            throw new ActivitiIllegalArgumentException("AttachmentRequest properties not found in request");
        }
        result = createSimpleAttachment(attachmentRequest, task);
    }
    response.setStatus(HttpStatus.CREATED.value());
    return result;
}
Also used : Task(org.activiti.engine.task.Task) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) AttachmentResponse(org.activiti.rest.service.api.engine.AttachmentResponse) AttachmentRequest(org.activiti.rest.service.api.engine.AttachmentRequest) ActivitiException(org.activiti.engine.ActivitiException) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) MultipartHttpServletRequest(org.springframework.web.multipart.MultipartHttpServletRequest) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 79 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskCollectionResource method createTask.

@RequestMapping(value = "/runtime/tasks", method = RequestMethod.POST, produces = "application/json")
public TaskResponse createTask(@RequestBody TaskRequest taskRequest, HttpServletRequest request, HttpServletResponse response) {
    Task task = taskService.newTask();
    // Populate the task properties based on the request
    populateTaskFromRequest(task, taskRequest);
    if (taskRequest.isTenantIdSet()) {
        ((TaskEntity) task).setTenantId(taskRequest.getTenantId());
    }
    taskService.saveTask(task);
    response.setStatus(HttpStatus.CREATED.value());
    return restResponseFactory.createTaskResponse(task);
}
Also used : Task(org.activiti.engine.task.Task) TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 80 with Task

use of org.activiti.engine.task.Task in project Activiti by Activiti.

the class TaskCommentResource method deleteComment.

@RequestMapping(value = "/runtime/tasks/{taskId}/comments/{commentId}", method = RequestMethod.DELETE)
public void deleteComment(@PathVariable("taskId") String taskId, @PathVariable("commentId") String commentId, HttpServletResponse response) {
    // Check if task exists
    Task task = getTaskFromRequest(taskId);
    Comment comment = taskService.getComment(commentId);
    if (comment == null || comment.getTaskId() == null || !comment.getTaskId().equals(task.getId())) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    taskService.deleteComment(commentId);
    response.setStatus(HttpStatus.NO_CONTENT.value());
}
Also used : Comment(org.activiti.engine.task.Comment) Task(org.activiti.engine.task.Task) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

Task (org.activiti.engine.task.Task)955 Deployment (org.activiti.engine.test.Deployment)548 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)502 HashMap (java.util.HashMap)197 Test (org.junit.Test)123 HistoricProcessInstance (org.activiti.engine.history.HistoricProcessInstance)109 ArrayList (java.util.ArrayList)74 Date (java.util.Date)65 Execution (org.activiti.engine.runtime.Execution)59 DelegateTask (org.activiti.engine.delegate.DelegateTask)54 TaskQuery (org.activiti.engine.task.TaskQuery)54 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)51 Job (org.activiti.engine.runtime.Job)49 Calendar (java.util.Calendar)44 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)44 RequestContext (org.alfresco.rest.api.tests.client.RequestContext)44 JsonNode (com.fasterxml.jackson.databind.JsonNode)41 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)41 JSONObject (org.json.simple.JSONObject)40 TasksClient (org.alfresco.rest.workflow.api.tests.WorkflowApiClient.TasksClient)38