Search in sources :

Example 51 with RestResponseFactory

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

the class HistoricProcessInstanceService method createComment.

@POST
@Path("/{processInstanceId}/comments")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
@Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response createComment(@PathParam("processInstanceId") String processInstanceId, CommentResponse comment) {
    HistoricProcessInstance instance = getHistoricProcessInstanceFromRequest(processInstanceId);
    if (comment.getMessage() == null) {
        throw new ActivitiIllegalArgumentException("Comment text is required.");
    }
    TaskService taskService = BPMNOSGIService.getTaskService();
    Comment createdComment = taskService.addComment(null, instance.getId(), comment.getMessage());
    CommentResponse commentResponse = new RestResponseFactory().createRestComment(createdComment, uriInfo.getBaseUri().toString());
    return Response.ok().status(Response.Status.CREATED).entity(commentResponse).build();
}
Also used : Comment(org.activiti.engine.task.Comment) CommentResponse(org.wso2.carbon.bpmn.rest.model.runtime.CommentResponse) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoricProcessInstance(org.activiti.engine.history.HistoricProcessInstance)

Example 52 with RestResponseFactory

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

the class HistoricTaskInstanceService method getVariableFromRequest.

protected RestVariable getVariableFromRequest(boolean includeBinary, String taskId, String variableName, String scope) {
    HistoryService historyService = BPMNOSGIService.getHistoryService();
    RestVariable.RestVariableScope variableScope = RestVariable.getScopeFromString(scope);
    HistoricTaskInstanceQuery taskQuery = historyService.createHistoricTaskInstanceQuery().taskId(taskId);
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            taskQuery.includeProcessVariables();
        } else {
            taskQuery.includeTaskLocalVariables();
        }
    } else {
        taskQuery.includeTaskLocalVariables().includeProcessVariables();
    }
    HistoricTaskInstance taskObject = taskQuery.singleResult();
    if (taskObject == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' couldn't be found.", HistoricTaskInstanceEntity.class);
    }
    Object value = null;
    if (variableScope != null) {
        if (variableScope == RestVariable.RestVariableScope.GLOBAL) {
            value = taskObject.getProcessVariables().get(variableName);
        } else {
            value = taskObject.getTaskLocalVariables().get(variableName);
        }
    } else {
        // look for local task restVariables first
        if (taskObject.getTaskLocalVariables().containsKey(variableName)) {
            value = taskObject.getTaskLocalVariables().get(variableName);
        } else {
            value = taskObject.getProcessVariables().get(variableName);
        }
    }
    if (value == null) {
        throw new ActivitiObjectNotFoundException("Historic task instance '" + taskId + "' variable value for " + variableName + " couldn't be found.", VariableInstanceEntity.class);
    } else {
        return new RestResponseFactory().createRestVariable(variableName, value, null, taskId, RestResponseFactory.VARIABLE_HISTORY_TASK, includeBinary, uriInfo.getBaseUri().toString());
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) HistoricTaskInstance(org.activiti.engine.history.HistoricTaskInstance) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HistoryService(org.activiti.engine.HistoryService) HistoricTaskInstanceQuery(org.activiti.engine.history.HistoricTaskInstanceQuery) ActivitiObjectNotFoundException(org.activiti.engine.ActivitiObjectNotFoundException)

Example 53 with RestResponseFactory

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

the class IdentityService method getGroups.

/**
 * Get all the groups that match the filters given by query parameters of the request.
 * @return DataResponse
 */
@GET
@Path("/groups")
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public DataResponse getGroups() {
    GroupQuery query = identityService.createGroupQuery();
    Map<String, String> allRequestParams = new HashMap<>();
    String id = uriInfo.getQueryParameters().getFirst("id");
    if (id != null) {
        query.groupId(id);
        allRequestParams.put("id", id);
    }
    String name = uriInfo.getQueryParameters().getFirst("name");
    if (name != null) {
        query.groupName(name);
        allRequestParams.put("name", name);
    }
    String nameLike = uriInfo.getQueryParameters().getFirst("nameLike");
    if (nameLike != null) {
        query.groupNameLike(nameLike);
        allRequestParams.put("nameLike", nameLike);
    }
    String type = uriInfo.getQueryParameters().getFirst("type");
    if (type != null) {
        query.groupType(type);
        allRequestParams.put("type", type);
    }
    String member = uriInfo.getQueryParameters().getFirst("name");
    if (member != null) {
        query.groupMember(member);
        allRequestParams.put("member", member);
    }
    String potentialStarter = uriInfo.getQueryParameters().getFirst("potentialStarter");
    if (potentialStarter != null) {
        query.potentialStarter(potentialStarter);
        allRequestParams.put("potentialStarter", potentialStarter);
    }
    allRequestParams = Utils.prepareCommonParameters(allRequestParams, uriInfo);
    GroupPaginateList groupPaginateList = new GroupPaginateList(new RestResponseFactory(), uriInfo);
    return groupPaginateList.paginateList(allRequestParams, query, "id", groupProperties);
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) HashMap(java.util.HashMap) GroupQuery(org.activiti.engine.identity.GroupQuery) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 54 with RestResponseFactory

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

the class BaseRuntimeService method getQueryResponse.

protected DataResponse getQueryResponse(ExecutionQueryRequest queryRequest, Map<String, String> requestParams, String serverRootUrl) {
    ExecutionQuery query = runtimeService.createExecutionQuery();
    // Populate query based on request
    if (queryRequest.getId() != null) {
        query.executionId(queryRequest.getId());
        requestParams.put("id", queryRequest.getId());
    }
    if (queryRequest.getProcessInstanceId() != null) {
        query.processInstanceId(queryRequest.getProcessInstanceId());
        requestParams.put("processInstanceId", queryRequest.getProcessInstanceId());
    }
    if (queryRequest.getProcessDefinitionKey() != null) {
        query.processDefinitionKey(queryRequest.getProcessDefinitionKey());
        requestParams.put("processDefinitionKey", queryRequest.getProcessDefinitionKey());
    }
    if (queryRequest.getProcessDefinitionId() != null) {
        query.processDefinitionId(queryRequest.getProcessDefinitionId());
        requestParams.put("processDefinitionId", queryRequest.getProcessDefinitionId());
    }
    if (queryRequest.getProcessBusinessKey() != null) {
        query.processInstanceBusinessKey(queryRequest.getProcessBusinessKey());
        requestParams.put("processInstanceBusinessKey", queryRequest.getProcessBusinessKey());
    }
    if (queryRequest.getActivityId() != null) {
        query.activityId(queryRequest.getActivityId());
        requestParams.put("activityId", queryRequest.getActivityId());
    }
    if (queryRequest.getParentId() != null) {
        query.parentId(queryRequest.getParentId());
        requestParams.put("parentId", queryRequest.getParentId());
    }
    if (queryRequest.getMessageEventSubscriptionName() != null) {
        query.messageEventSubscriptionName(queryRequest.getMessageEventSubscriptionName());
        requestParams.put("messageEventSubscriptionName", queryRequest.getMessageEventSubscriptionName());
    }
    if (queryRequest.getSignalEventSubscriptionName() != null) {
        query.signalEventSubscriptionName(queryRequest.getSignalEventSubscriptionName());
        requestParams.put("signalEventSubscriptionName", queryRequest.getSignalEventSubscriptionName());
    }
    if (queryRequest.getVariables() != null) {
        addVariables(query, queryRequest.getVariables(), false);
    }
    if (queryRequest.getProcessInstanceVariables() != null) {
        addVariables(query, queryRequest.getProcessInstanceVariables(), true);
    }
    if (queryRequest.getTenantId() != null) {
        query.executionTenantId(queryRequest.getTenantId());
        requestParams.put("tenantId", queryRequest.getTenantId());
    }
    if (queryRequest.getTenantIdLike() != null) {
        query.executionTenantIdLike(queryRequest.getTenantIdLike());
        requestParams.put("tenantIdLike", queryRequest.getTenantIdLike());
    }
    if (Boolean.TRUE.equals(queryRequest.getWithoutTenantId())) {
        query.executionWithoutTenantId();
        requestParams.put("withoutTenantId", queryRequest.getWithoutTenantId().toString());
    }
    return new ExecutionPaginateList(new RestResponseFactory(), uriInfo).paginateList(requestParams, queryRequest, query, "processInstanceId", allowedSortProperties);
}
Also used : RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory) ExecutionPaginateList(org.wso2.carbon.bpmn.rest.model.runtime.ExecutionPaginateList) ExecutionQuery(org.activiti.engine.runtime.ExecutionQuery)

Example 55 with RestResponseFactory

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

the class BaseRuntimeService method addGlobalVariables.

protected void addGlobalVariables(Execution execution, int variableType, Map<String, RestVariable> variableMap) {
    Map<String, Object> rawVariables = runtimeService.getVariables(execution.getId());
    List<RestVariable> globalVariables = new RestResponseFactory().createRestVariables(rawVariables, execution.getId(), variableType, RestVariable.RestVariableScope.GLOBAL, uriInfo.getBaseUri().toString());
    // since local variables get precedence over global ones at all times.
    for (RestVariable var : globalVariables) {
        if (!variableMap.containsKey(var.getName())) {
            variableMap.put(var.getName(), var);
        }
    }
}
Also used : RestVariable(org.wso2.carbon.bpmn.rest.engine.variable.RestVariable) RestResponseFactory(org.wso2.carbon.bpmn.rest.common.RestResponseFactory)

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