Search in sources :

Example 76 with RestResponseFactory

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

the class SignalService method signalEventReceived.

@POST
@Path("/")
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response signalEventReceived(SignalEventReceivedRequest signalRequest) {
    RestResponseFactory restResponseFactory = new RestResponseFactory();
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    if (signalRequest.getSignalName() == null) {
        throw new ActivitiIllegalArgumentException("signalName is required");
    }
    Map<String, Object> signalVariables = null;
    if (signalRequest.getVariables() != null) {
        signalVariables = new HashMap<String, Object>();
        for (RestVariable variable : signalRequest.getVariables()) {
            if (variable.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required.");
            }
            signalVariables.put(variable.getName(), restResponseFactory.getVariableValue(variable));
        }
    }
    if (signalRequest.isAsync()) {
        if (signalVariables != null) {
            throw new ActivitiIllegalArgumentException("Async signals cannot take variables as payload");
        }
        if (signalRequest.isCustomTenantSet()) {
            runtimeService.signalEventReceivedAsyncWithTenantId(signalRequest.getSignalName(), signalRequest.getTenantId());
        } else {
            runtimeService.signalEventReceivedAsync(signalRequest.getSignalName());
        }
        return Response.ok().status(Response.Status.ACCEPTED).build();
    } else {
        if (signalRequest.isCustomTenantSet()) {
            runtimeService.signalEventReceivedWithTenantId(signalRequest.getSignalName(), signalVariables, signalRequest.getTenantId());
        } else {
            runtimeService.signalEventReceived(signalRequest.getSignalName(), signalVariables);
        }
        return Response.ok().status(Response.Status.NO_CONTENT).build();
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 77 with RestResponseFactory

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

the class WorkflowTaskService method completeTask.

protected void completeTask(Task task, TaskActionRequest actionRequest, TaskService taskService) {
    if (actionRequest.getVariables() != null) {
        Map<String, Object> variablesToSet = new HashMap<String, Object>();
        RestResponseFactory restResponseFactory = new RestResponseFactory();
        for (RestVariable var : actionRequest.getVariables()) {
            if (var.getName() == null) {
                throw new ActivitiIllegalArgumentException("Variable name is required");
            }
            Object actualVariableValue = restResponseFactory.getVariableValue(var);
            variablesToSet.put(var.getName(), actualVariableValue);
        }
        taskService.complete(task.getId(), variablesToSet);
    } else {
        taskService.complete(task.getId());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

Example 78 with RestResponseFactory

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

the class WorkflowTaskService method getEvents.

@GET
@Path("/{taskId}/events")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getEvents(@PathParam("taskId") String taskId) {
    HistoricTaskInstance task = getHistoricTaskFromRequest(taskId);
    TaskService taskService = BPMNOSGIService.getTaskService();
    List<EventResponse> eventResponseList = new RestResponseFactory().createEventResponseList(taskService.getTaskEvents(task.getId()), uriInfo.getBaseUri().toString());
    EventResponseCollection eventResponseCollection = new EventResponseCollection();
    eventResponseCollection.setEventResponseList(eventResponseList);
    return Response.ok().entity(eventResponseCollection).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 79 with RestResponseFactory

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

the class WorkflowTaskService method getIdentityLink.

/*    protected AttachmentResponse createBinaryAttachment(HttpServletRequest httpServletRequest, Task task, Response.ResponseBuilder responseBuilder) throws
            IOException {

        String name = uriInfo.getQueryParameters().getFirst("name");
        String description = uriInfo.getQueryParameters().getFirst("description");
        String type = uriInfo.getQueryParameters().getFirst("type");


        byte[] byteArray = Utils.processMultiPartFile(httpServletRequest, "Attachment content");
        if (byteArray == null) {
            throw new ActivitiIllegalArgumentException("Empty attachment body was found in request body after " +
                    "decoding the request" +
                    ".");
        }

        if (name == null) {
            throw new ActivitiIllegalArgumentException("Attachment name is required.");
        }


        TaskService taskService = BPMNOSGIService.getTaskService();

        try {
            InputStream inputStream = new ByteArrayInputStream(byteArray);
            Attachment createdAttachment = taskService.createAttachment(type, task.getId(), task.getProcessInstanceId(), name,
                    description, inputStream);

            responseBuilder.status(Response.Status.CREATED);
            return new RestResponseFactory().createAttachmentResponse(createdAttachment, uriInfo.getBaseUri().toString());

        } catch (Exception e) {
            throw new ActivitiException("Error creating attachment response", e);
        }
    }*/
protected IdentityLink getIdentityLink(String family, String identityId, String type, String taskId) {
    boolean isUser = family.equals(RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS);
    TaskService taskService = BPMNOSGIService.getTaskService();
    // Perhaps it would be better to offer getting a single identitylink from the API
    List<IdentityLink> allLinks = taskService.getIdentityLinksForTask(taskId);
    for (IdentityLink link : allLinks) {
        boolean rightIdentity = false;
        if (isUser) {
            rightIdentity = identityId.equals(link.getUserId());
        } else {
            rightIdentity = identityId.equals(link.getGroupId());
        }
        if (rightIdentity && link.getType().equals(type)) {
            return link;
        }
    }
    throw new ActivitiObjectNotFoundException("Could not find the requested identity link.", IdentityLink.class);
}
Also used : BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)

Example 80 with RestResponseFactory

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

the class WorkflowTaskService method getIdentityLink.

@GET
@Path("/{taskId}/identitylinks/{family}/{identityId}/{type}")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getIdentityLink(@PathParam("taskId") String taskId, @PathParam("family") String family, @PathParam("identityId") String identityId, @PathParam("type") String type, @Context HttpServletRequest httpServletRequest) {
    Task task = getTaskFromRequest(taskId);
    validateIdentityLinkArguments(family, identityId, type);
    IdentityLink link = getIdentityLink(family, identityId, type, task.getId());
    return Response.ok().entity(new RestResponseFactory().createRestIdentityLink(link, uriInfo.getBaseUri().toString())).build();
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)

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