Search in sources :

Example 1 with REQUEST_LEVEL

use of org.folio.circulation.domain.representations.RequestProperties.REQUEST_LEVEL in project mod-circulation by folio-org.

the class RequestFromRepresentationService method validateRequestLevel.

private Result<Request> validateRequestLevel(Request request) {
    JsonObject representation = request.getRequestRepresentation();
    String requestLevelRaw = representation.getString(REQUEST_LEVEL);
    RequestLevel requestLevel = RequestLevel.from(requestLevelRaw);
    boolean tlrEnabled = request.getTlrSettingsConfiguration().isTitleLevelRequestsFeatureEnabled();
    List<RequestLevel> allowedStatuses = tlrEnabled ? List.of(ITEM, TITLE) : List.of(ITEM);
    if (!allowedStatuses.contains(requestLevel)) {
        String allowedStatusesJoined = allowedStatuses.stream().map(existingLevel -> StringUtils.wrap(existingLevel.getValue(), '"')).collect(Collectors.joining(", "));
        return failedValidation("requestLevel must be one of the following: " + allowedStatusesJoined, "requestLevel", requestLevelRaw);
    }
    return succeeded(request);
}
Also used : UserRepository(org.folio.circulation.infrastructure.storage.users.UserRepository) INSTANCE_DOES_NOT_EXIST(org.folio.circulation.resources.handlers.error.CirculationErrorType.INSTANCE_DOES_NOT_EXIST) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) JsonPropertyFetcher.getDateTimeProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getDateTimeProperty) ConfigurationRepository(org.folio.circulation.infrastructure.storage.ConfigurationRepository) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) MappingFunctions.when(org.folio.circulation.support.results.MappingFunctions.when) RequestQueueRepository(org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository) ItemStatus(org.folio.circulation.domain.ItemStatus) StringUtils(org.apache.commons.lang3.StringUtils) Item(org.folio.circulation.domain.Item) REQUEST_LEVEL(org.folio.circulation.domain.representations.RequestProperties.REQUEST_LEVEL) ServicePointRepository(org.folio.circulation.infrastructure.storage.ServicePointRepository) Map(java.util.Map) JsonObject(io.vertx.core.json.JsonObject) ItemRepository(org.folio.circulation.infrastructure.storage.inventory.ItemRepository) REQUEST_DATE(org.folio.circulation.domain.representations.RequestProperties.REQUEST_DATE) Result.of(org.folio.circulation.support.results.Result.of) AsynchronousResult.fromFutureResult(org.folio.circulation.support.results.AsynchronousResult.fromFutureResult) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) Collection(java.util.Collection) Loan(org.folio.circulation.domain.Loan) ATTEMPT_TO_CREATE_TLR_LINKED_TO_AN_ITEM(org.folio.circulation.resources.handlers.error.CirculationErrorType.ATTEMPT_TO_CREATE_TLR_LINKED_TO_AN_ITEM) INVALID_INSTANCE_ID(org.folio.circulation.resources.handlers.error.CirculationErrorType.INVALID_INSTANCE_ID) PageLimit.limit(org.folio.circulation.support.http.client.PageLimit.limit) UUID(java.util.UUID) Result(org.folio.circulation.support.results.Result) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) INVALID_ITEM_ID(org.folio.circulation.resources.handlers.error.CirculationErrorType.INVALID_ITEM_ID) ServicePointPickupLocationValidator(org.folio.circulation.domain.validation.ServicePointPickupLocationValidator) List(java.util.List) StringUtils.isNotBlank(org.apache.commons.lang3.StringUtils.isNotBlank) TITLE(org.folio.circulation.domain.RequestLevel.TITLE) InstanceRepository(org.folio.circulation.infrastructure.storage.inventory.InstanceRepository) RequestStatus(org.folio.circulation.domain.RequestStatus) Optional(java.util.Optional) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) Request(org.folio.circulation.domain.Request) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) ATTEMPT_HOLD_OR_RECALL_TLR_FOR_AVAILABLE_ITEM(org.folio.circulation.resources.handlers.error.CirculationErrorType.ATTEMPT_HOLD_OR_RECALL_TLR_FOR_AVAILABLE_ITEM) ITEM(org.folio.circulation.domain.RequestLevel.ITEM) INVALID_HOLDINGS_RECORD_ID(org.folio.circulation.resources.handlers.error.CirculationErrorType.INVALID_HOLDINGS_RECORD_ID) RequestAndRelatedRecords(org.folio.circulation.domain.RequestAndRelatedRecords) String.join(java.lang.String.join) PageLimit(org.folio.circulation.support.http.client.PageLimit) INSTANCE_ID(org.folio.circulation.domain.representations.RequestProperties.INSTANCE_ID) Result.failed(org.folio.circulation.support.results.Result.failed) INVALID_PICKUP_SERVICE_POINT(org.folio.circulation.resources.handlers.error.CirculationErrorType.INVALID_PICKUP_SERVICE_POINT) MultipleRecords(org.folio.circulation.domain.MultipleRecords) RequestFulfilmentPreference(org.folio.circulation.domain.RequestFulfilmentPreference) ItemByInstanceIdFinder(org.folio.circulation.storage.ItemByInstanceIdFinder) NO_AVAILABLE_ITEMS_FOR_TLR(org.folio.circulation.resources.handlers.error.CirculationErrorType.NO_AVAILABLE_ITEMS_FOR_TLR) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) ITEM_ID(org.folio.circulation.domain.representations.RequestProperties.ITEM_ID) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) User(org.folio.circulation.domain.User) Collectors.toList(java.util.stream.Collectors.toList) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) RequestLevel(org.folio.circulation.domain.RequestLevel) ProxyRelationshipValidator(org.folio.circulation.domain.validation.ProxyRelationshipValidator) INVALID_PROXY_RELATIONSHIP(org.folio.circulation.resources.handlers.error.CirculationErrorType.INVALID_PROXY_RELATIONSHIP) AllArgsConstructor(lombok.AllArgsConstructor) JsonPropertyFetcher.getProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getProperty) RequestLevel(org.folio.circulation.domain.RequestLevel) JsonObject(io.vertx.core.json.JsonObject)

Aggregations

JsonObject (io.vertx.core.json.JsonObject)1 String.join (java.lang.String.join)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 Collectors (java.util.stream.Collectors)1 Collectors.toList (java.util.stream.Collectors.toList)1 AllArgsConstructor (lombok.AllArgsConstructor)1 StringUtils (org.apache.commons.lang3.StringUtils)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 StringUtils.isNotBlank (org.apache.commons.lang3.StringUtils.isNotBlank)1 Item (org.folio.circulation.domain.Item)1 ItemStatus (org.folio.circulation.domain.ItemStatus)1 Loan (org.folio.circulation.domain.Loan)1