Search in sources :

Example 16 with DocumentInstance

use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.

the class DocumentResource method getDocument.

@ApiOperation(value = "Returns information about a specified document.")
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Document with given id not found"), @ApiResponse(code = 200, response = DocumentInstance.class, message = "Successful response", examples = @Example(value = { @ExampleProperty(mediaType = JSON, value = GET_DOCUMENT_RESPONSE_JSON) })) })
@GET
@Path(DOCUMENT_INSTANCE_GET_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response getDocument(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "document id of a document that should be retruned", required = true, example = "xxx-yyy-zzz") @PathParam("documentId") String documentId) {
    Variant v = getVariant(headers);
    // no container id available so only used to transfer conversation id if given by client
    Header conversationIdHeader = buildConversationIdHeader("", context, headers);
    try {
        DocumentInstance document = documentServiceBase.getDocument(documentId);
        return createCorrectVariant(document, headers, Response.Status.OK, conversationIdHeader);
    } catch (KieServerRuntimeException e) {
        return notFound("Document with id " + documentId + " not found", v, conversationIdHeader);
    } catch (Exception e) {
        logger.error("Unexpected error during processing {}", e.getMessage(), e);
        return internalServerError(errorMessage(e), v, conversationIdHeader);
    }
}
Also used : RestUtils.getVariant(org.kie.server.remote.rest.common.util.RestUtils.getVariant) RestUtils.createCorrectVariant(org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant) Variant(javax.ws.rs.core.Variant) KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) Header(org.kie.server.remote.rest.common.Header) RestUtils.buildConversationIdHeader(org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader) ResponseHeader(io.swagger.annotations.ResponseHeader) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) WebApplicationException(javax.ws.rs.WebApplicationException) KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 17 with DocumentInstance

use of org.kie.server.api.model.instance.DocumentInstance in project droolsjbpm-integration by kiegroup.

the class DocumentServicesClientImpl method getDocument.

@Override
public DocumentInstance getDocument(String identifier) {
    DocumentInstance result = null;
    if (config.isRest()) {
        Map<String, Object> valuesMap = new HashMap<String, Object>();
        valuesMap.put(DOCUMENT_ID, identifier);
        result = makeHttpGetRequestAndCreateCustomResponse(build(loadBalancer.getUrl(), DOCUMENT_URI + "/" + DOCUMENT_INSTANCE_GET_URI, valuesMap), DocumentInstance.class);
    } else {
        CommandScript script = new CommandScript(Collections.singletonList((KieServerCommand) new DescriptorCommand("DocumentService", "getDocument", new Object[] { identifier })));
        ServiceResponse<DocumentInstance> response = (ServiceResponse<DocumentInstance>) executeJmsCommand(script, DescriptorCommand.class.getName(), "BPM").getResponses().get(0);
        throwExceptionOnFailure(response);
        if (shouldReturnWithNullResponse(response)) {
            return null;
        }
        result = response.getResult();
    }
    return result;
}
Also used : 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) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) CommandScript(org.kie.server.api.commands.CommandScript)

Aggregations

DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)17 Test (org.junit.Test)9 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Document (org.jbpm.document.Document)4 KieServerRuntimeException (org.kie.server.services.api.KieServerRuntimeException)3 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 ResponseHeader (io.swagger.annotations.ResponseHeader)2 IOException (java.io.IOException)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 WebApplicationException (javax.ws.rs.WebApplicationException)2 Variant (javax.ws.rs.core.Variant)2 KieServicesException (org.kie.server.api.exception.KieServicesException)2 ServiceResponse (org.kie.server.api.model.ServiceResponse)2 DocumentInstanceList (org.kie.server.api.model.instance.DocumentInstanceList)2 Header (org.kie.server.remote.rest.common.Header)2 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)2