Search in sources :

Example 1 with KieServerRuntimeException

use of org.kie.server.services.api.KieServerRuntimeException in project droolsjbpm-integration by kiegroup.

the class DocumentServiceBase method deleteDocument.

public void deleteDocument(String documentId) {
    logger.debug("About to delete document with id {}", documentId);
    Document document = documentStorageService.getDocument(documentId);
    logger.debug("Document found {}", document != null);
    if (document == null) {
        throw new KieServerRuntimeException("No document found with id " + documentId);
    }
    documentStorageService.deleteDocument(document);
    logger.debug("Document {} deleted successfully", document);
}
Also used : KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) Document(org.jbpm.document.Document)

Example 2 with KieServerRuntimeException

use of org.kie.server.services.api.KieServerRuntimeException in project droolsjbpm-integration by kiegroup.

the class DocumentServiceBase method updateDocument.

public void updateDocument(String documentId, String documentPayload, String marshallingType) {
    logger.debug("About to unmarshal document payload '{}' with marshaling type {}", documentPayload, marshallingType);
    DocumentInstance documentInstance = marshallerHelper.unmarshal(documentPayload, marshallingType, DocumentInstance.class);
    logger.debug("Document created from payload {}", documentInstance);
    Document document = documentStorageService.getDocument(documentId);
    logger.debug("Document found {}", documentInstance != null);
    if (document == null) {
        throw new KieServerRuntimeException("No document found with id " + documentId);
    }
    documentStorageService.saveDocument(document, documentInstance.getContent());
    logger.debug("Document {} updated successfully", document);
}
Also used : KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) DocumentInstance(org.kie.server.api.model.instance.DocumentInstance) Document(org.jbpm.document.Document)

Example 3 with KieServerRuntimeException

use of org.kie.server.services.api.KieServerRuntimeException in project droolsjbpm-integration by kiegroup.

the class DocumentServiceBase method getDocument.

public DocumentInstance getDocument(String documentId) {
    logger.debug("About to load document with id {}", documentId);
    final Document document = documentStorageService.getDocument(documentId);
    logger.debug("Document loaded from repository {}", document);
    if (document == null) {
        throw new KieServerRuntimeException("No document found with id " + documentId);
    }
    return convertDocument(document, true);
}
Also used : KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) Document(org.jbpm.document.Document)

Example 4 with KieServerRuntimeException

use of org.kie.server.services.api.KieServerRuntimeException 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 5 with KieServerRuntimeException

use of org.kie.server.services.api.KieServerRuntimeException in project droolsjbpm-integration by kiegroup.

the class DocumentResource method deleteDocument.

@ApiOperation(value = "Deletes a specified document from KIE Server.", response = Void.class, code = 204)
@ApiResponses(value = { @ApiResponse(code = 500, message = "Unexpected error"), @ApiResponse(code = 404, message = "Document with given id not found") })
@DELETE
@Path(DOCUMENT_INSTANCE_DELETE_URI)
@Produces({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
public Response deleteDocument(@javax.ws.rs.core.Context HttpHeaders headers, @ApiParam(value = "document id of a document that should be deleted", required = true, example = "xxxx-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 {
        documentServiceBase.deleteDocument(documentId);
        // produce 204 NO_CONTENT response code
        return noContent(v, 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) WebApplicationException(javax.ws.rs.WebApplicationException) KieServerRuntimeException(org.kie.server.services.api.KieServerRuntimeException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

KieServerRuntimeException (org.kie.server.services.api.KieServerRuntimeException)6 ApiOperation (io.swagger.annotations.ApiOperation)3 ApiResponses (io.swagger.annotations.ApiResponses)3 ResponseHeader (io.swagger.annotations.ResponseHeader)3 IOException (java.io.IOException)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 Variant (javax.ws.rs.core.Variant)3 Document (org.jbpm.document.Document)3 Header (org.kie.server.remote.rest.common.Header)3 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)3 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)3 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)3 DocumentInstance (org.kie.server.api.model.instance.DocumentInstance)2 Consumes (javax.ws.rs.Consumes)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1