Search in sources :

Example 11 with RestResponseFactory

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

the class WorkflowTaskService method getIdentityLinksForFamily.

@GET
@Path("/{taskId}/identitylinks/{family}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLinksForFamily(@PathParam("taskId") String taskId, @PathParam("family") String family) {
    Task task = getTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    if (family == null || (!RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS.equals(family) && !RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS.equals(family))) {
        throw new ActivitiIllegalArgumentException("Identity link family should be 'users' or 'groups'.");
    }
    boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
    List<RestIdentityLink> results = new ArrayList<RestIdentityLink>();
    List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(task.getId());
    for (IdentityLink link : allLinks) {
        boolean match = false;
        if (isUser) {
            match = link.getUserId() != null;
        } else {
            match = link.getGroupId() != null;
        }
        if (match) {
            results.add(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString()));
        }
    }
    RestIdentityLinkCollection restIdentityLinkCollection = new RestIdentityLinkCollection();
    restIdentityLinkCollection.setRestIdentityLinks(results);
    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) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)

Example 12 with RestResponseFactory

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

the class WorkflowTaskService method getComment.

@GET
@Path("/{taskId}/comments/{commentId}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getComment(@PathParam("taskId") String taskId, @PathParam("commentId") String commentId) {
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    Comment comment = taskService.getComment(commentId);
    if (comment == null || !task.getId().equals(comment.getTaskId())) {
        throw new ActivitiObjectNotFoundException("Task '" + task.getId() + "' doesn't have a comment with id '" + commentId + "'.", Comment.class);
    }
    return Response.ok().entity(new RestResponseFactory().createRestComment(comment, uriInfo.getBaseUri().toString())).build();
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 13 with RestResponseFactory

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

the class WorkflowTaskService method createSimpleAttachment.

protected AttachmentResponse createSimpleAttachment(AttachmentRequest attachmentRequest, Task task) {
    if (attachmentRequest.getName() == null) {
        throw new ActivitiIllegalArgumentException("Attachment name is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    Attachment createdAttachment = taskService.createAttachment(attachmentRequest.getType(), task.getId(), task.getProcessInstanceId(), attachmentRequest.getName(), attachmentRequest.getDescription(), attachmentRequest.getExternalUrl());
    return new RestResponseFactory().createAttachmentResponse(createdAttachment, uriInfo.getBaseUri().toString());
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 14 with RestResponseFactory

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

the class WorkflowTaskService method getAttachments.

@GET
@Path("/{taskId}/attachments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getAttachments(@PathParam("taskId") String taskId) {
    List<AttachmentResponse> result = new ArrayList<AttachmentResponse>();
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    String baseUri = uriInfo.getBaseUri().toString();
    for (Attachment attachment : taskService.getProcessInstanceAttachments(task.getProcessInstanceId())) {
        result.add(restResponseFactory.createAttachmentResponse(attachment, baseUri));
    }
    AttachmentResponseCollection attachmentResponseCollection = new AttachmentResponseCollection();
    attachmentResponseCollection.setAttachmentResponseList(result);
    return Response.ok().entity(attachmentResponseCollection).build();
}
Also used : HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

Example 15 with RestResponseFactory

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

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