Skip to content

Commit

Permalink
[CIRC-1845] Release v23.5.5 (#1302)
Browse files Browse the repository at this point in the history
* working version of new timed rules cache

(cherry picked from commit 38841b6)

* working changes for check in and check out

(cherry picked from commit 941de6e)

* tests passing

(cherry picked from commit 6da9625)

* code cleanup

(cherry picked from commit 92abe63)

* making rules object thread-safe

(cherry picked from commit 6fd4275)

* now clearing only tenant cache

(cherry picked from commit e8897dd)

* removing source of code smell

(cherry picked from commit 7773c95)

* moving reload to stand-alone endpoint

(cherry picked from commit 7c54fd3)

* working test of new endpoint

(cherry picked from commit 24b7f9f)

* code cleanup

(cherry picked from commit 17d598f)

* incorporating review comments

(cherry picked from commit 9722702)

* Reload rules when new rules are submitted

(cherry picked from commit 83d9f8d)

* Extract method for getting rules as text CIRC-1783

(cherry picked from commit 58ef216)

* Reduce duplication when reloading rules CIRC-1783

(cherry picked from commit 69e9001)

* incorporating review comments

(cherry picked from commit 0f43b8c)

* review feedback

(cherry picked from commit 423d9d4)

* adding logging to timer endpoint

(cherry picked from commit 2639b21)

* changing log level to debug

(cherry picked from commit 9958e92)

* removing completeablefuture

(cherry picked from commit f3203c3)

* fixing code smells

* Update NEWS

* [maven-release-plugin] prepare release v23.5.5

* [maven-release-plugin] prepare for next development iteration

---------

Co-authored-by: felkerk <[email protected]>
Co-authored-by: Marc Johnson <[email protected]>
  • Loading branch information
3 people authored Jul 3, 2023
1 parent 8e74b85 commit 491772d
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 153 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 23.5.5 2023-07-03

* Circulation rules decoupling and timer-based refresh enhancement (CIRC-1783)

## 23.5.4 2023-03-29

* Only notify patron for recalls that change due date (CIRC-1747)
Expand Down
11 changes: 11 additions & 0 deletions descriptors/ModuleDescriptor-template.json
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,17 @@
"version": "1.0",
"interfaceType": "system",
"handlers": [
{
"methods": [
"POST"
],
"pathPattern": "/circulation/rules-reload",
"modulePermissions": [
"circulation.rules.get"
],
"unit": "minute",
"delay": "3"
},
{
"methods": [
"POST"
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>mod-circulation</artifactId>
<groupId>org.folio</groupId>
<version>23.5.5-SNAPSHOT</version>
<version>23.5.6-SNAPSHOT</version>
<licenses>
<license>
<name>Apache License 2.0</name>
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/folio/circulation/CirculationVerticle.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.folio.circulation.resources.ChangeDueDateResource;
import org.folio.circulation.resources.CheckInByBarcodeResource;
import org.folio.circulation.resources.CheckOutByBarcodeResource;
import org.folio.circulation.resources.CirculationRulesReloadResource;
import org.folio.circulation.resources.CirculationRulesResource;
import org.folio.circulation.resources.ClaimItemReturnedResource;
import org.folio.circulation.resources.DeclareClaimedReturnedItemAsMissingResource;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void start(Promise<Void> startFuture) {

new CirculationRulesResource("/circulation/rules", client)
.register(router);
new CirculationRulesReloadResource("/circulation/rules-reload", client)
.register(router);
new LoanCirculationRulesEngineResource(
"/circulation/rules/loan-policy",
"/circulation/rules/loan-policy-all", client)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.folio.circulation.resources;

import static org.folio.circulation.support.results.MappingFunctions.toFixedValue;

import java.lang.invoke.MethodHandles;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.folio.circulation.rules.cache.CirculationRulesCache;
import org.folio.circulation.support.Clients;
import org.folio.circulation.support.http.server.NoContentResponse;
import org.folio.circulation.support.http.server.WebContext;
import org.folio.circulation.support.results.CommonFailures;

import io.vertx.core.http.HttpClient;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

/**
* Write and read the circulation rules.
*/
public class CirculationRulesReloadResource extends Resource {
private final Logger log = LogManager.getLogger(MethodHandles.lookup().lookupClass());
private final String rootPath;

/**
* Set the URL path.
* @param rootPath URL path
* @param client HTTP client
*/
public CirculationRulesReloadResource(String rootPath, HttpClient client) {
super(client);
this.rootPath = rootPath;
}

/**
* Register the path set in the constructor.
* @param router where to register
*/
@Override
public void register(Router router) {
router.post(rootPath).handler(this::reload);
}

private void reload(RoutingContext routingContext) {
log.debug("reload:: starting reload of circulation rules");
final WebContext context = new WebContext(routingContext);
CirculationRulesCache.getInstance().reloadRules(context.getTenantId(),
Clients.create(context, client).circulationRulesStorage())
.thenApply(r -> {
if(r.failed()) {
log.debug("reload:: reload failed: {}", r.cause());
} else {
log.debug("reload:: reload succeeded.");
}
return r.map(toFixedValue(NoContentResponse::noContent));
})
.exceptionally(CommonFailures::failedDueToServerError)
.thenAccept(context::writeResultToHttpResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.mapping;
import static java.util.stream.Collectors.toSet;

import static org.apache.commons.collections4.CollectionUtils.isNotEmpty;
import static org.apache.commons.lang3.exception.ExceptionUtils.getStackTrace;
import static org.folio.circulation.support.http.server.JsonHttpResponse.ok;
Expand Down Expand Up @@ -130,10 +131,12 @@ private void proceedWithUpdate(Map<String, Set<String>> existingPoliciesIds,
final WebContext webContext = new WebContext(routingContext);

JsonObject rulesInput;
String rulesAsText;
try {
// try to convert, do not safe if conversion fails
rulesInput = routingContext.getBodyAsJson();
Text2Drools.convert(rulesInput.getString("rulesAsText"),
rulesAsText = getRulesAsText(rulesInput);
Text2Drools.convert(rulesAsText,
(policyType, policies, token) -> validatePolicy(
existingPoliciesIds, policyType, policies, token));
} catch (CirculationRulesException e) {
Expand All @@ -149,10 +152,10 @@ private void proceedWithUpdate(Map<String, Set<String>> existingPoliciesIds,

clients.circulationRulesStorage().put(rulesInput.copy())
.thenApply(this::failWhenResponseOtherThanNoContent)
.thenApply(result -> result.map(response -> CirculationRulesCache.getInstance()
.reloadRules(webContext.getTenantId(), rulesAsText)))
.thenApply(result -> result.map(response -> noContent()))
.thenAccept(webContext::writeResultToHttpResponse);

CirculationRulesCache.getInstance().clearCache(webContext.getTenantId());
}

private Result<Response> failWhenResponseOtherThanNoContent(Result<Response> result) {
Expand All @@ -161,6 +164,10 @@ private Result<Response> failWhenResponseOtherThanNoContent(Result<Response> res
ForwardOnFailure::new);
}

private static String getRulesAsText(JsonObject rulesInput) {
return rulesInput.getString("rulesAsText");
}

private void validatePolicy(Map<String, Set<String>> existingPoliciesIds,
String policyType, List<CirculationRulesParser.PolicyContext> policies, Token token) {

Expand Down
Loading

0 comments on commit 491772d

Please sign in to comment.