use of org.folio.circulation.domain.representations.RequestByInstanceIdRequest in project mod-circulation by folio-org.
the class RequestByInstanceIdResource method instanceToItemRequests.
static Result<List<JsonObject>> instanceToItemRequests(InstanceRequestRelatedRecords requestRecords) {
final RequestByInstanceIdRequest requestByInstanceIdRequest = requestRecords.getInstanceLevelRequest();
final List<Item> combinedItems = requestRecords.getCombinedSortedItemsList();
if (combinedItems == null || combinedItems.isEmpty()) {
return failedValidation("Cannot create request objects when items list is null or empty", "items", "null");
}
LinkedList<JsonObject> requests = new LinkedList<>();
for (Item item : combinedItems) {
for (RequestType requestType : ORDERED_REQUEST_TYPES) {
JsonObject requestBody = new JsonObject();
write(requestBody, ITEM_ID, item.getItemId());
write(requestBody, "requestDate", requestByInstanceIdRequest.getRequestDate());
write(requestBody, REQUESTER_ID, requestByInstanceIdRequest.getRequesterId().toString());
write(requestBody, "pickupServicePointId", requestByInstanceIdRequest.getPickupServicePointId().toString());
write(requestBody, "fulfilmentPreference", DEFAULT_FULFILMENT_PREFERENCE.getValue());
write(requestBody, "requestType", requestType.getValue());
if (requestByInstanceIdRequest.getRequestExpirationDate() != null) {
write(requestBody, "requestExpirationDate", requestByInstanceIdRequest.getRequestExpirationDate());
}
write(requestBody, "patronComments", requestByInstanceIdRequest.getPatronComments());
write(requestBody, "instanceId", requestByInstanceIdRequest.getInstanceId());
write(requestBody, "holdingsRecordId", item.getHoldingsRecordId());
write(requestBody, "requestLevel", requestByInstanceIdRequest.getRequestLevel());
requests.add(requestBody);
}
}
return succeeded(requests);
}
use of org.folio.circulation.domain.representations.RequestByInstanceIdRequest in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method canGetOrderedAvailableItemsListWithoutMatchingLocations.
@Test
void canGetOrderedAvailableItemsListWithoutMatchingLocations() {
UUID bookMaterialTypeId = UUID.randomUUID();
UUID loanTypeId = UUID.randomUUID();
JsonObject location = getLocationWithServicePoints(emptySet(), null, null);
Item item1 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.randomUUID()).create()).withLocation(Location.from(location));
Item item2 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.randomUUID()).create()).withLocation(Location.from(location));
Item item3 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.randomUUID()).create()).withLocation(Location.from(location));
Item item4 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.randomUUID()).create()).withLocation(Location.from(location));
// order added is important so the test deliberately add items in a certain order
List<Item> items = new ArrayList<>();
items.add(item3);
items.add(item2);
items.add(item4);
items.add(item1);
InstanceRequestRelatedRecords records = new InstanceRequestRelatedRecords();
JsonObject requestJson = getJsonInstanceRequest(UUID.randomUUID());
Result<RequestByInstanceIdRequest> request = RequestByInstanceIdRequest.from(requestJson);
records.setUnsortedAvailableItems(items);
records.setInstanceLevelRequest(request.value());
Result<InstanceRequestRelatedRecords> rankResult = rankItemsByMatchingServicePoint(records);
final List<Item> orderedItems = rankResult.value().getCombinedSortedItemsList();
assertEquals(4, orderedItems.size());
assertEquals(item3.getItemId(), orderedItems.get(0).getItemId());
assertEquals(item2.getItemId(), orderedItems.get(1).getItemId());
assertEquals(item4.getItemId(), orderedItems.get(2).getItemId());
assertEquals(item1.getItemId(), orderedItems.get(3).getItemId());
}
use of org.folio.circulation.domain.representations.RequestByInstanceIdRequest in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method canTransformInstanceToItemRequests.
@Test
void canTransformInstanceToItemRequests() {
UUID loanTypeId = UUID.randomUUID();
RequestByInstanceIdRequest requestByInstanceIdRequest = RequestByInstanceIdRequest.from(getJsonInstanceRequest(null)).value();
List<Item> items = getItems(2, loanTypeId);
InstanceRequestRelatedRecords records = new InstanceRequestRelatedRecords();
records.setSortedAvailableItems(items);
records.setInstanceLevelRequest(requestByInstanceIdRequest);
final Result<List<JsonObject>> collectionResult = RequestByInstanceIdResource.instanceToItemRequests(records);
assertTrue(collectionResult.succeeded());
Collection<JsonObject> requestRepresentations = collectionResult.value();
assertEquals(6, requestRepresentations.size());
int i = 0;
int j = 0;
Item item = items.get(j);
for (JsonObject itemRequestJson : requestRepresentations) {
assertEquals(item.getItemId(), itemRequestJson.getString("itemId"));
if (i == 0)
assertEquals(RequestType.HOLD.getValue(), itemRequestJson.getString("requestType"));
if (i == 1)
assertEquals(RequestType.RECALL.getValue(), itemRequestJson.getString("requestType"));
if (i == 2)
assertEquals(RequestType.PAGE.getValue(), itemRequestJson.getString("requestType"));
i++;
if (i > 2) {
i = 0;
j++;
if (j < 2) {
item = items.get(j);
}
}
}
}
use of org.folio.circulation.domain.representations.RequestByInstanceIdRequest in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method canGetOrderedAvailableItemsList.
@Test
void canGetOrderedAvailableItemsList() {
UUID primaryServicePointId = servicePointsFixture.cd2().getId();
UUID secondaryServicePointId = UUID.randomUUID();
UUID institutionId = UUID.randomUUID();
HashSet<UUID> servicePoints1 = new HashSet<>();
servicePoints1.add(secondaryServicePointId);
JsonObject location1 = getLocationWithServicePoints(servicePoints1, secondaryServicePointId, institutionId);
// Matching item and servicePoints
HashSet<UUID> servicePoints2 = new HashSet<>();
servicePoints2.add(primaryServicePointId);
servicePoints2.add(secondaryServicePointId);
JsonObject location2 = getLocationWithServicePoints(servicePoints2, primaryServicePointId, institutionId);
JsonObject location3 = getLocationWithServicePoints(emptySet(), null, institutionId);
// Matching item and servicePoints
HashSet<UUID> servicePoints4 = new HashSet<>();
servicePoints4.add(primaryServicePointId);
JsonObject location4 = getLocationWithServicePoints(servicePoints4, primaryServicePointId, institutionId);
UUID bookMaterialTypeId = UUID.randomUUID();
UUID loanTypeId = UUID.randomUUID();
Item item1 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location1.getString("id"))).create()).withLocation(Location.from(location1));
Item item2 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location2.getString("id"))).create()).withLocation(Location.from(location2));
Item item3 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location3.getString("id"))).create()).withLocation(Location.from(location3));
Item item4 = Item.from(ItemExamples.basedUponSmallAngryPlanet(bookMaterialTypeId, loanTypeId).withTemporaryLocation(UUID.fromString(location4.getString("id"))).create()).withLocation(Location.from(location4));
final ArrayList<Item> items = new ArrayList<>();
items.add(item2);
items.add(item3);
items.add(item4);
items.add(item1);
InstanceRequestRelatedRecords records = new InstanceRequestRelatedRecords();
JsonObject requestJson = getJsonInstanceRequest(primaryServicePointId);
Result<RequestByInstanceIdRequest> request = RequestByInstanceIdRequest.from(requestJson);
records.setUnsortedAvailableItems(items);
records.setInstanceLevelRequest(request.value());
Result<InstanceRequestRelatedRecords> rankResult = rankItemsByMatchingServicePoint(records);
final List<Item> orderedItems = rankResult.value().getCombinedSortedItemsList();
assertEquals(4, orderedItems.size());
assertEquals(item2.getItemId(), orderedItems.get(0).getItemId());
assertEquals(item4.getItemId(), orderedItems.get(1).getItemId());
assertEquals(item3.getItemId(), orderedItems.get(2).getItemId());
assertEquals(item1.getItemId(), orderedItems.get(3).getItemId());
}
Aggregations