use of org.folio.rest.jaxrs.model.InvoiceDocument 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));
}
}
use of org.folio.rest.jaxrs.model.InvoiceDocument in project mod-invoice by folio-org.
the class DocumentsApiTest method testGetDocument.
@Test
public void testGetDocument() {
logger.info("=== Test get document by id ===");
String endpoint = String.format(DOCUMENT_ENDPOINT_WITH_ID, DOCUMENT_ID);
final InvoiceDocument retrievedDocument = verifySuccessGet(endpoint, InvoiceDocument.class);
assertThat(MockServer.serverRqRs.get(INVOICE_DOCUMENTS, HttpMethod.GET), hasSize(1));
assertEquals(DOCUMENT_ID, retrievedDocument.getDocumentMetadata().getId());
}
use of org.folio.rest.jaxrs.model.InvoiceDocument in project mod-invoice by folio-org.
the class DocumentsApiTest method testPostAndDocumentOversize.
@Test
void testPostAndDocumentOversize(VertxTestContext context) throws Throwable {
logger.info("=== Test create document - oversize ===");
InvoiceDocument document = new JsonObject(getMockData(INVOICE_DOCUMENT_SAMPLE_PATH)).mapTo(InvoiceDocument.class);
String stringData = StringUtils.repeat("*", size);
document.getContents().setData(stringData);
HttpRequest<Buffer> request = WebClient.wrap(Vertx.vertx().createHttpClient()).requestAbs(HttpMethod.POST, RestAssured.baseURI + DOCUMENT_ENDPOINT);
prepareRequestHeaders(request);
context.assertComplete(request.sendBuffer(Buffer.buffer(JsonObject.mapFrom(document).encode()))).onComplete(event -> {
if (event.succeeded()) {
verifyErrorResponse(context, event.result());
} else {
processException(context, event.cause());
}
});
assertTrue(context.awaitCompletion(60, TimeUnit.SECONDS));
if (context.failed()) {
fail(context.causeOfFailure());
}
}
use of org.folio.rest.jaxrs.model.InvoiceDocument in project mod-invoice by folio-org.
the class MockServer method handleGetInvoiceDocumentById.
private void handleGetInvoiceDocumentById(RoutingContext ctx) {
logger.info("handleGetInvoiceDocumentById got: GET " + ctx.request().path());
String documentId = ctx.request().getParam("documentId");
logger.info("documentId: " + documentId);
if (ID_FOR_INTERNAL_SERVER_ERROR.equals(documentId)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else {
JsonObject document = getMockEntry(INVOICE_DOCUMENTS, documentId).orElseGet(getJsonObjectFromFile(INVOICE_DOCUMENTS_SAMPLE_PATH, documentId));
if (document == null) {
ctx.response().setStatusCode(404).end(documentId);
} else {
// validate content against schema
InvoiceDocument documentSchema = document.mapTo(InvoiceDocument.class);
documentSchema.getDocumentMetadata().setId(documentId);
document = JsonObject.mapFrom(documentSchema);
addServerRqRsData(HttpMethod.GET, INVOICE_DOCUMENTS, document);
serverResponse(ctx, 200, APPLICATION_JSON, document.encodePrettily());
}
}
}
use of org.folio.rest.jaxrs.model.InvoiceDocument in project mod-invoice by folio-org.
the class MockServer method handlePostInvoiceDocument.
private void handlePostInvoiceDocument(RoutingContext ctx) {
InvoiceDocument invoiceDocument = ctx.getBodyAsJson().mapTo(InvoiceDocument.class);
String id = UUID.randomUUID().toString();
invoiceDocument.getDocumentMetadata().setId(id);
JsonObject jsonDocument = JsonObject.mapFrom(invoiceDocument);
addServerRqRsData(HttpMethod.POST, INVOICE_DOCUMENTS, jsonDocument);
ctx.response().putHeader(HttpHeaders.LOCATION, ctx.request().path() + "/" + id);
serverResponse(ctx, 201, APPLICATION_JSON, jsonDocument.encodePrettily());
}
Aggregations