use of org.folio.circulation.domain.RequestType 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.RequestType in project mod-circulation by folio-org.
the class RequestsAPICreationTests method canFetchHundredRequests.
@Test
void canFetchHundredRequests() {
final List<IndividualResource> createdRequests = createOneHundredRequests();
final Map<String, JsonObject> foundRequests = requestsFixture.getRequests(exactMatch("requestType", "Page"), limit(100), noOffset()).stream().collect(Collectors.toMap(json -> json.getString("id"), identity()));
createdRequests.forEach(expectedRequest -> {
final JsonObject actualRequest = foundRequests.get(expectedRequest.getId().toString());
assertThat(actualRequest, notNullValue());
assertThat(actualRequest, hasJsonPath("requestType", "Page"));
assertThat(actualRequest, hasJsonPath("status", "Open - Not yet filled"));
});
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPolicyTests method cannotCreatePageRequestsWithRequestPolicyNotAllowingPagings.
@Test
void cannotCreatePageRequestsWithRequestPolicyNotAllowingPagings() {
final String anyNoticePolicy = noticePoliciesFixture.activeNotice().getId().toString();
final String nonCirculatingLoanTypePolicy = loanPoliciesFixture.canCirculateFixed().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.HOLD);
final String noPageRequestPolicy = requestPoliciesFixture.customRequestPolicy(allowedRequestTypes, "All But Page", "All but Page request policy").getId().toString();
final String rules = "priority: t, s, c, b, a, m, g " + "fallback-policy : l " + nonCirculatingLoanTypePolicy + " r " + noPageRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy;
setRules(rules);
// setting up a checked-out library item to attempt placing a PAGE request
final IndividualResource availableItem = itemsFixture.basedUponSmallAngryPlanet();
final Response pageResponse = requestsClient.attemptCreate(new RequestBuilder().page().forItem(availableItem).withPickupServicePointId(requestPickupServicePoint.getId()).by(// randomly picked James to represent "Any" patron
usersFixture.james()));
assertThat(pageResponse.getJson(), hasErrorWith(allOf(hasMessage("Page requests are not allowed for this patron and item combination"), hasParameter("requestType", "Page"))));
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPolicyTests method cannotCreateRecallRequestsWithRequestPolicyNotAllowingRecalls.
@Test
void cannotCreateRecallRequestsWithRequestPolicyNotAllowingRecalls() {
final String undergradPatronGroupPolicy = patronGroupsFixture.undergrad().getId().toString();
final String anyNoticePolicy = noticePoliciesFixture.activeNotice().getId().toString();
final String anyLoanPolicy = loanPoliciesFixture.canCirculateRolling().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.HOLD);
allowedRequestTypes.add(RequestType.PAGE);
final String noRecallRequestPolicy = requestPoliciesFixture.customRequestPolicy(allowedRequestTypes, "All But Recall", "All but Recall request policy").getId().toString();
// This rule is set up to show that the fallback policy won't be used but the patronGroup policy g is used instead.
// The patronGroup policy allows undergraduate students to place a request on any material type, loan or notice type, on any request type
// except for RECALL
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", "g " + undergradPatronGroupPolicy + ": l " + anyLoanPolicy + " r " + noRecallRequestPolicy + " n " + anyNoticePolicy + " o " + anyOverdueFinePolicy + " i " + anyLostItemFeePolicy);
setRules(rules);
// setting up a checked-out library item to perform recall
final IndividualResource checkedOutItem = itemsFixture.basedUponSmallAngryPlanet();
checkOutFixture.checkOutByBarcode(checkedOutItem, usersFixture.jessica());
final Response recallResponse = requestsClient.attemptCreate(new RequestBuilder().recall().forItem(checkedOutItem).withPickupServicePointId(requestPickupServicePoint.getId()).by(usersFixture.undergradHenry()));
assertThat(recallResponse.getJson(), hasErrorWith(allOf(hasMessage("Recall requests are not allowed for this patron and item combination"), hasParameter("requestType", "Recall"))));
}
use of org.folio.circulation.domain.RequestType in project mod-circulation by folio-org.
the class RequestPolicyBuilder method create.
@Override
public JsonObject create() {
JsonObject requestPolicy = new JsonObject();
if (id != null) {
put(requestPolicy, "id", id.toString());
}
put(requestPolicy, "name", this.name);
put(requestPolicy, "description", this.description);
JsonArray requestTypes = new JsonArray();
for (RequestType t : types) {
requestTypes.add(t.getValue());
}
put(requestPolicy, "requestTypes", requestTypes);
return requestPolicy;
}
Aggregations