Search in sources :

Example 56 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method createTask.

/**
 * Create a new task instance for a process instance.
 * @param taskRequest
 * @return
 */
@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createTask(TaskRequest taskRequest) {
    TaskService taskService = BPMNOSGIService.getTaskService();
    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);
    return Response.ok().entity(new RestResponseFactory().createTaskResponse(task, uriInfo.getBaseUri().toString())).build();
}
Also used : TaskEntity(org.activiti.engine.impl.persistence.entity.TaskEntity) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 57 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method createComment.

@POST
@Path("/{taskId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createComment(@PathParam("taskId") String taskId, CommentRequest comment) {
    Task task = getTaskFromRequest(taskId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    String processInstanceId = null;
    TaskService taskService = BPMNOSGIService.getTaskService();
    if (comment.isSaveProcessInstanceId()) {
        Task taskEntity = taskService.createTaskQuery().taskId(task.getId()).singleResult();
        processInstanceId = taskEntity.getProcessInstanceId();
    }
    Comment createdComment = taskService.addComment(task.getId(), processInstanceId, comment.getMessage());
    CommentResponse commentResponse = new RestResponseFactory().createRestComment(createdComment, uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(commentResponse).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 58 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method setSimpleVariable.

protected RestVariable setSimpleVariable(RestVariable restVariable, Task task, boolean isNew) {
    if (restVariable.getName() == null) {
        throw new ActivitiIllegalArgumentException("Variable name is required");
    }
    // Figure out scope, revert to local is omitted
    RestVariable.RestVariableScope scope = restVariable.getVariableScope();
    if (scope == null) {
        scope = RestVariable.RestVariableScope.LOCAL;
    }
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    Object actualVariableValue = restResponseFactory.getVariableValue(restVariable);
    setVariable(task, restVariable.getName(), actualVariableValue, scope, isNew);
    return restResponseFactory.createRestVariable(restVariable.getName(), actualVariableValue, scope, task.getId(), RestResponseFactory.VARIABLE_TASK, false, uriInfo.getBaseUri().toString());
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

Example 59 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method executeTaskAction.

@POST
@Path("/{taskId}")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response executeTaskAction(@PathParam("taskId") String taskId, TaskActionRequest actionRequest) {
    if (actionRequest == null) {
        throw new ActivitiException("A request body was expected when executing a task action.");
    }
    Task task = getTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    if (TaskActionRequest.ACTION_COMPLETE.equals(actionRequest.getAction())) {
        completeTask(task, actionRequest, taskService);
    } else if (TaskActionRequest.ACTION_CLAIM.equals(actionRequest.getAction())) {
        claimTask(task, actionRequest, taskService);
    } else if (TaskActionRequest.ACTION_DELEGATE.equals(actionRequest.getAction())) {
        delegateTask(task, actionRequest, taskService);
    } else if (TaskActionRequest.ACTION_RESOLVE.equals(actionRequest.getAction())) {
        resolveTask(task, taskService);
    } else {
        throw new ActivitiIllegalArgumentException("Invalid action: '" + actionRequest.getAction() + "'.");
    }
    return Response.ok().status(Response.Status.OK).build();
}
Also used : BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 60 with Task

use of org.wso2.carbon.humantask.core.dao.jpa.openjpa.model.Task in project carbon-business-process by wso2.

the class WorkflowTaskService method getIdentityLinks.

@GET
@Path("/{taskId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLinks(@PathParam("taskId") String taskId) {
    Task task = getTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    List<RestIdentityLink> restIdentityLinks = new RestResponseFactory().createRestIdentityLinks(taskService.getIdentityLinksForTask(task.getId()), uriInfo.getBaseUri().toString());
    RestIdentityLinkCollection restIdentityLinkCollection = new RestIdentityLinkCollection();
    restIdentityLinkCollection.setRestIdentityLinks(restIdentityLinks);
    return Response.ok().entity(restIdentityLinkCollection).build();
}
Also used : RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Aggregations

HumanTaskRuntimeException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskRuntimeException)41 RegistryException (org.wso2.carbon.registry.core.exceptions.RegistryException)35 HumanTaskIllegalAccessException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalAccessException)28 HumanTaskIllegalArgumentException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalArgumentException)28 HumanTaskIllegalStateException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalStateException)28 UserStoreException (org.wso2.carbon.user.core.UserStoreException)28 TaskDAO (org.wso2.carbon.humantask.core.dao.TaskDAO)27 HumanTaskException (org.wso2.carbon.humantask.core.engine.HumanTaskException)27 RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)25 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)25 HumanTaskIllegalOperationException (org.wso2.carbon.humantask.core.engine.runtime.api.HumanTaskIllegalOperationException)25 ArrayList (java.util.ArrayList)14 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)13 Element (org.w3c.dom.Element)12 QName (javax.xml.namespace.QName)11 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)11 IOException (java.io.IOException)9 HumanTaskEngine (org.wso2.carbon.humantask.core.engine.HumanTaskEngine)9 AxisFault (org.apache.axis2.AxisFault)8 HumanTaskDeploymentException (org.wso2.carbon.humantask.core.deployment.HumanTaskDeploymentException)8