Project

General

Profile

Download (31.5 KB) Statistics
| Branch: | Revision:
1
/**
2
* Copyright (C) 2017 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.greece;
10

    
11
import java.net.URI;
12
import java.util.UUID;
13

    
14
import org.apache.log4j.Logger;
15
import org.springframework.stereotype.Component;
16
import org.springframework.transaction.TransactionStatus;
17

    
18
import eu.etaxonomy.cdm.api.service.ITermService;
19
import eu.etaxonomy.cdm.ext.geo.GeoServiceArea;
20
import eu.etaxonomy.cdm.ext.geo.GeoServiceAreaAnnotatedMapping;
21
import eu.etaxonomy.cdm.io.common.CdmImportBase;
22
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
23
import eu.etaxonomy.cdm.model.common.OrderedTermBase;
24
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
25
import eu.etaxonomy.cdm.model.common.TermType;
26
import eu.etaxonomy.cdm.model.common.TermVocabulary;
27
import eu.etaxonomy.cdm.model.description.Feature;
28
import eu.etaxonomy.cdm.model.description.FeatureNode;
29
import eu.etaxonomy.cdm.model.description.FeatureTree;
30
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
31
import eu.etaxonomy.cdm.model.description.State;
32
import eu.etaxonomy.cdm.model.location.NamedArea;
33
import eu.etaxonomy.cdm.model.location.NamedAreaType;
34

    
35
/**
36
 * @author a.mueller
37
 * @date 13.05.2017
38
 *
39
 */
40
@Component
41
public class FloraHellenicaTermImport <CONFIG extends FloraHellenicaImportConfigurator>
42
            extends CdmImportBase<CONFIG, SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator>>{
43

    
44
    private static final long serialVersionUID = 1347759514044184010L;
45

    
46
    @SuppressWarnings("unused")
47
    private static final Logger logger = Logger.getLogger(FloraHellenicaTaxonImport.class);
48

    
49
    private NamedArea greece;
50

    
51

    
52

    
53
    /**
54
     * {@inheritDoc}
55
     */
56
    @Override
57
    protected void doInvoke(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
58

    
59
        TransactionStatus tx = this.startTransaction();
60
        initAreaVocabulary(state);
61
        initLifeformVocabulary(state);
62
        initHabitatVocabulary(state);
63
        initChorologicalVocabulary(state);
64
        initStatusVocabulary(state);
65
        makeFeatureTree(state);
66
        this.commitTransaction(tx);
67
    }
68

    
69

    
70
    @SuppressWarnings("unchecked")
71
    private void initAreaVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
72
        OrderedTermVocabulary<NamedArea> areasVoc = (OrderedTermVocabulary<NamedArea>)this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
73
        if (areasVoc == null){
74
            createAreasVoc(state);
75
        }
76
    }
77

    
78
    /**
79
     * @param state
80
     * @return
81
     */
82
    @SuppressWarnings("unchecked")
83
    private void createAreasVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
84
        //voc
85
        URI termSourceUri = null;
86
        String label = "Checklist of Greece Areas";
87
        String description = "Areas as used in the Checklist of Greece";
88
        OrderedTermVocabulary<NamedArea> areasVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea,
89
                description, label, null, termSourceUri);
90
        areasVoc.setUuid(FloraHellenicaTransformer.uuidFloraHellenicaAreasVoc);
91
//        Representation rep = Representation.NewInstance("Estados Méxicanos", "Estados Méxicanos", null, Language.SPANISH_CASTILIAN());
92
//        areasVoc.addRepresentation(rep);
93

    
94
        //greece country
95
        String countryLabel = "Greece";
96
        greece = NamedArea.NewInstance(countryLabel, countryLabel, "GR");
97
        greece.setUuid(FloraHellenicaTransformer.uuidAreaGreece);
98
        greece.setIdInVocabulary("GR");
99
        greece.setSymbol("GR");
100
        areasVoc.addTerm(greece);
101
        //FIXME
102
//        addMapping(greece, xx "mex_adm0", "iso", "MEX");
103

    
104
        addArea(state, areasVoc, "IoI", "Ionian Islands", 4, FloraHellenicaTransformer.uuidAreaIoI);
105
        addArea(state, areasVoc, "NPi", "North Pindos", 13, FloraHellenicaTransformer.uuidAreaNPi);
106
        addArea(state, areasVoc, "SPi", "South Pindos", 11, FloraHellenicaTransformer.uuidAreaSPi);
107
        addArea(state, areasVoc, "Pe", "Peloponnisos", 1, FloraHellenicaTransformer.uuidAreaPe);
108
        addArea(state, areasVoc, "StE", "Sterea Ellas", 12, FloraHellenicaTransformer.uuidAreaStE);
109
        addArea(state, areasVoc, "EC", "East Central Greece", 5, FloraHellenicaTransformer.uuidAreaEC);
110
        addArea(state, areasVoc, "NC", "North Central Greece", 2, FloraHellenicaTransformer.uuidAreaNC);
111
        addArea(state, areasVoc, "NE", "North-East Greece", 10, FloraHellenicaTransformer.uuidAreaNE);
112
        addArea(state, areasVoc, "NAe", "North Aegean islands", 7, FloraHellenicaTransformer.uuidAreaNAe);
113
        addArea(state, areasVoc, "WAe", "West Aegean islands", 9, FloraHellenicaTransformer.uuidAreaWAe);
114
        addArea(state, areasVoc, "Kik", "Kiklades", 8, FloraHellenicaTransformer.uuidAreaKik);
115
        addArea(state, areasVoc, "KK", "Kriti and Karpathos", 6, FloraHellenicaTransformer.uuidAreaKK);
116
        addArea(state, areasVoc, "EAe", "East Aegean islands", 3, FloraHellenicaTransformer.uuidAreaEAe);
117

    
118
        this.getVocabularyService().save(areasVoc);
119
        return;
120
    }
121

    
122

    
123
    private void addArea(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
124
            OrderedTermVocabulary<NamedArea> areasVoc,
125
            String abbrevLabel, String areaLabel,
126
            Integer id, UUID uuid) {
127
        addArea(state, areasVoc, abbrevLabel, areaLabel, uuid, String.valueOf(id));  //short cut if label and mapping label are equal
128
    }
129

    
130
    private void addArea(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
131
            OrderedTermVocabulary<NamedArea> areasVoc,
132
            String abbrevLabel, String areaLabel,
133
            UUID uuid, String mappingLabel) {
134
        addArea(state, areasVoc, abbrevLabel, areaLabel, uuid, mappingLabel, null);  //short cut if label and mapping label are equal
135
    }
136

    
137
    /**
138
     * @param state
139
     * @param string
140
     * @param uuidaguascalientes
141
     */
142
    private void addArea(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
143
            OrderedTermVocabulary<NamedArea> areasVoc,
144
            String abbrevLabel, String areaLabel,
145
            UUID uuid, String mappingLabel, Integer id1) {
146
        NamedArea newArea = NamedArea.NewInstance(
147
                areaLabel, areaLabel, abbrevLabel);
148
        newArea.setIdInVocabulary(abbrevLabel);
149
        newArea.setUuid(uuid);
150
        newArea.setPartOf(greece);
151
        newArea.setLevel(null);
152
        newArea.setType(NamedAreaType.NATURAL_AREA());
153
        areasVoc.addTerm(newArea);
154
        if (mappingLabel != null){
155
            addMapping(newArea, "phytogeographical_regions_of_greece", "id", mappingLabel);
156
        }
157
    }
158

    
159

    
160
    private void addMapping(NamedArea area, String mapping_layer, String mapping_field, String abbrev) {
161
        GeoServiceAreaAnnotatedMapping mapping = (GeoServiceAreaAnnotatedMapping)this.getBean("geoServiceAreaAnnotatedMapping");
162
        GeoServiceArea geoServiceArea = new GeoServiceArea();
163
        geoServiceArea.add(mapping_layer, mapping_field, abbrev);
164
        mapping.set(area, geoServiceArea);
165
    }
166

    
167

    
168
    /**
169
     * @param state
170
     */
171
    private void initChorologicalVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
172
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologicalVoc;
173
        OrderedTermVocabulary<State> chorologicalVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
174
        if (chorologicalVoc == null){
175
            createChorologicalVoc(state, uuid);
176
        }
177
    }
178

    
179
    /**
180
     * @param state
181
     * @param uuid
182
     */
183
    private void createChorologicalVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state, UUID vocUuid) {
184
        //voc
185
        URI termSourceUri = null;
186
        String label = "Checklist of Greece Chorological Categories";
187
        String description = "Chorological Categories as used in the Checklist of Greece";
188
        OrderedTermVocabulary<State> chorologicalVoc = OrderedTermVocabulary.NewInstance(TermType.State,
189
                description, label, null, termSourceUri);
190
        chorologicalVoc.setUuid(vocUuid);
191

    
192
        addChorological(state, chorologicalVoc, "*", "Greek endemic", "Greek endemics (incl. single-island and single-mountain endemics)", FloraHellenicaTransformer.uuidChorologicalStar);
193
        addChorological(state, chorologicalVoc, "Bk", "Balkan", "Taxa restricted to Balkan countries, occasionally extending to adjacent parts of SE Europe", FloraHellenicaTransformer.uuidChorologicalBk);
194
        addChorological(state, chorologicalVoc, "BI", "Balkan-Italy", "Taxa restricted to Balkan countries and Italy (amphi-Adreatic)", FloraHellenicaTransformer.uuidChorologicalBI);
195
        addChorological(state, chorologicalVoc, "BA", "Balkan-Anatolia", "Taxa restricted to Balkan countries and to Asia minor (Anatolia), occasionally extending to S Ukraine (Crimea), adjacent Caucasian countries (Georgia, Armenia) or N Iraq", FloraHellenicaTransformer.uuidChorologicalBA);
196
        addChorological(state, chorologicalVoc, "BC", "Balkan-Central Europe", "Taxa distributed in the Balkans, Carpathians, Alps and adjacent areas (mainly in the mountains)", FloraHellenicaTransformer.uuidChorologicalBC);
197
        addChorological(state, chorologicalVoc, "EM", "East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorologicalEM);
198
        addChorological(state, chorologicalVoc, "Me", "Mediterranean", "Taxa with a circum-Mediterranean distribution including Portugal, occasionally extending to the Caucasus area and N Iran", FloraHellenicaTransformer.uuidChorologicalMe);
199
        addChorological(state, chorologicalVoc, "MA", "Mediterranean-Atlantic", "Taxa restricted to maritime W Europe and the Mediterranean", FloraHellenicaTransformer.uuidChorologicalMA);
200
        addChorological(state, chorologicalVoc, "ME", "Mediterranean-European", "Taxa restricted to the Mediterranean and temperate Europe, occasionally extending to NW Africa and the Caucasus area", FloraHellenicaTransformer.uuidChorologicalME);
201
        addChorological(state, chorologicalVoc, "MS", "Mediterranean-SW Asian", "Taxa distributed in one or more Mediterranean countries and extending to SW and C Asia", FloraHellenicaTransformer.uuidChorologicalMS);
202
        addChorological(state, chorologicalVoc, "EA", "European-SW Asian", "Eruopean taxa (occasionally reachin N Africa) with a distribution extending to SW Asia, occasionally reaching C Asia", FloraHellenicaTransformer.uuidChorologicalEA);
203
        addChorological(state, chorologicalVoc, "ES", "Euro-Siberian", "Taxa with main distribution in temperate Eurasia (occasionally reaching the Caucasus area)", FloraHellenicaTransformer.uuidChorologicalES);
204
        addChorological(state, chorologicalVoc, "Eu", "European", "Taxa with a distribution all over Europe. In S European countries this category in fact represents the C European element", FloraHellenicaTransformer.uuidChorologicalEu);
205
        addChorological(state, chorologicalVoc, "Pt", "Paleotemperate", "Taxa of extratropical Eurasia including the Himalaya and E Asia, not (or at most marginally) extending to North America", FloraHellenicaTransformer.uuidChorologicalPt);
206
        addChorological(state, chorologicalVoc, "Ct", "Circumtemperate", "Taxa of both extratropical Eurasia and North America", FloraHellenicaTransformer.uuidChorologicalCt);
207
        addChorological(state, chorologicalVoc, "IT", "Irano-Turanian", "Taxa with main distribution in arid SW and C Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalIT);
208
        addChorological(state, chorologicalVoc, "SS", "Saharo-Sindian", "Taxa with main distribution in arid N Africa and SQ Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalSS);
209
        addChorological(state, chorologicalVoc, "ST", "Subtropical-tropical", "Taxa widespread in the warmer regions of both hemispheres", FloraHellenicaTransformer.uuidChorologicalST);
210
        addChorological(state, chorologicalVoc, "Bo", "(Circum-)Boreal", "Taxa with main distribution in N and high-montane Eurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalBo);
211
        addChorological(state, chorologicalVoc, "AA", "Arctic-Alpine", "Taxa with main distribution beyound the N and aove the high-montane timerlines o fEurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalAA);
212
        addChorological(state, chorologicalVoc, "Co", "Cosmopolitan", "Taxa distributed in all continents, i.e. beyond the N hemisphere. This category may be given in brackets after the known or supposed native distribution in cases of taxa that have been spread worldwide by humans", FloraHellenicaTransformer.uuidChorologicalCo);
213

    
214
        addChorological(state, chorologicalVoc, "[SS]", "[Saharo-Sindian]", "Taxa with main distribution in arid N Africa and SQ Asia, extrazonally extending to the Mediterranean, not native in Greece", FloraHellenicaTransformer.uuidChorological_SS_);
215
        addChorological(state, chorologicalVoc, "[?MS]", "[Mediterranean-SW Asian]", "Taxa distributed in one or more Mediterranean countries and extending to SW and C Asia, not native in Greece", FloraHellenicaTransformer.uuidChorological_dMS_);
216
        addChorological(state, chorologicalVoc, "?EM", "? East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorological_dEM);
217

    
218

    
219
        addChorological(state, chorologicalVoc, "[trop.]", "[tropical]", "", FloraHellenicaTransformer.uuidChorologicaltrop);
220
        addChorological(state, chorologicalVoc, "[subtrop.]", "[subtropical]", "", FloraHellenicaTransformer.uuidChorologicalsubtrop);
221
        addChorological(state, chorologicalVoc, "[paleotrop.]", "[paleotropical]", "", FloraHellenicaTransformer.uuidChorologicalpaleotrop);
222
        addChorological(state, chorologicalVoc, "[neotrop.]", "[neotropical]", "", FloraHellenicaTransformer.uuidChorologicalneotrop);
223
        addChorological(state, chorologicalVoc, "[pantrop.]", "[pantropical]", "", FloraHellenicaTransformer.uuidChorologicalpantrop);
224
        addChorological(state, chorologicalVoc, "[N-Am.]", "[North American]", "", FloraHellenicaTransformer.uuidChorologicalN_Am);
225
        addChorological(state, chorologicalVoc, "[S-Am.]", "[South American]", "", FloraHellenicaTransformer.uuidChorologicalS_Am);
226
        addChorological(state, chorologicalVoc, "[E-As.]", "[East Asian]", "", FloraHellenicaTransformer.uuidChorologicalE_As);
227
        addChorological(state, chorologicalVoc, "[SE-As.", "[South East Asian]", "", FloraHellenicaTransformer.uuidChorologicalSE_As);
228
        addChorological(state, chorologicalVoc, "[S-Afr.]", "[South African]", "", FloraHellenicaTransformer.uuidChorologicalS_Afr);
229
        addChorological(state, chorologicalVoc, "[Arab.]", "[Arabian]", "", FloraHellenicaTransformer.uuidChorologicalArab);
230
        addChorological(state, chorologicalVoc, "[Arab. NE-Afr.]", "[Arabian and North East African]", "", FloraHellenicaTransformer.uuidChorologicalArab_NE_Afr);
231
        addChorological(state, chorologicalVoc, "[Caucas.]", "[Caucasian]", "", FloraHellenicaTransformer.uuidChorologicalCaucas);
232
        addChorological(state, chorologicalVoc, "[Pontic]", "[Pontic]", "", FloraHellenicaTransformer.uuidChorologicalPontic);
233
        addChorological(state, chorologicalVoc, "[Europ.]", "[European]", "", FloraHellenicaTransformer.uuidChorologicalEurop);
234
        addChorological(state, chorologicalVoc, "[Austr.]", "[Australian]", "", FloraHellenicaTransformer.uuidChorologicalAustral);
235

    
236
        addChorological(state, chorologicalVoc, "[W-Med.]", "[West Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalW_Med);
237
        addChorological(state, chorologicalVoc, "[C-Med.]", "[Central Mediterranean]", "", FloraHellenicaTransformer.uuidChorologicalC_Med);
238
        addChorological(state, chorologicalVoc, "[W-Eur.]", "[West European]", "", FloraHellenicaTransformer.uuidChorologicalW_Eur);
239
        addChorological(state, chorologicalVoc, "[S-Eur.]", "[South European]", "", FloraHellenicaTransformer.uuidChorologicalS_Eur);
240
        addChorological(state, chorologicalVoc, "[C-Am.]", "[Central American]", "", FloraHellenicaTransformer.uuidChorologicalC_Am);
241
        addChorological(state, chorologicalVoc, "[C-As.]", "[Central Asian]", "", FloraHellenicaTransformer.uuidChorologicalC_As);
242
        addChorological(state, chorologicalVoc, "[SW-As.]", "[South West Asian]", "", FloraHellenicaTransformer.uuidChorologicalSW_As);
243
        addChorological(state, chorologicalVoc, "[unknown]", "[unknown]", "", FloraHellenicaTransformer.uuidChorologicalUnknown);
244
        addChorological(state, chorologicalVoc, "[N-Afr.]", "[North African]", "", FloraHellenicaTransformer.uuidChorologicalN_Afr);
245
        addChorological(state, chorologicalVoc, "[Am.]", "[American]", "", FloraHellenicaTransformer.uuidChorologicalAm);
246
        addChorological(state, chorologicalVoc, "[paleosubtrop.]", "[paleosubtropical]", "", FloraHellenicaTransformer.uuidChorologicalPaleosubtrop);
247
        addChorological(state, chorologicalVoc, "[SW-Eur.]", "[South West European]", "", FloraHellenicaTransformer.uuidChorologicalSW_Eur);
248

    
249
        addChorological(state, chorologicalVoc, "[S-As.]", "[South Asian]", "", FloraHellenicaTransformer.uuidChorologicalS_As);
250
        addChorological(state, chorologicalVoc, "[NE-Afr.]", "[North East African]", "", FloraHellenicaTransformer.uuidChorologicalNE_Afr);
251
        addChorological(state, chorologicalVoc, "[NW-Afr.]", "[North West African]", "", FloraHellenicaTransformer.uuidChorologicalNW_Afr);
252
        addChorological(state, chorologicalVoc, "[trop. Afr.]", "[tropical African]", "", FloraHellenicaTransformer.uuidChorologicalTrop_Afr);
253
        addChorological(state, chorologicalVoc, "[Afr.]", "[Arican]", "", FloraHellenicaTransformer.uuidChorologicalAfr);
254
        addChorological(state, chorologicalVoc, "[As.]", "[Asian]", "", FloraHellenicaTransformer.uuidChorologicalAs);
255
        addChorological(state, chorologicalVoc, "[W-As.]", "[West Asian]", "", FloraHellenicaTransformer.uuidChorologicalW_As);
256
        addChorological(state, chorologicalVoc, "[C-Eur.]", "[Central European]", "", FloraHellenicaTransformer.uuidChorologicalC_Eur);
257
        addChorological(state, chorologicalVoc, "[E-Afr.]", "[East African]", "", FloraHellenicaTransformer.uuidChorologicalE_Afr);
258
        addChorological(state, chorologicalVoc, "[W-Austr.]", "[West Australian]", "", FloraHellenicaTransformer.uuidChorologicalW_Austr);
259
        addChorological(state, chorologicalVoc, "[trop. As.]", "[tropical Asian]", "", FloraHellenicaTransformer.uuidChorologicaltrop_As);
260

    
261
        addChorological(state, chorologicalVoc, "[Co]", "[Cosmopolitan]", "Taxa distributed in all continents, i.e. beyond the N hemisphere. This category may be given in brackets after the known or supposed native distribution in cases of taxa that have been spread worldwide by humans", FloraHellenicaTransformer.uuidChorological__Co_);
262

    
263
        this.getVocabularyService().save(chorologicalVoc);
264
        return;
265

    
266
    }
267

    
268
    /**
269
     * @param state
270
     * @param chorologicalVoc
271
     * @param string
272
     * @param string2
273
     * @param string3
274
     * @param uuidchorologicalstar
275
     */
276
    private void addChorological(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
277
            OrderedTermVocabulary<State> chorologicalVoc, String abbrevLabel, String label,
278
            String desc, UUID uuidChorological) {
279
        desc = isBlank(desc)? label : desc;
280
        State chorologyTerm = addState(state, abbrevLabel, label, desc, uuidChorological, chorologicalVoc);
281
    }
282

    
283
 // ***************************** LIFEFORM ********************************/
284

    
285

    
286
    @SuppressWarnings("unchecked")
287
    private void initLifeformVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
288
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc;
289
        OrderedTermVocabulary<State> lifeformVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
290
        if (lifeformVoc == null){
291
            createLifeformVoc(state, uuid);
292
        }
293
    }
294

    
295
    /**
296
     * @param state
297
     * @param vocUuid
298
     */
299
    private void createLifeformVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
300
            UUID vocUuid) {
301
        //voc
302
        URI termSourceUri = null;
303
        String label = "Checklist of Greece Lifeforms";
304
        String description = "Lifeforms as used in the Checklist of Greece";
305
        OrderedTermVocabulary<State> lifeformVoc = OrderedTermVocabulary.NewInstance(TermType.State,
306
                description, label, null, termSourceUri);
307
        lifeformVoc.setUuid(vocUuid);
308

    
309
        addLifeform(state, lifeformVoc, "A", "Aquatic", FloraHellenicaTransformer.uuidLifeformA);
310
        addLifeform(state, lifeformVoc, "C", "Chamaephyte", FloraHellenicaTransformer.uuidLifeformC);
311
        addLifeform(state, lifeformVoc, "G", "Geophyte (Cryptophyte)", FloraHellenicaTransformer.uuidLifeformG);
312
        addLifeform(state, lifeformVoc, "H", "Hemicryptophyte", FloraHellenicaTransformer.uuidLifeformH);
313
        addLifeform(state, lifeformVoc, "P", "Phanerophyte", FloraHellenicaTransformer.uuidLifeformP);
314
        addLifeform(state, lifeformVoc, "T", "Therophyte", FloraHellenicaTransformer.uuidLifeformT);
315
        this.getVocabularyService().save(lifeformVoc);
316
        return;
317
    }
318

    
319
    /**
320
     * @param state
321
     * @param lifeformVoc
322
     * @param string
323
     * @param uuidlifeformt
324
     */
325
    private void addLifeform(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
326
            OrderedTermVocabulary<State> lifeformVoc, String abbrevLabel, String label, UUID uuidlifeform) {
327
        State lifeForm = addState(state, abbrevLabel, label, label, uuidlifeform, lifeformVoc);
328
    }
329

    
330

    
331
// ***************************** HABITAT ********************************/
332

    
333
    private void initHabitatVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
334
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc;
335
        OrderedTermVocabulary<State> habitatVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
336
        if (habitatVoc == null){
337
            createHabitatVoc(state, uuid);
338
        }
339
    }
340

    
341
    /**
342
     * @param state
343
     */
344
    private void createHabitatVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state, UUID vocUuid) {
345
        //voc
346
        URI termSourceUri = null;
347
        String label = "Checklist of Greece Habitats";
348
        String description = "Habitats as used in the Checklist of Greece";
349
        OrderedTermVocabulary<State> habitatVoc = OrderedTermVocabulary.NewInstance(TermType.State,
350
                description, label, null, termSourceUri);
351
        habitatVoc.setUuid(vocUuid);
352

    
353
        addHabitat(state, habitatVoc, "A", "Freshwater habitats", "Freshwater habitats (Aquatic habitats, springs and fens, reedbeds and damp tall herb vegetation, seasonally flooded depressions, damp and seepage meadows, streambanks, river and lake shores)", FloraHellenicaTransformer.uuidHabitatA);
354
        addHabitat(state, habitatVoc, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
355
        addHabitat(state, habitatVoc, "G", "Temperate and submediterranean Grasslands", "Temperate and submediterranean Grasslands (lowland to montane dry and mesic meadows and pastures, rock outcrops and stony ground, grassy non-ruderal verges and forest edges)", FloraHellenicaTransformer.uuidHabitatG);
356
        addHabitat(state, habitatVoc, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
357
        addHabitat(state, habitatVoc, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
358
        addHabitat(state, habitatVoc, "P", "Xeric Mediterranean Phrygana and grasslands", "Xeric Mediterranean Phrygana and grasslands (Mediterranean dwarf shrub formations, annual-rich pastures and lowland screes)", FloraHellenicaTransformer.uuidHabitatP);
359
        addHabitat(state, habitatVoc, "R", "Agricultural and Ruderal habitats", "Agricultural and Ruderal habitats (fields, gardens and plantations, roadsides and trampled sites, frequently disturbed and pioneer habitats)", FloraHellenicaTransformer.uuidHabitatR);
360
        addHabitat(state, habitatVoc, "W", "Woodlands and scrub", "Woodlands and scrub (broadleaved and coniferous forest, riparian and mountain forest and scrub, hedges, shady woodland margins)", FloraHellenicaTransformer.uuidHabitatW);
361

    
362
        this.getVocabularyService().save(habitatVoc);
363
        return;
364
    }
365

    
366
    /**
367
     * @param state
368
     * @param habitatVoc
369
     * @param string
370
     * @param uuidlifeformt
371
     */
372
    private void addHabitat(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
373
            OrderedTermVocabulary<State> habitatVoc, String abbrev, String label, String desc, UUID uuidHabitat) {
374
        addState(state, abbrev, label, desc, uuidHabitat, habitatVoc);
375
    }
376

    
377
// ***************************** STATUS ********************************/
378

    
379
    private void initStatusVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
380
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaStatusVoc;
381
        OrderedTermVocabulary<?> statusVoc = (OrderedTermVocabulary<?>)this.getVocabularyService().find(uuid);
382
        if (statusVoc == null){
383
            createStatusVoc(state, uuid);
384
        }
385
    }
386

    
387
    /**
388
     * @param state
389
     */
390
    private void createStatusVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state, UUID vocUuid) {
391
        //voc
392
        URI termSourceUri = null;
393
        String label = "Checklist of Greece Status";
394
        String description = "Status as used in the Checklist of Greece";
395

    
396
        OrderedTermVocabulary<?> statusVoc;
397
        if (state.getConfig().isStatusAsDistribution()){
398
            statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm,
399
                    description, label, null, termSourceUri);
400
        }else{
401
            statusVoc = OrderedTermVocabulary.NewInstance(TermType.State,
402
                    description, label, null, termSourceUri);
403
        }
404

    
405
        statusVoc.setUuid(vocUuid);
406

    
407
        if (!state.getConfig().isStatusAsDistribution()){
408
            addStatus(state, "N", "Native", "", FloraHellenicaTransformer.uuidStatusNative, statusVoc);
409
            addStatus(state, "X", "Xenophyte", "", FloraHellenicaTransformer.uuidStatusXenophyte, statusVoc);
410
            addStatus(state, "?X", "?Xenophyte", "", FloraHellenicaTransformer.uuidStatusXenophyteDoubtfully, statusVoc);
411
        }
412
        addStatus(state, "RR", "Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestricted, statusVoc);
413
        addStatus(state, "?RR", "?Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestrictedDoubtfully, statusVoc);
414

    
415

    
416

    
417
        this.getVocabularyService().save(statusVoc);
418
        return;
419
    }
420

    
421
// ************************** FEATURE TREE  ************************************/
422

    
423
    boolean hasFeatureTree = false;
424

    
425
    /**
426
     * @param state
427
     */
428
    private void makeFeatureTree(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
429
        if (hasFeatureTree  ){
430
            return;
431
        }
432
        if (getFeatureTreeService().find(state.getConfig().getUuidFeatureTree()) != null){
433
            hasFeatureTree = true;
434
            return;
435
        }
436
        FeatureTree result = FeatureTree.NewInstance(state.getConfig().getUuidFeatureTree());
437
        result.setTitleCache(state.getConfig().getFeatureTreeTitle(), true);
438
        FeatureNode root = result.getRoot();
439
        FeatureNode newNode;
440
        ITermService service = getTermService();
441

    
442
        Feature newFeature = (Feature)service.find(Feature.DESCRIPTION().getUuid());
443
        newNode = FeatureNode.NewInstance(newFeature);
444
        root.addChild(newNode);
445

    
446
        newFeature = (Feature)service.find(Feature.DISTRIBUTION().getUuid());
447
        newNode = FeatureNode.NewInstance(newFeature);
448
        root.addChild(newNode);
449

    
450
        newFeature = (Feature)service.find(Feature.STATUS().getUuid());
451
        newNode = FeatureNode.NewInstance(newFeature);
452
        root.addChild(newNode);
453
        newFeature.setSupportsCategoricalData(true);
454
        TermVocabulary<State> voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaStatusVoc);
455
        newFeature.addSupportedCategoricalEnumeration(voc);
456

    
457

    
458
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature;
459
        newFeature = getFeature(state, uuid, "Chorology", "Chorology", null, null);
460
        newFeature.setSupportsCategoricalData(true);
461
        voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaChorologicalVoc);
462
        newFeature.addSupportedCategoricalEnumeration(voc);
463
        newNode = FeatureNode.NewInstance(newFeature);
464
        root.addChild(newNode);
465

    
466
        newFeature = (Feature)service.find(Feature.LIFEFORM().getUuid());
467
        newNode = FeatureNode.NewInstance(newFeature);
468
        root.addChild(newNode);
469
        newFeature.setSupportsCategoricalData(true);
470
        voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc);
471
        newFeature.addSupportedCategoricalEnumeration(voc);
472

    
473
        newFeature = (Feature)service.find(Feature.HABITAT().getUuid());
474
        newNode = FeatureNode.NewInstance(newFeature);
475
        root.addChild(newNode);
476
        newFeature.setSupportsCategoricalData(true);
477
        voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc);
478
        newFeature.addSupportedCategoricalEnumeration(voc);
479

    
480

    
481
        newFeature = (Feature)service.find(Feature.NOTES().getUuid());
482
        newNode = FeatureNode.NewInstance(newFeature);
483
        root.addChild(newNode);
484

    
485
        getFeatureTreeService().saveOrUpdate(result);
486
        hasFeatureTree = true;
487

    
488
    }
489

    
490

    
491
    private State addState(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
492
            String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
493
        State newState = State.NewInstance(
494
                description, stateLabel, abbrev);
495
        newState.setUuid(uuid);
496
        newState.setIdInVocabulary(abbrev);
497
        voc.addTerm(newState);
498
        return newState;
499
    }
500

    
501
    private OrderedTermBase addStatus(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
502
            String abbrev, String stateLabel, String description, UUID uuid,
503
            OrderedTermVocabulary voc) {
504
        FloraHellenicaImportConfigurator config = state.getConfig();
505
        OrderedTermBase<?> newStatus;
506
        if (config.isStatusAsDistribution()){
507
            newStatus = PresenceAbsenceTerm.NewPresenceInstance( description, stateLabel, abbrev);
508
        }else{
509
            newStatus = State.NewInstance(description, stateLabel, abbrev);
510
        }
511

    
512
        newStatus.setUuid(uuid);
513
        newStatus.setIdInVocabulary(abbrev);
514
        newStatus.setSymbol(abbrev);
515
        voc.addTerm(newStatus);
516
        return newStatus;
517
    }
518

    
519

    
520

    
521
    /**
522
     * {@inheritDoc}
523
     */
524
    @Override
525
    protected boolean doCheck(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
526
        return false;
527
    }
528

    
529

    
530
    /**
531
     * {@inheritDoc}
532
     */
533
    @Override
534
    protected boolean isIgnore(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
535
        return false;
536
    }
537
}
(10-10/11)