#4932 Remove autowired members, Use serliaised cdm model map
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 23 Jul 2015 11:54:34 +0000 (13:54 +0200)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 23 Jul 2015 11:54:34 +0000 (13:54 +0200)
15 files changed:
eu.etaxonomy.taxeditor.cdmlib/.classpath
eu.etaxonomy.taxeditor.cdmlib/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.cdmlib/build.properties
eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser [new file with mode: 0644]
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteController.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationState.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/cache/CdmServiceCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmModelCacher.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/cache/CdmRemoteCacheManager.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CachedCommonServiceImpl.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/CdmServiceRequestExecutor.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/service/ICachedCommonService.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java [deleted file]
eu.etaxonomy.taxeditor.cdmlib/src/main/resources/eu/etaxonomy/cdm/remotingApplicationContext.xml
eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java [deleted file]

index b149b77d4f0b358bc853a498bcf2af11f493bba7..76e36337a21cacef1f71a0da6577f63201596140 100644 (file)
@@ -2,8 +2,9 @@
 <classpath>
        <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
        <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
-       <classpathentry kind="src" path="src/main/java/"/>
-       <classpathentry kind="src" path="src/main/resources/"/>
+       <classpathentry kind="src" path="src/main/java"/>
+       <classpathentry kind="src" path="resources"/>
+       <classpathentry kind="src" path="src/main/resources"/>
        <classpathentry exported="true" kind="lib" path="lib/activation-1.1.1.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/antlr-2.7.7.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/aopalliance-1.0.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-remote-3.8.0-SNAPSHOT.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/cdmlib-services-3.8.0-SNAPSHOT.jar"/>
        <classpathentry exported="true" kind="lib" path="lib/apache-log4j-extras-1.2.17.jar"/>
-       <classpathentry kind="output" path="bin"/>
+       <classpathentry kind="output" path="target/classes"/>
 </classpath>
index a7449bf40e6e559b37d28c0fda4a596701c687de..4a39ebbc6954adb0d245469ca5b8c3f89bc68dfd 100644 (file)
@@ -469,7 +469,8 @@ Bundle-Vendor: EDIT
 Bundle-RequiredExecutionEnvironment: JavaSE-1.6
 Require-Bundle: org.eclipse.osgi,
  org.eclipse.equinox.common,
- org.apache.commons.httpclient;bundle-version="3.1.0"
+ org.apache.commons.httpclient;bundle-version="3.1.0",
+ org.eclipse.core.runtime
 Bundle-ClassPath: .,
  lib/activation-1.1.1.jar,
  lib/antlr-2.7.7.jar,
index 3e92568d4dae8c79b3ef9edd347875327df080e5..89b98fae049f0a849c74ca6198d12bedd2610e03 100644 (file)
@@ -193,7 +193,8 @@ bin.includes = META-INF/,\
                lib/cdmlib-print-3.8.0-SNAPSHOT.jar,\\r
                lib/cdmlib-remote-3.8.0-SNAPSHOT.jar,\\r
                lib/cdmlib-services-3.8.0-SNAPSHOT.jar,\\r
-               lib/apache-log4j-extras-1.2.17.jar\r
+               lib/apache-log4j-extras-1.2.17.jar,\\r
+               cdm.map.ser\r
 \r
 jars.compile.order = .\r
 output.. = bin/\r
diff --git a/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser b/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser
new file mode 100644 (file)
index 0000000..931f12e
Binary files /dev/null and b/eu.etaxonomy.taxeditor.cdmlib/resources/cdm.map.ser differ
index 1d1e878eacb09fb222f287fd8eae52cf6cf4b33a..47af2ca42fffaab0a2cda1e3a12cce4453d97a35 100644 (file)
@@ -147,14 +147,14 @@ public class CdmApplicationRemoteController  extends CdmApplicationController {
 
         GenericApplicationContext applicationContext =  new GenericApplicationContext();
 
-        int nTasks = 2;
+        int nTasks = 3;
 
         progressMonitor.beginTask("Connecting to '" + remoteSource.getName() + "'", nTasks);
 
-        progressMonitor.subTask("Loading context beans ...");
-        // initialising the cdm model cache
+        progressMonitor.subTask("Initialising CDM Model Cache ...");
         CdmRemoteCacheManager.getInstance();
 
+        progressMonitor.subTask("Loading context beans ...");
         PropertySourcesPlaceholderConfigurer pspc = new PropertySourcesPlaceholderConfigurer();
         Properties properties = new Properties();
         properties.setProperty("remoteServer", remoteSource.getServer());
index 41f33d8196fd7a420fb9933f4897179e99a3620d..eb5eaa954249bf71254555e95e43c985ef8de856 100644 (file)
@@ -15,6 +15,7 @@ import java.lang.reflect.Type;
 
 import org.springframework.security.core.context.SecurityContext;
 
+import eu.etaxonomy.cdm.api.cache.CdmServiceCacher;
 import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.api.service.IService;
 import eu.etaxonomy.cdm.api.service.ITestService;
@@ -39,6 +40,7 @@ public class CdmApplicationState {
     public static CdmApplicationState getInstance() {
         if(cdmApplicationState == null) {
             cdmApplicationState = new CdmApplicationState();
+            new CdmServiceCacher();
         }
         return cdmApplicationState;
     }
index 475d586d296dd1f3a0ba15e206eea4fd5e1611ab..288b20eb1310bbca841295655c6be1ea98bd233c 100644 (file)
@@ -5,10 +5,9 @@ import java.util.UUID;
 import net.sf.ehcache.config.CacheConfiguration;
 import net.sf.ehcache.config.SizeOfPolicyConfiguration;
 
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
-import eu.etaxonomy.cdm.api.service.ITermService;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.taxeditor.remoting.cache.CacheLoader;
@@ -34,8 +33,6 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManagerObserver;
 @Component
 public class CdmServiceCacher extends CdmCacher  implements ICdmEntitySessionManagerObserver {
 
-    @Autowired
-    ITermService termService;
 
 
     private ICdmEntitySessionManager cdmEntitySessionManager;
@@ -49,6 +46,7 @@ public class CdmServiceCacher extends CdmCacher  implements ICdmEntitySessionMan
         DefinedTermBase.setCacher(this);
         CdmTransientEntityCacher.setDefaultCacher(this);
         TermServiceRequestExecutor.setDefaultCacher(this);
+
         cacheLoader = new CacheLoader(this);
     }
 
@@ -72,7 +70,7 @@ public class CdmServiceCacher extends CdmCacher  implements ICdmEntitySessionMan
 
     @Override
     protected CdmBase findByUuid(UUID uuid) {
-        CdmBase term = termService.findWithoutFlush(uuid);
+        CdmBase term = CdmApplicationState.getCurrentAppConfig().getTermService().findWithoutFlush(uuid);
         return load(term);
     }
 
index a0e095d91983504ed6a23b7c271a23c6e0a53b2b..45a3094e6a2322a7bbcde7376d932a443f086f77 100644 (file)
 package eu.etaxonomy.taxeditor.remoting.cache;
 
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.HashMap;
 import java.util.Iterator;
-import java.util.List;
+import java.util.Map;
 
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
-import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.Platform;
 import org.hibernate.cfg.Configuration;
 import org.hibernate.mapping.PersistentClass;
 import org.hibernate.mapping.Property;
 import org.hibernate.property.Getter;
+import org.osgi.framework.Bundle;
 
 
 public class CdmModelCacher {
 
 
-       private static final Logger logger = Logger.getLogger(CdmModelCacher.class);
 
-       public static String HB_CONFIG_FILE_PATH= "/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml";
 
-       private final List<CdmModelFieldPropertyFromClass> cmgmfcList = new ArrayList<CdmModelFieldPropertyFromClass>();
+    public static String HB_CONFIG_FILE_PATH= "/eu/etaxonomy/cdm/mappings/hibernate.cfg.xml";
 
+    public static final String CDM_MAP_SER_FILE_PATH = "resources/cdm.map.ser";
 
-       public static Configuration buildConfiguration() {
-           Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH);
+
+
+
+    public void cacheGetterFields(Cache cache) throws IOException, ClassNotFoundException, URISyntaxException {
+        Map<String, CdmModelFieldPropertyFromClass> modelClassMap = loadModelClassMap();
+
+        cache.removeAll();
+
+        for(Map.Entry<String, CdmModelFieldPropertyFromClass> entry : modelClassMap.entrySet()) {
+            cache.put(new Element(entry.getKey(), entry.getValue()));
+        }
+    }
+
+    public Map<String, CdmModelFieldPropertyFromClass> loadModelClassMap() throws URISyntaxException, IOException, ClassNotFoundException  {
+
+        Bundle bundle = Platform.getBundle("eu.etaxonomy.taxeditor.cdmlib");
+
+        URL modelMapFileURL = bundle.getEntry(CDM_MAP_SER_FILE_PATH);
+        File modelMapFile = new File(FileLocator.resolve(modelMapFileURL).toURI());
+
+        FileInputStream fin = new FileInputStream(modelMapFile);
+        ObjectInputStream ois = new ObjectInputStream(fin);
+        Map<String, CdmModelFieldPropertyFromClass> modelClassMap = (Map<String, CdmModelFieldPropertyFromClass>) ois.readObject();
+        ois.close();
+        return modelClassMap;
+    }
+
+
+    public Map<String, CdmModelFieldPropertyFromClass> generateModelClassMap() {
+
+        Configuration configuration = buildConfiguration(HB_CONFIG_FILE_PATH);
+        Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();
+
+        Map<String, CdmModelFieldPropertyFromClass> modelClassMap = new HashMap<String, CdmModelFieldPropertyFromClass>();
+
+        while(classMappingIterator.hasNext()) {
+            PersistentClass persistentClass = classMappingIterator.next();
+            Class mappedClass = persistentClass.getMappedClass();
+            String mappedClassName = mappedClass.getName();
+
+            CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
+            System.out.println("Adding class : " + mappedClassName + " to cache");
+            addGetters(persistentClass, cmgmfc);
+            modelClassMap.put(mappedClassName, cmgmfc);
+        }
+        return modelClassMap;
+    }
+
+
+    public static Configuration buildConfiguration(String hibernateConfigFilePath) {
+        Configuration configuration = new Configuration().configure(hibernateConfigFilePath);
         configuration.buildMappings();
         return configuration;
-       }
-
-       public void cacheGetterFields(Cache cache) {
-
-           Configuration configuration = buildConfiguration();
-               Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();
-
-               cache.removeAll();
-
-               while(classMappingIterator.hasNext()) {
-                       PersistentClass persistentClass = classMappingIterator.next();
-                       Class mappedClass = persistentClass.getMappedClass();
-                       String mappedClassName = mappedClass.getName();
-
-                       CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
-                       //logger.info("Adding class : " + mappedClassName + " to cache");
-                       addGetters(persistentClass, cmgmfc);
-                       cache.put(new Element(mappedClassName, cmgmfc));
-               }
-
-       }
-
-       private void addGetters(PersistentClass persistentClass, CdmModelFieldPropertyFromClass cmgmfc) {
-           if (persistentClass != null) {
-               Iterator propertyIt = persistentClass.getPropertyIterator();
-
-               while(propertyIt.hasNext())
-               {
-                   Property property = (Property)propertyIt.next();
-                   Getter getter = property.getGetter(persistentClass.getMappedClass());
-                   if(getter != null && getter.getMember() != null) {
-                       Field field = (Field)getter.getMember();
-
-                       //logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'");
-                       cmgmfc.addGetMethods(field.getName());
-                   }
-               }
-               addGetters(persistentClass.getSuperclass(), cmgmfc);
-           }
-       }
-
-       public void checkGetterMethods() {
-
-               Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH);
-               configuration.buildMappings();
-               Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();
-
-               Cache cache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
-               cache.removeAll();
-
-               while(classMappingIterator.hasNext()) {
-                       PersistentClass persistentClass = classMappingIterator.next();
-                       Class mappedClass = persistentClass.getMappedClass();
-                       String mappedClassName = mappedClass.getName();
-
-                       Iterator propertyIt = persistentClass.getPropertyIterator();
-
-                       Method[] methods = mappedClass.getMethods();
-
-                       while(propertyIt.hasNext())
-                       {
-                               Property property = (Property)propertyIt.next();
-                               Getter getter = property.getGetter(mappedClass);
-                               if(getter != null && getter.getMember() != null) {
-                                       Field field = (Field)getter.getMember();
-                                       String getMethod = getMethodNameFromFieldName(field.getName(), field.getType().getName());
-
-                                       boolean foundMethod = false;
-                                       for(Method method : methods) {
-                                               if(method.getName().equals(getMethod)) {
-                                                       foundMethod = true;
-                                                       break;
-                                               }
-                                       }
-                                       if(!foundMethod) {
-                                               logger.info("Inferred method " + getMethod + " does not exist in class " + mappedClassName);
-                                               //throw new CdmClientCacheException("Inferred method " + getMethod + " does not exist in class " + mappedClassName);
-                                       }
-                               }
-                       }
-
-
-               }
-
-       }
-
-       public List<CdmModelFieldPropertyFromClass> getCdmModelGetMethodFromClassList() {
-               cmgmfcList.clear();
-               Configuration configuration = new Configuration().configure(HB_CONFIG_FILE_PATH);
-               configuration.buildMappings();
-               Iterator<PersistentClass> classMappingIterator =   configuration.getClassMappings();
-
-               while(classMappingIterator.hasNext()) {
-                       PersistentClass persistentClass = classMappingIterator.next();
-                       Class mappedClass = persistentClass.getMappedClass();
-                       String mappedClassName = mappedClass.getName();
-
-                       CdmModelFieldPropertyFromClass cmgmfc = new CdmModelFieldPropertyFromClass(mappedClassName);
-                       Iterator propertyIt = persistentClass.getPropertyIterator();
-
-                       while(propertyIt.hasNext())
-                       {
-                               Property property = (Property)propertyIt.next();
-                               Getter getter = property.getGetter(mappedClass);
-                               if(getter != null && getter.getMember() != null) {
-                                       Field field = (Field)getter.getMember();
-                                       String getMethod = getMethodNameFromFieldName(getter.getMember().getName(),field.getType().getName());
-                                       cmgmfc.addGetMethods(getMethod);
-                               }
-                       }
-                       cmgmfcList.add(cmgmfc);
-               }
-               return cmgmfcList;
-
-       }
-
-       public static String getMethodNameFromFieldName(String fieldName, String type) {
-               String prefix = type != null && type.toLowerCase().endsWith("boolean") ? "is" : "get";
-               String getMethod =  prefix + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
-               return getMethod;
-       }
+    }
+
+    private void addGetters(PersistentClass persistentClass, CdmModelFieldPropertyFromClass cmgmfc) {
+        if (persistentClass != null) {
+            Iterator propertyIt = persistentClass.getPropertyIterator();
+
+            while(propertyIt.hasNext())
+            {
+                Property property = (Property)propertyIt.next();
+                Getter getter = property.getGetter(persistentClass.getMappedClass());
+                if(getter != null && getter.getMember() != null) {
+                    Field field = (Field)getter.getMember();
+
+                    //logger.info(" - contains field '" + field.getName() + "' of type '" + field.getType().getName() + "'");
+                    cmgmfc.addGetMethods(field.getName());
+                }
+            }
+            addGetters(persistentClass.getSuperclass(), cmgmfc);
+        }
+    }
+
+
+
+    public static void main(String argv[]) {
+
+        // To re-create the serialised cdm map run,
+        // mvn exec:java -Dexec.mainClass="eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher"
+        // in the eu.etaxonomy.taxeditor.cdmlib project root dir
+        String CDM_MAP_SER_DIR = "resources/";
+
+        CdmModelCacher cdmModelCacher = new CdmModelCacher();
+        Map<String, CdmModelFieldPropertyFromClass> modelClassMap = cdmModelCacher.generateModelClassMap();
+        try{
 
+            FileOutputStream fout = new FileOutputStream(CDM_MAP_SER_DIR + "cdm.map.ser");
+            ObjectOutputStream oos = new ObjectOutputStream(fout);
+            oos.writeObject(modelClassMap);
+            oos.close();
+            System.out.println("CDM Map serialized");
 
+        }catch(Exception ex){
+            ex.printStackTrace();
+        }
 
+    }
 
 
 }
index 84f88c24fb3c51a19b1d4d70bb0e12aa271b2f2e..a2c4d1c663961a885a222b89d35475889267db9e 100644 (file)
@@ -1,5 +1,8 @@
 package eu.etaxonomy.taxeditor.remoting.cache;
 
+import java.io.IOException;
+import java.net.URISyntaxException;
+
 import net.sf.ehcache.Cache;
 import net.sf.ehcache.CacheException;
 import net.sf.ehcache.CacheManager;
@@ -59,45 +62,23 @@ public class CdmRemoteCacheManager {
             cdmlibModelCache = new Cache(modelcc);
 
             CacheManager.create().addCache(cdmlibModelCache);
-            initCdmModelCache(cdmlibModelCache);
+            CdmModelCacher cmdmc = new CdmModelCacher();
+            cmdmc.cacheGetterFields(cdmlibModelCache);
 
         } catch (CacheException e) {
             throw new CdmClientCacheException(e);
+        } catch (ClassNotFoundException e) {
+            throw new CdmClientCacheException(e);
+        } catch (IOException e) {
+            throw new CdmClientCacheException(e);
+        } catch (URISyntaxException e) {
+            throw new CdmClientCacheException(e);
         }
 
     }
 
-    private void initCdmModelCache(final Cache cache) {
-
-        initThread = new Thread() {
-            @Override
-            public void run(){
-                synchronized (cdmlibModelCache) {
-                    CdmModelCacher cmdmc = new CdmModelCacher();
-                    cmdmc.cacheGetterFields(cache);
-                    cacheInitialised = true;
-                    logger.info("Initialisation of CDM getter fields complete");
-                    cdmlibModelCache.notify();
-                }
-            }
-
-        };
-        initThread.start();
-    }
 
     public Cache getCdmModelGetMethodsCache(){
-        //Note : Even though we synchronize this method, the cache can be simply
-        //       retrieved using CacheManager.create().getCache(CDM_MODEL_CACHE_NAME)
-        //       in which case the cache may not be fully initialised
-        synchronized (cdmlibModelCache) {
-            while(!cacheInitialised) {
-                try {
-                    logger.info("Waiting for initialisation of CDM getter fields to complete ...");
-                    cdmlibModelCache.wait();
-                } catch (InterruptedException e) {}
-            }
-        }
-        logger.info("CDM getter fields cache initialised");
         return cdmlibModelCache;
     }
 
@@ -110,7 +91,4 @@ public class CdmRemoteCacheManager {
             }
         }
     }
-
-
-
 }
index e36138e698f7a2f4539b8bdc5b0d9ff872851c84..0e5b8f9e6e50e578cddeef78eb8c5ce14d405acc 100644 (file)
@@ -12,16 +12,12 @@ package eu.etaxonomy.taxeditor.service;
 import java.util.List;
 import java.util.UUID;
 
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Component;
 
 import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
 import eu.etaxonomy.cdm.api.application.CdmApplicationState;
-import eu.etaxonomy.cdm.api.service.ICommonService;
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils.CollectionField;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
-import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
 /**
  * @author cmathew
@@ -32,15 +28,8 @@ import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 public class CachedCommonServiceImpl implements ICachedCommonService {
 
 
-    @Autowired
-    private ICommonService commonService;
-
     private static boolean cacheEnabled = true;
 
-    @Autowired
-    private ICdmEntitySessionManager cdmEntitySessionManager;
-
-
     public static boolean isCacheEnabled() {
         return cacheEnabled;
     }
@@ -55,7 +44,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
     @Override
     public CdmBase find(Class<? extends CdmBase> clazz, int id) {
 //        if(cacheEnabled) {
-            CdmBase cdmEntity = commonService.find(clazz, id, getPropertyPaths(clazz));
+            CdmBase cdmEntity = CdmApplicationState.getCurrentAppConfig().getCommonService().find(clazz, id, getPropertyPaths(clazz));
             if(cdmEntity == null) {
                 throw new NullPointerException("CDM Entity of type " + clazz.getName() + " with id " + id  + " is null.");
             }
@@ -77,19 +66,12 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
         return propertyPaths;
     }
 
-    @Override
-    public void updatePersistentCollection(CollectionField colf) {
-        if(cacheEnabled) {
-            cdmEntitySessionManager.load(colf.getCollection(), false);
-        }
-    }
-
     /* (non-Javadoc)
      * @see eu.etaxonomy.taxeditor.service.ICachedCommonService#initializeCollection(java.util.UUID, java.lang.String)
      */
     @Override
     public Object initializeCollection(UUID ownerUuid, String fieldName) {
-        return commonService.initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
+        return  CdmApplicationState.getCurrentAppConfig().getCommonService().initializeCollection(ownerUuid, fieldName, getPropertyPaths(fieldName));
     }
 
 
@@ -98,7 +80,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public boolean isEmpty(UUID ownerUuid, String fieldName) {
-            return commonService.isEmpty(ownerUuid, fieldName);
+            return  CdmApplicationState.getCurrentAppConfig().getCommonService().isEmpty(ownerUuid, fieldName);
 
     }
 
@@ -108,7 +90,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public int size(UUID ownerUuid, String fieldName) {
-        return commonService.size(ownerUuid, fieldName);
+        return  CdmApplicationState.getCurrentAppConfig().getCommonService().size(ownerUuid, fieldName);
     }
 
 
@@ -118,7 +100,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public boolean contains(UUID ownerUuid, String fieldName, Object element) {
-        return commonService.contains(ownerUuid, fieldName, element);
+        return  CdmApplicationState.getCurrentAppConfig().getCommonService().contains(ownerUuid, fieldName, element);
     }
 
 
@@ -127,7 +109,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public boolean containsKey(UUID ownerUuid, String fieldName, Object key) {
-        return commonService.containsKey(ownerUuid, fieldName, key);
+        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsKey(ownerUuid, fieldName, key);
     }
 
 
@@ -136,7 +118,7 @@ public class CachedCommonServiceImpl implements ICachedCommonService {
      */
     @Override
     public boolean containsValue(UUID ownerUuid, String fieldName, Object element) {
-        return commonService.containsValue(ownerUuid, fieldName, element);
+        return  CdmApplicationState.getCurrentAppConfig().getCommonService().containsValue(ownerUuid, fieldName, element);
     }
 
 
index 0b7ca355d920d5e66afbbb4e57caba5715c974d4..8084eac89bf742d6cdc4cb1b2508780e8c948f9d 100644 (file)
@@ -4,12 +4,13 @@ import java.io.IOException;
 import java.io.OutputStream;
 
 import org.apache.log4j.Logger;
-import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.remoting.httpinvoker.HttpInvokerClientConfiguration;
 import org.springframework.remoting.support.RemoteInvocation;
 import org.springframework.remoting.support.RemoteInvocationResult;
 import org.springframework.stereotype.Component;
 
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteController;
+import eu.etaxonomy.cdm.api.application.CdmApplicationState;
 import eu.etaxonomy.cdm.api.service.UpdateResult;
 import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
 
@@ -18,13 +19,18 @@ public class CdmServiceRequestExecutor extends CdmAuthenticatedHttpInvokerReques
 
     private static final Logger logger = Logger.getLogger(CdmServiceRequestExecutor.class);
 
-    @Autowired
-    private ICdmEntitySessionManager cdmEntitySessionManager;
+    private ICdmEntitySessionManager cdmEntitySessionManager ;
 
        private RemoteInvocation currentRemoteInvocation;
 
+
+
        @Override
        protected void writeRemoteInvocation(RemoteInvocation invocation, OutputStream os) throws IOException {
+           if(cdmEntitySessionManager == null) {
+               cdmEntitySessionManager =
+                       ((CdmApplicationRemoteController)CdmApplicationState.getCurrentAppConfig()).getCdmEntitySessionManager();
+           }
                currentRemoteInvocation = invocation;
                super.writeRemoteInvocation(invocation, os);
        }
index 3b85058ecdb3db67a3dbdd8ff899e883320e26e5..98c94d89981e7d71b2a9bd6387e510a6a7e2f73c 100644 (file)
@@ -12,7 +12,6 @@ package eu.etaxonomy.taxeditor.service;
 import java.util.UUID;
 
 import eu.etaxonomy.cdm.model.common.CdmBase;
-import eu.etaxonomy.taxeditor.remoting.cache.ProxyUtils.CollectionField;
 
 /**
  * @author cmathew
@@ -23,7 +22,6 @@ public interface ICachedCommonService {
 
     public CdmBase find(Class<? extends CdmBase> clazz, int id);
 
-       public void updatePersistentCollection(CollectionField colf);
 
     /**
      * Initializes a collection or map.
diff --git a/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java b/eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/util/Serializer.java
deleted file mode 100644 (file)
index 04e998e..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-// $Id$
-/**
-* Copyright (C) 2015 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
-package eu.etaxonomy.taxeditor.util;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectOutputStream;
-
-import org.apache.log4j.Logger;
-import org.hibernate.cfg.Configuration;
-
-import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher;
-
-/**
- * @author cmathew
- * @date 27 May 2015
- *
- */
-public class Serializer {
-    private static final Logger logger = Logger.getLogger(Serializer.class);
-
-
-    public static String HB_CONFIG_SER_FILE_NAME = "hibernate.cfg.ser";
-
-    public static boolean checkDir(String dirString) {
-        if(dirString == null || dirString.isEmpty()) {
-            logger.warn("Directory not set or set to empty string");
-            return false;
-        }
-
-        File dir = new File(dirString);
-
-        if(!dir.exists()) {
-            logger.warn("Directory does not exist");
-            return false;
-        }
-
-        return true;
-
-    }
-    public static void serializeHbConfig() {
-
-        Configuration configuration = CdmModelCacher.buildConfiguration();
-        String hbConfigDir = System.getProperty("hb.config.dir");
-        if(checkDir(hbConfigDir)) {
-            try {
-               FileOutputStream fileOut = new FileOutputStream(hbConfigDir + File.separator + HB_CONFIG_SER_FILE_NAME);
-               ObjectOutputStream out = new ObjectOutputStream(fileOut);
-               out.writeObject(configuration);
-               out.close();
-               fileOut.close();
-               logger.info("Serialized configuration object");
-            } catch(IOException i) {
-                i.printStackTrace();
-            }
-        }
-    }
-
-    public static void main(String[] args) {
-        serializeHbConfig();
-
-    }
-
-}
index adccb37c5618567095dc8034dfdd7c196620e0ee..928decf93413554054a6352939f876297759c5cd 100644 (file)
@@ -6,8 +6,6 @@
     http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
     http://www.springframework.org/schema/context  http://www.springframework.org/schema/context/spring-context-3.1.xsd">\r
 \r
-  <context:annotation-config />\r
-\r
   <import resource="classpath:/eu/etaxonomy/cdm/httpInvokerServiceClients.xml" />\r
 \r
   <bean id="cdmEntitySessionManager"  \r
     <property name="accessDecisionManager" ref="accessDecisionManager" />\r
   </bean>\r
 \r
-  <!-- The CdmSecurityHibernateInterceptor checks onSave() and on flushDirty() \r
-    if the currently authenticated principal or token has sufficient permissions \r
-    on the entity to be persisted -->\r
-  <bean id="securityHibernateInterceptor" \r
-    class="eu.etaxonomy.cdm.persistence.hibernate.CdmSecurityHibernateInterceptor">\r
-    <property name="permissionEvaluator" ref="cdmPermissionEvaluator" />\r
-  </bean>\r
-\r
   <bean id="authenticationManager"\r
     class="org.springframework.security.authentication.ProviderManager">\r
     <property name="providers">\r
@@ -81,9 +71,4 @@
     <property name="userPropertyToUse" value="getUsername" />\r
   </bean>\r
 \r
-\r
-  <bean id="cdmServiceCacher" \r
-    class="eu.etaxonomy.cdm.api.cache.CdmServiceCacher" />\r
-\r
-\r
 </beans>\r
diff --git a/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java b/eu.etaxonomy.taxeditor.test/src/test/java/eu/etaxonomy/cdm/api/cache/CdmModelGetMethodCacherTest.java
deleted file mode 100644 (file)
index 481dd12..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-package eu.etaxonomy.cdm.api.cache;
-
-import java.util.List;
-
-import net.sf.ehcache.Cache;
-
-import org.apache.log4j.Logger;
-import org.junit.Assert;
-import org.junit.Test;
-
-import eu.etaxonomy.taxeditor.remoting.cache.CdmModelCacher;
-import eu.etaxonomy.taxeditor.remoting.cache.CdmModelFieldPropertyFromClass;
-import eu.etaxonomy.taxeditor.remoting.cache.CdmRemoteCacheManager;
-
-
-public class CdmModelGetMethodCacherTest {
-
-       private static final Logger logger = Logger.getLogger(CdmModelGetMethodCacherTest.class);
-
-
-       @Test
-       public void cacheGettersTest() {
-
-               CdmModelCacher cmdmc = new CdmModelCacher();
-
-               Cache cdmlibCache = CdmRemoteCacheManager.getInstance().getCdmModelGetMethodsCache();
-               List<CdmModelFieldPropertyFromClass> cmgmfcList = cmdmc.getCdmModelGetMethodFromClassList();
-
-               List<Object> keys = cdmlibCache.getKeys();
-               Assert.assertEquals(cmgmfcList.size(), keys.size());
-
-               for(CdmModelFieldPropertyFromClass cmgmfc: cmgmfcList) {
-                       String className = cmgmfc.getClassName();
-                       Assert.assertTrue(keys.contains(className));
-                       logger.info("Class Name : " + className + " has been cached");
-               }
-
-               //FIXME:Remoting do we need to test this ?
-               // this will cause the following tests to fail since all caches are shutdown
-               //cdmlibCache.removeAll();
-               //CacheManager.create().shutdown();
-       }
-
-
-
-
-}