Search in sources :

Example 16 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat 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)

Example 17 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project rhpam-7-openshift-image by jboss-container-images.

the class HelloRulesClient method getMarshallingFormat.

private MarshallingFormat getMarshallingFormat() {
    // can use xstream, xml (jaxb), or json
    String type = System.getProperty("MarshallingFormat", "jaxb");
    if (type.trim().equalsIgnoreCase("jaxb")) {
        type = "xml";
    }
    MarshallingFormat marshallingFormat = MarshallingFormat.fromType(type);
    logger.debug(String.format("--------->  %s MarshallingFormat.%s", marshallingFormat.getType(), marshallingFormat.name()));
    return marshallingFormat;
}
Also used : MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat)

Aggregations

MarshallingFormat (org.kie.server.api.marshalling.MarshallingFormat)17 Marshaller (org.kie.server.api.marshalling.Marshaller)9 Consumes (javax.ws.rs.Consumes)6 Produces (javax.ws.rs.Produces)6 Variant (javax.ws.rs.core.Variant)6 Path (javax.ws.rs.Path)5 KieContainerInstance (org.kie.server.services.api.KieContainerInstance)4 ArrayList (java.util.ArrayList)3 POST (javax.ws.rs.POST)3 Wrapped (org.kie.server.api.model.Wrapped)3 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)3 MarshallerHelper (org.kie.server.services.impl.marshal.MarshallerHelper)3 HashSet (java.util.HashSet)2 GET (javax.ws.rs.GET)2 BatchExecutionCommand (org.kie.api.command.BatchExecutionCommand)2 ExecutionResults (org.kie.api.runtime.ExecutionResults)2 RuleServicesClient (org.kie.server.client.RuleServicesClient)2 RESTUtils.getVariant (org.redhat.gss.extension.RESTUtils.getVariant)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ApiOperation (io.swagger.annotations.ApiOperation)1