Search in sources :

Example 1 with OKAPI_HEADER_TENANT

use of org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT in project mod-orders by folio-org.

the class MockServer method handleGetContributorNameTypes.

private void handleGetContributorNameTypes(RoutingContext ctx) {
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam("query"));
    String tenantId = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    if (NON_EXIST_CONTRIBUTOR_NAME_TYPE_TENANT.equals(tenantId)) {
        String body = buildEmptyCollection(CONTRIBUTOR_NAME_TYPES);
        serverResponse(ctx, HttpStatus.HTTP_OK.toInt(), APPLICATION_JSON, body);
        addServerRqRsData(HttpMethod.GET, CONTRIBUTOR_NAME_TYPES, new JsonObject(body));
    } else if (queryParam.startsWith("id==")) {
        List<String> contributorNameTypeIds = extractIdsFromQuery(queryParam);
        JsonObject contributorNameTypeCollection = getMockAsJson(CONTRIBUTOR_NAME_TYPES_PATH);
        List<JsonObject> contributorNameTypes = contributorNameTypeCollection.getJsonArray(CONTRIBUTOR_NAME_TYPES).stream().map(o -> ((JsonObject) o)).filter(contributorNameType -> contributorNameTypeIds.contains(contributorNameType.getString(ID))).collect(Collectors.toList());
        contributorNameTypeCollection.put(CONTRIBUTOR_NAME_TYPES, contributorNameTypes);
        serverResponse(ctx, HttpStatus.HTTP_OK.toInt(), APPLICATION_JSON, contributorNameTypeCollection.encodePrettily());
        addServerRqRsData(HttpMethod.GET, CONTRIBUTOR_NAME_TYPES, contributorNameTypeCollection);
    } else {
        serverResponse(ctx, HttpStatus.HTTP_INTERNAL_SERVER_ERROR.toInt(), TEXT_PLAIN, "Illegal query");
    }
}
Also used : Arrays(java.util.Arrays) TestConstants(org.folio.TestConstants) LISTED_PRINT_MONOGRAPH_PATH(org.folio.rest.impl.PurchaseOrdersApiTest.LISTED_PRINT_MONOGRAPH_PATH) HttpServer(io.vertx.core.http.HttpServer) Header(io.restassured.http.Header) HashBasedTable(com.google.common.collect.HashBasedTable) FUND_ID(org.folio.orders.utils.HelperUtils.FUND_ID) StringUtils(org.apache.commons.lang3.StringUtils) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) REQUESTS(org.folio.service.inventory.InventoryManager.REQUESTS) Matcher(java.util.regex.Matcher) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) JsonObject(io.vertx.core.json.JsonObject) PURCHASE_ORDER_ID(org.folio.rest.impl.PurchaseOrdersApiTest.PURCHASE_ORDER_ID) Budget(org.folio.rest.acq.model.finance.Budget) REASON_FOR_CLOSURE(org.folio.rest.impl.crud.CrudTestEntities.REASON_FOR_CLOSURE) Ledger(org.folio.rest.acq.model.finance.Ledger) Fund(org.folio.rest.acq.model.finance.Fund) Title(org.folio.rest.acq.model.Title) ORGANIZATION_NOT_VENDOR(org.folio.rest.impl.PurchaseOrdersApiTest.ORGANIZATION_NOT_VENDOR) TestUtils.encodePrettily(org.folio.TestUtils.encodePrettily) INACTIVE_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.INACTIVE_VENDOR_ID) Logger(org.apache.logging.log4j.Logger) Assertions.fail(org.assertj.core.api.Assertions.fail) BUDGET_IS_INACTIVE(org.folio.rest.core.exceptions.ErrorCodes.BUDGET_IS_INACTIVE) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) VENDOR_WITH_BAD_CONTENT(org.folio.rest.impl.PurchaseOrdersApiTest.VENDOR_WITH_BAD_CONTENT) ACQUISITIONS_UNIT_ID(org.folio.service.ProtectionService.ACQUISITIONS_UNIT_ID) Transaction(org.folio.rest.acq.model.finance.Transaction) Supplier(java.util.function.Supplier) BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) ArrayList(java.util.ArrayList) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) NONEXISTING_PO_NUMBER(org.folio.rest.impl.PoNumberApiTest.NONEXISTING_PO_NUMBER) Lists(com.google.common.collect.Lists) ExchangeRate(org.folio.rest.acq.model.finance.ExchangeRate) ITEMS_NOT_FOUND(org.folio.rest.impl.PurchaseOrdersApiTest.ITEMS_NOT_FOUND) SequenceNumbers(org.folio.rest.acq.model.SequenceNumbers) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) ONLY_NEW_HOLDING_EXIST_ID(org.folio.service.inventory.InventoryManagerTest.ONLY_NEW_HOLDING_EXIST_ID) INTERNAL_SERVER_ERROR(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR) EXISTING_PO_NUMBER(org.folio.rest.impl.PoNumberApiTest.EXISTING_PO_NUMBER) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) BUDGET_NOT_FOUND_FOR_TRANSACTION(org.folio.rest.core.exceptions.ErrorCodes.BUDGET_NOT_FOUND_FOR_TRANSACTION) COMPOSITE_PO_LINES(org.folio.orders.utils.HelperUtils.COMPOSITE_PO_LINES) ExecutionException(java.util.concurrent.ExecutionException) JsonArray(io.vertx.core.json.JsonArray) DAYS(java.time.temporal.ChronoUnit.DAYS) IsbnUtil(org.folio.isbn.IsbnUtil) Piece(org.folio.rest.acq.model.Piece) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) AbstractHelper(org.folio.helper.AbstractHelper) NoSuchFileException(java.nio.file.NoSuchFileException) FUND_CANNOT_BE_PAID(org.folio.rest.core.exceptions.ErrorCodes.FUND_CANNOT_BE_PAID) Date(java.util.Date) DEFAULT_POLINE_LIMIT(org.folio.orders.utils.HelperUtils.DEFAULT_POLINE_LIMIT) Router(io.vertx.ext.web.Router) TimeoutException(java.util.concurrent.TimeoutException) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) SequenceNumber(org.folio.rest.acq.model.SequenceNumber) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) NEW_LOCATION_ID(org.folio.service.inventory.InventoryManagerTest.NEW_LOCATION_ID) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) HOLDING_INSTANCE_ID_2_HOLDING(org.folio.service.inventory.InventoryManagerTest.HOLDING_INSTANCE_ID_2_HOLDING) OLD_LOCATION_ID(org.folio.service.inventory.InventoryManagerTest.OLD_LOCATION_ID) LEDGER_NOT_FOUND_FOR_TRANSACTION(org.folio.rest.core.exceptions.ErrorCodes.LEDGER_NOT_FOUND_FOR_TRANSACTION) HttpHeaders(io.vertx.core.http.HttpHeaders) UUID(java.util.UUID) Instant(java.time.Instant) Tag(org.folio.rest.acq.model.tag.Tag) Collectors(java.util.stream.Collectors) FUND_ENCUMBRANCE_ERROR(org.folio.rest.impl.PurchaseOrdersApiTest.FUND_ENCUMBRANCE_ERROR) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) ACTIVE_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.ACTIVE_VENDOR_ID) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) NON_EXIST_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.NON_EXIST_VENDOR_ID) PieceCollection(org.folio.rest.acq.model.PieceCollection) MOD_VENDOR_INTERNAL_ERROR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.MOD_VENDOR_INTERNAL_ERROR_ID) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) TestUtils.getMockData(org.folio.TestUtils.getMockData) LedgerCollection(org.folio.rest.acq.model.finance.LedgerCollection) ITEM_PURCHASE_ORDER_LINE_IDENTIFIER(org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER) OrderTransactionSummary(org.folio.rest.acq.model.finance.OrderTransactionSummary) TestUtils.getTitle(org.folio.TestUtils.getTitle) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) ITEMS(org.folio.service.inventory.InventoryManager.ITEMS) Iterator(java.util.Iterator) PREFIX(org.folio.rest.impl.crud.CrudTestEntities.PREFIX) org.folio.rest.jaxrs.model(org.folio.rest.jaxrs.model) TimeUnit(java.util.concurrent.TimeUnit) Error(org.folio.rest.jaxrs.model.Error) SUFFIX(org.folio.rest.impl.crud.CrudTestEntities.SUFFIX) Collectors.toList(java.util.stream.Collectors.toList) ID_FOR_PRINT_MONOGRAPH_ORDER(org.folio.rest.impl.PurchaseOrdersApiTest.ID_FOR_PRINT_MONOGRAPH_ORDER) HttpMethod(io.vertx.core.http.HttpMethod) HelperUtils.calculateEstimatedPrice(org.folio.orders.utils.HelperUtils.calculateEstimatedPrice) HttpStatus(org.folio.HttpStatus) RECEIVING_HISTORY_PURCHASE_ORDER_ID(org.folio.rest.impl.ReceivingHistoryApiTest.RECEIVING_HISTORY_PURCHASE_ORDER_ID) FundCollection(org.folio.rest.acq.model.finance.FundCollection) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) TitleCollection(org.folio.rest.acq.model.TitleCollection) Collections(java.util.Collections) ResourcePathResolver(org.folio.orders.utils.ResourcePathResolver) ORDER_DELETE_ERROR_TENANT(org.folio.rest.impl.PurchaseOrdersApiTest.ORDER_DELETE_ERROR_TENANT) NON_EXISTED_NEW_HOLDING_ID(org.folio.service.inventory.InventoryManagerTest.NON_EXISTED_NEW_HOLDING_ID) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 2 with OKAPI_HEADER_TENANT

use of org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT in project mod-orders by folio-org.

the class MockServer method handleGetPoLines.

private void handleGetPoLines(RoutingContext ctx, String type) {
    logger.info("handleGetPoLines got: {}?{}", ctx.request().path(), ctx.request().query());
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam("query"));
    addServerRqQuery(type, queryParam);
    if (queryParam.contains(BAD_QUERY)) {
        serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
    } else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR) || queryParam.contains(PO_ID_GET_LINES_INTERNAL_SERVER_ERROR)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        String poId = EMPTY;
        String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
        List<String> polIds = Collections.emptyList();
        if (queryParam.contains(PURCHASE_ORDER_ID)) {
            Matcher matcher = Pattern.compile(".*" + PURCHASE_ORDER_ID + "==(\\S[^)]+).*").matcher(queryParam);
            poId = matcher.find() ? matcher.group(1) : EMPTY;
        } else if (queryParam.startsWith("id==")) {
            polIds = extractIdsFromQuery(queryParam);
        }
        List<JsonObject> postedPoLines = getRqRsEntries(HttpMethod.SEARCH, type);
        try {
            PoLineCollection poLineCollection = new PoLineCollection();
            if (postedPoLines.isEmpty()) {
                if (poId.equals(ORDER_ID_WITH_PO_LINES) || !polIds.isEmpty()) {
                    poLineCollection = new JsonObject(getMockData(POLINES_COLLECTION)).mapTo(PoLineCollection.class);
                    // Filter PO Lines either by PO id or by expected line ids
                    Iterator<PoLine> iterator = poLineCollection.getPoLines().iterator();
                    while (iterator.hasNext()) {
                        PoLine poLine = iterator.next();
                        if (polIds.isEmpty() ? !poId.equals(poLine.getPurchaseOrderId()) : !polIds.contains(poLine.getId())) {
                            iterator.remove();
                        }
                    }
                    poLineCollection.setTotalRecords(poLineCollection.getPoLines().size());
                } else {
                    String filePath;
                    if (ID_FOR_PRINT_MONOGRAPH_ORDER.equals(poId)) {
                        filePath = LISTED_PRINT_MONOGRAPH_PATH;
                    } else {
                        filePath = String.format("%s%s.json", COMP_ORDER_MOCK_DATA_PATH, poId);
                    }
                    JsonObject compPO = new JsonObject(getMockData(filePath));
                    // Build PoLineCollection to make sure content is valid
                    poLineCollection = buildPoLineCollection(tenant, compPO.getJsonArray(COMPOSITE_PO_LINES), poId);
                }
            } else {
                // Attempt to find POLine in mock server memory
                poLineCollection.getPoLines().addAll(postedPoLines.stream().map(jsonObj -> jsonObj.mapTo(PoLine.class)).collect(Collectors.toList()));
            }
            poLineCollection.setTotalRecords(poLineCollection.getPoLines().size());
            // Update calculated data
            updatePoLineCalculatedData(poLineCollection);
            JsonObject po_lines = JsonObject.mapFrom(poLineCollection);
            logger.info(po_lines.encodePrettily());
            addServerRqRsData(HttpMethod.GET, type, po_lines);
            serverResponse(ctx, 200, APPLICATION_JSON, po_lines.encode());
        } catch (NoSuchFileException e) {
            PoLineCollection poLineCollection = new PoLineCollection();
            // Attempt to find POLine in mock server memory
            if (postedPoLines != null) {
                String finalPoId = poId;
                poLineCollection.getPoLines().addAll(postedPoLines.stream().map(json -> json.mapTo(PoLine.class)).filter(line -> finalPoId.equals(line.getPurchaseOrderId())).collect(Collectors.toList()));
            }
            poLineCollection.setTotalRecords(poLineCollection.getPoLines().size());
            JsonObject entries = JsonObject.mapFrom(poLineCollection);
            addServerRqRsData(HttpMethod.GET, type, entries);
            serverResponse(ctx, 200, APPLICATION_JSON, entries.encodePrettily());
        } catch (IOException e) {
            PoLineCollection poLineCollection = new PoLineCollection();
            poLineCollection.setTotalRecords(0);
            JsonObject entries = JsonObject.mapFrom(poLineCollection);
            addServerRqRsData(HttpMethod.GET, type, entries);
            serverResponse(ctx, 200, APPLICATION_JSON, JsonObject.mapFrom(poLineCollection).encodePrettily());
        }
    }
}
Also used : Arrays(java.util.Arrays) TestConstants(org.folio.TestConstants) LISTED_PRINT_MONOGRAPH_PATH(org.folio.rest.impl.PurchaseOrdersApiTest.LISTED_PRINT_MONOGRAPH_PATH) HttpServer(io.vertx.core.http.HttpServer) Header(io.restassured.http.Header) HashBasedTable(com.google.common.collect.HashBasedTable) FUND_ID(org.folio.orders.utils.HelperUtils.FUND_ID) StringUtils(org.apache.commons.lang3.StringUtils) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) REQUESTS(org.folio.service.inventory.InventoryManager.REQUESTS) Matcher(java.util.regex.Matcher) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) JsonObject(io.vertx.core.json.JsonObject) PURCHASE_ORDER_ID(org.folio.rest.impl.PurchaseOrdersApiTest.PURCHASE_ORDER_ID) Budget(org.folio.rest.acq.model.finance.Budget) REASON_FOR_CLOSURE(org.folio.rest.impl.crud.CrudTestEntities.REASON_FOR_CLOSURE) Ledger(org.folio.rest.acq.model.finance.Ledger) Fund(org.folio.rest.acq.model.finance.Fund) Title(org.folio.rest.acq.model.Title) ORGANIZATION_NOT_VENDOR(org.folio.rest.impl.PurchaseOrdersApiTest.ORGANIZATION_NOT_VENDOR) TestUtils.encodePrettily(org.folio.TestUtils.encodePrettily) INACTIVE_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.INACTIVE_VENDOR_ID) Logger(org.apache.logging.log4j.Logger) Assertions.fail(org.assertj.core.api.Assertions.fail) BUDGET_IS_INACTIVE(org.folio.rest.core.exceptions.ErrorCodes.BUDGET_IS_INACTIVE) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) VENDOR_WITH_BAD_CONTENT(org.folio.rest.impl.PurchaseOrdersApiTest.VENDOR_WITH_BAD_CONTENT) ACQUISITIONS_UNIT_ID(org.folio.service.ProtectionService.ACQUISITIONS_UNIT_ID) Transaction(org.folio.rest.acq.model.finance.Transaction) Supplier(java.util.function.Supplier) BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) ArrayList(java.util.ArrayList) StringUtils.isNotEmpty(org.apache.commons.lang3.StringUtils.isNotEmpty) NONEXISTING_PO_NUMBER(org.folio.rest.impl.PoNumberApiTest.NONEXISTING_PO_NUMBER) Lists(com.google.common.collect.Lists) ExchangeRate(org.folio.rest.acq.model.finance.ExchangeRate) ITEMS_NOT_FOUND(org.folio.rest.impl.PurchaseOrdersApiTest.ITEMS_NOT_FOUND) SequenceNumbers(org.folio.rest.acq.model.SequenceNumbers) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) ONLY_NEW_HOLDING_EXIST_ID(org.folio.service.inventory.InventoryManagerTest.ONLY_NEW_HOLDING_EXIST_ID) INTERNAL_SERVER_ERROR(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR) EXISTING_PO_NUMBER(org.folio.rest.impl.PoNumberApiTest.EXISTING_PO_NUMBER) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) BUDGET_NOT_FOUND_FOR_TRANSACTION(org.folio.rest.core.exceptions.ErrorCodes.BUDGET_NOT_FOUND_FOR_TRANSACTION) COMPOSITE_PO_LINES(org.folio.orders.utils.HelperUtils.COMPOSITE_PO_LINES) ExecutionException(java.util.concurrent.ExecutionException) JsonArray(io.vertx.core.json.JsonArray) DAYS(java.time.temporal.ChronoUnit.DAYS) IsbnUtil(org.folio.isbn.IsbnUtil) Piece(org.folio.rest.acq.model.Piece) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) TestUtils.getMockAsJson(org.folio.TestUtils.getMockAsJson) AbstractHelper(org.folio.helper.AbstractHelper) NoSuchFileException(java.nio.file.NoSuchFileException) FUND_CANNOT_BE_PAID(org.folio.rest.core.exceptions.ErrorCodes.FUND_CANNOT_BE_PAID) Date(java.util.Date) DEFAULT_POLINE_LIMIT(org.folio.orders.utils.HelperUtils.DEFAULT_POLINE_LIMIT) Router(io.vertx.ext.web.Router) TimeoutException(java.util.concurrent.TimeoutException) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) SequenceNumber(org.folio.rest.acq.model.SequenceNumber) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.OrderInvoiceRelationshipCollection) NEW_LOCATION_ID(org.folio.service.inventory.InventoryManagerTest.NEW_LOCATION_ID) InvoiceLineCollection(org.folio.rest.acq.model.invoice.InvoiceLineCollection) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) HOLDING_INSTANCE_ID_2_HOLDING(org.folio.service.inventory.InventoryManagerTest.HOLDING_INSTANCE_ID_2_HOLDING) OLD_LOCATION_ID(org.folio.service.inventory.InventoryManagerTest.OLD_LOCATION_ID) LEDGER_NOT_FOUND_FOR_TRANSACTION(org.folio.rest.core.exceptions.ErrorCodes.LEDGER_NOT_FOUND_FOR_TRANSACTION) HttpHeaders(io.vertx.core.http.HttpHeaders) UUID(java.util.UUID) Instant(java.time.Instant) Tag(org.folio.rest.acq.model.tag.Tag) Collectors(java.util.stream.Collectors) FUND_ENCUMBRANCE_ERROR(org.folio.rest.impl.PurchaseOrdersApiTest.FUND_ENCUMBRANCE_ERROR) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) ACTIVE_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.ACTIVE_VENDOR_ID) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) NON_EXIST_VENDOR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.NON_EXIST_VENDOR_ID) PieceCollection(org.folio.rest.acq.model.PieceCollection) MOD_VENDOR_INTERNAL_ERROR_ID(org.folio.rest.impl.PurchaseOrdersApiTest.MOD_VENDOR_INTERNAL_ERROR_ID) HttpException(org.folio.rest.core.exceptions.HttpException) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) TestUtils.getMockData(org.folio.TestUtils.getMockData) LedgerCollection(org.folio.rest.acq.model.finance.LedgerCollection) ITEM_PURCHASE_ORDER_LINE_IDENTIFIER(org.folio.service.inventory.InventoryManager.ITEM_PURCHASE_ORDER_LINE_IDENTIFIER) OrderTransactionSummary(org.folio.rest.acq.model.finance.OrderTransactionSummary) TestUtils.getTitle(org.folio.TestUtils.getTitle) Encumbrance(org.folio.rest.acq.model.finance.Encumbrance) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) ITEMS(org.folio.service.inventory.InventoryManager.ITEMS) Iterator(java.util.Iterator) PREFIX(org.folio.rest.impl.crud.CrudTestEntities.PREFIX) org.folio.rest.jaxrs.model(org.folio.rest.jaxrs.model) TimeUnit(java.util.concurrent.TimeUnit) Error(org.folio.rest.jaxrs.model.Error) SUFFIX(org.folio.rest.impl.crud.CrudTestEntities.SUFFIX) Collectors.toList(java.util.stream.Collectors.toList) ID_FOR_PRINT_MONOGRAPH_ORDER(org.folio.rest.impl.PurchaseOrdersApiTest.ID_FOR_PRINT_MONOGRAPH_ORDER) HttpMethod(io.vertx.core.http.HttpMethod) HelperUtils.calculateEstimatedPrice(org.folio.orders.utils.HelperUtils.calculateEstimatedPrice) HttpStatus(org.folio.HttpStatus) RECEIVING_HISTORY_PURCHASE_ORDER_ID(org.folio.rest.impl.ReceivingHistoryApiTest.RECEIVING_HISTORY_PURCHASE_ORDER_ID) FundCollection(org.folio.rest.acq.model.finance.FundCollection) InvoiceLine(org.folio.rest.acq.model.invoice.InvoiceLine) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) TitleCollection(org.folio.rest.acq.model.TitleCollection) Collections(java.util.Collections) ResourcePathResolver(org.folio.orders.utils.ResourcePathResolver) ORDER_DELETE_ERROR_TENANT(org.folio.rest.impl.PurchaseOrdersApiTest.ORDER_DELETE_ERROR_TENANT) NON_EXISTED_NEW_HOLDING_ID(org.folio.service.inventory.InventoryManagerTest.NON_EXISTED_NEW_HOLDING_ID) Matcher(java.util.regex.Matcher) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) Iterator(java.util.Iterator) NoSuchFileException(java.nio.file.NoSuchFileException) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) IOException(java.io.IOException)

Example 3 with OKAPI_HEADER_TENANT

use of org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT in project mod-invoice by folio-org.

the class MockServer method handlePost.

private <T> void handlePost(RoutingContext ctx, Class<T> tClass, String entryName, boolean generateId) {
    logger.info("got: " + ctx.getBodyAsString());
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    if (ERROR_TENANT.equals(tenant) || CREATE_VOUCHER_ERROR_TENANT.equals(tenant) || CREATE_VOUCHER_LINES_ERROR_TENANT.equals(tenant)) {
        serverResponse(ctx, 500, TEXT_PLAIN, INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        JsonObject body = ctx.getBodyAsJson();
        if (generateId) {
            String id = UUID.randomUUID().toString();
            body.put(AbstractHelper.ID, id);
        }
        T entry = body.mapTo(tClass);
        addServerRqRsData(HttpMethod.POST, entryName, body);
        serverResponse(ctx, 201, APPLICATION_JSON, JsonObject.mapFrom(entry).encodePrettily());
    }
}
Also used : ID_FOR_INTERNAL_SERVER_ERROR_PUT(org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR_PUT) FUND_ID_WITH_NOT_ACTIVE_BUDGET(org.folio.rest.impl.InvoicesApiTest.FUND_ID_WITH_NOT_ACTIVE_BUDGET) PROTECTED_READ_ONLY_TENANT(org.folio.rest.impl.ApiTestBase.PROTECTED_READ_ONLY_TENANT) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) ID_DOES_NOT_EXIST(org.folio.rest.impl.ApiTestBase.ID_DOES_NOT_EXIST) JsonObject(io.vertx.core.json.JsonObject)

Example 4 with OKAPI_HEADER_TENANT

use of org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT in project mod-invoice by folio-org.

the class MockServer method handleGetBudgetExpenseClass.

private void handleGetBudgetExpenseClass(RoutingContext ctx) {
    logger.info("handle BudgetExpenseClasses got: {}?{}", ctx.request().path(), ctx.request().query());
    String tenant = ctx.request().getHeader(OKAPI_HEADER_TENANT);
    String queryParam = StringUtils.trimToEmpty(ctx.request().getParam(QUERY));
    addServerRqQuery(BUDGET_EXPENSE_CLASSES, queryParam);
    if (queryParam.contains(BAD_QUERY)) {
        serverResponse(ctx, 400, APPLICATION_JSON, Response.Status.BAD_REQUEST.getReasonPhrase());
    } else if (queryParam.contains(ID_FOR_INTERNAL_SERVER_ERROR)) {
        serverResponse(ctx, 500, APPLICATION_JSON, Response.Status.INTERNAL_SERVER_ERROR.getReasonPhrase());
    } else {
        // By default return 0
        BudgetExpenseClassCollection budgetExpenseClasses = new BudgetExpenseClassCollection().withTotalRecords(0);
        if (queryParam.contains(EXPENSE_CLASS_ID)) {
            String expenseClassId = queryParam.split(EXPENSE_CLASS_ID + "==")[1];
            Supplier<BudgetExpenseClassCollection> getFromFile = () -> {
                try {
                    return new JsonObject(getMockData(BUDGET_EXPENSE_CLASS_COLLECTION)).mapTo(BudgetExpenseClassCollection.class);
                } catch (IOException e) {
                    return new BudgetExpenseClassCollection().withTotalRecords(0);
                }
            };
            budgetExpenseClasses.withBudgetExpenseClasses(getFromFile.get().getBudgetExpenseClasses().stream().filter(bec -> bec.getExpenseClassId().equals(expenseClassId)).collect(toList()));
            budgetExpenseClasses.withTotalRecords(budgetExpenseClasses.getBudgetExpenseClasses().size());
        }
        JsonObject budgetExpenseClassesJson = JsonObject.mapFrom(budgetExpenseClasses);
        logger.info(budgetExpenseClassesJson.encodePrettily());
        addServerRqRsData(HttpMethod.GET, BUDGET_EXPENSE_CLASSES, budgetExpenseClassesJson);
        serverResponse(ctx, 200, APPLICATION_JSON, budgetExpenseClassesJson.encodePrettily());
    }
}
Also used : BAD_QUERY(org.folio.rest.impl.InvoicesApiTest.BAD_QUERY) HttpServer(io.vertx.core.http.HttpServer) Header(io.restassured.http.Header) HashBasedTable(com.google.common.collect.HashBasedTable) StringUtils(org.apache.commons.lang3.StringUtils) TransactionCollection(org.folio.rest.acq.model.finance.TransactionCollection) CompositePurchaseOrder(org.folio.rest.acq.model.orders.CompositePurchaseOrder) VoucherLine(org.folio.rest.acq.model.VoucherLine) ExpenseClass(org.folio.rest.acq.model.finance.ExpenseClass) Voucher(org.folio.rest.jaxrs.model.Voucher) Matcher(java.util.regex.Matcher) ProfileSnapshotWrapper(org.folio.rest.jaxrs.model.ProfileSnapshotWrapper) VOUCHER_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.VOUCHER_NUMBER_VALUE) JsonObject(io.vertx.core.json.JsonObject) VOUCHERS_LIST_PATH(org.folio.rest.impl.VouchersApiTest.VOUCHERS_LIST_PATH) EXISTING_VENDOR_INV_NO(org.folio.rest.impl.InvoicesApiTest.EXISTING_VENDOR_INV_NO) ID_FOR_INTERNAL_SERVER_ERROR(org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR) Budget(org.folio.rest.acq.model.finance.Budget) INVOICE_LINES_MOCK_DATA_PATH(org.folio.rest.impl.InvoiceLinesApiTest.INVOICE_LINES_MOCK_DATA_PATH) BatchVoucherExport(org.folio.rest.jaxrs.model.BatchVoucherExport) INVOICE_CONFIG_MODULE_NAME(org.folio.rest.impl.InvoiceHelper.INVOICE_CONFIG_MODULE_NAME) CompositePoLine(org.folio.rest.acq.model.orders.CompositePoLine) Ledger(org.folio.rest.acq.model.finance.Ledger) Fund(org.folio.rest.acq.model.finance.Fund) Logger(org.apache.logging.log4j.Logger) OrderInvoiceRelationshipCollection(org.folio.rest.acq.model.orders.OrderInvoiceRelationshipCollection) ID_FOR_INTERNAL_SERVER_ERROR_PUT(org.folio.rest.impl.ApiTestBase.ID_FOR_INTERNAL_SERVER_ERROR_PUT) INVOICE_MOCK_DATA_PATH(org.folio.rest.impl.InvoicesApiTest.INVOICE_MOCK_DATA_PATH) ApiTestBase.getMockData(org.folio.rest.impl.ApiTestBase.getMockData) CONFIGURATION_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.CONFIGURATION_ID) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) Invoice(org.folio.rest.jaxrs.model.Invoice) SYSTEM_CONFIG_MODULE_NAME(org.folio.rest.impl.InvoiceHelper.SYSTEM_CONFIG_MODULE_NAME) FOLIO_INVOICE_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.FOLIO_INVOICE_NUMBER_VALUE) ALL_UNITS_CQL(org.folio.invoices.utils.HelperUtils.ALL_UNITS_CQL) ExportConfig(org.folio.rest.jaxrs.model.ExportConfig) IS_DELETED_PROP(org.folio.invoices.utils.HelperUtils.IS_DELETED_PROP) BATCH_VOUCHER_EXPORTS_LIST_PATH(org.folio.rest.impl.BatchVoucherExportsApiTest.BATCH_VOUCHER_EXPORTS_LIST_PATH) Transaction(org.folio.rest.acq.model.finance.Transaction) Supplier(java.util.function.Supplier) BudgetCollection(org.folio.rest.acq.model.finance.BudgetCollection) ArrayList(java.util.ArrayList) BATCH_VOUCHER_EXPORTS_MOCK_DATA_PATH(org.folio.rest.impl.BatchVoucherExportsApiTest.BATCH_VOUCHER_EXPORTS_MOCK_DATA_PATH) InvoiceLineCollection(org.folio.rest.jaxrs.model.InvoiceLineCollection) BatchVoucher(org.folio.rest.jaxrs.model.BatchVoucher) ExchangeRate(org.folio.rest.acq.model.finance.ExchangeRate) ExpenseClassCollection(org.folio.rest.acq.model.finance.ExpenseClassCollection) VOUCHER_MOCK_DATA_PATH(org.folio.rest.impl.VouchersApiTest.VOUCHER_MOCK_DATA_PATH) VOUCHER_LINES_MOCK_DATA_PATH(org.folio.rest.impl.VoucherLinesApiTest.VOUCHER_LINES_MOCK_DATA_PATH) VoucherLineCollection(org.folio.rest.acq.model.VoucherLineCollection) INTERNAL_SERVER_ERROR(javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR) InvoiceDocument(org.folio.rest.jaxrs.model.InvoiceDocument) AcquisitionsUnit(org.folio.rest.acq.model.units.AcquisitionsUnit) Vertx(io.vertx.core.Vertx) IOException(java.io.IOException) CompositeFund(org.folio.rest.acq.model.finance.CompositeFund) ExecutionException(java.util.concurrent.ExecutionException) DAYS(java.time.temporal.ChronoUnit.DAYS) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection) UnixFakeFileSystem(org.mockftpserver.fake.filesystem.UnixFakeFileSystem) BATCH_VOUCHER_EXPORT_CONFIGS_SAMPLE_PATH(org.folio.rest.impl.BatchVoucherExportConfigTest.BATCH_VOUCHER_EXPORT_CONFIGS_SAMPLE_PATH) AcquisitionsUnitCollection(org.folio.rest.acq.model.units.AcquisitionsUnitCollection) BASE_MOCK_DATA_PATH(org.folio.rest.impl.ApiTestBase.BASE_MOCK_DATA_PATH) BATCH_VOUCHER_EXPORT_CONFIG_CREDENTIALS_SAMPLE_PATH_WITH_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.BATCH_VOUCHER_EXPORT_CONFIG_CREDENTIALS_SAMPLE_PATH_WITH_ID) VOUCHER_NUMBER_PREFIX_CONFIG(org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_PREFIX_CONFIG) Date(java.util.Date) TimeoutException(java.util.concurrent.TimeoutException) Router(io.vertx.ext.web.Router) LOCALE_SETTINGS(org.folio.rest.impl.InvoiceHelper.LOCALE_SETTINGS) FakeFtpServer(org.mockftpserver.fake.FakeFtpServer) RoutingContext(io.vertx.ext.web.RoutingContext) BodyHandler(io.vertx.ext.web.handler.BodyHandler) SequenceNumber(org.folio.rest.acq.model.SequenceNumber) APPLICATION_XML(javax.ws.rs.core.MediaType.APPLICATION_XML) FUND_ID_WITH_NOT_ACTIVE_BUDGET(org.folio.rest.impl.InvoicesApiTest.FUND_ID_WITH_NOT_ACTIVE_BUDGET) DocumentCollection(org.folio.rest.jaxrs.model.DocumentCollection) BATCH_VOUCHER_EXPORT_CONFIG_BAD_CREDENTIALS_SAMPLE_PATH_WITH_ID(org.folio.rest.impl.BatchVoucherExportConfigCredentialsTest.BATCH_VOUCHER_EXPORT_CONFIG_BAD_CREDENTIALS_SAMPLE_PATH_WITH_ID) BatchVoucherExportCollection(org.folio.rest.jaxrs.model.BatchVoucherExportCollection) INVOICE_SAMPLE_DOCUMENTS_PATH(org.folio.rest.impl.DocumentsApiTest.INVOICE_SAMPLE_DOCUMENTS_PATH) Assert.fail(org.junit.Assert.fail) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) BATCH_GROUPS_LIST_PATH(org.folio.rest.impl.BatchGroupsApiTest.BATCH_GROUPS_LIST_PATH) EXPENSE_CLASSES_LIST_PATH(org.folio.rest.impl.InvoicesApiTest.EXPENSE_CLASSES_LIST_PATH) InvoiceCollection(org.folio.rest.jaxrs.model.InvoiceCollection) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) INVOICE_LINE_NUMBER_VALUE(org.folio.rest.impl.ApiTestBase.INVOICE_LINE_NUMBER_VALUE) HttpHeaders(io.vertx.core.http.HttpHeaders) PROTECTED_READ_ONLY_TENANT(org.folio.rest.impl.ApiTestBase.PROTECTED_READ_ONLY_TENANT) UUID(java.util.UUID) Instant(java.time.Instant) BatchGroup(org.folio.rest.acq.model.BatchGroup) INVOICE_DOCUMENTS_SAMPLE_PATH(org.folio.rest.impl.DocumentsApiTest.INVOICE_DOCUMENTS_SAMPLE_PATH) List(java.util.List) FiscalYearCollection(org.folio.rest.acq.model.finance.FiscalYearCollection) Response(javax.ws.rs.core.Response) AcquisitionsUnitMembershipCollection(org.folio.rest.acq.model.units.AcquisitionsUnitMembershipCollection) StreamEx(one.util.streamex.StreamEx) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) UserAccount(org.mockftpserver.fake.UserAccount) FileSystem(org.mockftpserver.fake.filesystem.FileSystem) Json(io.vertx.core.json.Json) Credentials(org.folio.rest.jaxrs.model.Credentials) Document(org.folio.rest.jaxrs.model.Document) OKAPI_HEADER_TENANT(org.folio.rest.RestVerticle.OKAPI_HEADER_TENANT) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) FiscalYear(org.folio.rest.acq.model.finance.FiscalYear) VoucherCollection(org.folio.rest.jaxrs.model.VoucherCollection) Function(java.util.function.Function) LedgerCollection(org.folio.rest.acq.model.finance.LedgerCollection) ExportConfigCollection(org.folio.rest.jaxrs.model.ExportConfigCollection) EXISTING_LEDGER_ID(org.folio.rest.impl.InvoicesApiTest.EXISTING_LEDGER_ID) EMPTY(org.apache.commons.lang3.StringUtils.EMPTY) VOUCHER_NUMBER_CONFIG_NAME(org.folio.services.voucher.VoucherCommandService.VOUCHER_NUMBER_CONFIG_NAME) Config(org.folio.rest.jaxrs.model.Config) ACQUISITIONS_UNIT_ID(org.folio.rest.impl.ProtectionHelper.ACQUISITIONS_UNIT_ID) BATCH_GROUP_MOCK_DATA_PATH(org.folio.rest.impl.BatchGroupsApiTest.BATCH_GROUP_MOCK_DATA_PATH) BATCH_VOUCHER_MOCK_DATA_PATH(org.folio.rest.impl.BatchVoucherImplTest.BATCH_VOUCHER_MOCK_DATA_PATH) Configs(org.folio.rest.jaxrs.model.Configs) ID_DOES_NOT_EXIST(org.folio.rest.impl.ApiTestBase.ID_DOES_NOT_EXIST) EXPENSE_CLASSES_MOCK_DATA_PATH(org.folio.rest.impl.InvoicesApiTest.EXPENSE_CLASSES_MOCK_DATA_PATH) Iterator(java.util.Iterator) ResourcePathResolver(org.folio.invoices.utils.ResourcePathResolver) DirectoryEntry(org.mockftpserver.fake.filesystem.DirectoryEntry) BatchGroupCollection(org.folio.rest.acq.model.BatchGroupCollection) INVOICE_ID(org.folio.invoices.utils.HelperUtils.INVOICE_ID) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) HttpMethod(io.vertx.core.http.HttpMethod) QUERY_PARAM_START_WITH(org.folio.invoices.utils.HelperUtils.QUERY_PARAM_START_WITH) HttpStatus(org.folio.HttpStatus) FundCollection(org.folio.rest.acq.model.finance.FundCollection) Collections(java.util.Collections) Table(com.google.common.collect.Table) LogManager(org.apache.logging.log4j.LogManager) BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH(org.folio.rest.impl.BatchVoucherExportConfigTest.BATCH_VOUCHER_EXPORT_CONFIG_SAMPLE_PATH) JsonObject(io.vertx.core.json.JsonObject) Supplier(java.util.function.Supplier) IOException(java.io.IOException) BudgetExpenseClassCollection(org.folio.rest.acq.model.finance.BudgetExpenseClassCollection)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)4 HashBasedTable (com.google.common.collect.HashBasedTable)3 Table (com.google.common.collect.Table)3 Header (io.restassured.http.Header)3 Vertx (io.vertx.core.Vertx)3 HttpHeaders (io.vertx.core.http.HttpHeaders)3 HttpMethod (io.vertx.core.http.HttpMethod)3 HttpServer (io.vertx.core.http.HttpServer)3 Router (io.vertx.ext.web.Router)3 RoutingContext (io.vertx.ext.web.RoutingContext)3 BodyHandler (io.vertx.ext.web.handler.BodyHandler)3 IOException (java.io.IOException)3 Instant (java.time.Instant)3 DAYS (java.time.temporal.ChronoUnit.DAYS)3 ArrayList (java.util.ArrayList)3 Collections (java.util.Collections)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 List (java.util.List)3