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());
}
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;
}
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;
}
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);
}
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());
}
Aggregations