1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.cdm.io.markup;
|
12
|
|
13
|
import java.util.ArrayList;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
|
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.model.agent.TeamOrPersonBase;
|
27
|
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
|
28
|
import eu.etaxonomy.cdm.model.common.Language;
|
29
|
import eu.etaxonomy.cdm.model.description.Feature;
|
30
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
31
|
import eu.etaxonomy.cdm.model.description.PolytomousKey;
|
32
|
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
|
33
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
34
|
import eu.etaxonomy.cdm.model.media.Media;
|
35
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
36
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
37
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
38
|
|
39
|
/**
|
40
|
* @author a.mueller
|
41
|
* @created 11.05.2009
|
42
|
*/
|
43
|
public class MarkupImportState extends XmlImportState<MarkupImportConfigurator, MarkupDocumentImport>{
|
44
|
@SuppressWarnings("unused")
|
45
|
private static final Logger logger = Logger.getLogger(MarkupImportState.class);
|
46
|
|
47
|
|
48
|
private UnmatchedLeads unmatchedLeads;
|
49
|
private boolean onlyNumberedTaxaExist; //attribute in <key>
|
50
|
|
51
|
private Set<FeatureNode> featureNodesToSave = new HashSet<FeatureNode>();
|
52
|
|
53
|
private Set<PolytomousKeyNode> polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
|
54
|
|
55
|
private PolytomousKey currentKey;
|
56
|
|
57
|
private TeamOrPersonBase<?> currentCollector;
|
58
|
|
59
|
private Set<NamedArea> currentAreas = new HashSet<NamedArea>();
|
60
|
|
61
|
private Language defaultLanguage;
|
62
|
|
63
|
private Taxon currentTaxon;
|
64
|
private String currentTaxonNum;
|
65
|
|
66
|
private boolean taxonInClassification = true;
|
67
|
|
68
|
private String latestGenusEpithet = null;
|
69
|
|
70
|
private TeamOrPersonBase<?> latestAuthorInHomotype = null;
|
71
|
private Reference latestReferenceInHomotype = null;
|
72
|
|
73
|
private boolean isCitation = false;
|
74
|
private boolean isNameType = false;
|
75
|
private boolean isProParte = false;
|
76
|
|
77
|
private boolean isSpecimenType = false;
|
78
|
|
79
|
|
80
|
private String baseMediaUrl = null;
|
81
|
|
82
|
private Map<String, FootnoteDataHolder> footnoteRegister = new HashMap<String, FootnoteDataHolder>();
|
83
|
|
84
|
private Map<String, Media> figureRegister = new HashMap<String, Media>();
|
85
|
|
86
|
private Map<String, Set<AnnotatableEntity>> footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
|
87
|
private Map<String, Set<AnnotatableEntity>> figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
|
88
|
|
89
|
private Map<String, UUID> areaMap = new HashMap<String, UUID>();
|
90
|
|
91
|
private Map<String,UUID> unknownFeaturesUuids = new HashMap<String, UUID>();
|
92
|
|
93
|
private List<FeatureSorterInfo> currentGeneralFeatureSorterList; //keep in multiple imports
|
94
|
private List<FeatureSorterInfo> currentCharFeatureSorterList; //keep in multiple imports
|
95
|
private Map<String,List<FeatureSorterInfo>> generalFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>(); //keep in multiple imports
|
96
|
private Map<String,List<FeatureSorterInfo>> charFeatureSorterListMap = new HashMap<String, List<FeatureSorterInfo>>(); //keep in multiple imports
|
97
|
|
98
|
|
99
|
/**
|
100
|
* This method resets all those variables that should not be reused from one import to another.
|
101
|
* @see MarkupImportConfigurator#isReuseExistingState()
|
102
|
* @see MarkupImportConfigurator#getNewState()
|
103
|
*/
|
104
|
protected void reset(){
|
105
|
featureNodesToSave = new HashSet<FeatureNode>();
|
106
|
polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
|
107
|
currentKey = null;
|
108
|
defaultLanguage = null;
|
109
|
currentTaxon = null;
|
110
|
currentCollector = null;
|
111
|
footnoteRegister = new HashMap<String, FootnoteDataHolder>();
|
112
|
figureRegister = new HashMap<String, Media>();
|
113
|
footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
|
114
|
figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
|
115
|
currentAreas = new HashSet<NamedArea>();
|
116
|
|
117
|
this.resetUuidTermMaps();
|
118
|
}
|
119
|
|
120
|
|
121
|
//**************************** CONSTRUCTOR ******************************************/
|
122
|
|
123
|
public MarkupImportState(MarkupImportConfigurator config) {
|
124
|
super(config);
|
125
|
if (getTransformer() == null){
|
126
|
IInputTransformer newTransformer = config.getTransformer();
|
127
|
if (newTransformer == null){
|
128
|
newTransformer = new MarkupTransformer();
|
129
|
}
|
130
|
setTransformer(newTransformer);
|
131
|
}
|
132
|
}
|
133
|
|
134
|
// ********************************** GETTER / SETTER *************************************/
|
135
|
|
136
|
public UnmatchedLeads getUnmatchedLeads() {
|
137
|
return unmatchedLeads;
|
138
|
}
|
139
|
|
140
|
public void setUnmatchedLeads(UnmatchedLeads unmatchedKeys) {
|
141
|
this.unmatchedLeads = unmatchedKeys;
|
142
|
}
|
143
|
|
144
|
public void setFeatureNodesToSave(Set<FeatureNode> featureNodesToSave) {
|
145
|
this.featureNodesToSave = featureNodesToSave;
|
146
|
}
|
147
|
|
148
|
public Set<FeatureNode> getFeatureNodesToSave() {
|
149
|
return featureNodesToSave;
|
150
|
}
|
151
|
|
152
|
public Set<PolytomousKeyNode> getPolytomousKeyNodesToSave() {
|
153
|
return polytomousKeyNodesToSave;
|
154
|
}
|
155
|
|
156
|
public void setPolytomousKeyNodesToSave(Set<PolytomousKeyNode> polytomousKeyNodesToSave) {
|
157
|
this.polytomousKeyNodesToSave = polytomousKeyNodesToSave;
|
158
|
}
|
159
|
|
160
|
public Language getDefaultLanguage() {
|
161
|
return this.defaultLanguage;
|
162
|
}
|
163
|
|
164
|
public void setDefaultLanguage(Language defaultLanguage){
|
165
|
this.defaultLanguage = defaultLanguage;
|
166
|
}
|
167
|
|
168
|
|
169
|
public void setCurrentTaxon(Taxon currentTaxon) {
|
170
|
this.currentTaxon = currentTaxon;
|
171
|
}
|
172
|
|
173
|
public Taxon getCurrentTaxon() {
|
174
|
return currentTaxon;
|
175
|
}
|
176
|
|
177
|
public void setCurrentTaxonNum(String currentTaxonNum) {
|
178
|
this.currentTaxonNum = currentTaxonNum;
|
179
|
}
|
180
|
|
181
|
public String getCurrentTaxonNum() {
|
182
|
return currentTaxonNum;
|
183
|
}
|
184
|
|
185
|
|
186
|
|
187
|
/**
|
188
|
* Is the import currently handling a citation?
|
189
|
* @return
|
190
|
*/
|
191
|
public boolean isCitation() {
|
192
|
return isCitation;
|
193
|
}
|
194
|
|
195
|
public void setCitation(boolean isCitation) {
|
196
|
this.isCitation = isCitation;
|
197
|
}
|
198
|
|
199
|
|
200
|
public boolean isNameType() {
|
201
|
return isNameType;
|
202
|
}
|
203
|
|
204
|
public void setNameType(boolean isNameType) {
|
205
|
this.isNameType = isNameType;
|
206
|
}
|
207
|
|
208
|
public void setProParte(boolean isProParte) {
|
209
|
this.isProParte = isProParte;
|
210
|
}
|
211
|
|
212
|
public boolean isProParte() {
|
213
|
return isProParte;
|
214
|
}
|
215
|
|
216
|
public void setBaseMediaUrl(String baseMediaUrl) {
|
217
|
this.baseMediaUrl = baseMediaUrl;
|
218
|
}
|
219
|
|
220
|
public String getBaseMediaUrl() {
|
221
|
return baseMediaUrl;
|
222
|
}
|
223
|
|
224
|
|
225
|
|
226
|
public void registerFootnote(FootnoteDataHolder footnote) {
|
227
|
footnoteRegister.put(footnote.id, footnote);
|
228
|
}
|
229
|
|
230
|
public FootnoteDataHolder getFootnote(String key) {
|
231
|
return footnoteRegister.get(key);
|
232
|
}
|
233
|
|
234
|
|
235
|
public void registerFigure(String key, Media figure) {
|
236
|
figureRegister.put(key, figure);
|
237
|
}
|
238
|
|
239
|
public Media getFigure(String key) {
|
240
|
return figureRegister.get(key);
|
241
|
}
|
242
|
|
243
|
public Set<AnnotatableEntity> getFootnoteDemands(String footnoteId){
|
244
|
return footnoteRefRegister.get(footnoteId);
|
245
|
}
|
246
|
|
247
|
public void putFootnoteDemands(String footnoteId, Set<AnnotatableEntity> demands){
|
248
|
footnoteRefRegister.put(footnoteId, demands);
|
249
|
}
|
250
|
|
251
|
|
252
|
public Set<AnnotatableEntity> getFigureDemands(String figureId){
|
253
|
return figureRefRegister.get(figureId);
|
254
|
}
|
255
|
|
256
|
public void putFigureDemands(String figureId, Set<AnnotatableEntity> demands){
|
257
|
figureRefRegister.put(figureId, demands);
|
258
|
}
|
259
|
|
260
|
/**
|
261
|
* @param key
|
262
|
*/
|
263
|
public void setCurrentKey(PolytomousKey key) {
|
264
|
this.currentKey = key;
|
265
|
}
|
266
|
|
267
|
/**
|
268
|
* @return the currentKey
|
269
|
*/
|
270
|
public PolytomousKey getCurrentKey() {
|
271
|
return currentKey;
|
272
|
}
|
273
|
|
274
|
/**
|
275
|
* @param key
|
276
|
* @return
|
277
|
* @see java.util.Map#get(java.lang.Object)
|
278
|
*/
|
279
|
public UUID getAreaUuid(Object key) {
|
280
|
return areaMap.get(key);
|
281
|
}
|
282
|
|
283
|
/**
|
284
|
* @param key
|
285
|
* @param value
|
286
|
* @return
|
287
|
* @see java.util.Map#put(java.lang.Object, java.lang.Object)
|
288
|
*/
|
289
|
public UUID putAreaUuid(String key, UUID value) {
|
290
|
return areaMap.put(key, value);
|
291
|
}
|
292
|
|
293
|
public void putUnknownFeatureUuid(String featureLabel, UUID featureUuid) {
|
294
|
this.unknownFeaturesUuids.put(featureLabel, featureUuid);
|
295
|
}
|
296
|
|
297
|
public boolean isOnlyNumberedTaxaExist() {
|
298
|
return onlyNumberedTaxaExist;
|
299
|
}
|
300
|
|
301
|
public void setOnlyNumberedTaxaExist(boolean onlyNumberedTaxaExist) {
|
302
|
this.onlyNumberedTaxaExist = onlyNumberedTaxaExist;
|
303
|
}
|
304
|
|
305
|
public Map<String,List<FeatureSorterInfo>> getGeneralFeatureSorterListMap() {
|
306
|
return generalFeatureSorterListMap;
|
307
|
}
|
308
|
public Map<String,List<FeatureSorterInfo>> getCharFeatureSorterListMap() {
|
309
|
return charFeatureSorterListMap;
|
310
|
}
|
311
|
|
312
|
public UUID getUnknownFeatureUuid(String featureLabel){
|
313
|
return this.unknownFeaturesUuids.get(featureLabel);
|
314
|
}
|
315
|
|
316
|
|
317
|
/**
|
318
|
* Adds new lists to the feature sorter list maps using the given key.
|
319
|
* If at least 1 list already existed for the given key, true is returned. False
|
320
|
* @param key Key that identifies the feature sorter list.
|
321
|
* @return <code>true</code> if at least 1 list already exited for the given key. <code>false</code> otherwise.
|
322
|
*/
|
323
|
public boolean addNewFeatureSorterLists(String key) {
|
324
|
//general feature sorter list
|
325
|
List<FeatureSorterInfo> generalList = new ArrayList<FeatureSorterInfo>();
|
326
|
List<FeatureSorterInfo> previous1 = this.generalFeatureSorterListMap.put(key, generalList);
|
327
|
currentGeneralFeatureSorterList = generalList;
|
328
|
|
329
|
//character feature sorter list
|
330
|
List<FeatureSorterInfo> charList = new ArrayList<FeatureSorterInfo>();
|
331
|
List<FeatureSorterInfo> previous2 = this.charFeatureSorterListMap.put(key, charList);
|
332
|
currentCharFeatureSorterList = charList;
|
333
|
|
334
|
return (previous1 != null || previous2 != null);
|
335
|
}
|
336
|
|
337
|
/**
|
338
|
*
|
339
|
* @param feature
|
340
|
*/
|
341
|
public FeatureSorterInfo putFeatureToCharSorterList(Feature feature) {
|
342
|
FeatureSorterInfo featureSorterInfo = new FeatureSorterInfo(feature);
|
343
|
currentCharFeatureSorterList.add(featureSorterInfo);
|
344
|
return featureSorterInfo;
|
345
|
}
|
346
|
|
347
|
public FeatureSorterInfo getLatestCharFeatureSorterInfo() {
|
348
|
return currentCharFeatureSorterList.get(currentCharFeatureSorterList.size() - 1);
|
349
|
}
|
350
|
|
351
|
|
352
|
/**
|
353
|
*
|
354
|
* @param feature
|
355
|
*/
|
356
|
public void putFeatureToGeneralSorterList(Feature feature) {
|
357
|
currentGeneralFeatureSorterList.add(new FeatureSorterInfo(feature));
|
358
|
|
359
|
}
|
360
|
|
361
|
public String getLatestGenusEpithet() {
|
362
|
return latestGenusEpithet;
|
363
|
}
|
364
|
|
365
|
public void setLatestGenusEpithet(String latestGenusEpithet) {
|
366
|
this.latestGenusEpithet = latestGenusEpithet;
|
367
|
}
|
368
|
|
369
|
|
370
|
public boolean isTaxonInClassification() {
|
371
|
return taxonInClassification;
|
372
|
}
|
373
|
|
374
|
|
375
|
public void setTaxonInClassification(boolean taxonInClassification) {
|
376
|
this.taxonInClassification = taxonInClassification;
|
377
|
}
|
378
|
|
379
|
|
380
|
public TeamOrPersonBase<?> getCurrentCollector() {
|
381
|
return currentCollector;
|
382
|
}
|
383
|
|
384
|
|
385
|
public void setCurrentCollector(TeamOrPersonBase<?> currentCollector) {
|
386
|
this.currentCollector = currentCollector;
|
387
|
}
|
388
|
|
389
|
|
390
|
public void addCurrentArea(NamedArea area) {
|
391
|
currentAreas.add(area);
|
392
|
}
|
393
|
|
394
|
|
395
|
public Set<NamedArea> getCurrentAreas() {
|
396
|
return currentAreas;
|
397
|
}
|
398
|
|
399
|
public void removeCurrentAreas(){
|
400
|
currentAreas.clear();
|
401
|
}
|
402
|
|
403
|
|
404
|
public TeamOrPersonBase<?> getLatestAuthorInHomotype() {
|
405
|
return latestAuthorInHomotype;
|
406
|
}
|
407
|
|
408
|
|
409
|
public void setLatestAuthorInHomotype(TeamOrPersonBase<?> latestAuthorInHomotype) {
|
410
|
this.latestAuthorInHomotype = latestAuthorInHomotype;
|
411
|
}
|
412
|
|
413
|
|
414
|
public Reference getLatestReferenceInHomotype() {
|
415
|
return latestReferenceInHomotype;
|
416
|
}
|
417
|
|
418
|
|
419
|
public void setLatestReferenceInHomotype(Reference latestReferenceInHomotype) {
|
420
|
this.latestReferenceInHomotype = latestReferenceInHomotype;
|
421
|
}
|
422
|
|
423
|
public void setSpecimenType(boolean isSpecimenType) {
|
424
|
this.isSpecimenType = isSpecimenType;
|
425
|
}
|
426
|
|
427
|
public boolean isSpecimenType() {
|
428
|
return isSpecimenType;
|
429
|
}
|
430
|
|
431
|
|
432
|
//or do we need to make this a uuid?
|
433
|
private Map<String, Collection> collectionMap = new HashMap<String, Collection>();
|
434
|
public Collection getCollectionByCode(String code) {
|
435
|
return collectionMap.get(code);
|
436
|
}
|
437
|
|
438
|
public void putCollectionByCode(String code, Collection collection) {
|
439
|
collectionMap.put(code, collection);
|
440
|
}
|
441
|
|
442
|
|
443
|
String collectionAndType = "";
|
444
|
public void addCollectionAndType(String txt) {
|
445
|
collectionAndType = CdmUtils.concat("@", collectionAndType, txt);
|
446
|
}
|
447
|
public String getCollectionAndType() {
|
448
|
return collectionAndType;
|
449
|
}
|
450
|
public void resetCollectionAndType() {
|
451
|
collectionAndType = "";
|
452
|
}
|
453
|
|
454
|
|
455
|
|
456
|
}
|