Search in sources :

Example 1 with RestIdentityLink

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

the class RestResponseFactory method createRestIdentityLink.

public RestIdentityLink createRestIdentityLink(String type, String userId, String groupId, String taskId, String processDefinitionId, String processInstanceId, String baseUri) {
    RestUrlBuilder urlBuilder = createUrlBuilder(baseUri);
    RestIdentityLink result = new RestIdentityLink();
    result.setUser(userId);
    result.setGroup(groupId);
    result.setType(type);
    String family;
    if (userId != null) {
        family = RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_USERS;
    } else {
        family = RestUrls.SEGMENT_IDENTITYLINKS_FAMILY_GROUPS;
    }
    if (processDefinitionId != null) {
        result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_DEFINITION_IDENTITYLINK, processDefinitionId, family, (userId != null ? userId : groupId)));
    } else if (taskId != null) {
        result.setUrl(urlBuilder.buildUrl(RestUrls.URL_TASK_IDENTITYLINK, taskId, family, (userId != null ? userId : groupId), type));
    } else {
        result.setUrl(urlBuilder.buildUrl(RestUrls.URL_PROCESS_INSTANCE_IDENTITYLINK, processInstanceId, (userId != null ? userId : groupId), type));
    }
    return result;
}
Also used : RestIdentityLink(org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink)

Example 2 with RestIdentityLink

use of org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink 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 3 with RestIdentityLink

use of org.wso2.carbon.bpmn.rest.model.common.RestIdentityLink 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 4 with RestIdentityLink

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

the class ProcessInstanceService method getIdentityLinks.

@GET
@Path("/{processInstanceId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public List<RestIdentityLink> getIdentityLinks(@PathParam("processInstanceId") String processInstanceId) {
    RuntimeService runtimeService = BPMNOSGIService.getRuntimeService();
    ProcessInstance processInstance = getProcessInstanceFromRequest(processInstanceId);
    return new RestResponseFactory().createRestIdentityLinks(runtimeService.getIdentityLinksForProcessInstance(processInstance.getId()), uriInfo.getBaseUri().toString());
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) RuntimeService(org.activiti.engine.RuntimeService) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with RestIdentityLink

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

the class WorkflowTaskService method createIdentityLink.

@POST
@Path("/{taskId}/identitylinks")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createIdentityLink(@PathParam("taskId") String taskId, RestIdentityLink identityLink) {
    Task task = getTaskFromRequest(taskId);
    if (identityLink.getGroup() == null && identityLink.getUser() == null) {
        throw new ActivitiIllegalArgumentException("A group or a user is required to create an identity link.");
    }
    if (identityLink.getGroup() != null && identityLink.getUser() != null) {
        throw new ActivitiIllegalArgumentException("Only one of user or group can be used to create an identity link.");
    }
    if (identityLink.getType() == null) {
        throw new ActivitiIllegalArgumentException("The identity link type is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    if (identityLink.getGroup() != null) {
        taskService.addGroupIdentityLink(task.getId(), identityLink.getGroup(), identityLink.getType());
    } else {
        taskService.addUserIdentityLink(task.getId(), identityLink.getUser(), identityLink.getType());
    }
    RestIdentityLink restIdentityLink = new RestResponseFactory().createRestIdentityLink(identityLink.getType(), identityLink.getUser(), identityLink.getGroup(), task.getId(), null, null, 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) BaseTaskService(org.wso2.carbon.bpmn.rest.service.base.BaseTaskService)

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