cleanup
authorAndreas Müller <a.mueller@bgbm.org>
Thu, 4 Feb 2021 19:02:01 +0000 (20:02 +0100)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 4 Feb 2021 19:46:39 +0000 (20:46 +0100)
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/DozerBeanMapperFactoryBean.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DateTimeConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/DefaultRelatedPageConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyFieldMapper.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/HibernateProxyNullSafeDeepConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/LsidProxyConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/StripTagsConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/dto/assembler/converter/TimePeriodConverter.java
cdmlib-remote/src/main/java/eu/etaxonomy/cdm/remote/view/OaiPmhResponseView.java
cdmlib-remote/src/test/java/eu/etaxonomy/cdm/remote/view/JsonToCsvViewTest.java

index e4007906b51937109385972d2c491fad95eccc97..ee935242ba965528cc683ce0e51be96603b56384 100644 (file)
@@ -1,8 +1,8 @@
 /**\r
  * Copyright (C) 2007 EDIT\r
- * European Distributed Institute of Taxonomy \r
+ * European Distributed Institute of Taxonomy\r
  * http://www.e-taxonomy.eu\r
- * \r
+ *\r
  * The contents of this file are subject to the Mozilla Public License Version 1.1\r
  * See LICENSE.TXT at the top of this package for the full license terms.\r
  */\r
@@ -40,17 +40,17 @@ public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean
 \r
          public final void setMappingFiles(final Resource[] mappingFiles) {\r
            this.mappingFiles = mappingFiles;\r
-         }\r
+       }\r
 \r
-         public final void setCustomConverters(final List<CustomConverter> customConverters) {\r
+       public final void setCustomConverters(final List<CustomConverter> customConverters) {\r
            this.customConverters = customConverters;\r
-         }\r
+       }\r
 \r
-         public final void setEventListeners(final List<DozerEventListener> eventListeners) {\r
+       public final void setEventListeners(final List<EventListener> eventListeners) {\r
            this.eventListeners = eventListeners;\r
-         }\r
+       }\r
 \r
-         public final void setFactories(final Map<String, BeanFactory> factories) {\r
+       public final void setFactories(final Map<String, BeanFactory> factories) {\r
            this.factories = factories;\r
          }\r
          \r
@@ -67,44 +67,50 @@ public class DozerBeanMapperFactoryBean implements FactoryBean, InitializingBean
          // ==================================================================================================================================\r
          public final Object getObject() throws Exception {\r
            return this.beanMapper;\r
-         }\r
-         public final Class<Mapper> getObjectType() {\r
+       }\r
+\r
+       @Override\r
+    public final Class<Mapper> getObjectType() {\r
            return Mapper.class;\r
-         }\r
-         public final boolean isSingleton() {\r
+       }\r
+\r
+       @Override\r
+    public final boolean isSingleton() {\r
            return true;\r
-         }\r
+       }\r
+\r
+       // ==================================================================================================================================\r
+       // interface 'InitializingBean'\r
+       // ==================================================================================================================================\r
+       @Override\r
+    public final void afterPropertiesSet() throws Exception {\r
+\r
+        DozerBeanMapperBuilder beanMapperBuilder = DozerBeanMapperBuilder.create();\r
+\r
+        final List<String> mappings = new ArrayList<>(this.mappingFiles.length);\r
+        if (this.mappingFiles != null) {\r
+            for (Resource mappingFile : this.mappingFiles) {\r
+                mappings.add(mappingFile.getURL().toString());\r
+            }\r
+            beanMapperBuilder.withMappingFiles(mappings);\r
+        }\r
 \r
-         // ==================================================================================================================================\r
-         // interface 'InitializingBean'\r
-         // ==================================================================================================================================\r
-         public final void afterPropertiesSet() throws Exception {\r
-           this.beanMapper = new DozerBeanMapper();\r
-\r
-           if (this.mappingFiles != null) {\r
-             final List<String> mappings = new ArrayList<String>(this.mappingFiles.length);\r
-             for (Resource mappingFile : this.mappingFiles) {\r
-               mappings.add(mappingFile.getURL().toString());\r
-             }\r
-             this.beanMapper.setMappingFiles(mappings);\r
-           }\r
            if (this.customConverters != null) {\r
-             this.beanMapper.setCustomConverters(this.customConverters);\r
+               beanMapperBuilder.withCustomConverters(customConverters);\r
            }\r
            if (this.eventListeners != null) {\r
-             this.beanMapper.setEventListeners(this.eventListeners);\r
+               beanMapperBuilder.withEventListeners(eventListeners);\r
            }\r
            if (this.factories != null) {\r
-             this.beanMapper.setFactories(this.factories);\r
+               beanMapperBuilder.withBeanFactorys(factories);\r
            }\r
-           \r
+\r
            if(this.customFieldMapper != null) {\r
-               this.beanMapper.setCustomFieldMapper(customFieldMapper);\r
+               beanMapperBuilder.withCustomFieldMapper(customFieldMapper);\r
            }\r
-           \r
+\r
            if(this.customConvertersWithId != null) {\r
-               this.beanMapper.setCustomConvertersWithId(customConvertersWithId);\r
+               beanMapperBuilder.withCustomConvertersWithIds(customConvertersWithId);\r
            }\r
-         }\r
-\r
-       }
+       }\r
+}
\ No newline at end of file
index 9588e74abfd8a22a99dccee300e720063bbf61a3..49d588eb0d933ae784163c86f5f079cdc3c91f7d 100644 (file)
@@ -1,14 +1,13 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.cdm.remote.dto.assembler.converter;
 
-
 import javax.xml.datatype.DatatypeConfigurationException;
 import javax.xml.datatype.DatatypeFactory;
 import javax.xml.datatype.XMLGregorianCalendar;
@@ -19,31 +18,32 @@ import org.joda.time.DateTime;
 
 public class DateTimeConverter implements CustomConverter {
 
-       public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+       @Override
+    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
                if (source == null) {
                        return null;
                }
                Object result = null;
                if (source instanceof DateTime) {
                        if(destClass.equals(DateTime.class)){
-                               result =  new DateTime(((DateTime)source));
+                               result =  new DateTime((source));
                        } else if(destClass.equals(XMLGregorianCalendar.class)){
-                               result = dataTypeFactory().newXMLGregorianCalendar(((DateTime)source).toGregorianCalendar()); //naive approach, may mot result in correct representation of partial datetime 
-                       } 
+                               result = dataTypeFactory().newXMLGregorianCalendar(((DateTime)source).toGregorianCalendar()); //naive approach, may mot result in correct representation of partial datetime
+                       }
                }
-               
+
                if(result == null){
                        throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
                                        + destination + " and " + source);
                }
                return result;
        }
-       
+
          /**
           * Cache the DatatypeFactory because newInstance is very expensive.
           */
          private static DatatypeFactory dataTypeFactory;
-         
+
        /**
           * Returns a new instance of DatatypeFactory, or the cached one if previously created.
           *
@@ -59,5 +59,4 @@ public class DateTimeConverter implements CustomConverter {
            }
            return dataTypeFactory;
          }
-
-}
+}
\ No newline at end of file
index 4e8081e87827c893c2815ac2121922e658bfd25d..f84def1f454cdd0e8c20e12c032867ec188c2b9e 100644 (file)
@@ -1,3 +1,11 @@
+/**\r
+* Copyright (C) 2007 EDIT\r
+* European Distributed Institute of Taxonomy\r
+* http://www.e-taxonomy.eu\r
+*\r
+* The contents of this file are subject to the Mozilla Public License Version 1.1\r
+* See LICENSE.TXT at the top of this package for the full license terms.\r
+*/\r
 package eu.etaxonomy.cdm.remote.dto.assembler.converter;\r
 \r
 import java.net.URI;\r
@@ -31,7 +39,8 @@ public class DefaultRelatedPageConverter implements ConfigurableCustomConverter
        }\r
 \r
        @Override\r
-    public Object convert(Object existingDestinationFieldValue,        Object sourceFieldValue, Class<?> destinationClass, Class<?> sourceClass) {\r
+    public Object convert(Object existingDestinationFieldValue,        Object sourceFieldValue,\r
+            Class<?> destinationClass, Class<?> sourceClass) {\r
                if(sourceFieldValue == null) {\r
                        return null;\r
                }\r
@@ -51,5 +60,4 @@ public class DefaultRelatedPageConverter implements ConfigurableCustomConverter
                }\r
                return relation;\r
        }\r
-\r
-}\r
+}
\ No newline at end of file
index 135c2be68d2da17412c8f668750cbff4e3dd1c96..4435d59f62060dba395a64a819d9bbe1d746a78f 100644 (file)
@@ -19,13 +19,12 @@ import org.hibernate.envers.internal.entities.mapper.relation.lazy.proxy.Collect
 
 public class HibernateProxyFieldMapper implements CustomFieldMapper {
 
-
        @Override
     public boolean mapField(Object source, Object destination, Object sourceFieldValue, ClassMap classMap, FieldMap fieldMapping) {
 
                if(sourceFieldValue instanceof CollectionProxy) {
                        try {
-                               ((CollectionProxy)sourceFieldValue).hashCode();
+                               ((CollectionProxy<?,?>)sourceFieldValue).hashCode();
                        } catch(SessionException se) { // currently no way to tell if is initialized
                                return true;
                        }
@@ -35,6 +34,5 @@ public class HibernateProxyFieldMapper implements CustomFieldMapper {
                }else {
                        return true;
                }
-
        }
-}
+}
\ No newline at end of file
index eb2b920dbb4ec65f453fc6abd796cb83a0046726..e3a203be2e6dede611f1ee3c158b32f9e269d83a 100644 (file)
@@ -47,7 +47,6 @@ public class HibernateProxyNullSafeDeepConverter
                }\r
        }\r
 \r
-\r
        protected Mapper getMapper() {\r
                if(mapper == null) {\r
                        this.setMapper(this.applicationContext.getBean("dozerMapper", Mapper.class));\r
@@ -79,7 +78,6 @@ public class HibernateProxyNullSafeDeepConverter
                        } catch (Exception e) {\r
                                throw new MappingException("Converter HibernateProxyNullSafeDeepConverter used incorrectly. Arguments passed in were:"+ destination + " and " + source + " sourceClass " + sourceClass + " destClass " + destClass, e);\r
                        }\r
-\r
                }\r
        }\r
 \r
@@ -104,4 +102,4 @@ public class HibernateProxyNullSafeDeepConverter
                        throws BeansException {\r
                this.applicationContext = applicationContext;\r
        }\r
-}\r
+}
\ No newline at end of file
index f68d82eef9b044131cfd9a41a2fa8e378f0b092a..764a922f45941997907cc9f1a450e9b5beee93a2 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -17,18 +17,19 @@ import eu.etaxonomy.cdm.model.common.LSID;
 public class LsidProxyConverter implements CustomConverter {
 
        private String lsidProxyServiceUrl;
-       
+
        private String authorityPart;
-       
+
        public void setLsidProxyServiceUrl(String lsidProxyServiceUrl) {
                this.lsidProxyServiceUrl = lsidProxyServiceUrl;
        }
-       
+
        public void setAuthorityPart(String authorityPart) {
                this.authorityPart = authorityPart;
        }
 
-       public Object convert(Object destination, Object source, Class destClass, Class sourceClass) {
+       @Override
+    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
                if (source == null || ((LSID)source).toString() == null || ((LSID)source).toString().equals("")) {
                        return null;
                }
@@ -43,5 +44,4 @@ public class LsidProxyConverter implements CustomConverter {
                                        + destination + " and " + source);
                }
        }
-
-}
+}
\ No newline at end of file
index 94fb2a078dd36acf6ba12f52727660bbee1b1bd7..19506091bdf34c16cdc828af59607c493a175222 100644 (file)
@@ -1,8 +1,8 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.
 */
@@ -18,11 +18,12 @@ import org.dozer.MappingException;
 
 public class StripTagsConverter implements CustomConverter {
 
-       public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
+       @Override
+    public Object convert(Object destination, Object source, Class<?> destClass, Class<?> sourceClass) {
                if (source == null) {
                        return null;
                }
-               if (source instanceof String) {               
+               if (source instanceof String) {
                        Reader reader = new RemoveHTMLReader(new StringReader((String)source));
                        StringBuilder stringBuilder = new StringBuilder();
                        int charValue;
@@ -30,6 +31,7 @@ public class StripTagsConverter implements CustomConverter {
                                while ((charValue = reader.read()) != -1) {
                                    stringBuilder.append((char)charValue);
                                }
+                               reader.close();
                        } catch (IOException e) {return e.toString();}
                        return stringBuilder.toString();
                } else {
@@ -37,5 +39,4 @@ public class StripTagsConverter implements CustomConverter {
                                        + destination + " and " + source);
                }
        }
-
-}
+}
\ No newline at end of file
index caf2c9b7636d253859030b14116ba6831c39e3c9..9f43f95f96a04fae8e51a9bd3b9904d98b148690 100644 (file)
@@ -38,12 +38,10 @@ public class TimePeriodConverter implements CustomConverter {
                        //convert from DateTime -> TimePeriod
                        //FIXME implement
                        return null;
-
                } else {
 
                        throw new MappingException("Converter TestCustomConverter used incorrectly. Arguments passed in were:"
                                        + existingDestinationFieldValue + " and " + source);
                }
        }
-
-}
+}
\ No newline at end of file
index 03e468b96441beff8b80a61b3f455f78283635fa..0b7f3407ebaca3586c5348bf5f5f7f9e9cb6b047 100644 (file)
@@ -22,22 +22,22 @@ import eu.etaxonomy.cdm.remote.dto.oaipmh.OAIPMH;
  * @see com.ibm.lsid.MetadataResponse\r
  */\r
 public abstract class OaiPmhResponseView extends AbstractView {\r
-       \r
+\r
        private Marshaller marshaller;\r
-       \r
+\r
        protected Mapper mapper;\r
-       \r
+\r
        @Autowired\r
        @Qualifier("marshaller")\r
        public void setMarshaller(Marshaller marshaller) {\r
                this.marshaller = marshaller;\r
        }\r
-       \r
+\r
        @Autowired\r
        public void setMapper(Mapper mapper) {\r
                this.mapper = mapper;\r
        }\r
-       \r
+\r
     protected abstract void constructResponse(OAIPMH oaiPmh,Map<String,Object> model);\r
 \r
     @Override\r
index e2c15dedda74194034ddd75d3986db93b9ce3edc..797a920fc12d2487666f71dc582449e25cebef29 100644 (file)
@@ -52,11 +52,11 @@ public class JsonToCsvViewTest extends UnitilsJUnit4 {
 \r
     @Before\r
     public void setUp() throws Exception {\r
-    \r
+\r
         model = new HashMap<String,Object>();\r
         identifyView = new IdentifyView();\r
         identifyView.setMarshaller(marshaller);\r
-        \r
+\r
         metaDataRecord = new CsvDemoMetaDataRecord(true, "/tmp", "");\r
         config = CsvDemoExportConfigurator.NewInstance(null, null);\r
 \r
@@ -82,7 +82,7 @@ public class JsonToCsvViewTest extends UnitilsJUnit4 {
         demoRecord.setScientificName(taxon.getTitleCache());\r
         demoRecord.setAuthorName("Author");\r
         demoRecord.setDatasetName("Classification");\r
-        \r
+\r
         ArrayList<CsvDemoRecord> recordList = new ArrayList<CsvDemoRecord>();\r
         logger.info(recordList.size());\r
         recordList.add(demoRecord);\r