Project

General

Profile

Download (13.3 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.cdm.io.markup;
11

    
12
import java.util.ArrayList;
13
import java.util.HashMap;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Map;
17
import java.util.Set;
18
import java.util.UUID;
19

    
20
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
21

    
22
import eu.etaxonomy.cdm.common.CdmUtils;
23
import eu.etaxonomy.cdm.io.common.XmlImportState;
24
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
25
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26
import eu.etaxonomy.cdm.model.common.AnnotatableEntity;
27
import eu.etaxonomy.cdm.model.common.Language;
28
import eu.etaxonomy.cdm.model.description.Feature;
29
import eu.etaxonomy.cdm.model.description.PolytomousKey;
30
import eu.etaxonomy.cdm.model.description.PolytomousKeyNode;
31
import eu.etaxonomy.cdm.model.location.NamedArea;
32
import eu.etaxonomy.cdm.model.media.Media;
33
import eu.etaxonomy.cdm.model.occurrence.Collection;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.cdm.model.taxon.Taxon;
36
import eu.etaxonomy.cdm.model.term.TermNode;
37

    
38
/**
39
 * @author a.mueller
40
 * @since 11.05.2009
41
 */
42
public class MarkupImportState extends XmlImportState<MarkupImportConfigurator, MarkupDocumentImport>{
43
	@SuppressWarnings("unused")
44
	private static final Logger logger = LogManager.getLogger(MarkupImportState.class);
45

    
46
	private UnmatchedLeads unmatchedLeads;
47
	private boolean onlyNumberedTaxaExist; //attribute in <key>
48

    
49
	private Set<TermNode> termNodesToSave = new HashSet<>();
50

    
51
	private Set<PolytomousKeyNode> polytomousKeyNodesToSave = new HashSet<>();
52

    
53
	private PolytomousKey currentKey;
54

    
55
	private TeamOrPersonBase<?> currentCollector;
56

    
57
	private Set<NamedArea> currentAreas = new HashSet<NamedArea>();
58

    
59
	private Language defaultLanguage;
60

    
61
	private Taxon currentTaxon;
62
	private String currentTaxonNum;
63

    
64
	private boolean taxonInClassification = true;
65

    
66
	private String latestGenusEpithet = null;
67

    
68
	private TeamOrPersonBase<?> latestAuthorInHomotype = null;
69
	private Reference latestReferenceInHomotype = null;
70

    
71
	private boolean isCitation = false;
72
	private boolean isNameType = false;
73
	private boolean isProParte = false;
74
	private boolean currentTaxonExcluded = false;
75

    
76
	private boolean isSpecimenType = false;
77

    
78
	private boolean taxonIsHybrid = false;
79

    
80

    
81

    
82
	private String baseMediaUrl = null;
83

    
84
	private String nameStatus;
85

    
86

    
87
	private Map<String, FootnoteDataHolder> footnoteRegister = new HashMap<>();
88

    
89
	private Map<String, Media> figureRegister = new HashMap<>();
90

    
91
	private Map<String, Set<AnnotatableEntity>> footnoteRefRegister = new HashMap<>();
92
	private Map<String, Set<AnnotatableEntity>> figureRefRegister = new HashMap<>();
93

    
94
	private Map<String, UUID> areaMap = new HashMap<String, UUID>();
95

    
96
	private Map<String,UUID> unknownFeaturesUuids = new HashMap<String, UUID>();
97

    
98
	private List<FeatureSorterInfo> currentGeneralFeatureSorterList;  //keep in multiple imports
99
	private List<FeatureSorterInfo> currentCharFeatureSorterList; //keep in multiple imports
100
	private Map<String,List<FeatureSorterInfo>> generalFeatureSorterListMap = new HashMap<>();  //keep in multiple imports
101
	private Map<String,List<FeatureSorterInfo>> charFeatureSorterListMap = new HashMap<>(); //keep in multiple imports
102

    
103
    private String collectionAndType = "";
104

    
105
    private boolean firstSpecimenInFacade;
106

    
107
	/**
108
	 * This method resets all those variables that should not be reused from one import to another.
109
	 * @see MarkupImportConfigurator#isReuseExistingState()
110
	 * @see MarkupImportConfigurator#getNewState()
111
	 */
112
	protected void reset(){
113
		termNodesToSave = new HashSet<TermNode>();
114
		polytomousKeyNodesToSave = new HashSet<PolytomousKeyNode>();
115
		currentKey = null;
116
		defaultLanguage = null;
117
		currentTaxon = null;
118
		currentCollector = null;
119
		footnoteRegister = new HashMap<String, FootnoteDataHolder>();
120
		figureRegister = new HashMap<String, Media>();
121
		footnoteRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
122
		figureRefRegister = new HashMap<String, Set<AnnotatableEntity>>();
123
		currentAreas = new HashSet<NamedArea>();
124

    
125
		this.resetUuidTermMaps();
126
	}
127

    
128

    
129
//**************************** CONSTRUCTOR ******************************************/
130

    
131
	public MarkupImportState(MarkupImportConfigurator config) {
132
		super(config);
133
		if (getTransformer() == null){
134
			IInputTransformer newTransformer = config.getTransformer();
135
			if (newTransformer == null){
136
				newTransformer = new MarkupTransformer();
137
			}
138
			setTransformer(newTransformer);
139
		}
140
	}
141

    
142
// ********************************** GETTER / SETTER *************************************/
143

    
144
	public UnmatchedLeads getUnmatchedLeads() {
145
		return unmatchedLeads;
146
	}
147

    
148
	public void setUnmatchedLeads(UnmatchedLeads unmatchedKeys) {
149
		this.unmatchedLeads = unmatchedKeys;
150
	}
151

    
152
	public void setTermNodesToSave(Set<TermNode> termNodesToSave) {
153
		this.termNodesToSave = termNodesToSave;
154
	}
155

    
156
	public Set<TermNode> getTermNodesToSave() {
157
		return termNodesToSave;
158
	}
159

    
160
	public Set<PolytomousKeyNode> getPolytomousKeyNodesToSave() {
161
		return polytomousKeyNodesToSave;
162
	}
163

    
164
	public void setPolytomousKeyNodesToSave(Set<PolytomousKeyNode> polytomousKeyNodesToSave) {
165
		this.polytomousKeyNodesToSave = polytomousKeyNodesToSave;
166
	}
167

    
168
	public Language getDefaultLanguage() {
169
		return this.defaultLanguage;
170
	}
171

    
172
	public void setDefaultLanguage(Language defaultLanguage){
173
		this.defaultLanguage = defaultLanguage;
174
	}
175

    
176

    
177
	public void setCurrentTaxon(Taxon currentTaxon) {
178
		this.currentTaxon = currentTaxon;
179
	}
180

    
181
	public Taxon getCurrentTaxon() {
182
		return currentTaxon;
183
	}
184

    
185
	public void setCurrentTaxonNum(String currentTaxonNum) {
186
		this.currentTaxonNum = currentTaxonNum;
187
	}
188

    
189
	public String getCurrentTaxonNum() {
190
		return currentTaxonNum;
191
	}
192

    
193

    
194

    
195
	/**
196
	 * Is the import currently handling a citation?
197
	 * @return
198
	 */
199
	public boolean isCitation() {
200
		return isCitation;
201
	}
202

    
203
	public void setCitation(boolean isCitation) {
204
		this.isCitation = isCitation;
205
	}
206

    
207

    
208
	public boolean isNameType() {
209
		return isNameType;
210
	}
211

    
212
	public void setNameType(boolean isNameType) {
213
		this.isNameType = isNameType;
214
	}
215

    
216
	public void setProParte(boolean isProParte) {
217
		this.isProParte = isProParte;
218
	}
219

    
220
	public boolean isProParte() {
221
		return isProParte;
222
	}
223

    
224
	public void setBaseMediaUrl(String baseMediaUrl) {
225
		this.baseMediaUrl = baseMediaUrl;
226
	}
227

    
228
	public String getBaseMediaUrl() {
229
		return baseMediaUrl;
230
	}
231

    
232

    
233

    
234
	public void registerFootnote(FootnoteDataHolder footnote) {
235
		footnoteRegister.put(footnote.id, footnote);
236
	}
237

    
238
	public FootnoteDataHolder getFootnote(String key) {
239
		return footnoteRegister.get(key);
240
	}
241

    
242

    
243
	public void registerFigure(String key, Media figure) {
244
		figureRegister.put(key, figure);
245
	}
246

    
247
	public Media getFigure(String key) {
248
		return figureRegister.get(key);
249
	}
250

    
251
	public Set<AnnotatableEntity> getFootnoteDemands(String footnoteId){
252
		return footnoteRefRegister.get(footnoteId);
253
	}
254

    
255
	public void putFootnoteDemands(String footnoteId, Set<AnnotatableEntity> demands){
256
		footnoteRefRegister.put(footnoteId, demands);
257
	}
258

    
259

    
260
	public Set<AnnotatableEntity> getFigureDemands(String figureId){
261
		return figureRefRegister.get(figureId);
262
	}
263

    
264
	public void putFigureDemands(String figureId, Set<AnnotatableEntity> demands){
265
		figureRefRegister.put(figureId, demands);
266
	}
267

    
268
	/**
269
	 * @param key
270
	 */
271
	public void setCurrentKey(PolytomousKey key) {
272
		this.currentKey = key;
273
	}
274

    
275
	/**
276
	 * @return the currentKey
277
	 */
278
	public PolytomousKey getCurrentKey() {
279
		return currentKey;
280
	}
281

    
282
	/**
283
	 * @param key
284
	 * @return
285
	 * @see java.util.Map#get(java.lang.Object)
286
	 */
287
	public UUID getAreaUuid(Object key) {
288
		return areaMap.get(key);
289
	}
290

    
291
	/**
292
	 * @param key
293
	 * @param value
294
	 * @return
295
	 * @see java.util.Map#put(java.lang.Object, java.lang.Object)
296
	 */
297
	public UUID putAreaUuid(String key, UUID value) {
298
		return areaMap.put(key, value);
299
	}
300

    
301
	public void putUnknownFeatureUuid(String featureLabel, UUID featureUuid) {
302
		this.unknownFeaturesUuids.put(featureLabel, featureUuid);
303
	}
304

    
305
	public boolean isOnlyNumberedTaxaExist() {
306
		return onlyNumberedTaxaExist;
307
	}
308

    
309
	public void setOnlyNumberedTaxaExist(boolean onlyNumberedTaxaExist) {
310
		this.onlyNumberedTaxaExist = onlyNumberedTaxaExist;
311
	}
312

    
313
	public Map<String,List<FeatureSorterInfo>> getGeneralFeatureSorterListMap() {
314
		return generalFeatureSorterListMap;
315
	}
316
	public Map<String,List<FeatureSorterInfo>> getCharFeatureSorterListMap() {
317
		return charFeatureSorterListMap;
318
	}
319

    
320
	public UUID getUnknownFeatureUuid(String featureLabel){
321
		return this.unknownFeaturesUuids.get(featureLabel);
322
	}
323

    
324

    
325
	/**
326
	 * Adds new lists to the feature sorter list maps using the given key.
327
	 * If at least 1 list already existed for the given key, true is returned. False
328
	 * @param key Key that identifies the feature sorter list.
329
	 * @return <code>true</code> if at least 1 list already exited for the given key. <code>false</code> otherwise.
330
	 */
331
	public boolean addNewFeatureSorterLists(String key) {
332
		//general feature sorter list
333
		List<FeatureSorterInfo> generalList = new ArrayList<FeatureSorterInfo>();
334
		List<FeatureSorterInfo> previous1 = this.generalFeatureSorterListMap.put(key, generalList);
335
		currentGeneralFeatureSorterList = generalList;
336

    
337
		//character feature sorter list
338
		List<FeatureSorterInfo> charList = new ArrayList<FeatureSorterInfo>();
339
		List<FeatureSorterInfo> previous2 = this.charFeatureSorterListMap.put(key, charList);
340
		currentCharFeatureSorterList = charList;
341

    
342
		return (previous1 != null || previous2 != null);
343
	}
344

    
345
	/**
346
	 *
347
	 * @param feature
348
	 */
349
	public FeatureSorterInfo putFeatureToCharSorterList(Feature feature) {
350
		FeatureSorterInfo featureSorterInfo = new FeatureSorterInfo(feature);
351
		currentCharFeatureSorterList.add(featureSorterInfo);
352
		return featureSorterInfo;
353
	}
354

    
355
	public FeatureSorterInfo getLatestCharFeatureSorterInfo() {
356
		return currentCharFeatureSorterList.get(currentCharFeatureSorterList.size() - 1);
357
	}
358

    
359

    
360
	/**
361
	 *
362
	 * @param feature
363
	 */
364
	public void putFeatureToGeneralSorterList(Feature feature) {
365
		currentGeneralFeatureSorterList.add(new FeatureSorterInfo(feature));
366

    
367
	}
368

    
369
	public String getLatestGenusEpithet() {
370
		return latestGenusEpithet;
371
	}
372

    
373
	public void setLatestGenusEpithet(String latestGenusEpithet) {
374
		this.latestGenusEpithet = latestGenusEpithet;
375
	}
376

    
377

    
378
	public boolean isTaxonInClassification() {
379
		return taxonInClassification;
380
	}
381

    
382

    
383
	public void setTaxonInClassification(boolean taxonInClassification) {
384
		this.taxonInClassification = taxonInClassification;
385
	}
386

    
387

    
388
	public TeamOrPersonBase<?> getCurrentCollector() {
389
		return currentCollector;
390
	}
391

    
392

    
393
	public void setCurrentCollector(TeamOrPersonBase<?> currentCollector) {
394
		this.currentCollector = currentCollector;
395
	}
396

    
397

    
398
	public void addCurrentArea(NamedArea area) {
399
		currentAreas.add(area);
400
	}
401

    
402

    
403
	public Set<NamedArea> getCurrentAreas() {
404
		return currentAreas;
405
	}
406

    
407
	public void removeCurrentAreas(){
408
		currentAreas.clear();
409
	}
410

    
411

    
412
	public TeamOrPersonBase<?> getLatestAuthorInHomotype() {
413
		return latestAuthorInHomotype;
414
	}
415

    
416

    
417
	public void setLatestAuthorInHomotype(TeamOrPersonBase<?> latestAuthorInHomotype) {
418
		this.latestAuthorInHomotype = latestAuthorInHomotype;
419
	}
420

    
421

    
422
	public Reference getLatestReferenceInHomotype() {
423
		return latestReferenceInHomotype;
424
	}
425

    
426

    
427
	public void setLatestReferenceInHomotype(Reference latestReferenceInHomotype) {
428
		this.latestReferenceInHomotype = latestReferenceInHomotype;
429
	}
430

    
431
	public void setSpecimenType(boolean isSpecimenType) {
432
		this.isSpecimenType = isSpecimenType;
433
	}
434

    
435
	public boolean isSpecimenType() {
436
		return isSpecimenType;
437
	}
438

    
439

    
440
	//or do we need to make this a uuid?
441
	private Map<String, Collection> collectionMap = new HashMap<String, Collection>();
442

    
443
    public Collection getCollectionByCode(String code) {
444
		return collectionMap.get(code);
445
	}
446

    
447
	public void putCollectionByCode(String code, Collection collection) {
448
		collectionMap.put(code, collection);
449
	}
450

    
451

    
452

    
453
	public void addCollectionAndType(String txt) {
454
		collectionAndType = CdmUtils.concat("@", collectionAndType, txt);
455
	}
456
	public String getCollectionAndType() {
457
		return collectionAndType;
458
	}
459
	public void resetCollectionAndType() {
460
		collectionAndType = "";
461
	}
462

    
463

    
464
    public boolean isCurrentTaxonExcluded() {
465
        return currentTaxonExcluded;
466
    }
467
    public void setCurrentTaxonExcluded(boolean currentTaxonExcluded) {
468
        this.currentTaxonExcluded = currentTaxonExcluded;
469
    }
470

    
471
    public boolean isFirstSpecimenInFacade() {
472
        return firstSpecimenInFacade;
473
    }
474
    public void setFirstSpecimenInFacade(boolean firstSpecimenInFacade) {
475
        this.firstSpecimenInFacade = firstSpecimenInFacade;
476
    }
477

    
478
    public void setNameStatus(String nameStatus) {
479
        this.nameStatus = nameStatus;
480
    }
481
    public String getNameStatus() {
482
        return nameStatus;
483
    }
484

    
485
    public boolean isTaxonIsHybrid() {
486
        return taxonIsHybrid;
487
    }
488
    public void setTaxonIsHybrid(boolean taxonIsHybrid) {
489
        this.taxonIsHybrid = taxonIsHybrid;
490
    }
491

    
492
}
(11-11/19)