use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class MoveRequestPolicyTests method cannotMoveRecallRequestsWithRequestPolicyNotAllowingHolds.
@Test
void cannotMoveRecallRequestsWithRequestPolicyNotAllowingHolds() {
final String anyNoticePolicy = noticePoliciesFixture.activeNotice().getId().toString();
final String anyLoanPolicy = loanPoliciesFixture.canCirculateRolling().getId().toString();
final String bookMaterialType = materialTypesFixture.book().getId().toString();
final String anyRequestPolicy = requestPoliciesFixture.allowAllRequestPolicy().getId().toString();
final String anyOverdueFinePolicy = overdueFinePoliciesFixture.facultyStandard().getId().toString();
final String anyLostItemFeePolicy = lostItemFeePoliciesFixture.facultyStandard().getId().toString();
ArrayList<RequestType> allowedRequestTypes = new ArrayList<>();
allowedRequestTypes.add(RequestType.RECALL);
allowedRequestTypes.add(RequestType.PAGE);
final String noHoldRequestPolicy = requestPoliciesFixture.customRequestPolicy(allowedRequestTypes, "All But Hold", "All but Hold request policy").getId().toString();
// This rule is set up to show that the fallback policy won't be used but the material type rule m is used instead.
// The material type rule m allows any patron to place any request but HOLDs on any BOOK, loan or notice types
final String rules = String.join("\n", "priority: t, s, c, b, a, m, g", "fallback-policy : l " + anyLoanPolicy + " r " + anyRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy + "\n", "m " + bookMaterialType + ": l " + anyLoanPolicy + " r " + noHoldRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy);
setRules(rules);
List<ItemResource> items = itemsFixture.createMultipleItemsForTheSameInstance(2);
IndividualResource itemToMoveTo = items.get(0);
IndividualResource itemToMoveFrom = items.get(1);
IndividualResource james = usersFixture.james();
IndividualResource jessica = usersFixture.jessica();
IndividualResource charlotte = usersFixture.charlotte();
checkOutFixture.checkOutByBarcode(itemToMoveTo, jessica);
checkOutFixture.checkOutByBarcode(itemToMoveFrom, charlotte);
IndividualResource requestByCharlotte = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveTo, charlotte, getZonedDateTime().minusHours(2), RequestType.RECALL.getValue());
IndividualResource requestByJames = requestsFixture.placeItemLevelHoldShelfRequest(itemToMoveFrom, james, getZonedDateTime().minusHours(1), RequestType.RECALL.getValue());
// move james' recall request as a hold shelf request from itemToMoveTo to itemToMoveFrom
Response response = requestsFixture.attemptMove(new MoveRequestBuilder(requestByJames.getId(), itemToMoveTo.getId(), RequestType.HOLD.getValue()));
assertThat("Move request should have correct response status code", response.getStatusCode(), is(422));
assertThat("Move request should have correct response message", response.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("Hold requests are not allowed for this patron and item combination"));
requestByCharlotte = requestsClient.get(requestByCharlotte);
assertThat(requestByCharlotte.getJson().getString(REQUEST_TYPE), is(RequestType.RECALL.getValue()));
assertThat(requestByCharlotte.getJson().getInteger("position"), is(1));
assertThat(requestByCharlotte.getJson().getString("itemId"), is(itemToMoveTo.getId().toString()));
requestByJames = requestsClient.get(requestByJames);
assertThat(requestByJames.getJson().getString(REQUEST_TYPE), is(RequestType.RECALL.getValue()));
assertThat(requestByJames.getJson().getInteger("position"), is(1));
assertThat(requestByJames.getJson().getString("itemId"), is(itemToMoveFrom.getId().toString()));
// check item queues are correct size
MultipleRecords<JsonObject> smallAngryPlanetQueue = requestsFixture.getQueueFor(itemToMoveTo);
assertThat(smallAngryPlanetQueue.getTotalRecords(), is(1));
MultipleRecords<JsonObject> interestingTimesQueue = requestsFixture.getQueueFor(itemToMoveFrom);
assertThat(interestingTimesQueue.getTotalRecords(), is(1));
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPoliciesFixture method allowAllRequestPolicy.
public IndividualResource allowAllRequestPolicy(UUID id) {
List<RequestType> types = new ArrayList<>();
types.add(RequestType.HOLD);
types.add(RequestType.PAGE);
types.add(RequestType.RECALL);
return requestPolicyRecordCreator.createIfAbsent(new RequestPolicyBuilder(types, id));
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPoliciesFixture method allowAllRequestPolicy.
public IndividualResource allowAllRequestPolicy() {
ArrayList<RequestType> types = new ArrayList<>();
types.add(RequestType.HOLD);
types.add(RequestType.PAGE);
types.add(RequestType.RECALL);
final RequestPolicyBuilder allowAllPolicy = new RequestPolicyBuilder(types);
return requestPolicyRecordCreator.createIfAbsent(allowAllPolicy);
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPolicyTests method cannotCreateHoldRequestsWithRequestPolicyNotAllowingHolds.
@Test
void cannotCreateHoldRequestsWithRequestPolicyNotAllowingHolds() {
final String anyNoticePolicy = noticePoliciesFixture.activeNotice().getId().toString();
final String anyLoanPolicy = loanPoliciesFixture.canCirculateRolling().getId().toString();
final String bookMaterialType = materialTypesFixture.book().getId().toString();
final String anyRequestPolicy = requestPoliciesFixture.allowAllRequestPolicy().getId().toString();
final String anyOverdueFinePolicy = overdueFinePoliciesFixture.facultyStandard().getId().toString();
final String anyLostItemFeePolicy = lostItemFeePoliciesFixture.facultyStandard().getId().toString();
ArrayList<RequestType> allowedRequestTypes = new ArrayList<>();
allowedRequestTypes.add(RequestType.RECALL);
allowedRequestTypes.add(RequestType.PAGE);
final String noHoldRequestPolicy = requestPoliciesFixture.customRequestPolicy(allowedRequestTypes, "All But Hold", "All but Hold request policy").getId().toString();
// This rule is set up to show that the fallback policy won't be used but the material type rule m is used instead.
// The material type rule m allows any patron to place any request but HOLDs on any BOOK, loan or notice types
final String rules = String.join("\n", "priority: t, s, c, b, a, m, g", "fallback-policy : l " + anyLoanPolicy + " r " + anyRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy + "\n", "m " + bookMaterialType + ": l " + anyLoanPolicy + " r " + noHoldRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy);
setRules(rules);
// setting up a checked-out library item to perform HOLD
final IndividualResource checkedOutItem = itemsFixture.basedUponSmallAngryPlanet();
checkOutFixture.checkOutByBarcode(checkedOutItem, usersFixture.jessica());
final Response holdResponse = requestsClient.attemptCreate(new RequestBuilder().hold().forItem(checkedOutItem).withPickupServicePointId(requestPickupServicePoint.getId()).by(// randomly picked James to represent "Any" patron
usersFixture.james()));
assertThat(holdResponse.getJson(), hasErrorWith(allOf(hasMessage("Hold requests are not allowed for this patron and item combination"), hasParameter("requestType", "Hold"))));
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestCollectionResource method asMove.
private RequestAndRelatedRecords asMove(RequestAndRelatedRecords requestAndRelatedRecords, JsonObject representation) {
final var originalItemId = requestAndRelatedRecords.getItemId();
final var destinationItemId = representation.getString("destinationItemId");
if (representation.containsKey("requestType")) {
RequestType requestType = RequestType.from(representation.getString("requestType"));
return requestAndRelatedRecords.withRequestType(requestType).asMove(originalItemId, destinationItemId);
}
return requestAndRelatedRecords.asMove(originalItemId, destinationItemId);
}
Aggregations