Skip to content

Commit

Permalink
Merge branch 'ecs-tlr-feature' into CIRC-1980-for-rancher
Browse files Browse the repository at this point in the history
  • Loading branch information
Maksat-Galymzhan committed Jul 5, 2024
2 parents a0a7a2f + ea17564 commit 932707d
Show file tree
Hide file tree
Showing 64 changed files with 1,220 additions and 354 deletions.
67 changes: 58 additions & 9 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@
"methods": ["POST"],
"pathPattern": "/circulation/loans/{id}/change-due-date",
"permissionsRequired": [
"circulation.loans.change-due-date.post",
"configuration.entries.collection.get"
"circulation.loans.change-due-date.post"
],
"modulePermissions": [
"modperms.circulation.loans.change-due-date.post"
Expand Down Expand Up @@ -167,6 +166,22 @@
}
]
},
{
"id": "instance-items",
"version": "0.1",
"handlers": [
{
"methods": ["GET"],
"pathPattern": "/circulation/items-by-instance",
"permissionsRequired": [
"circulation.items-by-instance.get"
],
"modulePermissions": [
"search.instances.collection.get"
]
}
]
},
{
"id": "add-info",
"version": "0.1",
Expand Down Expand Up @@ -649,7 +664,7 @@
},
{
"id": "allowed-service-points",
"version": "1.0",
"version": "1.2",
"handlers": [
{
"methods": [
Expand Down Expand Up @@ -677,7 +692,10 @@
"inventory-storage.instances.item.get",
"inventory-storage.instances.collection.get",
"configuration.entries.item.get",
"configuration.entries.collection.get"
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation"
]
}
]
Expand Down Expand Up @@ -1577,6 +1595,11 @@
"displayName": "circulation settings - Read configuration",
"description": "To read the configuration from mod settings."
},
{
"permissionName": "circulation.items-by-instance.get",
"displayName": "circulation - get items by instance",
"description": "get items by instance"
},
{
"permissionName": "circulation.settings.collection.get",
"displayName": "circulation - get circulation settings",
Expand Down Expand Up @@ -1643,7 +1666,8 @@
"circulation.requests.allowed-service-points.get",
"circulation.inventory.items-in-transit-report.get",
"circulation.pick-slips.get",
"circulation.search-slips.get"
"circulation.search-slips.get",
"circulation.items-by-instance.get"
]
},
{
Expand Down Expand Up @@ -1747,6 +1771,9 @@
"proxiesfor.collection.get",
"patron-notice.post",
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation",
"calendar.endpoint.dates.get",
"pubsub.publish.post",
"circulation-storage.loans-history.collection.get"
Expand Down Expand Up @@ -1800,7 +1827,8 @@
"checkout-lock-storage.checkout-locks.item.delete",
"mod-settings.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.global.read.mod-circulation"
"mod-settings.global.read.mod-circulation",
"mod-settings.global.read.circulation"
],
"visible": false
},
Expand Down Expand Up @@ -1861,7 +1889,10 @@
"actual-cost-fee-fine-cancel.post",
"departments.item.get",
"departments.collection.get",
"circulation-storage.loans-history.collection.get"
"circulation-storage.loans-history.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation"
],
"visible": false
},
Expand Down Expand Up @@ -1893,6 +1924,9 @@
"proxiesfor.collection.get",
"calendar.endpoint.dates.get",
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation",
"scheduled-notice-storage.scheduled-notices.collection.delete",
"scheduled-notice-storage.scheduled-notices.item.post",
"patron-notice.post",
Expand Down Expand Up @@ -2077,6 +2111,9 @@
"scheduled-notice-storage.scheduled-notices.collection.delete",
"scheduled-notice-storage.scheduled-notices.item.post",
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation",
"manualblocks.collection.get",
"pubsub.publish.post",
"automated-patron-blocks.collection.get",
Expand Down Expand Up @@ -2157,6 +2194,9 @@
"proxiesfor.collection.get",
"patron-notice.post",
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation",
"scheduled-notice-storage.scheduled-notices.collection.delete",
"scheduled-notice-storage.scheduled-notices.item.post",
"pubsub.publish.post",
Expand Down Expand Up @@ -2200,7 +2240,10 @@
"addresstypes.collection.get",
"usergroups.collection.get",
"usergroups.item.get",
"pubsub.publish.post"
"pubsub.publish.post",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation"
],
"visible": false
},
Expand Down Expand Up @@ -2235,6 +2278,9 @@
"patron-notice.post",
"calendar.endpoint.dates.get",
"configuration.entries.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation",
"scheduled-notice-storage.scheduled-notices.collection.delete",
"scheduled-notice-storage.scheduled-notices.item.post",
"manualblocks.collection.get",
Expand Down Expand Up @@ -2293,7 +2339,10 @@
"addresstypes.collection.get",
"pubsub.publish.post",
"patron-notice.post",
"circulation-storage.loans-history.collection.get"
"circulation-storage.loans-history.collection.get",
"mod-settings.entries.item.get",
"mod-settings.entries.collection.get",
"mod-settings.global.read.circulation"
],
"visible": false
},
Expand Down
10 changes: 9 additions & 1 deletion ramls/circulation.raml
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,14 @@ resourceTypes:
description: "Instance ID"
pattern: "^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[1-5][a-fA-F0-9]{3}-[89abAB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$"
required: false
useStubItem:
description: "When true, allows to apply circulation rules based on patron group only"
type: boolean
required: false
ecsRequestRouting:
description: "When true, returns only service points with ecsRequestRouting"
type: boolean
required: false
responses:
200:
description: "List of allowed service points was retrieved successfully"
Expand All @@ -364,4 +372,4 @@ resourceTypes:
description: "Internal server error"
body:
text/plain:
example: "Internal server error"
example: "Internal server error"
2 changes: 2 additions & 0 deletions src/main/java/org/folio/circulation/CirculationVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.folio.circulation.resources.FeeFineNotRealTimeScheduledNoticeProcessingResource;
import org.folio.circulation.resources.FeeFineScheduledNoticeProcessingResource;
import org.folio.circulation.resources.HealthResource;
import org.folio.circulation.resources.ItemsByInstanceResource;
import org.folio.circulation.resources.ItemsInTransitResource;
import org.folio.circulation.resources.LoanAnonymizationResource;
import org.folio.circulation.resources.LoanCirculationRulesEngineResource;
Expand Down Expand Up @@ -93,6 +94,7 @@ public void start(Promise<Void> startFuture) {
new RequestCollectionResource(client).register(router);
new RequestQueueResource(client).register(router);
new RequestByInstanceIdResource(client).register(router);
new ItemsByInstanceResource(client).register(router);

new RequestHoldShelfClearanceResource(
"/circulation/requests-reports/hold-shelf-clearance/:servicePointId", client)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class AllowedServicePointsRequest {
private String requesterId;
private String instanceId;
private String itemId;
private String requestId;
private boolean useStubItem;
private boolean ecsRequestRouting;

public boolean isForTitleLevelRequest() {
return instanceId != null;
Expand All @@ -27,7 +30,6 @@ public boolean isForTitleLevelRequest() {
public boolean isForItemLevelRequest() {
return itemId != null;
}
private String requestId;

public AllowedServicePointsRequest updateWithRequestInformation(Request request) {
log.debug("updateWithRequestInformation:: parameters request: {}", request);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/folio/circulation/domain/Item.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,4 +415,15 @@ public String getLendingLibraryCode() {
public String getDcbItemTitle() {
return getProperty(itemRepresentation, "instanceTitle");
}

public String getTenantId() {
return getProperty(itemRepresentation, "tenantId");
}

public Item changeTenantId(String tenantId) {
if (itemRepresentation != null) {
write(itemRepresentation, "tenantId", tenantId);
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.validation.RequestLoanValidator;
import org.folio.circulation.infrastructure.storage.ConfigurationRepository;
import org.folio.circulation.infrastructure.storage.SettingsRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestPolicyRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestQueueRepository;
import org.folio.circulation.infrastructure.storage.requests.RequestRepository;
Expand All @@ -27,13 +28,14 @@ public class MoveRequestService {
private final ConfigurationRepository configurationRepository;
private final EventPublisher eventPublisher;
private final RequestQueueRepository requestQueueRepository;
private final SettingsRepository settingsRepository;
private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());

public MoveRequestService(RequestRepository requestRepository, RequestPolicyRepository requestPolicyRepository,
UpdateUponRequest updateUponRequest, MoveRequestProcessAdapter moveRequestHelper,
RequestLoanValidator requestLoanValidator, RequestNoticeSender requestNoticeSender,
ConfigurationRepository configurationRepository, EventPublisher eventPublisher,
RequestQueueRepository requestQueueRepository) {
RequestQueueRepository requestQueueRepository, SettingsRepository settingsRepository) {

this.requestRepository = requestRepository;
this.requestPolicyRepository = requestPolicyRepository;
Expand All @@ -44,11 +46,12 @@ public MoveRequestService(RequestRepository requestRepository, RequestPolicyRepo
this.configurationRepository = configurationRepository;
this.eventPublisher = eventPublisher;
this.requestQueueRepository = requestQueueRepository;
this.settingsRepository = settingsRepository;
}

public CompletableFuture<Result<RequestAndRelatedRecords>> moveRequest(
RequestAndRelatedRecords requestAndRelatedRecords, Request originalRequest) {
return configurationRepository.lookupTlrSettings()
return settingsRepository.lookupTlrSettings()
.thenApply(r -> r.map(requestAndRelatedRecords::withTlrSettings))
.thenApply(r -> r.next(RequestServiceUtility::refuseTlrProcessingWhenFeatureIsDisabled))
.thenApply(r -> r.next(records -> RequestServiceUtility.refuseMovingToOrFromHoldTlr(records,
Expand Down
50 changes: 50 additions & 0 deletions src/main/java/org/folio/circulation/domain/SearchInstance.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.folio.circulation.domain;

import static org.folio.circulation.support.json.JsonObjectArrayPropertyFetcher.mapToList;
import static org.folio.circulation.support.json.JsonPropertyWriter.write;

import java.lang.invoke.MethodHandles;
import java.util.Collection;
import java.util.List;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.domain.representations.ItemSummaryRepresentation;
import org.folio.circulation.storage.mappers.ItemMapper;

import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import lombok.NonNull;
import lombok.ToString;
import lombok.Value;

@Value
@ToString(onlyExplicitlyIncluded = true)
public class SearchInstance {

private static final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());
JsonObject representation;
String id;
@NonNull Collection<Item> items;

public static SearchInstance from(JsonObject representation) {
return new SearchInstance(representation, representation.getString("id"), mapItems(representation));
}

private static List<Item> mapItems(JsonObject representation) {
return mapToList(representation, "items", new ItemMapper()::toDomain);
}

public SearchInstance changeItems(Collection<Item> items) {
JsonArray itemsArray = new JsonArray();
for (Item item : items) {
itemsArray.add(new ItemSummaryRepresentation().createItemSummary(item));
}
write(representation, "items", itemsArray);
return new SearchInstance(representation, id, items);
}

public JsonObject toJson() {
return representation;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public JsonObject createItemSummary(Item item) {
write(itemSummary, "copyNumber", item.getCopyNumber());
write(itemSummary, CALL_NUMBER_COMPONENTS,
createCallNumberComponents(item.getCallNumberComponents()));
write(itemSummary, "tenantId", item.getTenantId());

JsonObject status = new JsonObject()
.put("name", item.getStatus().getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.folio.circulation.domain.ConfigurationService;
import org.folio.circulation.domain.MultipleRecords;
import org.folio.circulation.domain.anonymization.config.LoanAnonymizationConfiguration;
import org.folio.circulation.domain.configuration.TlrSettingsConfiguration;
import org.folio.circulation.support.Clients;
import org.folio.circulation.support.GetManyRecordsClient;
import org.folio.circulation.support.http.client.CqlQuery;
Expand Down Expand Up @@ -49,13 +48,6 @@ public CompletableFuture<Result<Integer>> lookupSessionTimeout() {
return lookupConfigurations(otherSettingsQuery, applySessionTimeout());
}

public CompletableFuture<Result<TlrSettingsConfiguration>> lookupTlrSettings() {
Result<CqlQuery> queryResult = defineModuleNameAndConfigNameFilter(
"SETTINGS", "TLR");

return findAndMapFirstConfiguration(queryResult, TlrSettingsConfiguration::from);
}

/**
* Gets loan history tenant configuration - settings for loan anonymization
*
Expand Down Expand Up @@ -123,26 +115,4 @@ private Function<MultipleRecords<Configuration>, Integer> applySessionTimeout()
.findSessionTimeout(configurations.getRecords());
}

/**
* Find first configuration and maps it to an object with a provided mapper
*/
private <T> CompletableFuture<Result<T>> findAndMapFirstConfiguration(
Result<CqlQuery> cqlQueryResult, Function<JsonObject, T> mapper) {

return cqlQueryResult
.after(query -> configurationClient.getMany(query, DEFAULT_PAGE_LIMIT))
.thenApply(result -> result.next(r -> from(r, Configuration::new, CONFIGS_KEY)))
.thenApply(result -> result.map(this::findFirstConfigurationAsJsonObject))
.thenApply(result -> result.map(mapper));
}

private JsonObject findFirstConfigurationAsJsonObject(
MultipleRecords<Configuration> configurations) {

return configurations.getRecords().stream()
.findFirst()
.map(Configuration::getValue)
.map(JsonObject::new)
.orElse(new JsonObject());
}
}
Loading

0 comments on commit 932707d

Please sign in to comment.