use of org.folio.rest.jaxrs.model.InvoiceCollection in project mod-invoice by folio-org.
the class InvoiceHelper method getInvoices.
/**
* Gets list of invoice
*
* @param limit Limit the number of elements returned in the response
* @param offset Skip over a number of elements by specifying an offset value for the query
* @param query A query expressed as a CQL string using valid searchable fields
* @return completable future with {@link InvoiceCollection} on success or an exception if processing fails
*/
public CompletableFuture<InvoiceCollection> getInvoices(int limit, int offset, String query) {
CompletableFuture<InvoiceCollection> future = new FolioVertxCompletableFuture<>(ctx);
RequestContext requestContext = new RequestContext(ctx, okapiHeaders);
try {
buildGetInvoicesQuery(query).thenCompose(getInvoicesQuery -> invoiceService.getInvoices(getInvoicesQuery, offset, limit, requestContext)).thenCompose(invoiceCollection -> invoiceService.updateInvoicesTotals(invoiceCollection, requestContext).thenAccept(v -> {
logger.info("Successfully retrieved invoices: {}", invoiceCollection);
future.complete(invoiceCollection);
})).exceptionally(t -> {
logger.error("Error getting invoices", t);
future.completeExceptionally(t);
return null;
});
} catch (Exception e) {
future.completeExceptionally(e);
}
return future;
}
use of org.folio.rest.jaxrs.model.InvoiceCollection in project mod-invoice by folio-org.
the class InvoicesApiTest method testGetInvoicingInvoices.
@Test
void testGetInvoicingInvoices() {
logger.info("=== Test Get Invoices by without query - get 200 by successful retrieval of invoices ===");
final InvoiceCollection resp = verifySuccessGet(INVOICE_PATH, InvoiceCollection.class, X_OKAPI_PROTECTED_READ_TENANT);
assertThat(resp.getTotalRecords(), is(3));
assertThat(getInvoiceSearches(), hasSize(1));
assertThat(getInvoiceLineSearches(), empty());
assertThat(getAcqUnitsSearches(), hasSize(1));
assertThat(getAcqMembershipsSearches(), hasSize(1));
verifyInvoiceUpdateCalls(0);
List<String> queryParams = getQueryParams(INVOICES);
assertThat(queryParams, hasSize(1));
assertThat(queryParams.get(0), Matchers.equalTo(getNoAcqUnitCQL(INVOICES)));
}
use of org.folio.rest.jaxrs.model.InvoiceCollection in project mod-invoice by folio-org.
the class InvoicesApiTest method testGetInvoicingInvoicesWithQueryParam.
@Test
void testGetInvoicingInvoicesWithQueryParam() {
logger.info("=== Test Get Invoices with query - get 200 by successful retrieval of invoices by query ===");
String sortBy = " sortBy folioInvoiceNo";
String queryValue = VENDOR_INVOICE_NUMBER_FIELD + "==" + EXISTING_VENDOR_INV_NO;
String endpointQuery = String.format("%s?query=%s%s", INVOICE_PATH, queryValue, sortBy);
final InvoiceCollection resp = verifySuccessGet(endpointQuery, InvoiceCollection.class, X_OKAPI_PROTECTED_READ_TENANT);
assertThat(resp.getTotalRecords(), is(1));
assertThat(getInvoiceSearches(), hasSize(1));
assertThat(getAcqUnitsSearches(), hasSize(1));
assertThat(getAcqMembershipsSearches(), hasSize(1));
assertThat(getInvoiceLineSearches(), empty());
verifyInvoiceUpdateCalls(0);
List<String> queryParams = getQueryParams(INVOICES);
assertThat(queryParams, hasSize(1));
String queryToStorage = queryParams.get(0);
assertThat(queryToStorage, containsString("(" + queryValue + ")"));
assertThat(queryToStorage, Matchers.not(containsString(ACQUISITIONS_UNIT_IDS + "=")));
assertThat(queryToStorage, containsString(getNoAcqUnitCQL(INVOICE)));
assertThat(queryToStorage, endsWith(sortBy));
}
use of org.folio.rest.jaxrs.model.InvoiceCollection in project mod-invoice by folio-org.
the class MockServer method handleGetInvoices.
private void handleGetInvoices(RoutingContext ctx) {
String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
addServerRqQuery(INVOICES, queryParam);
if (queryParam.contains(BAD_QUERY)) {
serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
} else if (queryParam.contains(ID_DOES_NOT_EXIST)) {
serverResponse(ctx, 404, APPLICATION_JSON, Response.Status.NOT_FOUND.getReasonPhrase());
} else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR)) {
serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
} else if (queryParam.startsWith(QUERY_PARAM_START_WITH)) {
Matcher lineIdMatcher = Pattern.compile(".*invoiceLines.id==(\\S+).*").matcher(queryParam);
final String lineId = lineIdMatcher.find() ? lineIdMatcher.group(1) : EMPTY;
List<Invoice> invoices;
InvoiceCollection invoiceCollection = new InvoiceCollection();
if (lineId.equals(SEARCH_INVOICE_BY_LINE_ID_NOT_FOUND)) {
invoiceCollection.setInvoices(new ArrayList<>());
invoiceCollection.setTotalRecords(invoiceCollection.getInvoices().size());
JsonObject invoicesJson = JsonObject.mapFrom(invoiceCollection);
addServerRqRsData(HttpMethod.GET, INVOICES, JsonObject.mapFrom(invoiceCollection));
serverResponse(ctx, 200, APPLICATION_JSON, invoicesJson.encode());
} else {
try {
invoices = new JsonObject(ApiTestBase.getMockData(MOCK_DATA_INVOICES)).mapTo(InvoiceCollection.class).getInvoices();
} catch (IOException e) {
invoices = new ArrayList<>();
}
Optional<List<Invoice>> invoiceOptional = getMockEntries(INVOICES, Invoice.class);
Invoice invoice0 = invoiceOptional.get().get(0);
invoices.set(0, invoice0);
invoiceCollection.setInvoices(invoices);
invoiceCollection.setTotalRecords(invoiceCollection.getInvoices().size());
JsonObject invoicesJson = JsonObject.mapFrom(invoiceCollection);
addServerRqRsData(HttpMethod.GET, INVOICES, JsonObject.mapFrom(invoiceCollection));
serverResponse(ctx, 200, APPLICATION_JSON, invoicesJson.encode());
}
} else if (queryParam.contains("id==")) {
List<Invoice> invoices;
InvoiceCollection invoiceCollection = new InvoiceCollection();
try {
invoices = new JsonObject(ApiTestBase.getMockData(MOCK_DATA_INVOICES)).mapTo(InvoiceCollection.class).getInvoices();
} catch (IOException e) {
invoices = new ArrayList<>();
}
invoiceCollection.setInvoices(invoices);
invoiceCollection.setTotalRecords(invoiceCollection.getInvoices().size());
JsonObject invoicesJson = JsonObject.mapFrom(invoiceCollection);
addServerRqRsData(HttpMethod.GET, INVOICES, JsonObject.mapFrom(invoiceCollection));
serverResponse(ctx, 200, APPLICATION_JSON, invoicesJson.encode());
} else {
JsonObject invoice = new JsonObject();
Matcher matcher = Pattern.compile(".*vendorInvoiceNo==(\\S[^)]+).*").matcher(queryParam);
final String vendorNumber = matcher.find() ? matcher.group(1) : EMPTY;
switch(vendorNumber) {
case EXISTING_VENDOR_INV_NO:
invoice.put(TOTAL_RECORDS, 1);
break;
case EMPTY:
invoice.put(TOTAL_RECORDS, 3);
break;
default:
invoice.put(TOTAL_RECORDS, 0);
}
addServerRqRsData(HttpMethod.GET, INVOICES, invoice);
serverResponse(ctx, 200, APPLICATION_JSON, invoice.encodePrettily());
}
}
use of org.folio.rest.jaxrs.model.InvoiceCollection in project mod-invoice by folio-org.
the class InvoiceRetrieveServiceTest method positiveGetInvoicesByChunksTest.
@Test
public void positiveGetInvoicesByChunksTest() throws IOException, ExecutionException, InterruptedException {
InvoiceService invoiceService = new BaseInvoiceService(new RestClient(), invoiceLineService, orderService);
InvoiceRetrieveService service = new InvoiceRetrieveService(invoiceService);
JsonObject vouchersList = new JsonObject(getMockData(VOUCHERS_LIST_PATH));
List<Voucher> vouchers = vouchersList.getJsonArray("vouchers").stream().map(obj -> ((JsonObject) obj).mapTo(Voucher.class)).collect(toList());
vouchers.remove(1);
CompletableFuture<List<InvoiceCollection>> future = service.getInvoicesByChunks(vouchers, new RequestContext(context, okapiHeaders));
List<InvoiceCollection> lineCollections = future.get();
Assertions.assertEquals(3, lineCollections.get(0).getInvoices().size());
}
Aggregations