Search in sources :

Example 1 with ProductId

use of org.folio.rest.jaxrs.model.ProductId in project mod-orders by folio-org.

the class PurchaseOrderLinesApiTest method testPostOrderLineToConvertToIsbn13.

@Test
void testPostOrderLineToConvertToIsbn13() {
    logger.info("=== Test Post order line to verify ISBN 10 is normalized to ISBN 13 ===");
    CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, ANOTHER_PO_LINE_ID_FOR_SUCCESS_CASE).mapTo(CompositePoLine.class);
    // To skip permission validation by units
    reqData.setId("0009662b-8b80-4001-b704-ca10971f175d");
    reqData.setPurchaseOrderId("9a952cd0-842b-4e71-bddd-014eb128dc8e");
    String isbn = "0-19-852663-6";
    ProductId productId = reqData.getDetails().getProductIds().get(0);
    reqData.getDetails().getProductIds().get(0).setProductId(isbn);
    reqData.getDetails().getProductIds().add(new ProductId().withProductIdType(productId.getProductIdType()).withQualifier(productId.getQualifier()).withProductId(isbn));
    assertThat(reqData.getDetails().getProductIds(), hasSize(2));
    CompositePoLine resp = verifyPostResponse(LINES_PATH, JsonObject.mapFrom(reqData).encodePrettily(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePoLine.class);
    assertThat(resp.getDetails().getProductIds(), hasSize(1));
    assertThat(resp.getDetails().getProductIds().get(0).getProductId(), equalTo("9780198526636"));
}
Also used : CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) ProductId(org.folio.rest.jaxrs.model.ProductId) Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProductId

use of org.folio.rest.jaxrs.model.ProductId in project mod-orders by folio-org.

the class PurchaseOrderLinesApiTest method testPostOrderLineToRemoveISBNDuplicates.

@Test
void testPostOrderLineToRemoveISBNDuplicates() {
    logger.info("=== Test Post order line to verify ISBN 13 is not repeated ===");
    CompositePoLine reqData = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, ANOTHER_PO_LINE_ID_FOR_SUCCESS_CASE).mapTo(CompositePoLine.class);
    // To skip permission validation by units
    reqData.setId("0009662b-8b80-4001-b704-ca10971f175d");
    reqData.setPurchaseOrderId("9a952cd0-842b-4e71-bddd-014eb128dc8e");
    final String invalidIsbn = "fcca2643-406a-482a-b760-7a7f8aec640e";
    reqData.getDetails().getProductIds().clear();
    final String isbn1 = "9780545010221";
    final String qualifier1 = "(q1)";
    final String qualifier2 = "(q2)";
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn1));
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn1).withQualifier(qualifier1));
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn1).withQualifier(qualifier1));
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn1).withQualifier(qualifier2));
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn1));
    final String isbn213 = "9780198526636";
    final String isbn210 = "0-19-852663-6";
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn210));
    reqData.getDetails().getProductIds().add(createIsbnProductId(isbn213));
    reqData.getDetails().getProductIds().add(new ProductId().withProductId(INVALID_ISBN).withProductIdType(invalidIsbn));
    assertThat(reqData.getDetails().getProductIds(), hasSize(8));
    CompositePoLine resp = verifyPostResponse(LINES_PATH, JsonObject.mapFrom(reqData).encodePrettily(), prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID), APPLICATION_JSON, 201).as(CompositePoLine.class);
    assertThat(resp.getDetails().getProductIds(), hasSize(4));
    assertThat(resp.getDetails().getProductIds().get(0).getProductId(), equalTo(isbn1));
    assertThat(resp.getDetails().getProductIds().get(0).getQualifier(), equalTo(qualifier1));
    assertThat(resp.getDetails().getProductIds().get(1).getProductId(), equalTo(isbn1));
    assertThat(resp.getDetails().getProductIds().get(1).getQualifier(), equalTo(qualifier2));
    assertThat(resp.getDetails().getProductIds().get(2).getProductId(), equalTo(isbn213));
    assertThat(resp.getDetails().getProductIds().get(3).getQualifier(), nullValue());
    assertThat(resp.getDetails().getProductIds().get(3).getProductId(), equalTo(INVALID_ISBN));
}
Also used : CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) TestUtils.getMinimalContentCompositePoLine(org.folio.TestUtils.getMinimalContentCompositePoLine) ProductId(org.folio.rest.jaxrs.model.ProductId) Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with ProductId

use of org.folio.rest.jaxrs.model.ProductId in project mod-orders by folio-org.

the class InventoryManager method buildInstanceRecordJsonObject.

public JsonObject buildInstanceRecordJsonObject(Title title, JsonObject lookupObj) {
    JsonObject instance = new JsonObject();
    // MODORDERS-145 The Source and source code are required by schema
    instance.put(INSTANCE_SOURCE, SOURCE_FOLIO);
    instance.put(INSTANCE_TITLE, title.getTitle());
    if (title.getEdition() != null) {
        instance.put(INSTANCE_EDITIONS, new JsonArray(singletonList(title.getEdition())));
    }
    instance.put(INSTANCE_STATUS_ID, lookupObj.getString(INSTANCE_STATUSES));
    instance.put(INSTANCE_TYPE_ID, lookupObj.getString(INSTANCE_TYPES));
    if (title.getPublisher() != null || title.getPublishedDate() != null) {
        JsonObject publication = new JsonObject();
        publication.put(INSTANCE_PUBLISHER, title.getPublisher());
        publication.put(INSTANCE_DATE_OF_PUBLICATION, title.getPublishedDate());
        instance.put(INSTANCE_PUBLICATION, new JsonArray(singletonList(publication)));
    }
    List<Contributor> titleContributors = title.getContributors();
    if (isNotEmpty(titleContributors)) {
        List<JsonObject> contributors = titleContributors.stream().map(compPolContributor -> {
            JsonObject invContributor = new JsonObject();
            invContributor.put(CONTRIBUTOR_NAME_TYPE_ID, compPolContributor.getContributorNameTypeId());
            invContributor.put(CONTRIBUTOR_NAME, compPolContributor.getContributor());
            return invContributor;
        }).collect(toList());
        instance.put(INSTANCE_CONTRIBUTORS, contributors);
    }
    List<ProductId> productIds = title.getProductIds();
    if (CollectionUtils.isNotEmpty(productIds)) {
        List<JsonObject> identifiers = productIds.stream().map(pId -> {
            JsonObject identifier = new JsonObject();
            identifier.put(INSTANCE_IDENTIFIER_TYPE_ID, pId.getProductIdType());
            identifier.put(INSTANCE_IDENTIFIER_TYPE_VALUE, pId.getProductId());
            return identifier;
        }).collect(toList());
        instance.put(INSTANCE_IDENTIFIERS, new JsonArray(identifiers));
    }
    return instance;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CheckInPiece(org.folio.rest.jaxrs.model.CheckInPiece) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) HelperUtils.collectResultsOnSuccess(org.folio.orders.utils.HelperUtils.collectResultsOnSuccess) StringUtils(org.apache.commons.lang3.StringUtils) Context(io.vertx.core.Context) StreamEx.ofSubLists(one.util.streamex.StreamEx.ofSubLists) MISSING_INSTANCE_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_INSTANCE_TYPE) Collections.singletonList(java.util.Collections.singletonList) ISBN_NOT_VALID(org.folio.rest.core.exceptions.ErrorCodes.ISBN_NOT_VALID) PoLineCommonUtil(org.folio.orders.utils.PoLineCommonUtil) HelperUtils.convertIdsToCqlQuery(org.folio.orders.utils.HelperUtils.convertIdsToCqlQuery) Map(java.util.Map) ListUtils(org.apache.commons.collections4.ListUtils) HOLDINGS_BY_ID_NOT_FOUND(org.folio.rest.core.exceptions.ErrorCodes.HOLDINGS_BY_ID_NOT_FOUND) PARTIALLY_RETURNED_COLLECTION(org.folio.rest.core.exceptions.ErrorCodes.PARTIALLY_RETURNED_COLLECTION) JsonObject(io.vertx.core.json.JsonObject) ORDER_CONFIG_MODULE_NAME(org.folio.orders.utils.HelperUtils.ORDER_CONFIG_MODULE_NAME) PieceStorageService(org.folio.service.pieces.PieceStorageService) LANG(org.folio.orders.utils.HelperUtils.LANG) Location(org.folio.rest.jaxrs.model.Location) Collection(java.util.Collection) ErrorCodes(org.folio.rest.core.exceptions.ErrorCodes) CompletionException(java.util.concurrent.CompletionException) HelperUtils.handleGetRequest(org.folio.orders.utils.HelperUtils.handleGetRequest) Collectors(java.util.stream.Collectors) TenantTool(org.folio.rest.tools.utils.TenantTool) Collectors.joining(java.util.stream.Collectors.joining) ConfigurationEntriesService(org.folio.service.configuration.ConfigurationEntriesService) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) Logger(org.apache.logging.log4j.Logger) Response(javax.ws.rs.core.Response) PieceItemPair(org.folio.models.PieceItemPair) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) StreamEx(one.util.streamex.StreamEx) HelperUtils.getFirstObjectFromResponse(org.folio.orders.utils.HelperUtils.getFirstObjectFromResponse) Optional(java.util.Optional) Parameter(org.folio.rest.jaxrs.model.Parameter) IntStreamEx(one.util.streamex.IntStreamEx) ITEM_CREATION_FAILED(org.folio.rest.core.exceptions.ErrorCodes.ITEM_CREATION_FAILED) MISSING_INSTANCE_STATUS(org.folio.rest.core.exceptions.ErrorCodes.MISSING_INSTANCE_STATUS) ELECTRONIC_RESOURCE(org.folio.rest.jaxrs.model.CompositePoLine.OrderFormat.ELECTRONIC_RESOURCE) RestClient(org.folio.rest.core.RestClient) HttpException(org.folio.rest.core.exceptions.HttpException) ProductId(org.folio.rest.jaxrs.model.ProductId) CompletableFuture(java.util.concurrent.CompletableFuture) FolioVertxCompletableFuture(org.folio.completablefuture.FolioVertxCompletableFuture) Contributor(org.folio.rest.jaxrs.model.Contributor) CollectionUtils(org.apache.commons.collections4.CollectionUtils) SharedData(io.vertx.core.shareddata.SharedData) ArrayList(java.util.ArrayList) MAX_IDS_FOR_GET_RQ(org.folio.rest.RestConstants.MAX_IDS_FOR_GET_RQ) MISSING_LOAN_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_LOAN_TYPE) PoLineUpdateHolder(org.folio.models.PoLineUpdateHolder) Title(org.folio.rest.jaxrs.model.Title) HelperUtils.extractId(org.folio.orders.utils.HelperUtils.extractId) CompletableFuture.allOf(java.util.concurrent.CompletableFuture.allOf) RequestContext(org.folio.rest.core.models.RequestContext) ReceivedItem(org.folio.rest.jaxrs.model.ReceivedItem) HelperUtils.isProductIdsExist(org.folio.orders.utils.HelperUtils.isProductIdsExist) Piece(org.folio.rest.jaxrs.model.Piece) HelperUtils(org.folio.orders.utils.HelperUtils) MISSING_CONTRIBUTOR_NAME_TYPE(org.folio.rest.core.exceptions.ErrorCodes.MISSING_CONTRIBUTOR_NAME_TYPE) RequestEntry(org.folio.rest.core.models.RequestEntry) PostResponseType(org.folio.rest.core.PostResponseType) InventoryException(org.folio.rest.core.exceptions.InventoryException) NOT_FOUND(org.folio.rest.RestConstants.NOT_FOUND) Error(org.folio.rest.jaxrs.model.Error) JsonArray(io.vertx.core.json.JsonArray) Collectors.toList(java.util.stream.Collectors.toList) Lock(io.vertx.core.shareddata.Lock) HelperUtils.encodeQuery(org.folio.orders.utils.HelperUtils.encodeQuery) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) JsonObject(io.vertx.core.json.JsonObject) Contributor(org.folio.rest.jaxrs.model.Contributor) ProductId(org.folio.rest.jaxrs.model.ProductId)

Aggregations

TestUtils.getMinimalContentCompositePoLine (org.folio.TestUtils.getMinimalContentCompositePoLine)2 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)2 ProductId (org.folio.rest.jaxrs.model.ProductId)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 Test (org.junit.jupiter.api.Test)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 Context (io.vertx.core.Context)1 JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 Lock (io.vertx.core.shareddata.Lock)1 SharedData (io.vertx.core.shareddata.SharedData)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1