Search in sources :

Example 6 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.

the class MarshallerHelper method marshal.

public String marshal(String containerId, String marshallingFormat, Object entity, ContainerLocator locator) {
    MarshallingFormat format = getFormat(marshallingFormat);
    if (format == null) {
        throw new IllegalArgumentException("Unknown marshalling format " + marshallingFormat);
    }
    KieContainerInstance containerInstance = registry.getContainer(containerId, locator);
    if (containerInstance == null) {
        throw new IllegalArgumentException("No container found for id " + containerId + " .");
    }
    Marshaller marshaller = containerInstance.getMarshaller(format);
    if (marshaller == null) {
        throw new IllegalArgumentException("No marshaller found for format " + format);
    }
    return marshaller.marshall(entity, MarshallingFormat.buildParameters(marshallingFormat));
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) KieContainerInstance(org.kie.server.services.api.KieContainerInstance)

Example 7 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.

the class ControllerUtils method unmarshal.

public static <T> T unmarshal(String data, String marshallingFormat, Class<T> unmarshalType) {
    if (data == null || data.isEmpty()) {
        return null;
    }
    MarshallingFormat format = getFormat(marshallingFormat);
    Marshaller marshaller = null;
    switch(format) {
        case JAXB:
            {
                marshaller = jaxbMarshaller;
                break;
            }
        case JSON:
            {
                marshaller = jsonMarshaller;
                break;
            }
        default:
            {
                marshaller = jsonMarshaller;
                break;
            }
    }
    Object instance = marshaller.unmarshall(data, unmarshalType);
    if (instance instanceof Wrapped) {
        return (T) ((Wrapped) instance).unwrap();
    }
    return (T) instance;
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) Wrapped(org.kie.server.api.model.Wrapped)

Example 8 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project droolsjbpm-integration by kiegroup.

the class CloudEventReader method readEvent.

@Override
public <T> T readEvent(byte[] value, Class<T> valueType) throws IOException {
    JsonNode node = mapper.readTree(value);
    MarshallingFormat contentType = MarshallingFormat.JSON;
    if (node.has("datacontenttype")) {
        contentType = MarshallingFormat.fromType(node.get("datacontenttype").asText());
    }
    if (node.has("data")) {
        Marshaller marshaller = marshallers.computeIfAbsent(contentType, c -> MarshallerFactory.getMarshaller(c, cl));
        return marshaller.unmarshall(node.get("data").toString(), valueType);
    }
    throw new IOException("Missing data field in cloud event " + new String(value));
}
Also used : Marshaller(org.kie.server.api.marshalling.Marshaller) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException)

Example 9 with MarshallingFormat

use of org.kie.server.api.marshalling.MarshallingFormat in project businessautomation-cop by redhat-cop.

the class ReopenProcessResource method queryCases.

@POST
@Path("/reopen/{instanceId}")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response queryCases(@Context HttpHeaders headers, @PathParam("instanceId") Long instanceId, List<String> nodes) {
    logger.info("Reopening process instance with id {} and nodes {}", instanceId, nodes);
    Variant v = getVariant(headers);
    String contentType = getContentType(headers);
    MarshallingFormat format = MarshallingFormat.fromType(contentType);
    if (format == null) {
        format = MarshallingFormat.valueOf(contentType);
    }
    try {
        Long newPid = reopenService.reopenProcess(instanceId, nodes);
        return createResponse(newPid, v, Response.Status.OK);
    } catch (Exception e) {
        // in case marshalling failed return the call container response to
        // keep backward compatibility
        e.printStackTrace();
        String response = "Execution failed with error : " + e.getMessage();
        logger.error("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) MarshallingFormat(org.kie.server.api.marshalling.MarshallingFormat) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 10 with MarshallingFormat

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

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