2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.io
.markup
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashMap
;
14 import java
.util
.HashSet
;
15 import java
.util
.List
;
18 import java
.util
.UUID
;
20 import org
.apache
.log4j
.Logger
;
22 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
23 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
24 import eu
.etaxonomy
.cdm
.io
.common
.XmlImportState
;
25 import eu
.etaxonomy
.cdm
.io
.common
.mapping
.IInputTransformer
;
26 import eu
.etaxonomy
.cdm
.io
.common
.utils
.ImportDeduplicationHelper
;
27 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
28 import eu
.etaxonomy
.cdm
.model
.common
.AnnotatableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
31 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
32 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKey
;
33 import eu
.etaxonomy
.cdm
.model
.description
.PolytomousKeyNode
;
34 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
35 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
36 import eu
.etaxonomy
.cdm
.model
.occurrence
.Collection
;
37 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
38 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
44 public class MarkupImportState
extends XmlImportState
<MarkupImportConfigurator
, MarkupDocumentImport
>{
45 @SuppressWarnings("unused")
46 private static final Logger logger
= Logger
.getLogger(MarkupImportState
.class);
48 private ImportDeduplicationHelper
<MarkupImportState
> deduplicationHelper
;
51 private UnmatchedLeads unmatchedLeads
;
52 private boolean onlyNumberedTaxaExist
; //attribute in <key>
54 private Set
<FeatureNode
> featureNodesToSave
= new HashSet
<FeatureNode
>();
56 private Set
<PolytomousKeyNode
> polytomousKeyNodesToSave
= new HashSet
<>();
58 private PolytomousKey currentKey
;
60 private TeamOrPersonBase
<?
> currentCollector
;
62 private Set
<NamedArea
> currentAreas
= new HashSet
<NamedArea
>();
64 private Language defaultLanguage
;
66 private Taxon currentTaxon
;
67 private String currentTaxonNum
;
69 private boolean taxonInClassification
= true;
71 private String latestGenusEpithet
= null;
73 private TeamOrPersonBase
<?
> latestAuthorInHomotype
= null;
74 private Reference latestReferenceInHomotype
= null;
76 private boolean isCitation
= false;
77 private boolean isNameType
= false;
78 private boolean isProParte
= false;
79 private boolean currentTaxonExcluded
= false;
81 private boolean isSpecimenType
= false;
83 private boolean taxonIsHybrid
= false;
87 private String baseMediaUrl
= null;
89 private String nameStatus
;
92 private Map
<String
, FootnoteDataHolder
> footnoteRegister
= new HashMap
<>();
94 private Map
<String
, Media
> figureRegister
= new HashMap
<>();
96 private Map
<String
, Set
<AnnotatableEntity
>> footnoteRefRegister
= new HashMap
<>();
97 private Map
<String
, Set
<AnnotatableEntity
>> figureRefRegister
= new HashMap
<>();
99 private Map
<String
, UUID
> areaMap
= new HashMap
<String
, UUID
>();
101 private Map
<String
,UUID
> unknownFeaturesUuids
= new HashMap
<String
, UUID
>();
103 private List
<FeatureSorterInfo
> currentGeneralFeatureSorterList
; //keep in multiple imports
104 private List
<FeatureSorterInfo
> currentCharFeatureSorterList
; //keep in multiple imports
105 private Map
<String
,List
<FeatureSorterInfo
>> generalFeatureSorterListMap
= new HashMap
<>(); //keep in multiple imports
106 private Map
<String
,List
<FeatureSorterInfo
>> charFeatureSorterListMap
= new HashMap
<>(); //keep in multiple imports
108 private String collectionAndType
= "";
110 private boolean firstSpecimenInFacade
;
113 * This method resets all those variables that should not be reused from one import to another.
114 * @see MarkupImportConfigurator#isReuseExistingState()
115 * @see MarkupImportConfigurator#getNewState()
117 protected void reset(){
118 featureNodesToSave
= new HashSet
<FeatureNode
>();
119 polytomousKeyNodesToSave
= new HashSet
<PolytomousKeyNode
>();
121 defaultLanguage
= null;
123 currentCollector
= null;
124 footnoteRegister
= new HashMap
<String
, FootnoteDataHolder
>();
125 figureRegister
= new HashMap
<String
, Media
>();
126 footnoteRefRegister
= new HashMap
<String
, Set
<AnnotatableEntity
>>();
127 figureRefRegister
= new HashMap
<String
, Set
<AnnotatableEntity
>>();
128 currentAreas
= new HashSet
<NamedArea
>();
130 this.resetUuidTermMaps();
134 //**************************** CONSTRUCTOR ******************************************/
136 public MarkupImportState(MarkupImportConfigurator config
) {
138 if (getTransformer() == null){
139 IInputTransformer newTransformer
= config
.getTransformer();
140 if (newTransformer
== null){
141 newTransformer
= new MarkupTransformer();
143 setTransformer(newTransformer
);
147 // ********************************** GETTER / SETTER *************************************/
149 public UnmatchedLeads
getUnmatchedLeads() {
150 return unmatchedLeads
;
153 public void setUnmatchedLeads(UnmatchedLeads unmatchedKeys
) {
154 this.unmatchedLeads
= unmatchedKeys
;
157 public void setFeatureNodesToSave(Set
<FeatureNode
> featureNodesToSave
) {
158 this.featureNodesToSave
= featureNodesToSave
;
161 public Set
<FeatureNode
> getFeatureNodesToSave() {
162 return featureNodesToSave
;
165 public Set
<PolytomousKeyNode
> getPolytomousKeyNodesToSave() {
166 return polytomousKeyNodesToSave
;
169 public void setPolytomousKeyNodesToSave(Set
<PolytomousKeyNode
> polytomousKeyNodesToSave
) {
170 this.polytomousKeyNodesToSave
= polytomousKeyNodesToSave
;
173 public Language
getDefaultLanguage() {
174 return this.defaultLanguage
;
177 public void setDefaultLanguage(Language defaultLanguage
){
178 this.defaultLanguage
= defaultLanguage
;
182 public void setCurrentTaxon(Taxon currentTaxon
) {
183 this.currentTaxon
= currentTaxon
;
186 public Taxon
getCurrentTaxon() {
190 public void setCurrentTaxonNum(String currentTaxonNum
) {
191 this.currentTaxonNum
= currentTaxonNum
;
194 public String
getCurrentTaxonNum() {
195 return currentTaxonNum
;
201 * Is the import currently handling a citation?
204 public boolean isCitation() {
208 public void setCitation(boolean isCitation
) {
209 this.isCitation
= isCitation
;
213 public boolean isNameType() {
217 public void setNameType(boolean isNameType
) {
218 this.isNameType
= isNameType
;
221 public void setProParte(boolean isProParte
) {
222 this.isProParte
= isProParte
;
225 public boolean isProParte() {
229 public void setBaseMediaUrl(String baseMediaUrl
) {
230 this.baseMediaUrl
= baseMediaUrl
;
233 public String
getBaseMediaUrl() {
239 public void registerFootnote(FootnoteDataHolder footnote
) {
240 footnoteRegister
.put(footnote
.id
, footnote
);
243 public FootnoteDataHolder
getFootnote(String key
) {
244 return footnoteRegister
.get(key
);
248 public void registerFigure(String key
, Media figure
) {
249 figureRegister
.put(key
, figure
);
252 public Media
getFigure(String key
) {
253 return figureRegister
.get(key
);
256 public Set
<AnnotatableEntity
> getFootnoteDemands(String footnoteId
){
257 return footnoteRefRegister
.get(footnoteId
);
260 public void putFootnoteDemands(String footnoteId
, Set
<AnnotatableEntity
> demands
){
261 footnoteRefRegister
.put(footnoteId
, demands
);
265 public Set
<AnnotatableEntity
> getFigureDemands(String figureId
){
266 return figureRefRegister
.get(figureId
);
269 public void putFigureDemands(String figureId
, Set
<AnnotatableEntity
> demands
){
270 figureRefRegister
.put(figureId
, demands
);
276 public void setCurrentKey(PolytomousKey key
) {
277 this.currentKey
= key
;
281 * @return the currentKey
283 public PolytomousKey
getCurrentKey() {
290 * @see java.util.Map#get(java.lang.Object)
292 public UUID
getAreaUuid(Object key
) {
293 return areaMap
.get(key
);
300 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
302 public UUID
putAreaUuid(String key
, UUID value
) {
303 return areaMap
.put(key
, value
);
306 public void putUnknownFeatureUuid(String featureLabel
, UUID featureUuid
) {
307 this.unknownFeaturesUuids
.put(featureLabel
, featureUuid
);
310 public boolean isOnlyNumberedTaxaExist() {
311 return onlyNumberedTaxaExist
;
314 public void setOnlyNumberedTaxaExist(boolean onlyNumberedTaxaExist
) {
315 this.onlyNumberedTaxaExist
= onlyNumberedTaxaExist
;
318 public Map
<String
,List
<FeatureSorterInfo
>> getGeneralFeatureSorterListMap() {
319 return generalFeatureSorterListMap
;
321 public Map
<String
,List
<FeatureSorterInfo
>> getCharFeatureSorterListMap() {
322 return charFeatureSorterListMap
;
325 public UUID
getUnknownFeatureUuid(String featureLabel
){
326 return this.unknownFeaturesUuids
.get(featureLabel
);
331 * Adds new lists to the feature sorter list maps using the given key.
332 * If at least 1 list already existed for the given key, true is returned. False
333 * @param key Key that identifies the feature sorter list.
334 * @return <code>true</code> if at least 1 list already exited for the given key. <code>false</code> otherwise.
336 public boolean addNewFeatureSorterLists(String key
) {
337 //general feature sorter list
338 List
<FeatureSorterInfo
> generalList
= new ArrayList
<FeatureSorterInfo
>();
339 List
<FeatureSorterInfo
> previous1
= this.generalFeatureSorterListMap
.put(key
, generalList
);
340 currentGeneralFeatureSorterList
= generalList
;
342 //character feature sorter list
343 List
<FeatureSorterInfo
> charList
= new ArrayList
<FeatureSorterInfo
>();
344 List
<FeatureSorterInfo
> previous2
= this.charFeatureSorterListMap
.put(key
, charList
);
345 currentCharFeatureSorterList
= charList
;
347 return (previous1
!= null || previous2
!= null);
354 public FeatureSorterInfo
putFeatureToCharSorterList(Feature feature
) {
355 FeatureSorterInfo featureSorterInfo
= new FeatureSorterInfo(feature
);
356 currentCharFeatureSorterList
.add(featureSorterInfo
);
357 return featureSorterInfo
;
360 public FeatureSorterInfo
getLatestCharFeatureSorterInfo() {
361 return currentCharFeatureSorterList
.get(currentCharFeatureSorterList
.size() - 1);
369 public void putFeatureToGeneralSorterList(Feature feature
) {
370 currentGeneralFeatureSorterList
.add(new FeatureSorterInfo(feature
));
374 public String
getLatestGenusEpithet() {
375 return latestGenusEpithet
;
378 public void setLatestGenusEpithet(String latestGenusEpithet
) {
379 this.latestGenusEpithet
= latestGenusEpithet
;
383 public boolean isTaxonInClassification() {
384 return taxonInClassification
;
388 public void setTaxonInClassification(boolean taxonInClassification
) {
389 this.taxonInClassification
= taxonInClassification
;
393 public TeamOrPersonBase
<?
> getCurrentCollector() {
394 return currentCollector
;
398 public void setCurrentCollector(TeamOrPersonBase
<?
> currentCollector
) {
399 this.currentCollector
= currentCollector
;
403 public void addCurrentArea(NamedArea area
) {
404 currentAreas
.add(area
);
408 public Set
<NamedArea
> getCurrentAreas() {
412 public void removeCurrentAreas(){
413 currentAreas
.clear();
417 public TeamOrPersonBase
<?
> getLatestAuthorInHomotype() {
418 return latestAuthorInHomotype
;
422 public void setLatestAuthorInHomotype(TeamOrPersonBase
<?
> latestAuthorInHomotype
) {
423 this.latestAuthorInHomotype
= latestAuthorInHomotype
;
427 public Reference
getLatestReferenceInHomotype() {
428 return latestReferenceInHomotype
;
432 public void setLatestReferenceInHomotype(Reference latestReferenceInHomotype
) {
433 this.latestReferenceInHomotype
= latestReferenceInHomotype
;
436 public void setSpecimenType(boolean isSpecimenType
) {
437 this.isSpecimenType
= isSpecimenType
;
440 public boolean isSpecimenType() {
441 return isSpecimenType
;
445 //or do we need to make this a uuid?
446 private Map
<String
, Collection
> collectionMap
= new HashMap
<String
, Collection
>();
448 public Collection
getCollectionByCode(String code
) {
449 return collectionMap
.get(code
);
452 public void putCollectionByCode(String code
, Collection collection
) {
453 collectionMap
.put(code
, collection
);
458 public void addCollectionAndType(String txt
) {
459 collectionAndType
= CdmUtils
.concat("@", collectionAndType
, txt
);
461 public String
getCollectionAndType() {
462 return collectionAndType
;
464 public void resetCollectionAndType() {
465 collectionAndType
= "";
469 public boolean isCurrentTaxonExcluded() {
470 return currentTaxonExcluded
;
472 public void setCurrentTaxonExcluded(boolean currentTaxonExcluded
) {
473 this.currentTaxonExcluded
= currentTaxonExcluded
;
476 public boolean isFirstSpecimenInFacade() {
477 return firstSpecimenInFacade
;
479 public void setFirstSpecimenInFacade(boolean firstSpecimenInFacade
) {
480 this.firstSpecimenInFacade
= firstSpecimenInFacade
;
483 public ImportDeduplicationHelper
<MarkupImportState
> getDeduplicationHelper(ICdmRepository repository
) {
484 if (this.deduplicationHelper
== null){
485 this.deduplicationHelper
= new ImportDeduplicationHelper
<>(repository
);
487 return deduplicationHelper
;
489 public void setDeduplicationHelper(ImportDeduplicationHelper
<MarkupImportState
> deduplicationHelper
) {
490 this.deduplicationHelper
= deduplicationHelper
;
493 public void setNameStatus(String nameStatus
) {
494 this.nameStatus
= nameStatus
;
496 public String
getNameStatus() {
500 public boolean isTaxonIsHybrid() {
501 return taxonIsHybrid
;
503 public void setTaxonIsHybrid(boolean taxonIsHybrid
) {
504 this.taxonIsHybrid
= taxonIsHybrid
;