Search in sources :

Example 1 with RequestType

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);
}
Also used : RequestByInstanceIdRequest(org.folio.circulation.domain.representations.RequestByInstanceIdRequest) UpdateItem(org.folio.circulation.domain.UpdateItem) Item(org.folio.circulation.domain.Item) JsonObject(io.vertx.core.json.JsonObject) LinkedList(java.util.LinkedList) RequestType(org.folio.circulation.domain.RequestType)

Example 2 with RequestType

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"));
    });
}
Also used : Limit.limit(api.support.http.Limit.limit) Arrays(java.util.Arrays) ResponseStatusCodeMatcher.hasStatus(api.support.matchers.ResponseStatusCodeMatcher.hasStatus) ValidationErrorMatchers.hasNullParameter(api.support.matchers.ValidationErrorMatchers.hasNullParameter) AVAILABLE(org.folio.circulation.domain.ItemStatus.AVAILABLE) ZonedDateTime(java.time.ZonedDateTime) Matchers.not(org.hamcrest.Matchers.not) HTTP_BAD_REQUEST(org.folio.HttpStatus.HTTP_BAD_REQUEST) FakePubSub(api.support.fakes.FakePubSub) Arrays.asList(java.util.Arrays.asList) Address(api.support.builders.Address) Matchers.nullValue(org.hamcrest.Matchers.nullValue) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) ItemExamples(api.support.fixtures.ItemExamples) JsonObject(io.vertx.core.json.JsonObject) MAX_OUTSTANDING_FEE_FINE_BALANCE_MESSAGE(api.support.fixtures.AutomatedPatronBlocksFixture.MAX_OUTSTANDING_FEE_FINE_BALANCE_MESSAGE) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FakeModNotify(api.support.fakes.FakeModNotify) ValidationErrorMatchers.isBlockRelatedError(api.support.matchers.ValidationErrorMatchers.isBlockRelatedError) PatronNoticeMatcher.hasEmailNoticeProperties(api.support.matchers.PatronNoticeMatcher.hasEmailNoticeProperties) Stream(java.util.stream.Stream) OPEN_NOT_YET_FILLED(api.support.builders.RequestBuilder.OPEN_NOT_YET_FILLED) Matchers.contains(org.hamcrest.Matchers.contains) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) RequestStatus(org.folio.circulation.domain.RequestStatus) CqlQuery.notEqual(api.support.http.CqlQuery.notEqual) Awaitility(org.awaitility.Awaitility) HTTP_UNPROCESSABLE_ENTITY(org.folio.HttpStatus.HTTP_UNPROCESSABLE_ENTITY) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ValidationErrorMatchers.hasMessage(api.support.matchers.ValidationErrorMatchers.hasMessage) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ValidationErrorMatchers.hasUUIDParameter(api.support.matchers.ValidationErrorMatchers.hasUUIDParameter) ItemBuilder(api.support.builders.ItemBuilder) IndividualResource(api.support.http.IndividualResource) TextDateTimeMatcher.isEquivalentTo(api.support.matchers.TextDateTimeMatcher.isEquivalentTo) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) REQUEST_CREATED_THROUGH_OVERRIDE(org.folio.circulation.domain.representations.logs.LogEventType.REQUEST_CREATED_THROUGH_OVERRIDE) CheckInFixture(api.support.fixtures.CheckInFixture) JsonObjectMatcher.hasNoJsonPath(api.support.matchers.JsonObjectMatcher.hasNoJsonPath) ValueSource(org.junit.jupiter.params.provider.ValueSource) RequestType(org.folio.circulation.domain.RequestType) OPEN_AWAITING_PICKUP(api.support.builders.RequestBuilder.OPEN_AWAITING_PICKUP) UsersFixture(api.support.fixtures.UsersFixture) HoldingBuilder(api.support.builders.HoldingBuilder) UserBuilder(api.support.builders.UserBuilder) ValidationErrorMatchers.hasErrorWith(api.support.matchers.ValidationErrorMatchers.hasErrorWith) JsonArray(io.vertx.core.json.JsonArray) AfterEach(org.junit.jupiter.api.AfterEach) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Matchers.hasItem(org.hamcrest.Matchers.hasItem) FakePubSub.getPublishedEventsAsList(api.support.fakes.FakePubSub.getPublishedEventsAsList) MAX_NUMBER_OF_ITEMS_CHARGED_OUT_MESSAGE(api.support.fixtures.AutomatedPatronBlocksFixture.MAX_NUMBER_OF_ITEMS_CHARGED_OUT_MESSAGE) Matcher(org.hamcrest.Matcher) NullSource(org.junit.jupiter.params.provider.NullSource) PublishedEvents(api.support.fakes.PublishedEvents) CoreMatchers(org.hamcrest.CoreMatchers) Response(org.folio.circulation.support.http.client.Response) CheckOutResource(api.support.http.CheckOutResource) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) PublishedEvents.byEventType(api.support.fakes.PublishedEvents.byEventType) Matchers.emptyString(org.hamcrest.Matchers.emptyString) UserManualBlockBuilder(api.support.builders.UserManualBlockBuilder) APITests(api.support.APITests) ItemStatus(org.folio.circulation.domain.ItemStatus) UUIDMatcher.is(api.support.matchers.UUIDMatcher.is) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) NoticeEventType(org.folio.circulation.domain.notice.NoticeEventType) EmptySource(org.junit.jupiter.params.provider.EmptySource) Period(org.folio.circulation.domain.policy.Period) PublishedEvents.byLogEventType(api.support.fakes.PublishedEvents.byLogEventType) BlockOverridesUtils.buildOkapiHeadersWithPermissions(api.support.utl.BlockOverridesUtils.buildOkapiHeadersWithPermissions) JsonObjectMatcher.hasJsonPath(api.support.matchers.JsonObjectMatcher.hasJsonPath) PatronNoticeTestHelper.verifyNumberOfPublishedEvents(api.support.utl.PatronNoticeTestHelper.verifyNumberOfPublishedEvents) Collections.emptyList(java.util.Collections.emptyList) CqlQuery.exactMatch(api.support.http.CqlQuery.exactMatch) UUID(java.util.UUID) MoveRequestBuilder(api.support.builders.MoveRequestBuilder) ItemResource(api.support.http.ItemResource) Collectors(java.util.stream.Collectors) BlockOverrides(org.folio.circulation.domain.override.BlockOverrides) Test(org.junit.jupiter.api.Test) EventMatchers.isValidLoanDueDateChangedEvent(api.support.matchers.EventMatchers.isValidLoanDueDateChangedEvent) UserResource(api.support.http.UserResource) List(java.util.List) RECALL(org.folio.circulation.domain.RequestType.RECALL) ClockUtil(org.folio.circulation.support.utils.ClockUtil) Matchers.equalTo(org.hamcrest.Matchers.equalTo) LocalDate(java.time.LocalDate) UTC(java.time.ZoneOffset.UTC) Function.identity(java.util.function.Function.identity) HTTP_CREATED(org.folio.HttpStatus.HTTP_CREATED) RequestsFixture(api.support.fixtures.RequestsFixture) Period.hours(org.folio.circulation.domain.policy.Period.hours) IntStream(java.util.stream.IntStream) NOTICE(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE) CsvSource(org.junit.jupiter.params.provider.CsvSource) Offset.noOffset(api.support.http.Offset.noOffset) PAGED(org.folio.circulation.domain.ItemStatus.PAGED) HashMap(java.util.HashMap) EnumSource(org.junit.jupiter.params.provider.EnumSource) RequestBuilder(api.support.builders.RequestBuilder) OkapiHeaders(api.support.http.OkapiHeaders) ValidationErrorMatchers.hasParameter(api.support.matchers.ValidationErrorMatchers.hasParameter) NoticePolicyBuilder(api.support.builders.NoticePolicyBuilder) ValidationErrorMatchers.isInsufficientPermissionsToOverridePatronBlockError(api.support.matchers.ValidationErrorMatchers.isInsufficientPermissionsToOverridePatronBlockError) ValidationErrorMatchers.hasErrors(api.support.matchers.ValidationErrorMatchers.hasErrors) CoreMatchers.allOf(org.hamcrest.CoreMatchers.allOf) MultipleRecords(org.folio.circulation.domain.MultipleRecords) NOTICE_ERROR(org.folio.circulation.domain.representations.logs.LogEventType.NOTICE_ERROR) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) NoticeConfigurationBuilder(api.support.builders.NoticeConfigurationBuilder) Matchers(org.hamcrest.Matchers) ItemsFixture(api.support.fixtures.ItemsFixture) PatronNoticeTestHelper.verifyNumberOfSentNotices(api.support.utl.PatronNoticeTestHelper.verifyNumberOfSentNotices) TimeUnit(java.util.concurrent.TimeUnit) CALL_NUMBER_COMPONENTS(org.folio.circulation.domain.representations.ItemProperties.CALL_NUMBER_COMPONENTS) TlrFeatureStatus(api.support.TlrFeatureStatus) RequestLevel(org.folio.circulation.domain.RequestLevel) ResourceClient(api.support.http.ResourceClient) PatronBlockOverride(org.folio.circulation.domain.override.PatronBlockOverride) Collections(java.util.Collections) SECONDS(java.util.concurrent.TimeUnit.SECONDS) TemplateContextMatchers(api.support.fixtures.TemplateContextMatchers) DueDateManagement(org.folio.circulation.domain.policy.DueDateManagement) JsonObject(io.vertx.core.json.JsonObject) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Matchers.emptyString(org.hamcrest.Matchers.emptyString) IndividualResource(api.support.http.IndividualResource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with RequestType

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"))));
}
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 4 with RequestType

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"))));
}
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 5 with RequestType

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;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) 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