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 String idNamespace
= "TaxonName";
112 List
<Element
> elTaxonNames
= root
.getChildren("TaxonName", taxonNameNamespace
);
116 for (Element elTaxonName
: elTaxonNames
){
118 if ((++i
% modCount
) == 0){ logger
.info("Names handled: " + (i
-1));}
120 Attribute about
= elTaxonName
.getAttribute("about", rdfNamespace
);
122 //create TaxonName element
123 String nameAbout
= elTaxonName
.getAttributeValue("about", rdfNamespace
);
124 String strRank
= XmlHelp
.getChildAttributeValue(elTaxonName
, "rank", taxonNameNamespace
, "resource", rdfNamespace
);
125 String strNomenclaturalCode
= XmlHelp
.getChildAttributeValue(elTaxonName
, "nomenclaturalCode", taxonNameNamespace
, "resource", rdfNamespace
);
128 Rank rank
= TcsTransformer
.rankString2Rank(strRank
);
129 NomenclaturalCode nomCode
= TcsTransformer
.nomCodeString2NomCode(strNomenclaturalCode
);
130 TaxonNameBase nameBase
= nomCode
.getNewTaxonNameInstance(rank
);
132 Set
<String
> omitAttributes
= null;
133 makeStandardMapper(elTaxonName
, nameBase
, omitAttributes
, standardMappers
);
137 tcsElementName
= "publishedIn";
138 tcsNamespace
= commonNamespace
;
139 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
141 Generic nomRef
= Generic
.NewInstance(); //TODO
142 nomRef
.setTitleCache(value
);
143 nameBase
.setNomenclaturalReference(nomRef
);
146 tcsElementName
= "year";
147 tcsNamespace
= taxonNameNamespace
;
149 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
152 year
= Integer
.valueOf(value
);
153 Calendar cal
= Calendar
.getInstance();
156 nomRef
.setDatePublished(TimePeriod
.NewInstance(cal
));
157 } catch (RuntimeException e
) {
158 logger
.warn("year could not be parsed");
164 tcsNamespace
= taxonNameNamespace
;
165 Element elAnnotation
= elTaxonName
.getChild("hasAnnotation", tcsNamespace
);
166 if (elAnnotation
!= null){
167 Element elNomenclaturalNote
= elAnnotation
.getChild("NomenclaturalNote", tcsNamespace
);
168 if (elNomenclaturalNote
!= null){
169 String statusValue
= (String
)ImportHelper
.getXmlInputValue(elNomenclaturalNote
, "note", tcsNamespace
);
170 String type
= XmlHelp
.getChildAttributeValue(elNomenclaturalNote
, "type", tcsNamespace
, "resource", rdfNamespace
);
171 String tdwgType
= "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
172 if (tdwgType
.equalsIgnoreCase(type
)){
174 NomenclaturalStatusType statusType
= TcsTransformer
.nomStatusString2NomStatus(statusValue
);
175 //NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
176 if (statusType
!= null){
177 nameBase
.addStatus(NomenclaturalStatus
.NewInstance(statusType
));
179 } catch (UnknownCdmTypeException e
) {
180 if (! statusValue
.equals("valid")){
181 logger
.warn("Unknown NomenclaturalStatusType: " + statusValue
);
188 if (nameBase
instanceof NonViralName
){
189 NonViralName nonViralName
= (NonViralName
)nameBase
;
193 tcsElementName
= "basionymAuthorship";
194 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
196 INomenclaturalAuthor basionymAuthor
= Team
.NewInstance();
197 basionymAuthor
.setNomenclaturalTitle(value
);
198 nonViralName
.setBasionymAuthorTeam(basionymAuthor
);
202 tcsElementName
= "combinationAuthorship";
203 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
205 INomenclaturalAuthor combinationAuthor
= Team
.NewInstance();
206 combinationAuthor
.setNomenclaturalTitle(value
);
207 nonViralName
.setCombinationAuthorTeam(combinationAuthor
);
211 ImportHelper
.setOriginalSource(nameBase
, config
.getSourceReference(), nameAbout
, idNamespace
);
213 checkAdditionalContents(elTaxonName
, standardMappers
, operationalMappers
, unclearMappers
);
217 //ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
218 taxonNameMap
.put(nameAbout
, nameBase
);
220 } catch (UnknownCdmTypeException e
) {
222 logger
.warn("Name with id " + nameAbout
+ " has unknown rank " + strRank
+ " and could not be saved.");
226 logger
.info(i
+ " names handled");
227 nameService
.saveTaxonNameAll(taxonNameMap
.objects());
228 // makeNameSpecificData(nameMap);
229 logger
.info("end makeTaxonNames ...");
234 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
236 protected boolean isIgnore(IImportConfigurator config
){
237 return ! config
.isDoTaxonNames();