Further model changes for DescriptionElementBase and DescriptionElementSource
authorAndreas Müller <a.mueller@bgbm.org>
Mon, 21 Sep 2009 14:55:33 +0000 (14:55 +0000)
committerAndreas Müller <a.mueller@bgbm.org>
Mon, 21 Sep 2009 14:55:33 +0000 (14:55 +0000)
Version 2.1.2.0.200909211654

cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelFactsImport.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/berlinModel/in/BerlinModelOccurrenceImport.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/faunaEuropaea/FaunaEuropaeaRefImport.java
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/taxonx/TaxonXDescriptionImport.java
cdmlib-io/src/test/resources/dbscripts/001_cdm.ddl
cdmlib-io/src/test/resources/eu/etaxonomy/cdm/io/dataset.dtd
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/CdmMetaData.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/common/DescriptionElementSource.java
cdmlib-model/src/main/java/eu/etaxonomy/cdm/model/description/DescriptionElementBase.java
cdmlib-persistence/src/test/resources/dbscripts/001_cdm.ddl
cdmlib-services/src/test/resources/dbscripts/001_cdm.ddl

index 0782123f48754ef87aa2271fd9688cf612089fae..c18df3040525154ea33283732846ac4a4441ddd2 100644 (file)
@@ -27,6 +27,7 @@ import eu.etaxonomy.cdm.io.common.ICdmIO;
 import eu.etaxonomy.cdm.io.common.MapWrapper;\r
 import eu.etaxonomy.cdm.io.common.Source;\r
 import eu.etaxonomy.cdm.model.common.Annotation;\r
+import eu.etaxonomy.cdm.model.common.DescriptionElementSource;\r
 import eu.etaxonomy.cdm.model.common.Language;\r
 import eu.etaxonomy.cdm.model.common.Marker;\r
 import eu.etaxonomy.cdm.model.common.MarkerType;\r
@@ -318,9 +319,12 @@ public class BerlinModelFactsImport  extends BerlinModelImportBase {
                                                        citation = null;\r
                                                }\r
 \r
-                                               \r
-                                               textData.setCitation(citation);\r
-                                               textData.setCitationMicroReference(details);\r
+                                               if (citation != null || CdmUtils.isNotEmpty(details)){\r
+                                                       DescriptionElementSource originalSource = DescriptionElementSource.NewInstance();\r
+                                                       originalSource.setCitation(citation);\r
+                                                       originalSource.setCitationMicroReference(details);\r
+                                                       textData.addSource(originalSource);\r
+                                               }\r
                                                taxonDescription.addElement(textData);\r
                                                //doubtfulFlag\r
                                                if (doubtfulFlag){\r
index 77417b2162bcd266dc5d77bd0b182cc1e87ce6ec..1ffcad4c9b0e9da8b26592805031b8dc3aad78ad 100644 (file)
@@ -12,28 +12,36 @@ package eu.etaxonomy.cdm.io.berlinModel.in;
 import java.sql.ResultSet;\r
 import java.sql.SQLException;\r
 import java.util.ArrayList;\r
+import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Map;\r
 import java.util.Set;\r
+import java.util.UUID;\r
 \r
 import org.apache.log4j.Logger;\r
 import org.springframework.stereotype.Component;\r
 \r
+import eu.etaxonomy.cdm.common.CdmUtils;\r
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;\r
 import eu.etaxonomy.cdm.io.berlinModel.BerlinModelTransformer;\r
 import eu.etaxonomy.cdm.io.common.ICdmIO;\r
 import eu.etaxonomy.cdm.io.common.MapWrapper;\r
 import eu.etaxonomy.cdm.io.common.Source;\r
+import eu.etaxonomy.cdm.model.common.DescriptionElementSource;\r
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
 import eu.etaxonomy.cdm.model.description.Distribution;\r
 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;\r
 import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
 import eu.etaxonomy.cdm.model.location.NamedArea;\r
 import eu.etaxonomy.cdm.model.location.TdwgArea;\r
+import eu.etaxonomy.cdm.model.name.NonViralName;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 import eu.etaxonomy.cdm.model.taxon.Taxon;\r
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;\r
 import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;\r
+import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;\r
 \r
 \r
 /**\r
@@ -114,6 +122,7 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                boolean success = true;\r
                MapWrapper<TaxonBase> taxonMap = (MapWrapper<TaxonBase>)state.getStore(ICdmIO.TAXON_STORE);\r
                MapWrapper<ReferenceBase> referenceMap = (MapWrapper<ReferenceBase>)state.getStore(ICdmIO.REFERENCE_STORE);\r
+               MapWrapper<Distribution> distributionMap = new MapWrapper<Distribution>(null);\r
                BerlinModelImportConfigurator config = state.getConfig();\r
                Source source = config.getSource();\r
                \r
@@ -136,6 +145,8 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                 " ORDER BY PTaxon.RIdentifier";\r
                        ResultSet rs = source.getResultSet(strQuery) ;\r
                        \r
+                       //map to store the mapping of duplicate berlin model occurrences to their real distributions\r
+                       Map<Integer, Distribution> duplicateMap = new HashMap<Integer, Distribution>();\r
                        int oldTaxonId = -1;\r
                        TaxonDescription oldDescription = null;\r
                        int i = 0;\r
@@ -155,7 +166,7 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                     //status\r
                      PresenceAbsenceTermBase<?> status = null;\r
                      if (emStatusId != null){\r
-                        status = BerlinModelTransformer.occStatus2PresenceAbsence(emStatusId);\r
+                       status = BerlinModelTransformer.occStatus2PresenceAbsence(emStatusId);\r
                      }\r
                      \r
                      //Create area list\r
@@ -169,13 +180,15 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                                  }\r
                            }\r
                      }\r
-                     \r
+                     ReferenceBase<?> sourceRef = state.getConfig().getSourceReference();\r
                      //create description(elements)\r
-                     TaxonDescription taxonDescription = getTaxonDescription(newTaxonId, oldTaxonId, oldDescription, taxonMap, occurrenceId);\r
+                     TaxonDescription taxonDescription = getTaxonDescription(newTaxonId, oldTaxonId, oldDescription, taxonMap, occurrenceId, sourceRef);\r
                      for (NamedArea tdwgArea : tdwgAreas){\r
                            Distribution distribution = Distribution.NewInstance(tdwgArea, status);\r
+//                         distribution.setCitation(sourceRef);\r
                            if (taxonDescription != null) { \r
-                               if (checkIsNoDuplicate(taxonDescription , distribution)){\r
+                               if (checkIsNoDuplicate(taxonDescription, distribution, duplicateMap , occurrenceId)){\r
+                                   distributionMap.put(occurrenceId, distribution);\r
                                           taxonDescription.addElement(distribution); \r
                                       countDistributions++; \r
                                       if (taxonDescription != oldDescription){ \r
@@ -184,8 +197,7 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                                           countDescriptions++; \r
                                        } \r
                                }else{\r
-                                  logger.debug("Distribution is duplicate");\r
-                               }\r
+                                  logger.debug("Distribution is duplicate");                              }\r
                                } else { \r
                                        logger.warn("Distribution " + tdwgArea.toString() + " ignored");\r
                                        success = false;\r
@@ -193,17 +205,15 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                      }\r
                      \r
                 } catch (UnknownCdmTypeException e) {\r
-                     // TODO Auto-generated catch block\r
-                     e.printStackTrace();\r
+                     logger.error("Unknown presenceAbsence status id: " + emStatusId); \r
+                       e.printStackTrace();\r
                      success = false;\r
                 }\r
-\r
-//              TODO\r
-//              sources\r
-//              references\r
+                \r
             }\r
-\r
-                       logger.info("Distributions: " + countDistributions + ", Descriptions: " + countDescriptions );\r
+            makeOccurreceSource(distributionMap, state, duplicateMap);\r
+                       \r
+            logger.info("Distributions: " + countDistributions + ", Descriptions: " + countDescriptions );\r
                        logger.warn("Unmatched occurrences: "  + (i - countDescriptions));\r
                        logger.info("Taxa to save: " + taxonStore.size());\r
                        getTaxonService().saveTaxonAll(taxonStore);     \r
@@ -217,15 +227,136 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
 \r
        }\r
 \r
+       /**\r
+        * @param distributionMap\r
+        * @param state\r
+        * @throws SQLException \r
+        */\r
+       private void makeOccurreceSource(MapWrapper<Distribution> distributionMap, BerlinModelImportState state, Map<Integer, Distribution> duplicateMap) \r
+                               throws SQLException {\r
+               //FIXME multiple sources for one distribution, needs model change first\r
+               Map<String, ReferenceBase<?>> sourceIdMap = makeSourceIdMap(state); \r
+               Source source = state.getConfig().getSource();\r
+               String strQuery = " SELECT OccurrenceSourceId, OccurrenceFk, SourceNumber, OldName, OldNameFk, PreferredReferenceFlag " + \r
+                                               " FROM emOccurrenceSource " +\r
+                                               " ORDER BY SourceNumber DESC ";\r
+               \r
+               \r
+               ResultSet rs = source.getResultSet(strQuery) ;\r
+               while (rs.next()){\r
+                       int occurrenceSourceId = rs.getInt("OccurrenceSourceId"); //TODO make originalSourceId\r
+                       Integer occurrenceFk = (Integer)rs.getObject("OccurrenceFk");\r
+                       String sourceNumber = rs.getString("SourceNumber");\r
+                       String oldName = rs.getString("OldName");\r
+                       int oldNameFk = rs.getInt("OldNameFk");\r
+                       Distribution distribution = distributionMap.get(occurrenceFk);\r
+                       if (distribution == null){\r
+                               distribution = duplicateMap.get(occurrenceFk);\r
+                       }\r
+                       if (distribution != null){\r
+                               ReferenceBase<?> ref = sourceIdMap.get(sourceNumber);\r
+                               if (ref != null){\r
+                                       DescriptionElementSource originalSource = DescriptionElementSource.NewInstance();\r
+                                       originalSource.setCitation(ref);\r
+                                       TaxonNameBase<?,?> taxonName = getName(state, oldName, oldNameFk);\r
+                                       if (taxonName != null){\r
+                                               originalSource.setNameUsedInSource(taxonName);\r
+                                       }else if(CdmUtils.isNotEmpty(oldName)){\r
+                                               originalSource.setOriginalNameString(oldName);\r
+                                       }\r
+                                       distribution.addSource(originalSource);\r
+                               }else{\r
+                                       logger.warn("reference for sourceId "+sourceNumber+" could not be found." );\r
+                               }\r
+                       }else{\r
+                               logger.warn("distribution ("+occurrenceFk+") could not be found." );\r
+                       }\r
+                       \r
+               }\r
+       }\r
+\r
        \r
-    /**\r
-     * Tests if a distribution with the same tdwgArea and the same status already exists in the description\r
-     * Returns false, if a duplicate exists. True otherwise\r
+       private NonViralNameParserImpl nameParser = NonViralNameParserImpl.NewInstance();\r
+       /**\r
+        * @param state\r
+        * @param oldName\r
+        * @param oldNameFk\r
+        * @return\r
+        */\r
+       private TaxonNameBase<?, ?> getName(BerlinModelImportState state, String oldName, int oldNameFk) {\r
+               TaxonNameBase<?,?> taxonName = null;\r
+               MapWrapper<TaxonNameBase<?,?>> taxonNameMap = (MapWrapper<TaxonNameBase<?,?>>)state.getStore(ICdmIO.TAXONNAME_STORE);\r
+               taxonName = taxonNameMap.get(oldNameFk);\r
+               if (taxonName == null && oldName != null){\r
+                       List<NonViralName> names = getNameService().getNamesByNameCache(oldName);\r
+                       if (names.size() == 1){\r
+                               return names.get(0);\r
+                       }else {\r
+                               if (names.size()> 2){\r
+                                       logger.info("Name has non unique NameCache: " + oldName + ".");\r
+                               }\r
+                               return null;\r
+                               //taxonName = nameParser.parseSimpleName(oldName);\r
+                       }\r
+               }\r
+               return taxonName;\r
+       }\r
+\r
+       /**\r
+        * @param state\r
+        * @return\r
+     * @throws SQLException \r
+        */\r
+       private Map<String, ReferenceBase<?>> makeSourceIdMap(\r
+                       BerlinModelImportState state) throws SQLException {\r
+               MapWrapper<ReferenceBase<?>> referenceMap = (MapWrapper<ReferenceBase<?>>)state.getStore(ICdmIO.REFERENCE_STORE);\r
+               MapWrapper<ReferenceBase<?>> nomRefMap = (MapWrapper<ReferenceBase<?>>)state.getStore(ICdmIO.NOMREF_STORE);\r
+               \r
+               Map<String, ReferenceBase<?>> result = new HashMap<String, ReferenceBase<?>>();\r
+               Source source = state.getConfig().getSource();\r
+               String strQuery = " SELECT RefId, IdInSource " +  \r
+                                                 " FROM Reference " + \r
+                                                 " WHERE     (IdInSource IS NOT NULL) AND (IdInSource NOT LIKE '') ";\r
+               ResultSet rs = source.getResultSet(strQuery) ;\r
+               while (rs.next()){\r
+                       int refId = rs.getInt("RefId");\r
+                       String idInSource = rs.getString("IdInSource");\r
+                       if (idInSource != null){\r
+                               String[] singleSources = idInSource.split("\\|");\r
+                               for (String singleSource : singleSources){\r
+                                       singleSource = singleSource.trim();\r
+                                       ReferenceBase<?> ref = getReference(refId, referenceMap, nomRefMap);\r
+                                       if (ref == null){\r
+                                               logger.warn("Reference ("+refId+")not found in refStore.");\r
+                                       }\r
+                                       result.put(singleSource, ref);\r
+                               }\r
+                       }\r
+               }\r
+               return result;\r
+       }\r
+\r
+       /**\r
+        * @param refId\r
+        * @param referenceMap\r
+        * @param nomRefMap\r
+        */\r
+       private ReferenceBase<?> getReference(int refId, MapWrapper<ReferenceBase<?>> referenceMap, MapWrapper<ReferenceBase<?>> nomRefMap) {\r
+               ReferenceBase<?> ref = referenceMap.get(refId);\r
+               if (ref == null){\r
+                       ref = nomRefMap.get(refId);\r
+               }\r
+               return ref;\r
+       }\r
+\r
+       /**\r
+     * Tests if a distribution with the same tdwgArea and the same status already exists in the description. If so \r
+     * the duplicate will be registered in the duplicateMap.\r
      * @param description\r
      * @param tdwgArea\r
-     * @return\r
+     * @return false, if dupplicate exists. True otherwise.\r
      */\r
-    private boolean checkIsNoDuplicate(TaxonDescription description, Distribution distribution){\r
+    private boolean checkIsNoDuplicate(TaxonDescription description, Distribution distribution, Map<Integer, Distribution> duplicateMap, Integer bmDistributionId){\r
        for (DescriptionElementBase descElBase : description.getElements()){\r
                if (descElBase.isInstanceOf(Distribution.class)){\r
                        Distribution oldDistr = HibernateProxyHelper.deproxy(descElBase, Distribution.class);\r
@@ -233,6 +364,7 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                        if (oldArea != null && oldArea.equals(distribution.getArea())){\r
                                PresenceAbsenceTermBase<?> oldStatus = oldDistr.getStatus();\r
                                if (oldStatus != null && oldStatus.equals(distribution.getStatus())){\r
+                                       duplicateMap.put(bmDistributionId, oldDistr);\r
                                        return false;\r
                                }\r
                        }\r
@@ -249,7 +381,7 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
         * @param taxonMap\r
         * @return\r
         */\r
-       private TaxonDescription getTaxonDescription(int newTaxonId, int oldTaxonId, TaxonDescription oldDescription, MapWrapper<TaxonBase> taxonMap, int occurrenceId){\r
+       private TaxonDescription getTaxonDescription(int newTaxonId, int oldTaxonId, TaxonDescription oldDescription, MapWrapper<TaxonBase> taxonMap, int occurrenceId, ReferenceBase<?> sourceSec){\r
                TaxonDescription result = null;\r
                if (oldDescription == null || newTaxonId != oldTaxonId){\r
                        TaxonBase taxonBase = taxonMap.get(newTaxonId);\r
@@ -264,12 +396,15 @@ public class BerlinModelOccurrenceImport  extends BerlinModelImportBase {
                        } else {\r
                                logger.warn("TaxonBase for Occurrence " + occurrenceId + " is null.");\r
                                return null;\r
+                       }               \r
+                       Set<TaxonDescription> descriptionSet= taxon.getDescriptions();\r
+                       if (descriptionSet.size() > 0) {\r
+                               result = descriptionSet.iterator().next(); \r
+                       }else{\r
+                               result = TaxonDescription.NewInstance();\r
+                               result.setTitleCache(sourceSec.getTitleCache());\r
+                               taxon.addDescription(result);\r
                        }\r
-                       \r
-                       result = TaxonDescription.NewInstance();\r
-                       taxon.addDescription(result);\r
-                       //TODO add source title as title (or reference at least)\r
-                       //result.setTitleCache("");\r
                }else{\r
                        result = oldDescription;\r
                }\r
index d311b4935b50d3770d2970b07883232a126edada..d9d710b8c972f4a3b98210dc12a4834b872f3fdb 100644 (file)
@@ -28,6 +28,8 @@ import eu.etaxonomy.cdm.io.common.Source;
 import eu.etaxonomy.cdm.model.agent.Team;\r
 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;\r
 import eu.etaxonomy.cdm.model.common.CdmBase;\r
+import eu.etaxonomy.cdm.model.common.DescriptionElementSource;\r
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
 import eu.etaxonomy.cdm.model.description.Feature;\r
 import eu.etaxonomy.cdm.model.description.TaxonDescription;\r
 import eu.etaxonomy.cdm.model.description.TextData;\r
@@ -294,12 +296,15 @@ public class FaunaEuropaeaRefImport extends FaunaEuropaeaImportBase {
                                                                for (FaunaEuropaeaReference storedReference : fauEuHelperTaxon.getReferences()) {\r
 \r
                                                                        TextData textData = TextData.NewInstance(Feature.CITATION());\r
+                                                                       \r
+                                                                       ReferenceBase citation = storedReference.getCdmReference();\r
+                                                                       String microCitation = storedReference.getPage();\r
+                                                                       DescriptionElementSource originalSource = DescriptionElementSource.NewInstance(null, null, citation, microCitation, null, null);\r
                                                                        if (isSynonym){\r
                                                                                Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);\r
-                                                                               textData.setNameUsedInReference(syn.getName());\r
+                                                                               originalSource.setNameUsedInSource(syn.getName());\r
                                                                        }\r
-                                                                       textData.setCitation(storedReference.getCdmReference());\r
-                                                                       textData.setCitationMicroReference(storedReference.getPage());\r
+                                                                       textData.addSource(originalSource);\r
                                                                        taxonDescription.addElement(textData);\r
                                                                }\r
                                                        }\r
index 67ce8d4c2b2602c42061b0af86b7cd95fe3a78cf..6c5931c563a6d1f4bff2ca9729b9d70fb4f21c42 100644 (file)
@@ -130,7 +130,9 @@ public class TaxonXDescriptionImport extends CdmIoBase<TaxonXImportState> implem
                                description.addElement(descriptionElement);\r
                                \r
                                //add reference\r
-                               descriptionElement.setCitation(state.getModsReference());\r
+                               if (state.getModsReference() != null){\r
+                                       descriptionElement.addSource(null, null, state.getModsReference(), null, null, null);\r
+                               }\r
                        }\r
 \r
                }\r
index 4fb2f9415d3a63bafcc70ce0049cecbc8b06adb7..04bca36ddeac03e63998f52c7a5206d0a74a3fc4 100644 (file)
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         sourcedObj_type varchar(255),
         sourcedObj_id integer not null,
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         createdby_id integer,
         updatedby_id integer,
         foreign key (citation_id) 
         references Reference;
 
+    alter table OriginalSourceBase 
+        add constraint FK820A492C9803E12F 
+        foreign key (nameUsedInSource_id) 
+        references TaxonNameBase;
+
     alter table OriginalSourceBase 
         add constraint FK229A496CBC5DA539 
         foreign key (updatedby_id) 
index f54f802e407de1b50f981e82f8f360a473d56e1d..cf11343e9d2867dce0c74fa52af4fd80b4ed7486 100644 (file)
     UPDATED CDATA #IMPLIED
     CITATIONMICROREFERENCE CDATA #IMPLIED
     ORIGINALNAMESTRING CDATA #IMPLIED
+    NAMEUSEDINSOURCE_ID CDATA #IMPLIED
     IDINSOURCE CDATA #IMPLIED
     IDNAMESPACE CDATA #IMPLIED
     SOURCEDOBJ_TYPE CDATA #IMPLIED
index 0ec2d65b08e827b5fc00303c7c44b6f077ee208a..ea24cca8b8b1fb3026dadebf0d3a64c7e42a273b 100644 (file)
@@ -38,7 +38,7 @@ public class CdmMetaData extends CdmBase{
         * be handled by SCHEMA_VALIDATION.UPDATE\r
         * The last number represents the date of change.\r
         */\r
-       private static final String dbSchemaVersion = "2.1.1.0.200909181723";\r
+       private static final String dbSchemaVersion = "2.1.2.0.200909211654";\r
        \r
        public enum MetaDataPropertyName{\r
                DB_SCHEMA_VERSION\r
index d6fdce37982adf2e5b5d3e7c6128ab8e3a29356c..bc6071d2b6dbea15e594f946bd049d6b34565b36 100644 (file)
@@ -14,6 +14,7 @@ import javax.persistence.Column;
 import javax.persistence.Entity;\r
 import javax.persistence.FetchType;\r
 import javax.persistence.JoinColumn;\r
+import javax.persistence.ManyToOne;\r
 import javax.xml.bind.annotation.XmlElement;\r
 import javax.xml.bind.annotation.XmlIDREF;\r
 import javax.xml.bind.annotation.XmlSchemaType;\r
@@ -21,10 +22,13 @@ import javax.xml.bind.annotation.XmlType;
 \r
 import org.apache.log4j.Logger;\r
 import org.hibernate.annotations.Any;\r
+import org.hibernate.annotations.Cascade;\r
+import org.hibernate.annotations.CascadeType;\r
 import org.hibernate.envers.Audited;\r
 import org.hibernate.envers.NotAudited;\r
 \r
 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;\r
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;\r
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;\r
 \r
 /**\r
@@ -33,7 +37,8 @@ import eu.etaxonomy.cdm.model.reference.ReferenceBase;
  * @version 1.0\r
  */\r
 @XmlType(name = "DescriptionElementSource", propOrder = {\r
-           "sourcedObj"\r
+           "sourcedObj",\r
+           "nameUsedInSource",\r
        })\r
 @Entity\r
 @Audited\r
@@ -70,6 +75,13 @@ public class DescriptionElementSource extends OriginalSourceBase<DescriptionElem
                return result;\r
        }\r
        \r
+       public static DescriptionElementSource NewInstance(String id, String idNamespace, ReferenceBase citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){\r
+               DescriptionElementSource result = NewInstance(id, idNamespace, citation, microReference);\r
+               result.setNameUsedInSource(nameUsedInSource);\r
+               result.setOriginalNameString(originalNameString);\r
+               return result;\r
+       }\r
+       \r
        @XmlElement(name = "SourcedObject")\r
     @XmlIDREF\r
     @XmlSchemaType(name = "IDREF")\r
@@ -81,7 +93,21 @@ public class DescriptionElementSource extends OriginalSourceBase<DescriptionElem
        @NotAudited\r
        private DescriptionElementBase sourcedObj;\r
        \r
-\r
+       @XmlElement(name = "nameUsedInSource")\r
+       @XmlIDREF\r
+       @XmlSchemaType(name = "IDREF")\r
+       @ManyToOne(fetch = FetchType.LAZY)\r
+       @Cascade({CascadeType.SAVE_UPDATE})\r
+       private TaxonNameBase nameUsedInSource;\r
+       \r
+       private DescriptionElementSource(){\r
+               \r
+       }\r
+       \r
+       \r
+// **************************  GETTER / SETTER ****************************************************/\r
+       \r
+       \r
        /* (non-Javadoc)\r
         * @see eu.etaxonomy.cdm.model.common.IOriginalSource#getSourcedObj()\r
         */\r
@@ -96,4 +122,22 @@ public class DescriptionElementSource extends OriginalSourceBase<DescriptionElem
                this.sourcedObj = sourcedObj;\r
        }\r
        \r
+       \r
+       /**\r
+        * @return the taxonNameUsedInSource\r
+        */\r
+       public TaxonNameBase getNameUsedInSource() {\r
+               return nameUsedInSource;\r
+       }\r
+\r
+       /**\r
+        * @param nameUsedInReference the nameUsedInReference to set\r
+        */\r
+       public void setNameUsedInSource(TaxonNameBase nameUsedInSource) {\r
+               this.nameUsedInSource = nameUsedInSource;\r
+       }\r
+\r
+       \r
+       \r
+       \r
 }\r
index fa6d2c52e2794f3124cab6e110f8d7cafc02ef16..a6c6b0fa534c508efbab83414cf6c6e64eded714 100644 (file)
@@ -43,6 +43,7 @@ import org.hibernate.envers.Audited;
 import org.hibernate.search.annotations.IndexedEmbedded;
 
 import eu.etaxonomy.cdm.jaxb.MultilanguageTextAdapter;
+import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
 import eu.etaxonomy.cdm.model.common.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.common.ISourceable;
 import eu.etaxonomy.cdm.model.common.Language;
@@ -53,6 +54,7 @@ import eu.etaxonomy.cdm.model.common.TermVocabulary;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.reference.ReferenceBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.strategy.merge.Merge;
 import eu.etaxonomy.cdm.strategy.merge.MergeMode;
@@ -82,13 +84,12 @@ import eu.etaxonomy.cdm.strategy.merge.MergeMode;
            "modifyingText",
            "media",
            "inDescription",
-           "nameUsedInReference",
            "sources"
 })
 @Entity
 @Audited
 @Inheritance(strategy=InheritanceType.SINGLE_TABLE)
-public abstract class DescriptionElementBase extends ReferencedEntityBase implements ISourceable<DescriptionElementSource> {
+public abstract class DescriptionElementBase extends AnnotatableEntity implements ISourceable<DescriptionElementSource> {
        private static final long serialVersionUID = 5000910777835755905L;
        @SuppressWarnings("unused")
        private static final Logger logger = Logger.getLogger(DescriptionElementBase.class);
@@ -133,12 +134,12 @@ public abstract class DescriptionElementBase extends ReferencedEntityBase implem
     private DescriptionBase inDescription;
        
        //TODO can this be handled together with ReferencedEntityBase.originalNameString??
-       @XmlElement(name = "nameUsedInReference")
-       @XmlIDREF
-       @XmlSchemaType(name = "IDREF")
-       @ManyToOne(fetch = FetchType.LAZY)
-       @Cascade({CascadeType.SAVE_UPDATE})
-       private TaxonNameBase nameUsedInReference;
+//     @XmlElement(name = "nameUsedInReference")
+//     @XmlIDREF
+//     @XmlSchemaType(name = "IDREF")
+//     @ManyToOne(fetch = FetchType.LAZY)
+//     @Cascade({CascadeType.SAVE_UPDATE})
+//     private TaxonNameBase nameUsedInReference;
        
     @XmlElementWrapper(name = "Sources")
     @XmlElement(name = "OriginalSource")
@@ -362,6 +363,11 @@ public abstract class DescriptionElementBase extends ReferencedEntityBase implem
                        source.setSourcedObj(this);
                }
        }
+       
+       public void addSource(String id, String idNamespace, ReferenceBase citation, String microReference, TaxonNameBase nameUsedInSource, String originalNameString){
+               DescriptionElementSource newSource = DescriptionElementSource.NewInstance(id, idNamespace, citation, microReference, nameUsedInSource, originalNameString);
+               addSource(newSource);
+       }
         
        /* (non-Javadoc)
         * @see eu.etaxonomy.cdm.model.common.ISourceable#removeSource(eu.etaxonomy.cdm.model.common.IOriginalSource)
@@ -372,18 +378,129 @@ public abstract class DescriptionElementBase extends ReferencedEntityBase implem
 
        
        /**
-        * @return the nameUsedInReference
+        * Gets the citation micro reference of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * @return
         */
-       public TaxonNameBase getNameUsedInReference() {
-               return nameUsedInReference;
+       @Transient
+       @Deprecated
+       public String getCitationMicroReference(){
+               if (this.sources.size() < 1){
+                       return null;
+               }else{
+                       return this.sources.iterator().next().getCitationMicroReference();
+               }
+       }
+       
+       /**
+        * Sets the citation micro reference of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * If more than one source exists an IllegalStateException is thrown
+        **/
+       @Transient
+       @Deprecated
+       public void setCitationMicroReference(String citationMicroReference){
+               if (this.sources.size() < 1){
+                       this.addSource(DescriptionElementSource.NewInstance(null, null, null, citationMicroReference));
+               }else if (this.sources.size() > 1){
+                       throw new IllegalStateException("When adding a microcitation via the setCitationMicroReference method there must be only one source available");
+               }else{
+                       this.sources.iterator().next().setCitationMicroReference(citationMicroReference);
+               }
        }
 
        /**
-        * @param nameUsedInReference the nameUsedInReference to set
+        * Gets the citation of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        */ 
+       @Transient
+       @Deprecated
+       public ReferenceBase getCitation(){
+               if (this.sources.size() < 1){
+                       return null;
+               }else{
+                       return this.sources.iterator().next().getCitation();
+               }
+       }
+       
+       /**
+        * Sets the citation of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * If more than one source exists an IllegalStateException is thrown
+        **/
+       @Deprecated
+       public void setCitation(ReferenceBase citation) {
+               if (this.sources.size() < 1){
+                       this.addSource(DescriptionElementSource.NewInstance(null, null, citation, null));
+               }else if (this.sources.size() > 1){
+                       throw new IllegalStateException("When adding a citation via the setCitation method there must be only one source available");
+               }else{
+                       this.sources.iterator().next().setCitation(citation);
+               }
+       }
+       
+       
+       /**
+        * Gets the original name string of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * @return
         */
-       public void setNameUsedInReference(TaxonNameBase nameUsedInReference) {
-               this.nameUsedInReference = nameUsedInReference;
+       @Transient
+       @Deprecated
+       public String getOriginalNameString(){
+               if (this.sources.size() < 1){
+                       return null;
+               }else{
+                       return this.sources.iterator().next().getOriginalNameString();
+               }
+       }
+       
+       /**
+        * Sets the original name string of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * If more than one source exists an IllegalStateException is thrown
+        **/
+       @Transient
+       @Deprecated
+       public void setOriginalNameString(String originalNameString){
+               if (this.sources.size() < 1){
+                       this.addSource(DescriptionElementSource.NewInstance(null, null, null, null, null, originalNameString));
+               }else if (this.sources.size() > 1){
+                       throw new IllegalStateException("When adding a microcitation via the setCitationMicroReference method there must be only one source available");
+               }else{
+                       this.sources.iterator().next().setOriginalNameString(originalNameString);
+               }
        }
        
+
+       /**
+        * Gets the name used in source of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        */ 
+       @Transient
+       @Deprecated
+       public TaxonNameBase getNameUsedInReference(){
+               if (this.sources.size() < 1){
+                       return null;
+               }else{
+                       return this.sources.iterator().next().getNameUsedInSource();
+               }
+       }
+       
+       /**
+        * Sets the name used in reference of the first source. This method is deprecated and exists only to be compliant with version 2.0.
+        * It will be removed in v2.3
+        * If more than one source exists an IllegalStateException is thrown
+        **/
+       @Deprecated
+       public void setNameUsedInReference(TaxonNameBase nameUsedInSource) {
+               if (this.sources.size() < 1){
+                       this.addSource(DescriptionElementSource.NewInstance(null, null, null, null, nameUsedInSource, null));
+               }else if (this.sources.size() > 1){
+                       throw new IllegalStateException("When adding a citation via the setCitation method there must be only one source available");
+               }else{
+                       this.sources.iterator().next().setNameUsedInSource(nameUsedInSource);
+               }
+       }
        
 }
\ No newline at end of file
index 7d33dc83e795bba3a81251c6ec46d03039fdb60f..e500b082e7901d89fd9ab4afbcf9276a137c0c6f 100644 (file)
@@ -2536,7 +2536,8 @@ create table DefinedTermBase_MeasurementUnit (
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         sourcedObj_type varchar(255),
         sourcedObj_id integer not null,
@@ -2557,7 +2558,8 @@ create table DefinedTermBase_MeasurementUnit (
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         createdby_id integer,
         updatedby_id integer,
@@ -6743,6 +6745,11 @@ create table DefinedTermBase_MeasurementUnit (
         foreign key (citation_id) 
         references Reference;
 
+    alter table OriginalSourceBase 
+        add constraint FK820A492C9803E12F 
+        foreign key (nameUsedInSource_id) 
+        references TaxonNameBase;
+
     alter table OriginalSourceBase 
         add constraint FK229A496CBC5DA539 
         foreign key (updatedby_id) 
index 2137c5098fb4e0187ef9825e19d0e08025ca00aa..741f3cb1163572bb5353ae7b94a9acb178cf8871 100644 (file)
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         sourcedObj_type varchar(255),
         sourcedObj_id integer not null,
         updated timestamp,
         citationmicroreference varchar(255),
         originalnamestring varchar(255),
-        idinsource varchar(255),
+        nameUsedInSource_id integer,
+               idinsource varchar(255),
         idnamespace varchar(255),
         createdby_id integer,
         updatedby_id integer,
         foreign key (citation_id) 
         references Reference;
 
+    alter table OriginalSourceBase 
+        add constraint FK820A492C9803E12F 
+        foreign key (nameUsedInSource_id) 
+        references TaxonNameBase;
+
     alter table OriginalSourceBase 
         add constraint FK229A496CBC5DA539 
         foreign key (updatedby_id)