1
|
/**
|
2
|
* Copyright (C) 2009 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
|
package eu.etaxonomy.cdm.io.pesi.out;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.HashMap;
|
13
|
import java.util.List;
|
14
|
import java.util.Map;
|
15
|
import java.util.UUID;
|
16
|
|
17
|
import org.apache.log4j.Logger;
|
18
|
import org.springframework.beans.factory.annotation.Autowired;
|
19
|
|
20
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
21
|
import eu.etaxonomy.cdm.io.common.DbExportStateBase;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
24
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
25
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
26
|
|
27
|
/**
|
28
|
* The export state class.
|
29
|
* Holds data needed while the export classes are running.
|
30
|
* @author e.-m.lee
|
31
|
* @since 12.02.2010
|
32
|
*
|
33
|
*/
|
34
|
public class PesiExportState extends DbExportStateBase<PesiExportConfigurator, PesiTransformer>{
|
35
|
@SuppressWarnings("unused")
|
36
|
private static final Logger logger = Logger.getLogger(PesiExportState.class);
|
37
|
|
38
|
private static List<Integer> processedSourceList = new ArrayList<Integer>();
|
39
|
|
40
|
private IdentifiableEntity<?> currentToObject;
|
41
|
private IdentifiableEntity<?> currentFromObject;
|
42
|
private TaxonBase<?> currentTaxon;
|
43
|
private boolean sourceForAdditionalSourceCreated = false;
|
44
|
|
45
|
private final Map<UUID, MarkerType> markerTypeMap = new HashMap<UUID, MarkerType>();
|
46
|
private final Map<String,Integer> treeIndexKingdomMap = new HashMap<String,Integer>();
|
47
|
/**
|
48
|
* @return the treeIndexKingdomMap
|
49
|
*/
|
50
|
public Map<String,Integer> getTreeIndexKingdomMap() {
|
51
|
return treeIndexKingdomMap;
|
52
|
}
|
53
|
|
54
|
|
55
|
public static final UUID uuidUserDefinedMarkerTypeVocabulary = UUID.fromString("5f02a261-fd7d-4fce-bbe4-21472de8cd51");
|
56
|
|
57
|
@Autowired
|
58
|
//@Qualifier("termService")
|
59
|
private ITermService termService;
|
60
|
|
61
|
|
62
|
/**
|
63
|
* @param config
|
64
|
*/
|
65
|
public PesiExportState(PesiExportConfigurator config) {
|
66
|
super(config);
|
67
|
}
|
68
|
|
69
|
|
70
|
/**
|
71
|
* Stores the Datawarehouse.id to a specific CDM object originally.
|
72
|
* Does nothing now since we do not want to store Cdm.id/Datawarehouse.id pairs. This saves precious memory.
|
73
|
* @param cdmBase
|
74
|
* @param dbId
|
75
|
*/
|
76
|
@Override
|
77
|
public void putDbId(CdmBase cdmBase, int dbId) {
|
78
|
// Do nothing
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* TODO -> move to PesiExportBase
|
83
|
* Gets the Datawarehouse.id to a specific CDM object originally.
|
84
|
* Here it just returns the CDM object's id.
|
85
|
* @param cdmBase
|
86
|
* @return
|
87
|
*/
|
88
|
@Override
|
89
|
public Integer getDbId(CdmBase cdmBase) {
|
90
|
return (Integer)getCurrentIO().getDbId(cdmBase, this);
|
91
|
}
|
92
|
|
93
|
private ITermService getTermService(){
|
94
|
return this.termService;
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* Returns whether the given Source object was processed before or not.
|
99
|
* @param
|
100
|
* @return
|
101
|
*/
|
102
|
public boolean alreadyProcessedSource(Integer sourceId) {
|
103
|
if (processedSourceList.contains(sourceId)) {
|
104
|
return true;
|
105
|
} else {
|
106
|
return false;
|
107
|
}
|
108
|
}
|
109
|
|
110
|
/**
|
111
|
* Adds given Source to the list of processed Sources.
|
112
|
*/
|
113
|
public boolean addToProcessedSources(Integer sourceId) {
|
114
|
if (! processedSourceList.contains(sourceId)) {
|
115
|
processedSourceList.add(sourceId);
|
116
|
}
|
117
|
|
118
|
return true;
|
119
|
}
|
120
|
|
121
|
/**
|
122
|
* Clears the list of already processed Sources.
|
123
|
*/
|
124
|
public void clearAlreadyProcessedSources() {
|
125
|
processedSourceList.clear();
|
126
|
}
|
127
|
|
128
|
|
129
|
public IdentifiableEntity<?> getCurrentToObject() {
|
130
|
return currentToObject;
|
131
|
}
|
132
|
|
133
|
|
134
|
public void setCurrentToObject(IdentifiableEntity<?> currentToObject) {
|
135
|
this.currentToObject = currentToObject;
|
136
|
}
|
137
|
|
138
|
|
139
|
public IdentifiableEntity<?> getCurrentFromObject() {
|
140
|
return currentFromObject;
|
141
|
}
|
142
|
|
143
|
|
144
|
public void setCurrentFromObject(IdentifiableEntity<?> currentFromObject) {
|
145
|
this.currentFromObject = currentFromObject;
|
146
|
}
|
147
|
|
148
|
|
149
|
public TaxonBase<?> getCurrentTaxon() {
|
150
|
return currentTaxon;
|
151
|
}
|
152
|
|
153
|
|
154
|
public void setCurrentTaxon(TaxonBase<?> currentTaxon) {
|
155
|
this.currentTaxon = currentTaxon;
|
156
|
}
|
157
|
|
158
|
public void putMarkerType(MarkerType markerType) {
|
159
|
|
160
|
markerTypeMap.put(markerType.getUuid(), markerType);
|
161
|
|
162
|
}
|
163
|
|
164
|
|
165
|
public MarkerType getMarkerType(UUID uuid){
|
166
|
return markerTypeMap.get(uuid);
|
167
|
}
|
168
|
|
169
|
|
170
|
public boolean isSourceForAdditionalSourceCreated() {
|
171
|
return sourceForAdditionalSourceCreated;
|
172
|
}
|
173
|
|
174
|
|
175
|
public void setSourceForAdditionalSourceCreated(
|
176
|
boolean sourceForAdditionalSourceCreated) {
|
177
|
this.sourceForAdditionalSourceCreated = sourceForAdditionalSourceCreated;
|
178
|
}
|
179
|
|
180
|
|
181
|
|
182
|
|
183
|
}
|