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));
}
}
Aggregations