Search in sources :

Example 16 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCaseInstancesByData.

@Override
public List<CaseInstance> getCaseInstancesByData(String dataItemName, String dataItemValue, List<String> status, Integer page, Integer pageSize) {
    CaseInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        String queryString = getPagingQueryString("", page, pageSize);
        queryString = getAdditionalParams(queryString, "status", status);
        queryString = queryString + "&dataItemName=" + dataItemName;
        if (dataItemValue != null && !dataItemValue.isEmpty()) {
            queryString = queryString + "&dataItemValue=" + dataItemValue;
        }
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_QUERY_URI + "/" + CASE_ALL_INSTANCES_GET_URI, valuesMap) + queryString, CaseInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCaseInstancesByCaseFileData", new Object[] { dataItemName, dataItemValue, safeList(status), page, pageSize, "", true })));
        ServiceResponse<CaseInstanceList> response = (ServiceResponse<CaseInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 17 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseServicesClientImpl method getCaseInstancesByContainer.

@Override
public List<CaseInstance> getCaseInstancesByContainer(String containerId, List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder, boolean withData) {
    CaseInstanceList list = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(CONTAINER_ID, containerId);
        String queryString = getPagingQueryString("", page, pageSize);
        queryString = getAdditionalParams(queryString, "status", status);
        queryString = getSortingQueryString(queryString, sort, sortOrder);
        queryString = getAdditionalParams(queryString, "withData", Collections.singletonList(withData));
        list = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), CASE_URI + "/" + CASE_INSTANCES_GET_URI, valuesMap) + queryString, CaseInstanceList.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("CaseQueryService", "getCaseInstancesByContainer", new Object[] { containerId, safeList(status), page, pageSize, sort, sortOrder, withData })));
        ServiceResponse<CaseInstanceList> response = (ServiceResponse<CaseInstanceList>) executeJmsCommand(script, DescriptorCommand.class.getName(), KieServerConstants.CAPABILITY_CASE).getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        list = response.getResult();
    }
    if (list != null) {
        return list.getItems();
    }
    return Collections.emptyList();
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) DescriptorCommand(org.kie.server.api.commands.DescriptorCommand) ServiceResponse(org.kie.server.api.model.ServiceResponse) KieServerCommand(org.kie.server.api.model.KieServerCommand) HashMap(java.util.HashMap) CommandScript(org.kie.server.api.commands.CommandScript)

Example 18 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseManagementRuntimeDataServiceBase method getCaseInstancesByRole.

public CaseInstanceList getCaseInstancesByRole(String roleName, List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder, boolean withData) {
    List<CaseStatus> caseStatus = safeCaseStatus(status);
    sort = safeCaseInstanceSort(sort);
    Collection<org.jbpm.casemgmt.api.model.instance.CaseInstance> caseInstanceDescs = caseRuntimeDataService.getCaseInstancesByRole(roleName, caseStatus, withData, ConvertUtils.buildQueryContext(page, pageSize, sort, sortOrder));
    List<CaseInstance> caseInstances = ConvertUtils.transformCaseInstances(caseInstanceDescs);
    CaseInstanceList caseInstancesList = new CaseInstanceList(caseInstances);
    return caseInstancesList;
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus)

Example 19 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project droolsjbpm-integration by kiegroup.

the class CaseManagementRuntimeDataServiceBase method getCaseInstancesAnyRole.

public CaseInstanceList getCaseInstancesAnyRole(List<String> status, Integer page, Integer pageSize, String sort, boolean sortOrder, boolean withData) {
    List<CaseStatus> caseStatus = safeCaseStatus(status);
    sort = safeCaseInstanceSort(sort);
    Collection<org.jbpm.casemgmt.api.model.instance.CaseInstance> caseInstanceDescs = caseRuntimeDataService.getCaseInstancesAnyRole(caseStatus, withData, ConvertUtils.buildQueryContext(page, pageSize, sort, sortOrder));
    List<CaseInstance> caseInstances = ConvertUtils.transformCaseInstances(caseInstanceDescs);
    CaseInstanceList caseInstancesList = new CaseInstanceList(caseInstances);
    return caseInstancesList;
}
Also used : CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) CaseStatus(org.jbpm.casemgmt.api.model.CaseStatus)

Example 20 with CaseInstanceList

use of org.kie.server.api.model.cases.CaseInstanceList in project businessautomation-cop by redhat-cop.

the class GetCasesWithDataResource method getCaseInstancesWithData.

@SuppressWarnings("unchecked")
@GET
@Path("/instancesWithData")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response getCaseInstancesWithData(@Context HttpHeaders headers, @QueryParam("dataItem") List<String> dataItems) {
    Variant v = getVariant(headers);
    String contentType = getContentType(headers);
    MarshallingFormat format = MarshallingFormat.fromType(contentType);
    if (format == null) {
        format = MarshallingFormat.valueOf(contentType);
    }
    MarshallerHelper marshallerHelper = new MarshallerHelper(registry);
    try {
        // Fetching all OPEN cases
        CaseInstanceList cases = this.caseManagementRuntimeDataService.getCaseInstancesAnyRole(Arrays.asList("open"), 0, 0, "", true);
        List<CaseInstance> finalList = new ArrayList<CaseInstance>();
        // for every case instance found, let's fetch the case data specified in the query parameter 'dateItems'
        for (CaseInstance caseInstance : cases.getItems()) {
            String caseFileData = caseManagementServiceBase.getCaseFileData(caseInstance.getContainerId(), caseInstance.getCaseId(), dataItems, format.toString());
            logger.debug("Following data were fetched :" + caseFileData + "\n for case instance id:" + caseInstance.getCaseId());
            Map<String, Object> caseFileDataUnmarshalled = marshallerHelper.unmarshal(caseInstance.getContainerId(), caseFileData, format.toString(), Map.class, new ByCaseIdContainerLocator(caseInstance.getCaseId()));
            caseInstance.setCaseFile(CaseFile.builder().data(caseFileDataUnmarshalled).build());
            finalList.add(caseInstance);
        }
        cases.setCaseInstances(finalList.toArray(new CaseInstance[finalList.size()]));
        String result = marshallerHelper.marshal(format.toString(), cases);
        logger.debug("Returning OK response with content '{}'", result);
        return createResponse(result, v, Response.Status.OK);
    } catch (Exception e) {
        // backward compatibility
        String response = "Execution failed with error : " + e.getMessage();
        logger.debug("Returning Failure response with content '{}'", response);
        return createResponse(response, v, Response.Status.INTERNAL_SERVER_ERROR);
    }
}
Also used : RESTUtils.getVariant(org.redhat.gss.extension.RESTUtils.getVariant) Variant(javax.ws.rs.core.Variant) CaseInstanceList(org.kie.server.api.model.cases.CaseInstanceList) CaseInstance(org.kie.server.api.model.cases.CaseInstance) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) ArrayList(java.util.ArrayList) ByCaseIdContainerLocator(org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)20 CaseInstance (org.kie.server.api.model.cases.CaseInstance)9 CaseStatus (org.jbpm.casemgmt.api.model.CaseStatus)7 HashMap (java.util.HashMap)6 GET (javax.ws.rs.GET)6 Path (javax.ws.rs.Path)6 Produces (javax.ws.rs.Produces)6 Variant (javax.ws.rs.core.Variant)6 CommandScript (org.kie.server.api.commands.CommandScript)6 DescriptorCommand (org.kie.server.api.commands.DescriptorCommand)6 KieServerCommand (org.kie.server.api.model.KieServerCommand)6 ServiceResponse (org.kie.server.api.model.ServiceResponse)6 ApiOperation (io.swagger.annotations.ApiOperation)5 ApiResponses (io.swagger.annotations.ApiResponses)5 Header (org.kie.server.remote.rest.common.Header)5 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)5 ArrayList (java.util.ArrayList)2 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)2 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)2 Consumes (javax.ws.rs.Consumes)1