Search in sources :

Example 16 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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 17 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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 18 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory 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)

Example 19 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method getComments.

@GET
@Path("/{processInstanceId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getComments(@PathParam("processInstanceId") String processInstanceId) {
    TaskService taskService = BPMNOSGIService.getTaskService();
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    List<CommentResponse> commentResponseList = new RestResponseFactory().createRestCommentList(taskService.getProcessInstanceComments(instance.getId()), uriInfo.getBaseUri().toString());
    CommentResponseCollection commentResponseCollection = new CommentResponseCollection();
    commentResponseCollection.setCommentResponseList(commentResponseList);
    return Response.ok().entity(commentResponseCollection).build();
}
Also used : CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance) CommentResponseCollection(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponseCollection)

Example 20 with RestResponseFactory

use of org.wso2.carbon.bpmn.rest.common.RestResponseFactory in project carbon-business-process by wso2.

the class HistoricProcessInstanceService method getVariableFromRequest.

public RestVariable getVariableFromRequest(boolean includeBinary, String processInstanceId, String variableName) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    HistoricProcessInstance processObject = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId).includeProcessVariables().singleResult();
    if (processObject == null) {
        throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' couldn't be found.", HistoricProcessInstanceEntity.class);
    }
    Object value = processObject.getProcessVariables().get(variableName);
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic process instance '" + processInstanceId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, processInstanceId, RestResponseFactory.VARIABLE_HISTORY_PROCESS, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Aggregations

RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)90 RestVariable (org.wso2.carbon.bpmn.rest.engine.variable.RestVariable)28 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)26 Path (javax.ws.rs.Path)20 Produces (javax.ws.rs.Produces)20 RuntimeService (org.activiti.engine.RuntimeService)16 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)16 GET (javax.ws.rs.GET)14 QueryVariable (org.wso2.carbon.bpmn.rest.engine.variable.QueryVariable)14 DataResponse (org.wso2.carbon.bpmn.rest.model.common.DataResponse)14 HistoryService (org.activiti.engine.HistoryService)11 ActivitiObjectNotFoundException (org.activiti.engine.ActivitiObjectNotFoundException)10 HashMap (java.util.HashMap)8 Response (javax.ws.rs.core.Response)8 RepositoryService (org.activiti.engine.RepositoryService)8 HistoricTaskInstance (org.activiti.engine.history.HistoricTaskInstance)7 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)7 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)7 ArrayList (java.util.ArrayList)6 JAXBContext (javax.xml.bind.JAXBContext)6