Project

General

Profile

Download (31.8 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.text.ParseException;
13
import java.util.UUID;
14

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

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

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

    
45
    private static final long serialVersionUID = 1347759514044184010L;
46

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

    
50
    private NamedArea greece;
51

    
52

    
53

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

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

    
71

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

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

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

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

    
120
        this.getVocabularyService().save(areasVoc);
121
        return;
122
    }
123

    
124

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

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

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

    
161

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

    
169

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

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

    
194
        addChorological(state, chorologicalVoc, "*", "Greek endemic", "Greek endemics (incl. single-island and single-mountain endemics)", FloraHellenicaTransformer.uuidChorologicalStar);
195
        addChorological(state, chorologicalVoc, "Bk", "Balkan", "Taxa restricted to Balkan countries, occasionally extending to adjacent parts of SE Europe", FloraHellenicaTransformer.uuidChorologicalBk);
196
        addChorological(state, chorologicalVoc, "BI", "Balkan-Italy", "Taxa restricted to Balkan countries and Italy (amphi-Adreatic)", FloraHellenicaTransformer.uuidChorologicalBI);
197
        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);
198
        addChorological(state, chorologicalVoc, "BC", "Balkan-Central Europe", "Taxa distributed in the Balkans, Carpathians, Alps and adjacent areas (mainly in the mountains)", FloraHellenicaTransformer.uuidChorologicalBC);
199
        addChorological(state, chorologicalVoc, "EM", "East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorologicalEM);
200
        addChorological(state, chorologicalVoc, "Me", "Mediterranean", "Taxa with a circum-Mediterranean distribution including Portugal, occasionally extending to the Caucasus area and N Iran", FloraHellenicaTransformer.uuidChorologicalMe);
201
        addChorological(state, chorologicalVoc, "MA", "Mediterranean-Atlantic", "Taxa restricted to maritime W Europe and the Mediterranean", FloraHellenicaTransformer.uuidChorologicalMA);
202
        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);
203
        addChorological(state, chorologicalVoc, "MS", "Mediterranean-SW Asian", "Taxa distributed in one or more Mediterranean countries and extending to SW and C Asia", FloraHellenicaTransformer.uuidChorologicalMS);
204
        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);
205
        addChorological(state, chorologicalVoc, "ES", "Euro-Siberian", "Taxa with main distribution in temperate Eurasia (occasionally reaching the Caucasus area)", FloraHellenicaTransformer.uuidChorologicalES);
206
        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);
207
        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);
208
        addChorological(state, chorologicalVoc, "Ct", "Circumtemperate", "Taxa of both extratropical Eurasia and North America", FloraHellenicaTransformer.uuidChorologicalCt);
209
        addChorological(state, chorologicalVoc, "IT", "Irano-Turanian", "Taxa with main distribution in arid SW and C Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalIT);
210
        addChorological(state, chorologicalVoc, "SS", "Saharo-Sindian", "Taxa with main distribution in arid N Africa and SQ Asia, extrazonally extending to the Mediterranean", FloraHellenicaTransformer.uuidChorologicalSS);
211
        addChorological(state, chorologicalVoc, "ST", "Subtropical-tropical", "Taxa widespread in the warmer regions of both hemispheres", FloraHellenicaTransformer.uuidChorologicalST);
212
        addChorological(state, chorologicalVoc, "Bo", "(Circum-)Boreal", "Taxa with main distribution in N and high-montane Eurasia (occasionally extending to North America)", FloraHellenicaTransformer.uuidChorologicalBo);
213
        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);
214
        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);
215

    
216
        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_);
217
        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_);
218
        addChorological(state, chorologicalVoc, "?EM", "? East Mediterranean", "Taxa restricted to the E Mediterranean, occasionally extending to S Italy or adjacent Caucasian countries", FloraHellenicaTransformer.uuidChorological_dEM);
219

    
220

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

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

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

    
263
        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_);
264

    
265
        this.getVocabularyService().save(chorologicalVoc);
266
        return;
267

    
268
    }
269

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

    
285
 // ***************************** LIFEFORM ********************************/
286

    
287

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

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

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

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

    
332

    
333
// ***************************** HABITAT ********************************/
334

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

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

    
355
        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);
356
        addHabitat(state, habitatVoc, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
357
        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);
358
        addHabitat(state, habitatVoc, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
359
        addHabitat(state, habitatVoc, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
360
        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);
361
        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);
362
        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);
363

    
364
        this.getVocabularyService().save(habitatVoc);
365
        return;
366
    }
367

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

    
379
// ***************************** STATUS ********************************/
380

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

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

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

    
407
        statusVoc.setUuid(vocUuid);
408

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

    
417

    
418

    
419
        this.getVocabularyService().save(statusVoc);
420
        return;
421
    }
422

    
423
// ************************** FEATURE TREE  ************************************/
424

    
425
    boolean hasFeatureTree = false;
426

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

    
443
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaTaxonInfoFeature;
444
        Feature newFeature = getFeature(state, uuid, "Taxon info", "Taxon info", null, null);
445
        root.addChild(newFeature);
446

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

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

    
456

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

    
464
        newFeature = (Feature)service.find(Feature.LIFEFORM().getUuid());
465
        root.addChild(newFeature);
466
        newFeature.setSupportsCategoricalData(true);
467
        voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc);
468
        newFeature.addSupportedCategoricalEnumeration(voc);
469

    
470
        newFeature = (Feature)service.find(Feature.HABITAT().getUuid());
471
        root.addChild(newFeature);
472
        newFeature.setSupportsCategoricalData(true);
473
        voc = this.getVocabularyService().find(FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc);
474
        newFeature.addSupportedCategoricalEnumeration(voc);
475

    
476

    
477
        newFeature = (Feature)service.find(Feature.NOTES().getUuid());
478
        root.addChild(newFeature);
479

    
480
        getFeatureTreeService().saveOrUpdate(result);
481
        hasFeatureTree = true;
482

    
483
    }
484

    
485

    
486
    private State addState(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
487
            String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
488
        State newState = State.NewInstance(
489
                description, stateLabel, abbrev);
490
        newState.setUuid(uuid);
491
        newState.setIdInVocabulary(abbrev);
492
        voc.addTerm(newState);
493
        return newState;
494
    }
495

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

    
507
        newStatus.setUuid(uuid);
508
        newStatus.setIdInVocabulary(abbrev);
509
        newStatus.setSymbol(abbrev);
510
        voc.addTerm(newStatus);
511
        return newStatus;
512
    }
513

    
514

    
515
    /**
516
     * @param state
517
     */
518
    private void makeMapColors(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
519
        PresenceAbsenceTerm presentTerm = (PresenceAbsenceTerm)getTermService().find(PresenceAbsenceTerm.uuidPresent);
520
        try {
521
            presentTerm.setDefaultColor("ff0000");
522
            getTermService().saveOrUpdate(presentTerm);
523
        } catch (ParseException e) {
524
            // TODO Auto-generated catch block
525
            e.printStackTrace();
526
        }
527

    
528
    }
529

    
530

    
531
    /**
532
     * {@inheritDoc}
533
     */
534
    @Override
535
    protected boolean doCheck(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
536
        return false;
537
    }
538

    
539

    
540
    /**
541
     * {@inheritDoc}
542
     */
543
    @Override
544
    protected boolean isIgnore(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
545
        return false;
546
    }
547
}
(10-10/16)