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