1 package eu
.etaxonomy
.cdm
.io
.tcs
;
3 import java
.util
.Calendar
;
8 import org
.apache
.log4j
.Logger
;
9 import org
.jdom
.Attribute
;
10 import org
.jdom
.Element
;
11 import org
.jdom
.Namespace
;
13 import eu
.etaxonomy
.cdm
.api
.application
.CdmApplicationController
;
14 import eu
.etaxonomy
.cdm
.api
.service
.INameService
;
15 import eu
.etaxonomy
.cdm
.common
.XmlHelp
;
16 import eu
.etaxonomy
.cdm
.io
.common
.ICdmIO
;
17 import eu
.etaxonomy
.cdm
.io
.common
.IImportConfigurator
;
18 import eu
.etaxonomy
.cdm
.io
.common
.ImportHelper
;
19 import eu
.etaxonomy
.cdm
.io
.common
.MapWrapper
;
20 import eu
.etaxonomy
.cdm
.model
.agent
.INomenclaturalAuthor
;
21 import eu
.etaxonomy
.cdm
.model
.agent
.Team
;
22 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
23 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
24 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
25 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
26 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatus
;
27 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalStatusType
;
28 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
29 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
30 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
31 import eu
.etaxonomy
.cdm
.model
.reference
.Generic
;
32 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceBase
;
33 import eu
.etaxonomy
.cdm
.strategy
.exceptions
.UnknownCdmTypeException
;
36 public class TcsTaxonNameIO
extends TcsIoBase
implements ICdmIO
{
37 private static final Logger logger
= Logger
.getLogger(TcsTaxonNameIO
.class);
39 private static int modCount
= 5000;
41 public TcsTaxonNameIO(){
46 public boolean doCheck(IImportConfigurator config
){
47 boolean result
= true;
48 logger
.warn("BasionymRelations not yet implemented");
49 logger
.warn("Checking for TaxonNames not yet implemented");
50 //result &= checkArticlesWithoutJournal(tcsConfig);
51 //result &= checkPartOfJournal(tcsConfig);
56 protected static CdmIoXmlMapperBase
[] standardMappers
= new CdmIoXmlMapperBase
[]{
57 new CdmTextElementMapper("genusPart", "genusOrUninomial")
58 , new CdmTextElementMapper("specificEpithet", "specificEpithet")
59 , new CdmTextElementMapper("infraspecificEpithet", "infraSpecificEpithet")
60 , new CdmTextElementMapper("infragenericEpithet", "infraGenericEpithet")
61 , new CdmTextElementMapper("microReference", nsTcom
, "nomenclaturalMicroReference")
64 protected static CdmIoXmlMapperBase
[] operationalMappers
= new CdmIoXmlMapperBase
[]{
65 new CdmUnclearMapper("basionymAuthorship")
66 , new CdmUnclearMapper("combinationAuthorship")
67 , new CdmUnclearMapper("hasAnnotation")
68 , new CdmUnclearMapper("rank")
69 , new CdmUnclearMapper("nomenclaturalCode")
70 , new CdmUnclearMapper("publishedIn", nsTcom
)
71 , new CdmUnclearMapper("year")
74 protected static CdmIoXmlMapperBase
[] unclearMappers
= new CdmIoXmlMapperBase
[]{
75 new CdmUnclearMapper("authorship")
76 , new CdmUnclearMapper("rankString")
77 , new CdmUnclearMapper("nameComplete")
78 , new CdmUnclearMapper("hasBasionym")
79 , new CdmUnclearMapper("dateOfEntry", nsTpalm
)
83 public boolean doInvoke(IImportConfigurator config
, CdmApplicationController cdmApp
, Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
85 MapWrapper
<TaxonNameBase
> taxonNameMap
= (MapWrapper
<TaxonNameBase
>)stores
.get(ICdmIO
.TAXONNAME_STORE
);
86 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
87 MapWrapper
<TeamOrPersonBase
> authorMap
= (MapWrapper
<TeamOrPersonBase
>)stores
.get(ICdmIO
.AUTHOR_STORE
);
89 String tcsElementName
;
90 Namespace tcsNamespace
;
94 logger
.info("start makeTaxonNames ...");
95 TcsImportConfigurator tcsConfig
= (TcsImportConfigurator
)config
;
96 Element root
= tcsConfig
.getSourceRoot();
97 boolean success
=true;
98 INameService nameService
= cdmApp
.getNameService();
100 Namespace rdfNamespace
= root
.getNamespace();
101 String prefix
= "tn";
102 Namespace taxonNameNamespace
= root
.getNamespace(prefix
);
104 Namespace taxonConceptNamespace
= root
.getNamespace(prefix
);
106 Namespace commonNamespace
= root
.getNamespace(prefix
);
107 //String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
108 //Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
110 List
<Element
> elTaxonNames
= root
.getChildren("TaxonName", taxonNameNamespace
);
115 for (Element elTaxonName
: elTaxonNames
){
117 if ((++i
% modCount
) == 0){ logger
.info("Names handled: " + (i
-1));}
119 Attribute about
= elTaxonName
.getAttribute("about", rdfNamespace
);
121 //create TaxonName element
122 String nameAbout
= elTaxonName
.getAttributeValue("about", rdfNamespace
);
123 String strRank
= XmlHelp
.getChildAttributeValue(elTaxonName
, "rank", taxonNameNamespace
, "resource", rdfNamespace
);
124 String strNomenclaturalCode
= XmlHelp
.getChildAttributeValue(elTaxonName
, "nomenclaturalCode", taxonNameNamespace
, "resource", rdfNamespace
);
127 Rank rank
= TcsTransformer
.rankString2Rank(strRank
);
128 NomenclaturalCode nomCode
= TcsTransformer
.nomCodeString2NomCode(strNomenclaturalCode
);
129 TaxonNameBase nameBase
= nomCode
.getNewTaxonNameInstance(rank
);
131 Set
<String
> omitAttributes
= null;
132 makeStandardMapper(elTaxonName
, nameBase
, omitAttributes
, standardMappers
);
136 tcsElementName
= "publishedIn";
137 tcsNamespace
= commonNamespace
;
138 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
140 Generic nomRef
= Generic
.NewInstance(); //TODO
141 nomRef
.setTitleCache(value
);
142 nameBase
.setNomenclaturalReference(nomRef
);
145 tcsElementName
= "year";
146 tcsNamespace
= taxonNameNamespace
;
148 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
151 year
= Integer
.valueOf(value
);
152 Calendar cal
= Calendar
.getInstance();
155 nomRef
.setDatePublished(TimePeriod
.NewInstance(cal
));
156 } catch (RuntimeException e
) {
157 logger
.warn("year could not be parsed");
163 tcsNamespace
= taxonNameNamespace
;
164 Element elAnnotation
= elTaxonName
.getChild("hasAnnotation", tcsNamespace
);
165 if (elAnnotation
!= null){
166 Element elNomenclaturalNote
= elAnnotation
.getChild("NomenclaturalNote", tcsNamespace
);
167 if (elNomenclaturalNote
!= null){
168 String statusValue
= (String
)ImportHelper
.getXmlInputValue(elNomenclaturalNote
, "note", tcsNamespace
);
169 String type
= XmlHelp
.getChildAttributeValue(elNomenclaturalNote
, "type", tcsNamespace
, "resource", rdfNamespace
);
170 String tdwgType
= "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
171 if (tdwgType
.equalsIgnoreCase(type
)){
173 NomenclaturalStatusType statusType
= TcsTransformer
.nomStatusString2NomStatus(statusValue
);
174 //NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
175 if (statusType
!= null){
176 nameBase
.addStatus(NomenclaturalStatus
.NewInstance(statusType
));
178 } catch (UnknownCdmTypeException e
) {
179 if (! statusValue
.equals("valid")){
180 logger
.warn("Unknown NomenclaturalStatusType: " + statusValue
);
187 if (nameBase
instanceof NonViralName
){
188 NonViralName nonViralName
= (NonViralName
)nameBase
;
192 tcsElementName
= "basionymAuthorship";
193 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
195 INomenclaturalAuthor basionymAuthor
= Team
.NewInstance();
196 basionymAuthor
.setNomenclaturalTitle(value
);
197 nonViralName
.setBasionymAuthorTeam(basionymAuthor
);
201 tcsElementName
= "combinationAuthorship";
202 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
204 INomenclaturalAuthor combinationAuthor
= Team
.NewInstance();
205 combinationAuthor
.setNomenclaturalTitle(value
);
206 nonViralName
.setCombinationAuthorTeam(combinationAuthor
);
211 checkAdditionalContents(elTaxonName
, standardMappers
, operationalMappers
, unclearMappers
);
215 //ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
216 taxonNameMap
.put(nameAbout
, nameBase
);
218 } catch (UnknownCdmTypeException e
) {
220 logger
.warn("Name with id " + nameAbout
+ " has unknown rank " + strRank
+ " and could not be saved.");
224 logger
.info(i
+ " names handled");
225 nameService
.saveTaxonNameAll(taxonNameMap
.objects());
226 // makeNameSpecificData(nameMap);
227 logger
.info("end makeTaxonNames ...");
232 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
234 protected boolean isIgnore(IImportConfigurator config
){
235 return ! config
.isDoTaxonNames();