Search in sources :

Example 1 with MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY

use of org.folio.invoices.utils.ErrorCodes.MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY in project mod-invoice by folio-org.

the class InvoicesImpl method processDocumentCreation.

private void processDocumentCreation(String id, String lang, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    DocumentHelper documentHelper = new DocumentHelper(okapiHeaders, vertxContext, lang);
    InvoiceDocument entity = new JsonObject(new String(requestBytesArray, StandardCharsets.UTF_8)).mapTo(InvoiceDocument.class);
    if (!entity.getDocumentMetadata().getInvoiceId().equals(id)) {
        asyncResultHandler.handle(succeededFuture(documentHelper.buildErrorResponse(new HttpException(422, MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY))));
    } else {
        documentHelper.createDocument(id, entity).thenAccept(document -> {
            logInfo("Successfully created document with id={}", document);
            asyncResultHandler.handle(succeededFuture(documentHelper.buildResponseWithLocation(String.format(DOCUMENTS_LOCATION_PREFIX, id, document.getDocumentMetadata().getId()), document)));
        }).exceptionally(t -> handleErrorResponse(asyncResultHandler, documentHelper, t));
    }
}
Also used : Future.succeededFuture(io.vertx.core.Future.succeededFuture) BufferedInputStream(java.io.BufferedInputStream) ArrayUtils(org.apache.commons.lang3.ArrayUtils) Context(io.vertx.core.Context) StringUtils(org.apache.commons.lang3.StringUtils) HttpException(org.folio.invoices.rest.exceptions.HttpException) STREAM_ABORT(org.folio.rest.RestVerticle.STREAM_ABORT) RequestContext(org.folio.rest.core.models.RequestContext) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) AsyncResult(io.vertx.core.AsyncResult) STREAM_COMPLETE(org.folio.rest.RestVerticle.STREAM_COMPLETE) Errors(org.folio.rest.jaxrs.model.Errors) DOCUMENT_IS_TOO_LARGE(org.folio.invoices.utils.ErrorCodes.DOCUMENT_IS_TOO_LARGE) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) InvoiceDocument(org.folio.rest.jaxrs.model.InvoiceDocument) IOException(java.io.IOException) Validate(org.folio.rest.annotations.Validate) StandardCharsets(java.nio.charset.StandardCharsets) ONE_MB(org.apache.commons.io.FileUtils.ONE_MB) Objects(java.util.Objects) IOUtils(org.apache.commons.io.IOUtils) Stream(org.folio.rest.annotations.Stream) MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY(org.folio.invoices.utils.ErrorCodes.MISMATCH_BETWEEN_ID_IN_PATH_AND_BODY) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) Handler(io.vertx.core.Handler) LogManager(org.apache.logging.log4j.LogManager) Collections(java.util.Collections) Invoice(org.folio.rest.jaxrs.model.Invoice) InputStream(java.io.InputStream) JsonObject(io.vertx.core.json.JsonObject) HttpException(org.folio.invoices.rest.exceptions.HttpException) InvoiceDocument(org.folio.rest.jaxrs.model.InvoiceDocument)

Aggregations

AsyncResult (io.vertx.core.AsyncResult)1 Context (io.vertx.core.Context)1 Future.succeededFuture (io.vertx.core.Future.succeededFuture)1 Handler (io.vertx.core.Handler)1 JsonObject (io.vertx.core.json.JsonObject)1 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Collections (java.util.Collections)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Response (javax.ws.rs.core.Response)1 ONE_MB (org.apache.commons.io.FileUtils.ONE_MB)1 IOUtils (org.apache.commons.io.IOUtils)1 ArrayUtils (org.apache.commons.lang3.ArrayUtils)1 StringUtils (org.apache.commons.lang3.StringUtils)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 HttpException (org.folio.invoices.rest.exceptions.HttpException)1