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);
}
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);
}
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());
});
}
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;
}
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));
}
Aggregations