2 * Copyright (C) 2016 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.
9 package eu
.etaxonomy
.cdm
.io
.specimen
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashMap
;
13 import java
.util
.HashSet
;
14 import java
.util
.List
;
17 import java
.util
.UUID
;
19 import org
.springframework
.transaction
.TransactionStatus
;
21 import eu
.etaxonomy
.cdm
.api
.application
.ICdmRepository
;
22 import eu
.etaxonomy
.cdm
.common
.URI
;
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
;
43 public class SpecimenImportStateBase
<CONFIG
extends SpecimenImportConfiguratorBase
, STATE
extends SpecimenImportStateBase
>
44 extends ImportStateBase
<CONFIG
, CdmImportBase
<CONFIG
, STATE
>>{
46 public SpecimenImportStateBase(CONFIG config
) {
50 private TransactionStatus tx
;
52 private ICdmRepository cdmRepository
;
53 private Classification classification
= null;
54 private Classification defaultClassification
= null;
55 private Reference ref
= null;
57 private HashMap
<UUID
, TaxonDescription
> descriptionsPerTaxon
= new HashMap
<>();
58 private DerivedUnit derivedUnitBase
;
60 private SpecimenImportReport report
;
62 protected SpecimenDataHolder dataHolder
;
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
<>();
76 MapWrapper
<TeamOrPersonBase
<?
>> personStore
;
77 private Map
<String
, Reference
> importReferences
= new HashMap
<>();
78 private URI actualAccessPoint
;
79 private Set
<URI
> allAccesPoints
= new HashSet
<>();
81 // ************************* Getter/Setter **************/
83 public MapWrapper
<TeamOrPersonBase
<?
>> getPersonStore() {
86 public void setPersonStore(MapWrapper
<TeamOrPersonBase
<?
>> personStore
) {
87 this.personStore
= personStore
;
90 public FieldUnit
getFieldUnit(String fieldNumber
) {
91 return fieldUnits
.get(fieldNumber
);
93 public void setFieldUnit(FieldUnit fieldUnit
) {
94 this.fieldUnits
.put(fieldUnit
.getFieldNumber(), fieldUnit
);
98 public CONFIG
getConfig(){
99 return super.getConfig();
102 public List
<OriginalSourceBase
> getAssociationRefs() {
103 return associationRefs
;
106 public void setAssociationRefs(List
<OriginalSourceBase
> associationRefs
) {
107 this.associationRefs
= associationRefs
;
110 public boolean isAssociationSourcesSet() {
111 return associationSourcesSet
;
114 public void setAssociationSourcesSet(boolean associationSourcesSet
) {
115 this.associationSourcesSet
= associationSourcesSet
;
118 public List
<OriginalSourceBase
> getDescriptionRefs() {
119 return descriptionRefs
;
122 public void setDescriptionRefs(List
<OriginalSourceBase
> descriptionRefs
) {
123 this.descriptionRefs
= descriptionRefs
;
126 public boolean isDescriptionSourcesSet() {
127 return descriptionSourcesSet
;
130 public void setDescriptionSourcesSet(boolean descriptionSourcesSet
) {
131 this.descriptionSourcesSet
= descriptionSourcesSet
;
134 public List
<OriginalSourceBase
> getDerivedUnitSources() {
135 return derivedUnitSources
;
138 public void setDerivedUnitSources(List
<OriginalSourceBase
> derivedUnitSources
) {
139 this.derivedUnitSources
= derivedUnitSources
;
142 public boolean isDerivedUnitSourcesSet() {
143 return derivedUnitSourcesSet
;
146 public void setDerivedUnitSourcesSet(boolean derivedUnitSourcesSet
) {
147 this.derivedUnitSourcesSet
= derivedUnitSourcesSet
;
150 public boolean isDescriptionGroupSet() {
151 return descriptionGroupSet
;
154 public void setDescriptionGroupSet(boolean descriptionGroupSet
) {
155 this.descriptionGroupSet
= descriptionGroupSet
;
158 public TransactionStatus
getTx() {
162 public void setTx(TransactionStatus tx
) {
166 public ICdmRepository
getCdmRepository() {
167 return cdmRepository
;
170 public void setCdmRepository(ICdmRepository cdmRepository
) {
171 this.cdmRepository
= cdmRepository
;
174 public Classification
getClassification() {
175 return classification
;
178 public void setClassification(Classification classification
) {
179 this.classification
= classification
;
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
.getReference()!=null && classif
.getReference().equals(getRef())) {
188 defaultClassification
= classif
;
192 if(defaultClassification
==null){
193 defaultClassification
= Classification
.NewInstance(defaultClassificationAbcd
);
194 cdmRepository
.getClassificationService().save(defaultClassification
);
197 return defaultClassification
;
200 public void setDefaultClassification(Classification defaultClassification
) {
201 this.defaultClassification
= defaultClassification
;
204 public Reference
getRef() {
208 public void setRef(Reference ref
) {
212 public TaxonDescription
getDescriptionPerTaxon(UUID taxonUUID
) {
213 return descriptionsPerTaxon
.get(taxonUUID
);
216 public void setDescriptionGroup(TaxonDescription description
) {
217 this.descriptionsPerTaxon
.put(description
.getTaxon().getUuid(), description
);
220 public DerivedUnit
getDerivedUnitBase() {
221 return derivedUnitBase
;
224 public void setDerivedUnitBase(DerivedUnit derivedUnitBase
) {
225 this.derivedUnitBase
= derivedUnitBase
;
228 public URI
getActualAccessPoint() {
229 return actualAccessPoint
;
232 public Set
<URI
> getAllAccesPoint() {
233 return allAccesPoints
;
236 public void addActualAccesPoint(URI actualAccesPoint
) {
237 this.allAccesPoints
.add(actualAccesPoint
);
239 public void setActualAccessPoint(URI actualAccessPoint
) {
240 this.addActualAccesPoint(actualAccessPoint
);
241 this.actualAccessPoint
= actualAccessPoint
;
244 public SpecimenImportReport
getReport() {
246 report
= new SpecimenImportReport();
250 public void setReport(SpecimenImportReport report
) {
251 this.report
= report
;
254 public SpecimenDataHolder
getDataHolder() {
257 public void setDataHolder(SpecimenDataHolder dataHolder
) {
258 this.dataHolder
= dataHolder
;
260 public void reset() {
261 getDataHolder().reset();
262 // setDerivedUnitBase(null);
265 public Reference
getImportReference(URI accessPoint
){
266 if (accessPoint
== null){
269 if (importReferences
== null){
270 importReferences
= new HashMap
<>();
272 if (this.importReferences
.containsKey(accessPoint
.toString())){
273 return this.importReferences
.get(accessPoint
.toString());
275 Reference ref
= ReferenceFactory
.newGeneric();
276 ref
.setUri(accessPoint
);
277 ref
.setTitle(accessPoint
.toString());
278 this.importReferences
.put(accessPoint
.toString(), ref
);
283 public void addImportReference(Reference ref
) {
284 if (ref
.getUri() != null){
285 this.importReferences
.put(ref
.getUri().toString(), ref
);