#5000 Use new metadata service
authorCherian Mathew <c.mathew@bgbm.org>
Fri, 20 Nov 2015 17:46:46 +0000 (18:46 +0100)
committerCherian Mathew <c.mathew@bgbm.org>
Fri, 20 Nov 2015 17:47:09 +0000 (18:47 +0100)
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationRemoteConfiguration.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmPersistentRemoteSource.java
eu.etaxonomy.taxeditor.cdmlib/src/main/java/eu/etaxonomy/taxeditor/remoting/source/CdmRemoteSourceBase.java
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/dataimport/transientServices/TransientCdmRepository.java

index 760b71c..a1ce7e4 100644 (file)
@@ -52,6 +52,7 @@ import eu.etaxonomy.cdm.api.service.IGroupService;
 import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;\r
 import eu.etaxonomy.cdm.api.service.ILocationService;\r
 import eu.etaxonomy.cdm.api.service.IMediaService;\r
+import eu.etaxonomy.cdm.api.service.IMetadataService;\r
 import eu.etaxonomy.cdm.api.service.INameService;\r
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;\r
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;\r
@@ -105,7 +106,7 @@ public class CdmApplicationRemoteConfiguration implements ICdmApplicationConfigu
 \r
     private ICdmRemoteSource remoteSource;\r
 \r
-    private Map serviceMap = new HashMap<Class<IService>, IService>();\r
+    private static Map serviceMap = new HashMap<Class<IService>, IService>();\r
 \r
     private ICdmEntitySessionManager cdmEntitySessionManager;\r
 \r
@@ -119,6 +120,7 @@ public class CdmApplicationRemoteConfiguration implements ICdmApplicationConfigu
 \r
     public CdmApplicationRemoteConfiguration(ICdmRemoteSource remoteSource) {\r
         this.remoteSource = remoteSource;\r
+        serviceMap.clear();\r
     }\r
 \r
     public void setRemoteSource(ICdmRemoteSource remoteSource) {\r
@@ -126,6 +128,10 @@ public class CdmApplicationRemoteConfiguration implements ICdmApplicationConfigu
     }\r
 \r
     private Object getService(Class<?> clazz, String serviceSuffix, CdmAuthenticatedHttpInvokerRequestExecutor executor) {\r
+        return getService(clazz, serviceSuffix, remoteSource, executor);\r
+    }\r
+\r
+    public static Object getService(Class<?> clazz, String serviceSuffix, ICdmRemoteSource remoteSource, CdmAuthenticatedHttpInvokerRequestExecutor executor) {\r
         if(serviceMap.containsKey(clazz)) {\r
             return serviceMap.get(clazz);\r
         }\r
@@ -293,6 +299,15 @@ public class CdmApplicationRemoteConfiguration implements ICdmApplicationConfigu
     }\r
 \r
     @Override\r
+    public IMetadataService getMetadataService() {\r
+        return (IMetadataService) getService(IMetadataService.class, "/remoting-public/metadata.service", new CdmServiceRequestExecutor());\r
+    }\r
+\r
+    public static IMetadataService getMetadataService(ICdmRemoteSource remoteSource) {\r
+        return (IMetadataService) getService(IMetadataService.class, "/remoting-public/metadata.service", remoteSource, new CdmServiceRequestExecutor());\r
+    }\r
+\r
+    @Override\r
     public IGrantedAuthorityService getGrantedAuthorityService(){\r
         return (IGrantedAuthorityService) getService(IGrantedAuthorityService.class, "/remoting/grantedauthority.service", new CdmServiceRequestExecutor());\r
     }\r
index d8edcbf..a005d50 100644 (file)
@@ -84,8 +84,6 @@ public class CdmPersistentRemoteSource extends CdmRemoteSourceBase implements IC
                        checkProperties(cdmSourceProperties);
                } else {
                        throw new CdmRemoteSourceException("Remote source '" + remoteSource + "' does not exist in settings file");
-               }
-               initDatabaseConnection();
        }
 
        private static void checkProperties(Properties cdmSourceProperties) throws CdmRemoteSourceException {
index 1e1556f..59c24ea 100644 (file)
@@ -10,9 +10,8 @@ package eu.etaxonomy.taxeditor.remoting.source;
 
 import java.util.Map;
 
-import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
-
-import eu.etaxonomy.cdm.api.service.IUserService;
+import eu.etaxonomy.cdm.api.application.CdmApplicationRemoteConfiguration;
+import eu.etaxonomy.cdm.api.service.IMetadataService;
 import eu.etaxonomy.cdm.config.CdmSource;
 import eu.etaxonomy.cdm.config.CdmSourceException;
 import eu.etaxonomy.cdm.model.metadata.CdmMetaData.MetaDataPropertyName;
@@ -34,7 +33,7 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
        private String contextPath;
        private String baseUrl;
 
-       private IUserService userService;
+       private IMetadataService metadataService;
 
        /**
         * Constructs a CdmRemoteSourceBase object with default values.
@@ -63,26 +62,9 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
                setPort(port);
                setContextPath(contextPath);
                setNomenclaturalCode(nomenclaturalCode);
-               initDatabaseConnection();
+               metadataService = CdmApplicationRemoteConfiguration.getMetadataService(this);
        }
 
-       protected void initDatabaseConnection() {
-               if(getContextPath() == null || getContextPath().equals("")) {
-                       setBaseUrl("http://" + getServer() + ":" + String.valueOf(getPort()));
-               } else {
-                       setBaseUrl("http://" + getServer()  + ":" + String.valueOf(getPort()) + "/" + getContextPath());
-               }
-               // the database service needs to be initialised (before the spring
-               // application context initialsation) since it is required to
-               // to make queries related to the source database
-           HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
-           proxy.setServiceInterface(IUserService.class);
-           // FIXME:Remoting need to fix this hardcoded url and make it configurable somehow
-           proxy.setServiceUrl(baseUrl + "/remoting-public/user.service");
-           proxy.afterPropertiesSet();
-           userService = (IUserService) proxy.getObject();
-
-       }
 
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.remote.ICdmRemoteSource#getBaseUrl()
@@ -128,7 +110,7 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
         */
        @Override
        public String getDbSchemaVersion() throws CdmSourceException {
-               return userService.getDbSchemaVersion();
+               return metadataService.getDbSchemaVersion();
 
        }
 
@@ -137,7 +119,7 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
         */
        @Override
        public boolean isDbEmpty() throws CdmSourceException {
-               return userService.isDbEmpty();
+               return metadataService.isDbEmpty();
 
        }
 
@@ -151,7 +133,7 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
                // if no exception is thrown then we assume that the
                // connection is up
                // FIXME:Remoting is this really correct?
-               userService.getDbSchemaVersion();
+               metadataService.getDbSchemaVersion();
 
                return true;
        }
@@ -167,7 +149,7 @@ public class CdmRemoteSourceBase extends CdmSource implements ICdmRemoteSource {
 
        @Override
        public Map<MetaDataPropertyName, String> getMetaDataMap() throws CdmSourceException {
-               return userService.getCdmMetadataMap();
+               return metadataService.getCdmMetadataMap();
        }
 
 
index 2a2caea..13b11ce 100644 (file)
@@ -33,6 +33,7 @@ import eu.etaxonomy.cdm.api.service.IGroupService;
 import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;
 import eu.etaxonomy.cdm.api.service.ILocationService;
 import eu.etaxonomy.cdm.api.service.IMediaService;
+import eu.etaxonomy.cdm.api.service.IMetadataService;
 import eu.etaxonomy.cdm.api.service.INameService;
 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
 import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
@@ -427,4 +428,12 @@ public class TransientCdmRepository implements ICdmApplicationConfiguration {
     public IProgressMonitorService getProgressMonitorService() {
         return defaultApplicationConfiguration.getProgressMonitorService();
     }
+
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    public IMetadataService getMetadataService() {
+        return defaultApplicationConfiguration.getMetadataService();
+    }
 }