1
|
/**
|
2
|
* Copyright (C) 2016 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.specimen;
|
10
|
|
11
|
import java.net.URI;
|
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.springframework.transaction.TransactionStatus;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.application.ICdmRepository;
|
23
|
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
24
|
import eu.etaxonomy.cdm.io.common.ImportStateBase;
|
25
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
26
|
import eu.etaxonomy.cdm.io.specimen.abcd206.in.SpecimenImportReport;
|
27
|
import eu.etaxonomy.cdm.model.agent.Institution;
|
28
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
29
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
30
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
31
|
import eu.etaxonomy.cdm.model.occurrence.Collection;
|
32
|
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
|
33
|
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
|
34
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
35
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
36
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
37
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
38
|
|
39
|
/**
|
40
|
* @author k.luther
|
41
|
* @since 15.07.2016
|
42
|
*/
|
43
|
public class SpecimenImportStateBase<CONFIG extends SpecimenImportConfiguratorBase, STATE extends SpecimenImportStateBase>
|
44
|
extends ImportStateBase<CONFIG , CdmImportBase<CONFIG , STATE >>{
|
45
|
|
46
|
public SpecimenImportStateBase(CONFIG config) {
|
47
|
super(config);
|
48
|
}
|
49
|
|
50
|
private TransactionStatus tx;
|
51
|
|
52
|
private ICdmRepository cdmRepository;
|
53
|
private Classification classification = null;
|
54
|
private Classification defaultClassification = null;
|
55
|
private Reference ref = null;
|
56
|
|
57
|
private HashMap<UUID, TaxonDescription> descriptionsPerTaxon = new HashMap<>();
|
58
|
private DerivedUnit derivedUnitBase;
|
59
|
|
60
|
private SpecimenImportReport report;
|
61
|
|
62
|
protected SpecimenDataHolder dataHolder;
|
63
|
|
64
|
private List<OriginalSourceBase<?>> associationRefs = new ArrayList<>();
|
65
|
private boolean associationSourcesSet=false;
|
66
|
private List<OriginalSourceBase<?>> descriptionRefs = new ArrayList<>();
|
67
|
private boolean descriptionSourcesSet=false;
|
68
|
private List<OriginalSourceBase<?>> derivedUnitSources = new ArrayList<>();
|
69
|
private boolean derivedUnitSourcesSet=false;
|
70
|
private boolean descriptionGroupSet = false;
|
71
|
protected HashMap<String, Institution> institutions = new HashMap<>();
|
72
|
protected HashMap<String, Collection> collections= new HashMap<>();
|
73
|
protected HashMap<String, TaxonName> names= new HashMap<>();
|
74
|
private HashMap<String,FieldUnit> fieldUnits = new HashMap<>();
|
75
|
|
76
|
MapWrapper<TeamOrPersonBase<?>> personStore;
|
77
|
private Map<String, Reference> importReferences = new HashMap<>();
|
78
|
private URI actualAccessPoint;
|
79
|
private Set<URI> allAccesPoints = new HashSet<>();
|
80
|
|
81
|
// ************************* Getter/Setter **************/
|
82
|
|
83
|
public MapWrapper<TeamOrPersonBase<?>> getPersonStore() {
|
84
|
return personStore;
|
85
|
}
|
86
|
public void setPersonStore(MapWrapper<TeamOrPersonBase<?>> personStore) {
|
87
|
this.personStore = personStore;
|
88
|
}
|
89
|
|
90
|
public FieldUnit getFieldUnit(String fieldNumber) {
|
91
|
return fieldUnits.get(fieldNumber);
|
92
|
}
|
93
|
public void setFieldUnit(FieldUnit fieldUnit) {
|
94
|
this.fieldUnits.put(fieldUnit.getFieldNumber(), fieldUnit);
|
95
|
}
|
96
|
|
97
|
@Override
|
98
|
public CONFIG getConfig(){
|
99
|
return super.getConfig();
|
100
|
}
|
101
|
|
102
|
public List<OriginalSourceBase<?>> getAssociationRefs() {
|
103
|
return associationRefs;
|
104
|
}
|
105
|
|
106
|
public void setAssociationRefs(List<OriginalSourceBase<?>> associationRefs) {
|
107
|
this.associationRefs = associationRefs;
|
108
|
}
|
109
|
|
110
|
public boolean isAssociationSourcesSet() {
|
111
|
return associationSourcesSet;
|
112
|
}
|
113
|
|
114
|
public void setAssociationSourcesSet(boolean associationSourcesSet) {
|
115
|
this.associationSourcesSet = associationSourcesSet;
|
116
|
}
|
117
|
|
118
|
public List<OriginalSourceBase<?>> getDescriptionRefs() {
|
119
|
return descriptionRefs;
|
120
|
}
|
121
|
|
122
|
public void setDescriptionRefs(List<OriginalSourceBase<?>> descriptionRefs) {
|
123
|
this.descriptionRefs = descriptionRefs;
|
124
|
}
|
125
|
|
126
|
public boolean isDescriptionSourcesSet() {
|
127
|
return descriptionSourcesSet;
|
128
|
}
|
129
|
|
130
|
public void setDescriptionSourcesSet(boolean descriptionSourcesSet) {
|
131
|
this.descriptionSourcesSet = descriptionSourcesSet;
|
132
|
}
|
133
|
|
134
|
public List<OriginalSourceBase<?>> getDerivedUnitSources() {
|
135
|
return derivedUnitSources;
|
136
|
}
|
137
|
|
138
|
public void setDerivedUnitSources(List<OriginalSourceBase<?>> derivedUnitSources) {
|
139
|
this.derivedUnitSources = derivedUnitSources;
|
140
|
}
|
141
|
|
142
|
public boolean isDerivedUnitSourcesSet() {
|
143
|
return derivedUnitSourcesSet;
|
144
|
}
|
145
|
|
146
|
public void setDerivedUnitSourcesSet(boolean derivedUnitSourcesSet) {
|
147
|
this.derivedUnitSourcesSet = derivedUnitSourcesSet;
|
148
|
}
|
149
|
|
150
|
public boolean isDescriptionGroupSet() {
|
151
|
return descriptionGroupSet;
|
152
|
}
|
153
|
|
154
|
public void setDescriptionGroupSet(boolean descriptionGroupSet) {
|
155
|
this.descriptionGroupSet = descriptionGroupSet;
|
156
|
}
|
157
|
|
158
|
public TransactionStatus getTx() {
|
159
|
return tx;
|
160
|
}
|
161
|
|
162
|
public void setTx(TransactionStatus tx) {
|
163
|
this.tx = tx;
|
164
|
}
|
165
|
|
166
|
public ICdmRepository getCdmRepository() {
|
167
|
return cdmRepository;
|
168
|
}
|
169
|
|
170
|
public void setCdmRepository(ICdmRepository cdmRepository) {
|
171
|
this.cdmRepository = cdmRepository;
|
172
|
}
|
173
|
|
174
|
public Classification getClassification() {
|
175
|
return classification;
|
176
|
}
|
177
|
|
178
|
public void setClassification(Classification classification) {
|
179
|
this.classification = classification;
|
180
|
}
|
181
|
|
182
|
public Classification getDefaultClassification(boolean createIfNotExist) {
|
183
|
if(defaultClassification==null && createIfNotExist){
|
184
|
final String defaultClassificationAbcd = "Default Classification Specimen Import";
|
185
|
for (Classification classif : cdmRepository.getClassificationService().list(Classification.class, null, null, null, null)){
|
186
|
if (classif.getTitleCache()!=null && classif.getTitleCache().equalsIgnoreCase(defaultClassificationAbcd)
|
187
|
&& classif.getCitation()!=null && classif.getCitation().equals(getRef())) {
|
188
|
defaultClassification = classif;
|
189
|
break;
|
190
|
}
|
191
|
}
|
192
|
if(defaultClassification==null){
|
193
|
defaultClassification = Classification.NewInstance(defaultClassificationAbcd);
|
194
|
cdmRepository.getClassificationService().save(defaultClassification);
|
195
|
}
|
196
|
}
|
197
|
return defaultClassification;
|
198
|
}
|
199
|
|
200
|
public void setDefaultClassification(Classification defaultClassification) {
|
201
|
this.defaultClassification = defaultClassification;
|
202
|
}
|
203
|
|
204
|
public Reference getRef() {
|
205
|
return ref;
|
206
|
}
|
207
|
|
208
|
public void setRef(Reference ref) {
|
209
|
this.ref = ref;
|
210
|
}
|
211
|
|
212
|
public TaxonDescription getDescriptionPerTaxon(UUID taxonUUID) {
|
213
|
return descriptionsPerTaxon.get(taxonUUID);
|
214
|
}
|
215
|
|
216
|
public void setDescriptionGroup(TaxonDescription description) {
|
217
|
this.descriptionsPerTaxon.put(description.getTaxon().getUuid(), description);
|
218
|
}
|
219
|
|
220
|
public DerivedUnit getDerivedUnitBase() {
|
221
|
return derivedUnitBase;
|
222
|
}
|
223
|
|
224
|
public void setDerivedUnitBase(DerivedUnit derivedUnitBase) {
|
225
|
this.derivedUnitBase = derivedUnitBase;
|
226
|
}
|
227
|
|
228
|
public URI getActualAccessPoint() {
|
229
|
return actualAccessPoint;
|
230
|
}
|
231
|
|
232
|
public Set<URI> getAllAccesPoint() {
|
233
|
return allAccesPoints;
|
234
|
}
|
235
|
|
236
|
public void addActualAccesPoint(URI actualAccesPoint) {
|
237
|
this.allAccesPoints.add(actualAccesPoint);
|
238
|
}
|
239
|
public void setActualAccessPoint(URI actualAccessPoint) {
|
240
|
this.addActualAccesPoint(actualAccessPoint);
|
241
|
this.actualAccessPoint = actualAccessPoint;
|
242
|
}
|
243
|
|
244
|
public SpecimenImportReport getReport() {
|
245
|
if (report == null){
|
246
|
report = new SpecimenImportReport();
|
247
|
}
|
248
|
return report;
|
249
|
}
|
250
|
public void setReport(SpecimenImportReport report) {
|
251
|
this.report = report;
|
252
|
}
|
253
|
|
254
|
public SpecimenDataHolder getDataHolder() {
|
255
|
return dataHolder;
|
256
|
}
|
257
|
public void setDataHolder(SpecimenDataHolder dataHolder) {
|
258
|
this.dataHolder = dataHolder;
|
259
|
}
|
260
|
public void reset() {
|
261
|
getDataHolder().reset();
|
262
|
// setDerivedUnitBase(null);
|
263
|
}
|
264
|
|
265
|
public Reference getImportReference(URI accessPoint){
|
266
|
if (accessPoint == null){
|
267
|
return null;
|
268
|
}
|
269
|
if (importReferences == null){
|
270
|
importReferences = new HashMap<>();
|
271
|
}
|
272
|
if (this.importReferences.containsKey(accessPoint.toString())){
|
273
|
return this.importReferences.get(accessPoint.toString());
|
274
|
}else{
|
275
|
Reference ref = ReferenceFactory.newGeneric();
|
276
|
ref.setUri(accessPoint);
|
277
|
ref.setTitle(accessPoint.toString());
|
278
|
this.importReferences.put(accessPoint.toString(), ref);
|
279
|
return ref;
|
280
|
}
|
281
|
}
|
282
|
|
283
|
public void addImportReference(Reference ref) {
|
284
|
if (ref.getUri() != null){
|
285
|
this.importReferences.put(ref.getUri().toString(), ref);
|
286
|
}
|
287
|
}
|
288
|
}
|