Search in sources :

Example 1 with MarshallerHelper

use of org.kie.server.services.impl.marshal.MarshallerHelper in project businessautomation-cop by redhat-cop.

the class AbortAllResource method abortAllContainerInstances.

@DELETE
@Path("/abortAll")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response abortAllContainerInstances(@Context HttpHeaders headers, @PathParam("id") String containerId) {
    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 {
        // get active instances
        Collection<ProcessInstanceDesc> activeInstances = runtimeDataService.getProcessInstancesByDeploymentId(containerId, Arrays.asList(1), /* active */
        null);
        // extract their pids
        List<Long> pids = activeInstances.stream().map(activeInstance -> activeInstance.getId()).collect(Collectors.toList());
        // abort them all
        processService.abortProcessInstances(containerId, pids);
        String result = marshallerHelper.marshal(format.toString(), pids);
        logger.debug("Aborted following instances:" + result + ", in a following container:" + containerId);
        return createResponse(result, v, Response.Status.OK);
    } catch (Exception e) {
        // in case marshalling failed return the call container response to keep
        // 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.kie.server.remote.rest.common.util.RestUtils.getVariant) Variant(javax.ws.rs.core.Variant) Arrays(java.util.Arrays) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) ProcessService(org.jbpm.services.api.ProcessService) Path(javax.ws.rs.Path) LoggerFactory(org.slf4j.LoggerFactory) RestUtils.createResponse(org.kie.server.remote.rest.common.util.RestUtils.createResponse) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) MediaType(javax.ws.rs.core.MediaType) Consumes(javax.ws.rs.Consumes) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) Logger(org.slf4j.Logger) Collection(java.util.Collection) Collectors(java.util.stream.Collectors) KieServerRegistry(org.kie.server.services.api.KieServerRegistry) List(java.util.List) RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) HttpHeaders(javax.ws.rs.core.HttpHeaders) Response(javax.ws.rs.core.Response) RuntimeDataService(org.jbpm.services.api.RuntimeDataService) RestUtils.getContentType(org.kie.server.remote.rest.common.util.RestUtils.getContentType) Variant(javax.ws.rs.core.Variant) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) ProcessInstanceDesc(org.jbpm.services.api.model.ProcessInstanceDesc) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 2 with MarshallerHelper

use of org.kie.server.services.impl.marshal.MarshallerHelper 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)

Example 3 with MarshallerHelper

use of org.kie.server.services.impl.marshal.MarshallerHelper in project businessautomation-cop by redhat-cop.

the class CustomResource method insertFireReturn.

@GET
@Path("/{aliasId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response insertFireReturn(@Context HttpHeaders headers, @PathParam("aliasId") String alias) {
    Variant v = getVariant(headers);
    String contentType = getContentType(headers);
    MarshallingFormat format = MarshallingFormat.fromType(contentType);
    if (format == null) {
        format = MarshallingFormat.valueOf(contentType);
    }
    MarshallerHelper marshallerHelper = new MarshallerHelper(context);
    try {
        // get all the containers with the given alias
        List<KieContainerInstanceImpl> filteredContainers = context.getContainersForAlias(alias);
        List<ProcessInstance> instances = new ArrayList<ProcessInstance>();
        // for each container obtain a list of active process instances
        filteredContainers.forEach(container -> {
            String containerId = container.getContainerId();
            ProcessInstanceList instanceList = runtimeDataService.getProcessInstancesByDeploymentId(containerId, Arrays.asList(1), 0, 0, "", true);
            logger.debug("Found " + instanceList.getItems().size() + " active process instances  in container with id " + containerId);
            instances.addAll(instanceList.getItems());
        });
        // return the list to the client
        ProcessInstanceList finalList = new ProcessInstanceList(instances);
        String result = marshallerHelper.marshal(format.toString(), finalList);
        logger.debug("Returning OK response with content '{}'", result);
        return createResponse(result, v, Response.Status.OK);
    } catch (Exception e) {
        // in case marshalling failed return the call container response to keep
        // 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) ProcessInstanceList(org.kie.server.api.model.instance.ProcessInstanceList) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) MarshallerHelper(org.kie.server.services.impl.marshal.MarshallerHelper) ArrayList(java.util.ArrayList) ProcessInstance(org.kie.server.api.model.instance.ProcessInstance) KieContainerInstanceImpl(org.kie.server.services.impl.KieContainerInstanceImpl) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

Consumes (javax.ws.rs.Consumes)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 Variant (javax.ws.rs.core.Variant)3 MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)3 MarshallerHelper (org.kie.server.services.impl.marshal.MarshallerHelper)3 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 RESTUtils.getVariant (org.redhat.gss.extension.RESTUtils.getVariant)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 DELETE (javax.ws.rs.DELETE)1 PathParam (javax.ws.rs.PathParam)1 Context (javax.ws.rs.core.Context)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 ProcessService (org.jbpm.services.api.ProcessService)1