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")
82 public boolean doInvoke(IImportConfigurator config
, CdmApplicationController cdmApp
, Map
<String
, MapWrapper
<?
extends CdmBase
>> stores
){
84 MapWrapper
<TaxonNameBase
> taxonNameMap
= (MapWrapper
<TaxonNameBase
>)stores
.get(ICdmIO
.TAXONNAME_STORE
);
85 MapWrapper
<ReferenceBase
> referenceMap
= (MapWrapper
<ReferenceBase
>)stores
.get(ICdmIO
.REFERENCE_STORE
);
86 MapWrapper
<TeamOrPersonBase
> authorMap
= (MapWrapper
<TeamOrPersonBase
>)stores
.get(ICdmIO
.AUTHOR_STORE
);
88 String tcsElementName
;
89 Namespace tcsNamespace
;
93 logger
.info("start makeTaxonNames ...");
94 TcsImportConfigurator tcsConfig
= (TcsImportConfigurator
)config
;
95 Element root
= tcsConfig
.getSourceRoot();
96 boolean success
=true;
97 INameService nameService
= cdmApp
.getNameService();
99 Namespace rdfNamespace
= root
.getNamespace();
100 String prefix
= "tn";
101 Namespace taxonNameNamespace
= root
.getNamespace(prefix
);
103 Namespace taxonConceptNamespace
= root
.getNamespace(prefix
);
105 Namespace commonNamespace
= root
.getNamespace(prefix
);
106 //String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
107 //Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
109 List
<Element
> elTaxonNames
= root
.getChildren("TaxonName", taxonNameNamespace
);
114 for (Element elTaxonName
: elTaxonNames
){
116 if ((++i
% modCount
) == 0){ logger
.info("Names handled: " + (i
-1));}
118 Attribute about
= elTaxonName
.getAttribute("about", rdfNamespace
);
120 //create TaxonName element
121 String nameAbout
= elTaxonName
.getAttributeValue("about", rdfNamespace
);
122 String strRank
= XmlHelp
.getChildAttributeValue(elTaxonName
, "rank", taxonNameNamespace
, "resource", rdfNamespace
);
123 String strNomenclaturalCode
= XmlHelp
.getChildAttributeValue(elTaxonName
, "nomenclaturalCode", taxonNameNamespace
, "resource", rdfNamespace
);
126 Rank rank
= TcsTransformer
.rankString2Rank(strRank
);
127 NomenclaturalCode nomCode
= TcsTransformer
.nomCodeString2NomCode(strNomenclaturalCode
);
128 TaxonNameBase nameBase
= nomCode
.getNewTaxonNameInstance(rank
);
130 Set
<String
> omitAttributes
= null;
131 makeStandardMapper(elTaxonName
, nameBase
, omitAttributes
, standardMappers
);
135 tcsElementName
= "publishedIn";
136 tcsNamespace
= commonNamespace
;
137 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
139 Generic nomRef
= Generic
.NewInstance(); //TODO
140 nomRef
.setTitleCache(value
);
141 nameBase
.setNomenclaturalReference(nomRef
);
144 tcsElementName
= "year";
145 tcsNamespace
= taxonNameNamespace
;
147 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, tcsNamespace
);
150 year
= Integer
.valueOf(value
);
151 Calendar cal
= Calendar
.getInstance();
154 nomRef
.setDatePublished(TimePeriod
.NewInstance(cal
));
155 } catch (RuntimeException e
) {
156 logger
.warn("year could not be parsed");
162 tcsNamespace
= taxonNameNamespace
;
163 Element elAnnotation
= elTaxonName
.getChild("hasAnnotation", tcsNamespace
);
164 if (elAnnotation
!= null){
165 Element elNomenclaturalNote
= elAnnotation
.getChild("NomenclaturalNote", tcsNamespace
);
166 if (elNomenclaturalNote
!= null){
167 String statusValue
= (String
)ImportHelper
.getXmlInputValue(elNomenclaturalNote
, "note", tcsNamespace
);
168 String type
= XmlHelp
.getChildAttributeValue(elNomenclaturalNote
, "type", taxonConceptNamespace
, "resource", rdfNamespace
);
169 String tdwgType
= "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
170 if (tdwgType
.equalsIgnoreCase(type
)){
172 //NomenclaturalStatusType statusType = TaxonXTransformer.nomStatusString2NomStatus(statusValue);
173 NomenclaturalStatusType statusType
= NomenclaturalStatusType
.getNomenclaturalStatusTypeByAbbreviation(statusValue
);
174 if (statusType
!= null){
175 nameBase
.addStatus(NomenclaturalStatus
.NewInstance(statusType
));
177 } catch (UnknownCdmTypeException e
) {
178 if (! statusValue
.equals("valid")){
179 logger
.warn("Unknown NomenclaturalStatusType: " + statusValue
);
186 if (nameBase
instanceof NonViralName
){
187 NonViralName nonViralName
= (NonViralName
)nameBase
;
191 tcsElementName
= "basionymAuthorship";
192 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
194 INomenclaturalAuthor basionymAuthor
= Team
.NewInstance();
195 basionymAuthor
.setNomenclaturalTitle(value
);
196 nonViralName
.setBasionymAuthorTeam(basionymAuthor
);
200 tcsElementName
= "combinationAuthorship";
201 value
= (String
)ImportHelper
.getXmlInputValue(elTaxonName
, tcsElementName
, taxonNameNamespace
);
203 INomenclaturalAuthor combinationAuthor
= Team
.NewInstance();
204 combinationAuthor
.setNomenclaturalTitle(value
);
205 nonViralName
.setCombinationAuthorTeam(combinationAuthor
);
210 checkAdditionalContents(elTaxonName
, standardMappers
, operationalMappers
, unclearMappers
);
214 //ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
215 taxonNameMap
.put(nameAbout
, nameBase
);
217 } catch (UnknownCdmTypeException e
) {
219 logger
.warn("Name with id " + nameAbout
+ " has unknown rank " + strRank
+ " and could not be saved.");
223 logger
.info(i
+ " names handled");
224 nameService
.saveTaxonNameAll(taxonNameMap
.objects());
225 // makeNameSpecificData(nameMap);
226 logger
.info("end makeTaxonNames ...");
231 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
233 protected boolean isIgnore(IImportConfigurator config
){
234 return ! config
.isDoTaxonNames();