improvements for looking up existing areas
authorAndreas Müller <a.mueller@bgbm.org>
Thu, 13 Jan 2011 11:47:04 +0000 (11:47 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Thu, 13 Jan 2011 11:47:04 +0000 (11:47 +0000)
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/TdwgArea.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/location/WaterbodyOrCountry.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/BotanicalName.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/name/NonViralName.java

index e517e3c8eaf649358010ecf19d406b461713e836..806538ac7ab9f0d297cd74fca59e5444dd924c11 100644 (file)
@@ -106,6 +106,7 @@ public class TdwgArea extends NamedArea {
                if (labelMap == null){\r
                        initMaps();\r
                }\r
                if (labelMap == null){\r
                        initMaps();\r
                }\r
+               tdwgLabel = tdwgLabel.toLowerCase();\r
                UUID uuid = labelMap.get(tdwgLabel);\r
                if (uuid == null){\r
                        logger.info("Unknown TDWG area: " + CdmUtils.Nz(tdwgLabel));\r
                UUID uuid = labelMap.get(tdwgLabel);\r
                if (uuid == null){\r
                        logger.info("Unknown TDWG area: " + CdmUtils.Nz(tdwgLabel));\r
@@ -115,6 +116,7 @@ public class TdwgArea extends NamedArea {
        }\r
        \r
        public static boolean isTdwgAreaLabel(String label){\r
        }\r
        \r
        public static boolean isTdwgAreaLabel(String label){\r
+               label = (label == null? null : label.toLowerCase());\r
                if (labelMap.containsKey(label)){\r
                        return true;\r
                }else{\r
                if (labelMap.containsKey(label)){\r
                        return true;\r
                }else{\r
@@ -160,7 +162,7 @@ public class TdwgArea extends NamedArea {
                Language lang = Language.DEFAULT();\r
                Representation representation = area.getRepresentation(lang);\r
                String tdwgAbbrevLabel = representation.getAbbreviatedLabel();\r
                Language lang = Language.DEFAULT();\r
                Representation representation = area.getRepresentation(lang);\r
                String tdwgAbbrevLabel = representation.getAbbreviatedLabel();\r
-               String tdwgLabel = representation.getLabel();\r
+               String tdwgLabel = representation.getLabel().toLowerCase();\r
                if (tdwgAbbrevLabel == null){\r
                        logger.warn("tdwgLabel = null");\r
                        return;\r
                if (tdwgAbbrevLabel == null){\r
                        logger.warn("tdwgLabel = null");\r
                        return;\r
index 64bc601e7855e49239fa5b20c5b9efae8e91e8b3..7c88e54523a934c2c7f4839e63e142b781fb61e2 100644 (file)
@@ -36,8 +36,11 @@ import org.hibernate.envers.Audited;
 import org.hibernate.search.annotations.Indexed;
 
 import au.com.bytecode.opencsv.CSVWriter;
 import org.hibernate.search.annotations.Indexed;
 
 import au.com.bytecode.opencsv.CSVWriter;
+import eu.etaxonomy.cdm.common.CdmUtils;
+import eu.etaxonomy.cdm.model.common.DefaultTermInitializer;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
 import eu.etaxonomy.cdm.model.common.DefinedTermBase;
 import eu.etaxonomy.cdm.model.common.Language;
+import eu.etaxonomy.cdm.model.common.Representation;
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 
 /**
 import eu.etaxonomy.cdm.model.common.TermVocabulary;
 
 /**
@@ -76,7 +79,8 @@ public class WaterbodyOrCountry extends NamedArea {
        @JoinTable(name="DefinedTermBase_Continent")
        private Set<Continent> continents = new HashSet<Continent>();
        
        @JoinTable(name="DefinedTermBase_Continent")
        private Set<Continent> continents = new HashSet<Continent>();
        
-       protected static Map<UUID, NamedArea> termMap = null;           
+       protected static Map<UUID, NamedArea> termMap = null;
+       protected static Map<String, UUID> labelMap = null;
 
        private static final UUID uuidAfghanistan = UUID.fromString("974ce01a-5bce-4be8-b728-a46869354960");
        private static final UUID uuidAlbaniaPeoplesSocialistRepublicof = UUID.fromString("238a6a93-8857-4fd6-af9e-6437c90817ac");
 
        private static final UUID uuidAfghanistan = UUID.fromString("974ce01a-5bce-4be8-b728-a46869354960");
        private static final UUID uuidAlbaniaPeoplesSocialistRepublicof = UUID.fromString("238a6a93-8857-4fd6-af9e-6437c90817ac");
@@ -635,8 +639,15 @@ public class WaterbodyOrCountry extends NamedArea {
        @Override
        public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms) {
                try {
        @Override
        public NamedArea readCsvLine(Class<NamedArea> termClass, List<String> csvLine, Map<UUID,DefinedTermBase> terms) {
                try {
+                       Language lang= Language.DEFAULT();
                        WaterbodyOrCountry newInstance = WaterbodyOrCountry.class.newInstance();
                        WaterbodyOrCountry newInstance = WaterbodyOrCountry.class.newInstance();
-                       super.readCsvLine(newInstance, csvLine, Language.DEFAULT());
+                       newInstance.setUuid(UUID.fromString(csvLine.get(0)));
+                       newInstance.setUri(csvLine.get(1));
+                       String label = csvLine.get(3).trim();
+                       String text = csvLine.get(3).trim();
+                       String abbreviatedLabel = csvLine.get(2);
+                       newInstance.addRepresentation(Representation.NewInstance(text, label, abbreviatedLabel, lang) );
+                       
                        // iso codes extra
                        newInstance.setIso3166_A2(csvLine.get(4).trim());
                        
                        // iso codes extra
                        newInstance.setIso3166_A2(csvLine.get(4).trim());
                        
@@ -670,24 +681,65 @@ public class WaterbodyOrCountry extends NamedArea {
                writer.writeNext(line);
        }       
 
                writer.writeNext(line);
        }       
 
+       public static boolean isWaterbodyOrCountryLabel(String label) {
+               if (labelMap.containsKey(label)){
+                       return true;
+               }else{
+                       return false;
+               }
+       }
+
 
        
 //************************** METHODS ********************************
        
 
        
 //************************** METHODS ********************************
        
+       
+       private static void initMaps(){
+               labelMap = new HashMap<String, UUID>();
+               termMap = new HashMap<UUID, NamedArea>();
+       }
+       
+       /**
+        * FIXME This class should really be refactored into an interface and service implementation,
+        * relying on TermVocabularyDao / service (Ben)
+        * @param tdwgLabel
+        * @return
+        */
+       public static WaterbodyOrCountry getWaterbodyOrCountryByLabel(String label) {
+               if (labelMap == null){
+                       initMaps();
+               }
+               UUID uuid = labelMap.get(label);
+               if (uuid == null){
+                       logger.info("Unknown country: " + CdmUtils.Nz(label));
+                       return null;
+               }
+               return (WaterbodyOrCountry)termMap.get(uuid); 
+               
+       }
+       
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
         */
        @Override
        public void resetTerms(){
                termMap = null;
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.DefinedTermBase#resetTerms()
         */
        @Override
        public void resetTerms(){
                termMap = null;
+               labelMap = null;
        }
 
        }
 
+
        
        @Override
        protected void setDefaultTerms(TermVocabulary<NamedArea> termVocabulary) {
        
        @Override
        protected void setDefaultTerms(TermVocabulary<NamedArea> termVocabulary) {
-               termMap = new HashMap<UUID, NamedArea>();
+               initMaps();
                for (NamedArea term : termVocabulary.getTerms()){
                        termMap.put(term.getUuid(), (NamedArea)term);  //TODO casting
                }
                for (NamedArea term : termVocabulary.getTerms()){
                        termMap.put(term.getUuid(), (NamedArea)term);  //TODO casting
                }
+               for (NamedArea term : termVocabulary.getTerms()){
+                       labelMap.put(term.getLabel(), term.getUuid());  
+               }
+               
        }
        }
+
+       
 }
\ No newline at end of file
 }
\ No newline at end of file
index de101d5019c3abe8fd8bfbd7456c97a129b34b10..65267e96f48d6d326be04a4d43604967390b7a9a 100644 (file)
@@ -355,4 +355,5 @@ public class BotanicalName extends NonViralName<BotanicalName> implements Clonea
                return result;
        }
 
                return result;
        }
 
+
 }
\ No newline at end of file
 }
\ No newline at end of file
index 2c7c5ecefed97d804ae71aed1bb116abe5838c43..13f32463e1e3f09ac6ba6570f88b2c6a1ffa0511 100644 (file)
@@ -1301,6 +1301,58 @@ public class NonViralName<T extends NonViralName> extends TaxonNameBase<T, INonV
                }
        }
        
                }
        }
        
+
+       /**
+        * Tests if the given name has any authors.
+        * @return false if no author ((ex)combination or (ex)basionym) exists, true otherwise
+        */
+       public boolean hasAuthors() {
+               return (this.getCombinationAuthorTeam() != null || 
+                               this.getExCombinationAuthorTeam() != null ||
+                               this.getBasionymAuthorTeam() != null ||
+                               this.getExBasionymAuthorTeam() != null);
+       }
+       
+       /**
+        * Shortcut. Returns the combination authors title cache. Returns null if no combination author exists.
+        * @return
+        */
+       public String computeCombinationAuthorNomenclaturalTitle() {
+               return computeNomenclaturalTitle(this.getCombinationAuthorTeam());
+       }
+
+       /**
+        * Shortcut. Returns the basionym authors title cache. Returns null if no basionym author exists.
+        * @return
+        */
+       public String computeBasionymAuthorNomenclaturalTitle() {
+               return computeNomenclaturalTitle(this.getBasionymAuthorTeam());
+       }
+       
+       
+       /**
+        * Shortcut. Returns the ex-combination authors title cache. Returns null if no ex-combination author exists.
+        * @return
+        */
+       public String computeExCombinationAuthorNomenclaturalTitle() {
+               return computeNomenclaturalTitle(this.getExCombinationAuthorTeam());
+       }
+
+       /**
+        * Shortcut. Returns the ex-basionym authors title cache. Returns null if no exbasionym author exists.
+        * @return
+        */
+       public String computeExBasionymAuthorNomenclaturalTitle() {
+               return computeNomenclaturalTitle(this.getExBasionymAuthorTeam());
+       }
+       
+       private String computeNomenclaturalTitle(INomenclaturalAuthor author){
+               if (author == null){
+                       return null;
+               }else{
+                       return author.getNomenclaturalTitle();
+               }
+       }
        
 //*********************** CLONE ********************************************************/
 
        
 //*********************** CLONE ********************************************************/