Search in sources :

Example 1 with Contributor

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

the class PurchaseOrderLinesApiTest method testPutOrderLineByIdProtectedFieldsChanged.

@Test
void testPutOrderLineByIdProtectedFieldsChanged() {
    logger.info("=== Test PUT Order Line By Id - Protected fields changed ===");
    String lineId = "0009662b-8b80-4001-b704-ca10971f175d";
    JsonObject body = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, lineId);
    String url = String.format(LINE_BY_ID_PATH, lineId);
    Map<String, Object> allProtectedFieldsModification = new HashMap<>();
    allProtectedFieldsModification.put(POLineProtectedFields.ACQUISITION_METHOD.getFieldName(), TestUtils.APPROVAL_PLAN_METHOD);
    allProtectedFieldsModification.put(POLineProtectedFields.DONOR.getFieldName(), "Donor");
    allProtectedFieldsModification.put(POLineProtectedFields.ERESOURCE_USER_LIMIT.getFieldName(), 100);
    // adding trial because a default value is added while sending the request
    allProtectedFieldsModification.put(POLineProtectedFields.ERESOURCE_TRIAL.getFieldName(), true);
    Contributor contributor = new Contributor();
    contributor.setContributor("Mr Test");
    contributor.setContributorNameTypeId("fbdd42a8-e47d-4694-b448-cc571d1b44c3");
    List<Contributor> contributors = new ArrayList<>();
    contributors.add(contributor);
    allProtectedFieldsModification.put(POLineProtectedFields.CONTRIBUTORS.getFieldName(), contributors);
    checkPreventProtectedFieldsModificationRule(url, body, allProtectedFieldsModification);
    // 2 calls each to fetch Order Line, Purchase Order
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    assertEquals(2, column.size());
    assertThat(column, hasKey(PO_LINES_STORAGE));
    // Verify no message sent via event bus
    HandlersTestHelper.verifyOrderStatusUpdateEvent(0);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Contributor(org.folio.rest.jaxrs.model.Contributor) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 2 with Contributor

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

the class PurchaseOrderLinesApiTest method testPutOrderLineByIdForPhysicalOrderAndProtectedFieldsChanged.

@Test
void testPutOrderLineByIdForPhysicalOrderAndProtectedFieldsChanged() {
    logger.info("=== Test PUT Order Line By Id - Protected fields changed ===");
    String lineId = "0009662b-8b80-4001-b704-ca10971f175d";
    JsonObject body = getMockAsJson(COMP_PO_LINES_MOCK_DATA_PATH, lineId);
    String url = String.format(LINE_BY_ID_PATH, lineId);
    Map<String, Object> allProtectedFieldsModification = new HashMap<>();
    allProtectedFieldsModification.put(POLineFieldNames.ACQUISITION_METHOD.getFieldName(), TestUtils.APPROVAL_PLAN_METHOD);
    allProtectedFieldsModification.put(POLineFieldNames.DONOR.getFieldName(), "Donor");
    // adding trial because a default value is added while sending the request
    allProtectedFieldsModification.put(POLineFieldNames.PHYSICAL_MATERIAL_TYPE.getFieldName(), UUID.randomUUID().toString());
    Contributor contributor = new Contributor();
    contributor.setContributor("Mr Test");
    contributor.setContributorNameTypeId("fbdd42a8-e47d-4694-b448-cc571d1b44c3");
    List<Contributor> contributors = new ArrayList<>();
    contributors.add(contributor);
    allProtectedFieldsModification.put(POLineFieldNames.CONTRIBUTORS.getFieldName(), contributors);
    checkPreventProtectedFieldsModificationRule(url, body, allProtectedFieldsModification);
    // 2 calls each to fetch Order Line, Purchase Order
    Map<String, List<JsonObject>> column = MockServer.serverRqRs.column(HttpMethod.GET);
    assertEquals(2, column.size());
    assertThat(column, hasKey(PO_LINES_STORAGE));
    // Verify no message sent via event bus
    HandlersTestHelper.verifyOrderStatusUpdateEvent(0);
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Contributor(org.folio.rest.jaxrs.model.Contributor) JsonObject(io.vertx.core.json.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.containsString(org.hamcrest.Matchers.containsString) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with Contributor

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

the class InventoryManager method getContributorNameTypeByIds.

private CompletableFuture<List<JsonObject>> getContributorNameTypeByIds(List<String> ids, RequestContext requestContext) {
    String query = convertIdsToCqlQuery(ids);
    RequestEntry requestEntry = new RequestEntry(INVENTORY_LOOKUP_ENDPOINTS.get(CONTRIBUTOR_NAME_TYPES)).withQuery(query).withOffset(0).withLimit(ids.size());
    return restClient.getAsJsonObject(requestEntry, requestContext).thenApply(entries -> entries.getJsonArray(CONTRIBUTOR_NAME_TYPES).stream().map(JsonObject::mapFrom).collect(Collectors.toList())).exceptionally(e -> {
        logger.error("The issue happened getting contributor name types", e);
        throw new CompletionException(e.getCause());
    });
}
Also used : 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) CompletionException(java.util.concurrent.CompletionException) RequestEntry(org.folio.rest.core.models.RequestEntry)

Example 4 with Contributor

use of org.folio.rest.jaxrs.model.Contributor 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)

Example 5 with Contributor

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

the class PurchaseOrdersApiTest method testInventoryHelperMissingContributorNameTypeThrowsProperError.

@Test
void testInventoryHelperMissingContributorNameTypeThrowsProperError() throws Exception {
    CompositePurchaseOrder reqData = getMockDraftOrder().mapTo(CompositePurchaseOrder.class);
    MockServer.addMockTitles(reqData.getCompositePoLines());
    reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.OPEN);
    reqData.getCompositePoLines().remove(1);
    assertThat(reqData.getCompositePoLines(), hasSize(1));
    reqData.getCompositePoLines().get(0).getContributors().add(new Contributor().withContributor("Test").withContributorNameTypeId(ID_DOES_NOT_EXIST));
    Headers headers = prepareHeaders(EXIST_CONFIG_X_OKAPI_TENANT_LIMIT_10, X_OKAPI_USER_ID);
    Response resp = verifyPostResponse(COMPOSITE_ORDERS_PATH, JsonObject.mapFrom(reqData).encodePrettily(), headers, APPLICATION_JSON, 500);
    int expectedContributorNameTypesSearches = Math.toIntExact(reqData.getCompositePoLines().get(0).getContributors().stream().map(Contributor::getContributorNameTypeId).distinct().count() / MAX_IDS_FOR_GET_RQ + 1);
    assertThat(getContributorNameTypesSearches(), hasSize(expectedContributorNameTypesSearches));
    Error err = resp.getBody().as(Errors.class).getErrors().get(0);
    assertThat(err.getCode(), equalTo(ErrorCodes.MISSING_CONTRIBUTOR_NAME_TYPE.getCode()));
    assertThat(err.getMessage(), equalTo(ErrorCodes.MISSING_CONTRIBUTOR_NAME_TYPE.getDescription()));
    assertThat(err.getParameters().get(0).getValue(), equalTo(ID_DOES_NOT_EXIST));
}
Also used : RestTestUtils.verifyPostResponse(org.folio.RestTestUtils.verifyPostResponse) Response(io.restassured.response.Response) RestTestUtils.verifyDeleteResponse(org.folio.RestTestUtils.verifyDeleteResponse) Headers(io.restassured.http.Headers) RestTestUtils.prepareHeaders(org.folio.RestTestUtils.prepareHeaders) Contributor(org.folio.rest.jaxrs.model.Contributor) Error(org.folio.rest.jaxrs.model.Error) TestUtils.getMinimalContentCompositePurchaseOrder(org.folio.TestUtils.getMinimalContentCompositePurchaseOrder) CompositePurchaseOrder(org.folio.rest.jaxrs.model.CompositePurchaseOrder) Test(org.junit.jupiter.api.Test)

Aggregations

Contributor (org.folio.rest.jaxrs.model.Contributor)6 JsonObject (io.vertx.core.json.JsonObject)5 ArrayList (java.util.ArrayList)5 List (java.util.List)5 JsonArray (io.vertx.core.json.JsonArray)3 Map (java.util.Map)3 Objects (java.util.Objects)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 CollectionUtils (org.apache.commons.collections4.CollectionUtils)3 StringUtils (org.apache.commons.lang3.StringUtils)3 LogManager (org.apache.logging.log4j.LogManager)3 Logger (org.apache.logging.log4j.Logger)3 HelperUtils (org.folio.orders.utils.HelperUtils)3 PoLineCommonUtil (org.folio.orders.utils.PoLineCommonUtil)3 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)3 Error (org.folio.rest.jaxrs.model.Error)3 Location (org.folio.rest.jaxrs.model.Location)3 Piece (org.folio.rest.jaxrs.model.Piece)3 ReceivedItem (org.folio.rest.jaxrs.model.ReceivedItem)3