Search in sources :

Example 6 with RequestType

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));
}
Also used : Response(org.folio.circulation.support.http.client.Response) MoveRequestBuilder(api.support.builders.MoveRequestBuilder) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(api.support.http.IndividualResource) ItemResource(api.support.http.ItemResource) RequestType(org.folio.circulation.domain.RequestType) Test(org.junit.jupiter.api.Test)

Example 7 with RequestType

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));
}
Also used : RequestPolicyBuilder(api.support.builders.RequestPolicyBuilder) ArrayList(java.util.ArrayList) RequestType(org.folio.circulation.domain.RequestType)

Example 8 with RequestType

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);
}
Also used : RequestPolicyBuilder(api.support.builders.RequestPolicyBuilder) ArrayList(java.util.ArrayList) RequestType(org.folio.circulation.domain.RequestType)

Example 9 with RequestType

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"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) RequestBuilder(api.support.builders.RequestBuilder) ArrayList(java.util.ArrayList) IndividualResource(api.support.http.IndividualResource) RequestType(org.folio.circulation.domain.RequestType) Test(org.junit.jupiter.api.Test)

Example 10 with RequestType

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);
}
Also used : RequestType(org.folio.circulation.domain.RequestType)

Aggregations

RequestType (org.folio.circulation.domain.RequestType)10 ArrayList (java.util.ArrayList)6 IndividualResource (api.support.http.IndividualResource)5 Response (org.folio.circulation.support.http.client.Response)5 Test (org.junit.jupiter.api.Test)5 RequestBuilder (api.support.builders.RequestBuilder)4 JsonObject (io.vertx.core.json.JsonObject)4 MoveRequestBuilder (api.support.builders.MoveRequestBuilder)2 RequestPolicyBuilder (api.support.builders.RequestPolicyBuilder)2 ItemResource (api.support.http.ItemResource)2 JsonArray (io.vertx.core.json.JsonArray)2 APITests (api.support.APITests)1 TlrFeatureStatus (api.support.TlrFeatureStatus)1 Address (api.support.builders.Address)1 HoldingBuilder (api.support.builders.HoldingBuilder)1 ItemBuilder (api.support.builders.ItemBuilder)1 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)1 NoticeConfigurationBuilder (api.support.builders.NoticeConfigurationBuilder)1 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)1 OPEN_AWAITING_PICKUP (api.support.builders.RequestBuilder.OPEN_AWAITING_PICKUP)1