CdmServiceCacher : Added class to load / cache CDM entities using services
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 27 Jun 2014 09:57:30 +0000 (09:57 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 27 Jun 2014 09:57:30 +0000 (09:57 +0000)
remotingApplicationContext : updated cacher bean config
httpInvokerServiceClients : removed unnecessary loading of remote config
CdmServiceCacherTest : added cacher test

.gitattributes
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/httpInvokerServiceClients.xml
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml
eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmServiceCacherTest.java [new file with mode: 0644]

index 1267314462c39b9128574565a27517b4ea724fde..ba2b9885c191e221b6f815bae215f3d5a8c02365 100644 (file)
@@ -322,6 +322,7 @@ eu.etaxonomy.taxeditor.cdmlib/lib/yjp-controller-api-redist-9.0.8.jar -text
 eu.etaxonomy.taxeditor.cdmlib/pom.xml -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/lazyloading/CdmLazyLoader.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmPersistentRemoteSource.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/remote/CdmRemoteSource.java -text
@@ -339,6 +340,7 @@ eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remoting_servi
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmApplicationRemoteControllerTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmPersistentRemoteSourceTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmRemoteSourceTest.java -text
+eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmServiceCacherTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/HttpInvokerServicesTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteApplicationConfigurationTest.java -text
 eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/RemoteLazyLoadingTest.java -text
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java
new file mode 100644 (file)
index 0000000..6be6919
--- /dev/null
@@ -0,0 +1,33 @@
+package eu.etaxonomy.cdm.api.cache;
+
+import java.util.UUID;
+
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.model.common.CdmBase;
+
+/**
+ * Class which uses CDM services to cache cdm entities
+ * 
+ * FIXME: Currently only handles terms entities. It would be 
+ *        interesting to have a generic method which finds the
+ *        correct service to load / cache the entity.
+ * 
+ * @author cmathew
+ *
+ * @param <T>
+ */
+@Component
+public class CdmServiceCacher<T extends CdmBase> extends CdmCacher<T> {
+
+       @Autowired
+       ITermService termService;
+       
+       @Override
+       protected T findByUuid(UUID uuid) {
+               return (T)termService.findWithoutFlush(uuid);
+       }
+
+}
index 4b121cf02957ea483cced8e927a6f447bcf5f324..e3c0f9fd8ef75e7c6a175a3d9c1a5fd0d74c6dba 100644 (file)
@@ -7,10 +7,6 @@
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd\r
     http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">\r
 \r
-       <bean id="propertyConfigurer"\r
-               class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">\r
-               <property name="location" value="/eu/etaxonomy/cdm/config.properties" />\r
-       </bean>\r
        \r
    <bean id="agentService"\r
                class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">\r
index 549d4825f3aa93787a2623ae76ee054c3584ce08..66be8d6e19cc46652413a952b5bf558e326af0ed 100644 (file)
     \r
     <bean id="cdmApplicationRemoteConfiguration" class="eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration"/>    \r
     \r
-       <import resource="classpath:/eu/etaxonomy/cdm/remoting_services_security.xml"/> \r
+       <import resource="classpath:/eu/etaxonomy/cdm/remoting_services_security.xml"/>         \r
        \r
-       <context:component-scan base-package="eu/etaxonomy/cdm/api/cache"/>\r
-       \r
-       <bean id="cdmCacher" class="eu.etaxonomy.cdm.api.cache.CdmCacher"/>\r
+       <bean id="cdmServiceCacher" class="eu.etaxonomy.cdm.api.cache.CdmServiceCacher"/>\r
        \r
        \r
        <!-- EditGeoService was moved to ext. Therefore it will not be found by the default component scan.
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmServiceCacherTest.java b/eu.etaxonomy.taxeditor.cdmlib/src/test/java/eu/etaxonomy/taxeditor/remoting/CdmServiceCacherTest.java
new file mode 100644 (file)
index 0000000..a8564a5
--- /dev/null
@@ -0,0 +1,38 @@
+package eu.etaxonomy.taxeditor.remoting;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Assert;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
+import eu.etaxonomy.cdm.model.common.Language;
+
+public class CdmServiceCacherTest extends RemoteApplicationConfigurationTest {
+       private static final Logger logger = Logger.getLogger(CdmServiceCacherTest.class);
+       
+       
+       private static CdmServiceCacher cdmServiceCacher;
+       
+       @BeforeClass
+       public static void initialize() {
+               Logger.getRootLogger().setLevel(Level.INFO);
+               cdmServiceCacher = (CdmServiceCacher)applicationController.getBean("cdmServiceCacher");
+       }
+       
+       @Test
+       public void testLanguageCache() {
+               Language defaultLanguage = Language.getDefaultLanguage();       
+               
+               Language defaultLanguageInCache = (Language)cdmServiceCacher.getFromCache(defaultLanguage.getUuid());
+               Assert.assertEquals("Loaded Language Term should match Language Term in Cache",defaultLanguage,defaultLanguageInCache);         
+               
+               Language language = Language.getLanguageFromUuid(Language.uuidFrench);
+               Language languageInCache = (Language)cdmServiceCacher.getFromCache(language.getUuid());
+               Assert.assertEquals("Loaded Language Term should match Language Term in Cache",language,languageInCache);
+               
+       }
+
+}