Search in sources :

Example 6 with RestIdentityLink

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

the class ProcessInstanceService method createIdentityLink.

@POST
@Path("/{processInstanceId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createIdentityLink(@PathParam("processInstanceId") String processInstanceId, RestIdentityLink identityLink) {
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    if (identityLink.getGroup() != null) {
        throw new ActivitiIllegalArgumentException("Only user identity links are supported on a process instance.");
    }
    if (identityLink.getUser() == null) {
        throw new ActivitiIllegalArgumentException("The user is required.");
    }
    if (identityLink.getType() == null) {
        throw new ActivitiIllegalArgumentException("The identity link type is required.");
    }
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    runtimeService.addUserIdentityLink(processInstance.getId(), identityLink.getUser(), identityLink.getType());
    RestIdentityLink restIdentityLink = new RestResponseFactory().createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), null, null, processInstance.getId(), uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(restIdentityLink).build();
}
Also used : RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ActivitiIllegalArgumentException(org.activiti.engine.ActivitiIllegalArgumentException) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

Aggregations

RestResponseFactory (org.wso2.carbon.bpmn.rest.common.RestResponseFactory)5 RestIdentityLink (org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)5 BaseTaskService (org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)3 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 RuntimeService (org.activiti.engine.RuntimeService)2 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)2 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 ActivitiIllegalArgumentException (org.activiti.engine.ActivitiIllegalArgumentException)1