Project

General

Profile

Download (29.7 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.description.Feature;
27
import eu.etaxonomy.cdm.model.description.FeatureNode;
28
import eu.etaxonomy.cdm.model.description.FeatureTree;
29
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
30
import eu.etaxonomy.cdm.model.description.State;
31
import eu.etaxonomy.cdm.model.location.NamedArea;
32
import eu.etaxonomy.cdm.model.location.NamedAreaType;
33

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

    
43
    private static final long serialVersionUID = 1347759514044184010L;
44

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

    
48
    private NamedArea greece;
49

    
50

    
51

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

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

    
68

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

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

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

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

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

    
121

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

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

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

    
158

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

    
166

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

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

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

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

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

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

    
255
        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_);
256

    
257
        this.getVocabularyService().save(chorologicalVoc);
258
        return;
259

    
260
    }
261

    
262
    /**
263
     * @param state
264
     * @param chorologicalVoc
265
     * @param string
266
     * @param string2
267
     * @param string3
268
     * @param uuidchorologicalstar
269
     */
270
    private void addChorological(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
271
            OrderedTermVocabulary<State> chorologicalVoc, String abbrevLabel, String label,
272
            String desc, UUID uuidChorological) {
273
        desc = isBlank(desc)? label : desc;
274
        State chorologyTerm = addState(state, abbrevLabel, label, desc, uuidChorological, chorologicalVoc);
275
    }
276

    
277
 // ***************************** LIFEFORM ********************************/
278

    
279

    
280
    @SuppressWarnings("unchecked")
281
    private void initLifeformVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
282
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaLifeformVoc;
283
        OrderedTermVocabulary<State> lifeformVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
284
        if (lifeformVoc == null){
285
            createLifeformVoc(state, uuid);
286
        }
287
    }
288

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

    
303
        addLifeform(state, lifeformVoc, "A", "Aquatic", FloraHellenicaTransformer.uuidLifeformA);
304
        addLifeform(state, lifeformVoc, "C", "Chamaephyte", FloraHellenicaTransformer.uuidLifeformC);
305
        addLifeform(state, lifeformVoc, "G", "Geophyte (Cryptophyte)", FloraHellenicaTransformer.uuidLifeformG);
306
        addLifeform(state, lifeformVoc, "H", "Hemicryptophyte", FloraHellenicaTransformer.uuidLifeformH);
307
        addLifeform(state, lifeformVoc, "P", "Phanerophyte", FloraHellenicaTransformer.uuidLifeformP);
308
        addLifeform(state, lifeformVoc, "T", "Therophyte", FloraHellenicaTransformer.uuidLifeformT);
309
        this.getVocabularyService().save(lifeformVoc);
310
        return;
311
    }
312

    
313
    /**
314
     * @param state
315
     * @param lifeformVoc
316
     * @param string
317
     * @param uuidlifeformt
318
     */
319
    private void addLifeform(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
320
            OrderedTermVocabulary<State> lifeformVoc, String abbrevLabel, String label, UUID uuidlifeform) {
321
        State lifeForm = addState(state, abbrevLabel, label, label, uuidlifeform, lifeformVoc);
322
    }
323

    
324

    
325
// ***************************** HABITAT ********************************/
326

    
327
    private void initHabitatVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
328
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaHabitatVoc;
329
        OrderedTermVocabulary<State> habitatVoc = (OrderedTermVocabulary<State>)this.getVocabularyService().find(uuid);
330
        if (habitatVoc == null){
331
            createHabitatVoc(state, uuid);
332
        }
333
    }
334

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

    
347
        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);
348
        addHabitat(state, habitatVoc, "C", "Cliffs, rocks, walls, ravines, boulders", "Cliffs, rocks, walls, ravines, boulders", FloraHellenicaTransformer.uuidHabitatC);
349
        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);
350
        addHabitat(state, habitatVoc, "H", "High mountain vegetation", "High mountain vegetation (subalpine and alpine grasslands, screes and rocks, scrub above the treeline)", FloraHellenicaTransformer.uuidHabitatH);
351
        addHabitat(state, habitatVoc, "M", "Coastal habitats", "Coastal habitats (Marine waters and mudflats, salt marshes, sand dunes, littoral rocks, halo-nitrophilous scrub)", FloraHellenicaTransformer.uuidHabitatM);
352
        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);
353
        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);
354
        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);
355

    
356
        this.getVocabularyService().save(habitatVoc);
357
        return;
358
    }
359

    
360
    /**
361
     * @param state
362
     * @param habitatVoc
363
     * @param string
364
     * @param uuidlifeformt
365
     */
366
    private void addHabitat(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
367
            OrderedTermVocabulary<State> habitatVoc, String abbrev, String label, String desc, UUID uuidHabitat) {
368
        addState(state, abbrev, label, desc, uuidHabitat, habitatVoc);
369
    }
370

    
371
// ***************************** STATUS ********************************/
372

    
373
    private void initStatusVocabulary(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
374
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaStatusVoc;
375
        OrderedTermVocabulary<?> statusVoc = (OrderedTermVocabulary<?>)this.getVocabularyService().find(uuid);
376
        if (statusVoc == null){
377
            createStatusVoc(state, uuid);
378
        }
379
    }
380

    
381
    /**
382
     * @param state
383
     */
384
    private void createStatusVoc(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state, UUID vocUuid) {
385
        //voc
386
        URI termSourceUri = null;
387
        String label = "Checklist of Greece Status";
388
        String description = "Status as used in the Checklist of Greece";
389

    
390
        OrderedTermVocabulary<?> statusVoc;
391
        if (state.getConfig().isStatusAsDistribution()){
392
            statusVoc = OrderedTermVocabulary.NewInstance(TermType.PresenceAbsenceTerm,
393
                    description, label, null, termSourceUri);
394
        }else{
395
            statusVoc = OrderedTermVocabulary.NewInstance(TermType.State,
396
                    description, label, null, termSourceUri);
397
        }
398

    
399
        statusVoc.setUuid(vocUuid);
400

    
401
        if (!state.getConfig().isStatusAsDistribution()){
402
            addStatus(state, "N", "Native", "", FloraHellenicaTransformer.uuidStatusNative, statusVoc);
403
            addStatus(state, "X", "Xenophyte", "", FloraHellenicaTransformer.uuidStatusXenophyte, statusVoc);
404
            addStatus(state, "?X", "?Xenophyte", "", FloraHellenicaTransformer.uuidStatusXenophyteDoubtfully, statusVoc);
405
        }
406
        addStatus(state, "RR", "Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestricted, statusVoc);
407
        addStatus(state, "?RR", "?Range-restricted", "", FloraHellenicaTransformer.uuidStatusRangeRestrictedDoubtfully, statusVoc);
408

    
409

    
410

    
411
        this.getVocabularyService().save(statusVoc);
412
        return;
413
    }
414

    
415
// ************************** FEATURE TREE  ************************************/
416

    
417
    boolean hasFeatureTree = false;
418

    
419
    /**
420
     * @param state
421
     */
422
    private void makeFeatureTree(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
423
        if (hasFeatureTree  ){
424
            return;
425
        }
426
        if (getFeatureTreeService().find(state.getConfig().getUuidFeatureTree()) != null){
427
            hasFeatureTree = true;
428
            return;
429
        }
430
        FeatureTree result = FeatureTree.NewInstance(state.getConfig().getUuidFeatureTree());
431
        result.setTitleCache(state.getConfig().getFeatureTreeTitle(), true);
432
        FeatureNode root = result.getRoot();
433
        FeatureNode newNode;
434

    
435
        ITermService service = getTermService();
436
        Feature newFeature = (Feature)service.find(Feature.DISTRIBUTION().getUuid());
437
        newNode = FeatureNode.NewInstance(newFeature);
438
        root.addChild(newNode);
439

    
440
        newFeature = (Feature)service.find(Feature.STATUS().getUuid());
441
        newNode = FeatureNode.NewInstance(newFeature);
442
        root.addChild(newNode);
443

    
444
        UUID uuid = FloraHellenicaTransformer.uuidFloraHellenicaChorologyFeature;
445
        newFeature = getFeature(state, uuid, "Chorology", "Chorology", null, null);
446
        newNode = FeatureNode.NewInstance(newFeature);
447
        root.addChild(newNode);
448

    
449
        newFeature = (Feature)service.find(Feature.LIFEFORM().getUuid());
450
        newNode = FeatureNode.NewInstance(newFeature);
451
        root.addChild(newNode);
452

    
453
        newFeature = (Feature)service.find(Feature.HABITAT().getUuid());
454
        newNode = FeatureNode.NewInstance(newFeature);
455
        root.addChild(newNode);
456

    
457

    
458
        newFeature = (Feature)service.find(Feature.NOTES().getUuid());
459
        newNode = FeatureNode.NewInstance(newFeature);
460
        root.addChild(newNode);
461

    
462
        getFeatureTreeService().saveOrUpdate(result);
463
        hasFeatureTree = true;
464

    
465
    }
466

    
467

    
468
    private State addState(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
469
            String abbrev, String stateLabel, String description, UUID uuid, OrderedTermVocabulary<State> voc) {
470
        State newState = State.NewInstance(
471
                description, stateLabel, abbrev);
472
        newState.setUuid(uuid);
473
        newState.setIdInVocabulary(abbrev);
474
        voc.addTerm(newState);
475
        return newState;
476
    }
477

    
478
    private OrderedTermBase addStatus(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state,
479
            String abbrev, String stateLabel, String description, UUID uuid,
480
            OrderedTermVocabulary voc) {
481
        FloraHellenicaImportConfigurator config = state.getConfig();
482
        OrderedTermBase<?> newStatus;
483
        if (config.isStatusAsDistribution()){
484
            newStatus = PresenceAbsenceTerm.NewPresenceInstance( description, stateLabel, abbrev);
485
        }else{
486
            newStatus = State.NewInstance(description, stateLabel, abbrev);
487
        }
488

    
489
        newStatus.setUuid(uuid);
490
        newStatus.setIdInVocabulary(abbrev);
491
        newStatus.setSymbol(abbrev);
492
        voc.addTerm(newStatus);
493
        return newStatus;
494
    }
495

    
496

    
497

    
498
    /**
499
     * {@inheritDoc}
500
     */
501
    @Override
502
    protected boolean doCheck(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
503
        return false;
504
    }
505

    
506

    
507
    /**
508
     * {@inheritDoc}
509
     */
510
    @Override
511
    protected boolean isIgnore(SimpleExcelTaxonImportState<FloraHellenicaImportConfigurator> state) {
512
        return false;
513
    }
514
}
(8-8/9)