Search in sources :

Example 11 with ByCaseIdContainerLocator

use of org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator in project droolsjbpm-integration by kiegroup.

the class CaseManagementServiceBase method getCaseInstance.

public String getCaseInstance(String containerId, String caseId, boolean withData, boolean withRoles, boolean withMilestones, boolean withStages, String marshallingType) {
    verifyContainerId(containerId, caseId);
    CaseInstance actualCaseInstance = caseService.getCaseInstance(caseId, withData, withRoles, withMilestones, withStages);
    org.kie.server.api.model.cases.CaseInstance caseInstance = ConvertUtils.transformCaseInstance(actualCaseInstance);
    if (actualCaseInstance.getStatus().equals(ProcessInstance.STATE_ACTIVE)) {
        if (withData) {
            caseInstance.setCaseFile(CaseFile.builder().data(actualCaseInstance.getCaseFile().getData()).build());
        }
        if (withMilestones) {
            caseInstance.setMilestones(ConvertUtils.transformMilestones(actualCaseInstance.getCaseMilestones()));
        }
        if (withStages) {
            caseInstance.setStages(ConvertUtils.transformStages(actualCaseInstance.getCaseStages()));
        }
        if (withRoles) {
            caseInstance.setRoleAssignments(ConvertUtils.transformRoleAssignment(actualCaseInstance.getCaseRoles()));
        }
    }
    logger.debug("About to marshal case instance with id '{}' {}", caseId, caseInstance);
    return marshallerHelper.marshal(containerId, marshallingType, caseInstance, new ByCaseIdContainerLocator(caseId));
}
Also used : CaseInstance(org.jbpm.casemgmt.api.model.instance.CaseInstance) ByCaseIdContainerLocator(org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator)

Example 12 with ByCaseIdContainerLocator

use of org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator in project droolsjbpm-integration by kiegroup.

the class CaseManagementServiceBase method triggerAdHocNode.

public void triggerAdHocNode(String containerId, String caseId, String stageId, String adHocName, String payload, String marshallingType) {
    verifyContainerId(containerId, caseId);
    logger.debug("About to unmarshal task data from payload: '{}'", payload);
    Map<String, Object> adHocTaskData = marshallerHelper.unmarshal(containerId, payload, marshallingType, Map.class, new ByCaseIdContainerLocator(caseId));
    logger.debug("AdHoc task {} will be triggered with data = {}", adHocName, adHocTaskData);
    if (stageId != null && !stageId.isEmpty()) {
        caseService.triggerAdHocFragment(caseId, stageId, adHocName, adHocTaskData);
    } else {
        caseService.triggerAdHocFragment(caseId, adHocName, adHocTaskData);
    }
}
Also used : ByCaseIdContainerLocator(org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator)

Example 13 with ByCaseIdContainerLocator

use of org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator 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

ByCaseIdContainerLocator (org.kie.server.services.casemgmt.locator.ByCaseIdContainerLocator)13 HashMap (java.util.HashMap)2 CaseFileInstance (org.jbpm.casemgmt.api.model.instance.CaseFileInstance)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Consumes (javax.ws.rs.Consumes)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Variant (javax.ws.rs.core.Variant)1 CaseNotFoundException (org.jbpm.casemgmt.api.CaseNotFoundException)1 TaskSpecification (org.jbpm.casemgmt.api.dynamic.TaskSpecification)1 CaseDefinition (org.jbpm.casemgmt.api.model.CaseDefinition)1 CaseInstance (org.jbpm.casemgmt.api.model.instance.CaseInstance)1 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)1 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)1 CaseInstance (org.kie.server.api.model.cases.CaseInstance)1 CaseInstanceList (org.kie.server.api.model.cases.CaseInstanceList)1 KieContainerInstanceImpl (org.kie.server.services.impl.KieContainerInstanceImpl)1 MarshallerHelper (org.kie.server.services.impl.marshal.MarshallerHelper)1