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
.greece
;
11 import java
.util
.HashMap
;
12 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.io
.mexico
.SimpleExcelTaxonImport
;
19 import eu
.etaxonomy
.cdm
.io
.mexico
.SimpleExcelTaxonImportState
;
20 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
22 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
26 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
33 public abstract class FloraHellenicaImportBase
<CONFIG
extends FloraHellenicaImportConfigurator
>
34 extends SimpleExcelTaxonImport
<CONFIG
>{
36 private static final long serialVersionUID
= 2593130403213346396L;
37 private static final Logger logger
= Logger
.getLogger(FloraHellenicaImportBase
.class);
39 private Map
<UUID
, Taxon
> acceptedTaxonMap
= new HashMap
<>();
40 private Reference sourceReference
;
41 private Reference secReference
;
42 private Reference secReference2
;
44 protected TaxonDescription
getTaxonDescription(Taxon taxon
) {
45 if (!taxon
.getDescriptions().isEmpty()){
46 return taxon
.getDescriptions().iterator().next();
48 TaxonDescription desc
= TaxonDescription
.NewInstance(taxon
);
49 desc
.setDefault(true);
54 protected Reference
getSourceCitation(SimpleExcelTaxonImportState
<CONFIG
> state
) {
55 if (this.sourceReference
== null){
56 this.sourceReference
= getPersistentReference(state
.getConfig().getSourceReference());
58 return this.sourceReference
;
61 protected Reference
getSecReference(SimpleExcelTaxonImportState
<CONFIG
> state
) {
62 if (this.secReference
== null){
63 this.secReference
= getPersistentReference(state
.getConfig().getSecReference());
65 return this.secReference
;
68 protected Reference
getSecReference2(SimpleExcelTaxonImportState
<CONFIG
> state
) {
69 if (this.secReference2
== null){
70 this.secReference2
= getPersistentReference(state
.getConfig().getSecReference2());
72 return this.secReference2
;
75 private Reference
getPersistentReference(Reference reference
) {
76 Reference result
= getReferenceService().find(reference
.getUuid());
83 protected Taxon
getAcceptedTaxon(Map
<String
, String
> record
,
84 SimpleExcelTaxonImportState
<CONFIG
> state
, String key
) {
86 String accStr
= getValue(record
, key
);
90 accStr
= accStr
.trim();
92 Taxon accTaxon
= state
.getTaxon(accStr
);
93 if (accTaxon
== null){
94 String message
= state
.getCurrentLine()+ ": Accepted taxon could not be found: " + accStr
;
98 initAcceptedTaxonMap();
99 // accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid());
100 accTaxon
= acceptedTaxonMap
.get(accTaxon
.getUuid());
105 private void initAcceptedTaxonMap() {
106 if (acceptedTaxonMap
.isEmpty()){
107 List
<Taxon
> list
= getTaxonService().list(Taxon
.class, null, null, null, null);
108 for (Taxon taxon
: list
){
109 acceptedTaxonMap
.put(taxon
.getUuid(), taxon
);
119 protected Taxon
getHigherTaxon(Map
<String
, String
> record
,
120 SimpleExcelTaxonImportState
<CONFIG
> state
, String key
) {
122 String accStr
= getValue(record
, key
);
126 accStr
= accStr
.trim();
128 Taxon accTaxon
= state
.getHigherTaxon(accStr
);
129 if (accTaxon
== null){
130 String message
= state
.getCurrentLine()+ ": Higher taxon could not be found: " + accStr
;
131 logger
.info(message
); //not critical
134 initAcceptedTaxonMap();
135 // accTaxon = (Taxon)getTaxonService().find(accTaxon.getUuid());
136 accTaxon
= acceptedTaxonMap
.get(accTaxon
.getUuid());
142 protected TaxonName
makeFamilyName(SimpleExcelTaxonImportState
<CONFIG
> state
,
144 TaxonName name
= TaxonNameFactory
.NewBotanicalInstance(Rank
.FAMILY());
145 famStr
= famStr
.substring(0,1).toUpperCase() + famStr
.substring(1).toLowerCase();
146 name
.setGenusOrUninomial(famStr
);
147 name
.addSource(makeOriginalSource(state
));
151 protected TaxonName
replaceNameAuthorsAndReferences(SimpleExcelTaxonImportState
<CONFIG
> state
, TaxonName name
) {
152 TaxonName result
= state
.getDeduplicationHelper().getExistingName(name
);
153 state
.getDeduplicationHelper().replaceAuthorNamesAndNomRef(result
);
158 protected IdentifiableSource
makeOriginalSource(SimpleExcelTaxonImportState
<CONFIG
> state
) {
159 return IdentifiableSource
.NewDataImportInstance("line: " + state
.getCurrentLine(), null, getSourceCitation(state
));