From ca97a3754454cc13891a91a060be51df6c798139 Mon Sep 17 00:00:00 2001 From: xurror Date: Sat, 13 Jun 2020 08:56:39 +0100 Subject: [PATCH] FINERACT-1022 - Update to org.ehcache --- fineract-provider/build.gradle | 3 ++- fineract-provider/dependencies.gradle | 7 ++++++- .../basicauth/application.properties | 1 + .../basicauth/twofactor/application.properties | 1 + .../properties/oauth/application.properties | 3 ++- .../oauth/twofactor/application.properties | 1 + .../service/RuntimeDelegatingCacheManager.java | 18 +++++++++++------- .../monetary/domain/MoneyHelper.java | 4 ++-- .../loanproduct/data/LoanProductData.java | 6 +++--- .../main/resources/META-INF/spring/cache.xml | 5 ++--- .../main/resources/META-INF/spring/ehcache.xml | 7 ++++--- 11 files changed, 35 insertions(+), 21 deletions(-) diff --git a/fineract-provider/build.gradle b/fineract-provider/build.gradle index b5b064f8d..14664b527 100644 --- a/fineract-provider/build.gradle +++ b/fineract-provider/build.gradle @@ -94,7 +94,7 @@ dependencyManagement { dependency 'org.flywaydb:flyway-core:6.4.4' dependency 'org.quartz-scheduler:quartz:2.3.2' dependency 'com.amazonaws:aws-java-sdk-s3:1.11.800' - dependency 'net.sf.ehcache:ehcache:2.10.6' // TODO FINERACT-1018 + dependency 'org.ehcache:ehcache:3.8.1' dependency 'com.github.spullara.mustache.java:compiler:0.9.6' dependency 'com.jayway.jsonpath:json-path:2.4.0' dependency 'org.apache.tika:tika-core:1.24.1' @@ -110,6 +110,7 @@ dependencyManagement { dependency 'io.github.classgraph:classgraph:4.8.85' dependency 'org.awaitility:awaitility:4.0.3' dependency 'com.github.spotbugs:spotbugs-annotations:4.0.4' + dependency 'javax.cache:cache-api:1.1.1' dependency ('org.dom4j:dom4j:2.1.3') { exclude 'relaxngDatatype:relaxngDatatype' // already in com.sun.xml.bind:jaxb-osgi:2.3.0.1 diff --git a/fineract-provider/dependencies.gradle b/fineract-provider/dependencies.gradle index 1de39f9ed..81ae52b25 100644 --- a/fineract-provider/dependencies.gradle +++ b/fineract-provider/dependencies.gradle @@ -33,6 +33,7 @@ dependencies { 'org.springframework.boot:spring-boot-starter-web', 'org.springframework.boot:spring-boot-starter-security', + 'org.springframework.boot:spring-boot-starter-cache', 'org.springframework:spring-jms', 'org.springframework:spring-context-support', @@ -65,7 +66,6 @@ dependencies { 'org.drizzle.jdbc:drizzle-jdbc', 'org.flywaydb:flyway-core', - 'net.sf.ehcache:ehcache', 'com.github.librepdf:openpdf', 'com.github.spullara.mustache.java:compiler', 'com.jayway.jsonpath:json-path', @@ -74,6 +74,8 @@ dependencies { 'jakarta.xml.bind:jakarta.xml.bind-api', 'org.dom4j:dom4j', + 'javax.cache:cache-api', + 'com.github.spotbugs:spotbugs-annotations', ) implementation ('io.swagger:swagger-jersey-jaxrs') { @@ -98,6 +100,9 @@ dependencies { implementation ('org.mnode.ical4j:ical4j') { exclude group: 'commons-logging' } + implementation ('org.ehcache:ehcache') { + exclude group: 'org.glassfish.jaxb', module: 'jaxb-runtime' + } // runtimeOnly dependencies are things that Fineract code has no direct compile time dependency on, but which must be present at run-time runtimeOnly( diff --git a/fineract-provider/properties/basicauth/application.properties b/fineract-provider/properties/basicauth/application.properties index 64e5421f6..406e6b70d 100644 --- a/fineract-provider/properties/basicauth/application.properties +++ b/fineract-provider/properties/basicauth/application.properties @@ -25,3 +25,4 @@ management.info.git.mode=FULL # FINERACT-914 server.forward-headers-strategy=framework +spring.cache.jcache.config=classpath:/META-INF/spring/ehcache.xml diff --git a/fineract-provider/properties/basicauth/twofactor/application.properties b/fineract-provider/properties/basicauth/twofactor/application.properties index a9b13cc5e..43cb20bba 100644 --- a/fineract-provider/properties/basicauth/twofactor/application.properties +++ b/fineract-provider/properties/basicauth/twofactor/application.properties @@ -26,3 +26,4 @@ management.info.git.mode=FULL # FINERACT-914 server.forward-headers-strategy=framework +spring.cache.jcache.config=classpath:/META-INF/spring/ehcache.xml diff --git a/fineract-provider/properties/oauth/application.properties b/fineract-provider/properties/oauth/application.properties index 02419415e..881ad0e8c 100644 --- a/fineract-provider/properties/oauth/application.properties +++ b/fineract-provider/properties/oauth/application.properties @@ -25,4 +25,5 @@ management.health.jms.enabled=false management.info.git.mode=FULL # FINERACT-914 -server.forward-headers-strategy=framework \ No newline at end of file +server.forward-headers-strategy=framework +spring.cache.jcache.config=classpath:/META-INF/spring/ehcache.xml \ No newline at end of file diff --git a/fineract-provider/properties/oauth/twofactor/application.properties b/fineract-provider/properties/oauth/twofactor/application.properties index 562fbd3ae..4e4ecd39f 100644 --- a/fineract-provider/properties/oauth/twofactor/application.properties +++ b/fineract-provider/properties/oauth/twofactor/application.properties @@ -26,3 +26,4 @@ management.info.git.mode=FULL # FINERACT-914 server.forward-headers-strategy=framework +spring.cache.jcache.config=classpath:/META-INF/spring/ehcache.xml diff --git a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/service/RuntimeDelegatingCacheManager.java b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/service/RuntimeDelegatingCacheManager.java index 424680749..db9309406 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/service/RuntimeDelegatingCacheManager.java +++ b/fineract-provider/src/main/java/org/apache/fineract/infrastructure/cache/service/RuntimeDelegatingCacheManager.java @@ -30,7 +30,7 @@ import org.apache.fineract.infrastructure.core.data.EnumOptionData; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; -import org.springframework.cache.ehcache.EhCacheCacheManager; +import org.springframework.cache.jcache.JCacheCacheManager; import org.springframework.cache.support.NoOpCacheManager; import org.springframework.stereotype.Component; @@ -45,13 +45,13 @@ import org.springframework.stereotype.Component; @Component(value = "runtimeDelegatingCacheManager") public class RuntimeDelegatingCacheManager implements CacheManager { - private final EhCacheCacheManager ehcacheCacheManager; + private final JCacheCacheManager jcacheCacheManager; private final CacheManager noOpCacheManager = new NoOpCacheManager(); private CacheManager currentCacheManager; @Autowired - public RuntimeDelegatingCacheManager(final EhCacheCacheManager ehcacheCacheManager) { - this.ehcacheCacheManager = ehcacheCacheManager; + public RuntimeDelegatingCacheManager(final JCacheCacheManager jcacheCacheManager) { + this.jcacheCacheManager = jcacheCacheManager; this.currentCacheManager = this.noOpCacheManager; } @@ -68,7 +68,7 @@ public class RuntimeDelegatingCacheManager implements CacheManager { public Collection retrieveAll() { final boolean noCacheEnabled = this.currentCacheManager instanceof NoOpCacheManager; - final boolean ehcacheEnabled = this.currentCacheManager instanceof EhCacheCacheManager; + final boolean ehcacheEnabled = this.currentCacheManager instanceof JCacheCacheManager; // final boolean distributedCacheEnabled = false; @@ -107,7 +107,7 @@ public class RuntimeDelegatingCacheManager implements CacheManager { changes.put(CacheApiConstants.cacheTypeParameter, toCacheType.getValue()); clearEhCache(); } - this.currentCacheManager = this.ehcacheCacheManager; + this.currentCacheManager = this.jcacheCacheManager; break; case MULTI_NODE: if (!distributedCacheEnabled) { @@ -120,6 +120,10 @@ public class RuntimeDelegatingCacheManager implements CacheManager { } private void clearEhCache() { - this.ehcacheCacheManager.getCacheManager().clearAll(); + javax.cache.CacheManager cacheManager = this.jcacheCacheManager.getCacheManager(); + Iterable cacheNames = cacheManager.getCacheNames(); + for (String cacheName: cacheNames) { + cacheManager.getCache(cacheName).clear(); + } } } diff --git a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java index ca2fc3840..b6bfbe21a 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java +++ b/fineract-provider/src/main/java/org/apache/fineract/organisation/monetary/domain/MoneyHelper.java @@ -18,10 +18,10 @@ */ package org.apache.fineract.organisation.monetary.domain; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.math.MathContext; import java.math.RoundingMode; import javax.annotation.PostConstruct; -import net.sf.ehcache.util.FindBugsSuppressWarnings; import org.apache.fineract.infrastructure.configuration.domain.ConfigurationDomainService; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; @@ -40,7 +40,7 @@ public class MoneyHelper { @PostConstruct // This is a hack, but fixing this is not trivial, because some @Entity domain classes use this helper - @FindBugsSuppressWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") + @SuppressFBWarnings("ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD") public void someFunction () { staticConfigurationDomainService = configurationDomainService; } diff --git a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java index 677c3cabf..9be3f1788 100644 --- a/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java +++ b/fineract-provider/src/main/java/org/apache/fineract/portfolio/loanproduct/data/LoanProductData.java @@ -18,13 +18,13 @@ */ package org.apache.fineract.portfolio.loanproduct.data; +import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import java.io.Serializable; import java.math.BigDecimal; import java.util.ArrayList; import java.util.Collection; import java.util.List; import java.util.Map; -import net.sf.ehcache.util.FindBugsSuppressWarnings; import org.apache.fineract.accounting.common.AccountingEnumerations; import org.apache.fineract.accounting.common.AccountingRuleType; import org.apache.fineract.accounting.glaccount.data.GLAccountData; @@ -1160,12 +1160,12 @@ public class LoanProductData implements Serializable { return null; } - @FindBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL") + @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL") public Boolean isCompoundingToBePostedAsTransaction() { return isInterestRecalculationEnabled() ? this.interestRecalculationData.isCompoundingToBePostedAsTransaction() : null; } - @FindBugsSuppressWarnings("NP_BOOLEAN_RETURN_NULL") + @SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL") public Boolean allowCompoundingOnEod() { return isInterestRecalculationEnabled() ? this.interestRecalculationData.allowCompoundingOnEod() : null; } diff --git a/fineract-provider/src/main/resources/META-INF/spring/cache.xml b/fineract-provider/src/main/resources/META-INF/spring/cache.xml index 1526df774..891ada53b 100644 --- a/fineract-provider/src/main/resources/META-INF/spring/cache.xml +++ b/fineract-provider/src/main/resources/META-INF/spring/cache.xml @@ -30,11 +30,10 @@ http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd"> - + class="org.springframework.cache.jcache.JCacheManagerFactoryBean"/> \ No newline at end of file diff --git a/fineract-provider/src/main/resources/META-INF/spring/ehcache.xml b/fineract-provider/src/main/resources/META-INF/spring/ehcache.xml index b5a442df5..40f13b486 100644 --- a/fineract-provider/src/main/resources/META-INF/spring/ehcache.xml +++ b/fineract-provider/src/main/resources/META-INF/spring/ehcache.xml @@ -21,8 +21,9 @@ --> - + + @@ -52,4 +53,4 @@ overflowToDisk="false" timeToIdleSeconds="7200" /> - \ No newline at end of file + \ No newline at end of file