Project

General

Profile

« Previous | Next » 

Revision ede5c502

Added by Andreas Müller over 8 years ago

Add Cuba flora import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/cuba/CubaActivator.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.app.cuba;
11

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

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.api.application.ICdmApplicationConfiguration;
18
import eu.etaxonomy.cdm.api.service.ITermService;
19
import eu.etaxonomy.cdm.app.common.CdmDestinations;
20
import eu.etaxonomy.cdm.database.DbSchemaValidation;
21
import eu.etaxonomy.cdm.database.ICdmDataSource;
22
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
23
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
24
import eu.etaxonomy.cdm.io.cuba.CubaImportConfigurator;
25
import eu.etaxonomy.cdm.model.agent.Person;
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.reference.Reference;
30
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
31

  
32
/**
33
 * @author a.mueller
34
 * @created 04.01.2016
35
 */
36
public class CubaActivator {
37
	private static final Logger logger = Logger.getLogger(CubaActivator.class);
38

  
39
	//database validation status (create, update, validate ...)
40
	static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
41

  
42
	private static final URI source = monocots();
43
//    private static final URI source = cyperaceae();
44

  
45

  
46
//	static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
47
	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
48
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_dev();
49
//	static final ICdmDataSource cdmDestination = CdmDestinations.cdm_cyprus_production();
50

  
51

  
52
	//feature tree uuid
53
	public static final UUID featureTreeUuid = UUID.fromString("dad6b9b5-693f-4367-a7aa-076cc9c99476");
54

  
55
	//classification
56
	static final UUID classificationUuid = UUID.fromString("5de394de-9c76-4b97-b04d-71be31c7f44b");
57

  
58
	static final String sourceReferenceTitle = "Cuba import";
59

  
60
	//check - import
61
	static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
62

  
63
	//taxa
64
	static final boolean doTaxa = true;
65
	static final boolean doDeduplicate = false;
66
	static final boolean doDistribution = false;
67

  
68

  
69
	private void doImport(ICdmDataSource cdmDestination){
70

  
71
		//make Source
72
		CubaImportConfigurator config= CubaImportConfigurator.NewInstance(source, cdmDestination);
73
		config.setClassificationUuid(classificationUuid);
74
		config.setCheck(check);
75
//		config.setDoDistribution(doDistribution);
76
		config.setDoTaxa(doTaxa);
77
		config.setDbSchemaValidation(hbm2dll);
78
		config.setSourceReferenceTitle(sourceReferenceTitle);
79

  
80
		CdmDefaultImport<CubaImportConfigurator> myImport = new CdmDefaultImport();
81

  
82

  
83
		//...
84
		if (true){
85
			System.out.println("Start import from ("+ source.toString() + ") ...");
86
			config.setSourceReference(getSourceReference(sourceReferenceTitle));
87
			myImport.invoke(config);
88
			if (doTaxa){
89
				FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
90
				myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
91
			}
92

  
93
			System.out.println("End import from ("+ source.toString() + ")...");
94
		}
95

  
96

  
97

  
98
		//deduplicate
99
		if (doDeduplicate){
100
			ICdmApplicationConfiguration app = myImport.getCdmAppController();
101
			int count = app.getAgentService().deduplicate(Person.class, null, null);
102
			logger.warn("Deduplicated " + count + " persons.");
103
//			count = app.getAgentService().deduplicate(Team.class, null, null);
104
//			logger.warn("Deduplicated " + count + " teams.");
105
			count = app.getReferenceService().deduplicate(Reference.class, null, null);
106
			logger.warn("Deduplicated " + count + " references.");
107
		}
108

  
109
	}
110

  
111
	private Reference<?> getSourceReference(String string) {
112
		Reference<?> result = ReferenceFactory.newGeneric();
113
		result.setTitleCache(string, true);
114
		return result;
115
	}
116

  
117
	private FeatureTree makeFeatureNodes(ITermService service){
118
//		CyprusTransformer transformer = new CyprusTransformer();
119

  
120
		FeatureTree result = FeatureTree.NewInstance(featureTreeUuid);
121
		result.setTitleCache("Cuba Feature Tree", true);
122
		FeatureNode root = result.getRoot();
123
		FeatureNode newNode;
124

  
125
//		newNode = FeatureNode.NewInstance(Feature.STATUS());
126
//		root.addChild(newNode);
127

  
128
		newNode = FeatureNode.NewInstance(Feature.DISTRIBUTION());
129
		root.addChild(newNode);
130

  
131
//		newNode = FeatureNode.NewInstance(Feature.SYSTEMATICS());
132
//		root.addChild(newNode);
133

  
134
		//user defined features
135
//		String [] featureList = new String[]{"Red Book", "Endemism"};
136
//		addFeataureNodesByStringList(featureList, root, transformer, service);
137

  
138
		return result;
139
	}
140

  
141

  
142
	//Monocots
143
	public static URI monocots() {
144
	    return URI.create("file:////BGBM-PESIHPC/Cuba/Monocot.xlsx");
145
	}
146

  
147
	//Cyperaceae
148
	public static URI cyperaceae() {
149
	    return URI.create("file:////BGBM-PESIHPC/Cuba/Cyper_Poaceae.xlsx");
150
	}
151

  
152

  
153

  
154
	/**
155
	 * @param args
156
	 */
157
	public static void main(String[] args) {
158
	    CubaActivator me = new CubaActivator();
159
		me.doImport(cdmDestination);
160
	}
161

  
162
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaExcelImport.java
1
/**
2
 * Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.io.cuba;
11

  
12
import java.util.Arrays;
13
import java.util.HashMap;
14
import java.util.List;
15
import java.util.Set;
16
import java.util.UUID;
17

  
18
import org.apache.commons.lang.StringUtils;
19
import org.apache.log4j.Logger;
20
import org.springframework.stereotype.Component;
21

  
22
import eu.etaxonomy.cdm.common.CdmUtils;
23
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
24
import eu.etaxonomy.cdm.io.cyprus.CyprusRow;
25
import eu.etaxonomy.cdm.io.excel.common.ExcelImporterBase;
26
import eu.etaxonomy.cdm.model.common.Annotation;
27
import eu.etaxonomy.cdm.model.common.AnnotationType;
28
import eu.etaxonomy.cdm.model.common.Language;
29
import eu.etaxonomy.cdm.model.description.Distribution;
30
import eu.etaxonomy.cdm.model.description.Feature;
31
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
33
import eu.etaxonomy.cdm.model.description.TextData;
34
import eu.etaxonomy.cdm.model.location.NamedArea;
35
import eu.etaxonomy.cdm.model.name.BotanicalName;
36
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
37
import eu.etaxonomy.cdm.model.name.NonViralName;
38
import eu.etaxonomy.cdm.model.name.Rank;
39
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
40
import eu.etaxonomy.cdm.model.reference.Reference;
41
import eu.etaxonomy.cdm.model.taxon.Classification;
42
import eu.etaxonomy.cdm.model.taxon.Synonym;
43
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
44
import eu.etaxonomy.cdm.model.taxon.Taxon;
45
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
46
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
47
import eu.etaxonomy.cdm.strategy.parser.INonViralNameParser;
48
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
49

  
50
/**
51
 * @author a.mueller
52
 * @created 05.01.2016
53
 */
54

  
55
@Component
56
public class CubaExcelImport extends ExcelImporterBase<CubaImportState> {
57
    private static final long serialVersionUID = -747486709409732371L;
58

  
59
    private static final Logger logger = Logger.getLogger(CubaExcelImport.class);
60

  
61
    private static INonViralNameParser<?> nameParser = NonViralNameParserImpl.NewInstance();
62
    private static NomenclaturalCode nc = NomenclaturalCode.ICNAFP;
63

  
64
    private  static List<String> expectedKeys= Arrays.asList(new String[]{"Fam.","(Fam.)","Taxón","(Notas)","Syn.","End","Ind","Ind? D","Nat","Dud P","Adv","Cult C","CuW","PR PR*","Art","Hab(*)","May","Mat","IJ","CuC","VC","Ci","SS","CA","Cam","LT","CuE","Gr","Ho","SC","Gu","Esp","Ja","PR","Men","Bah","Cay","AmN","AmC","AmS","VM"});
65

  
66
    private  static List<String> dummy= Arrays.asList(new String[]{
67
            "(Fam.)","Syn.","Ind? D","Nat","Dud P","Adv","Cult C",
68
            "CuW","PR PR*","Art","Hab(*)","May","Mat","IJ",
69
            "CuC","VC","Ci","SS","CA","Cam","LT",
70
            "CuE","Gr","Ho","SC","Gu",
71
            "Esp","Ja","PR","Men","Bah","Cay",
72
            "AmN","AmC","AmS","VM"});
73

  
74

  
75
	@Override
76
    protected void analyzeRecord(HashMap<String, String> record, CubaImportState state) {
77

  
78
		Set<String> keys = record.keySet();
79
        for (String key: keys) {
80
            if (! expectedKeys.contains(key)){
81
                logger.warn("Unexpected Key: " + key);
82
            }
83
        }
84

  
85
        //Fam.
86
        TaxonNode familyTaxon = getFamilyTaxon(record, state);
87
        if (familyTaxon == null){
88
            logger.warn("Family not recognized. Do not handle row");
89
            return;
90
        }
91

  
92
        //(Fam.)
93
        //TODO
94

  
95
        //Taxón
96
        Taxon taxon = makeTaxon(record, state, familyTaxon);
97

  
98
        //(Notas)
99
        makeNotes(record, state, taxon);
100

  
101
        //Syn.
102
        makeSynonyms(record, state, taxon);
103

  
104
        //End, Ind, Ind? D, Nat N, Dud P, Adv A, Cult C
105
        makeCubanDistribution(record, state, taxon);
106

  
107
    	return;
108
    }
109

  
110

  
111
    /**
112
     * @param record
113
     * @param state
114
     * @param taxon
115
     */
116
    private void makeCubanDistribution(HashMap<String, String> record, CubaImportState state, Taxon taxon) {
117
        try {
118
            NamedArea cuba = getNamedArea(state, state.getTransformer().getNamedAreaUuid("C"), null, null, null, null, null);
119
            TaxonDescription desc = getTaxonDescription(taxon, false, true);
120
            PresenceAbsenceTerm status =  makeCubanStatus(record, state);
121
            Distribution distribution = Distribution.NewInstance(cuba, status);
122
            desc.addElement(distribution);
123
        } catch (UndefinedTransformerMethodException e) {
124
            e.printStackTrace();
125
        }
126
    }
127

  
128

  
129
    /**
130
     * @param record
131
     * @param state
132
     * @return
133
     * @throws UndefinedTransformerMethodException
134
     */
135
    private PresenceAbsenceTerm makeCubanStatus(HashMap<String, String> record, CubaImportState state) throws UndefinedTransformerMethodException {
136
        boolean isAbsent = false;  //TODO
137

  
138
        String endemicStr = getValue(record, "End");
139
        String indigenousStr = getValue(record, "Ind");
140
        String indigenousDoubtStr = getValue(record, "Ind? D");
141
        String naturalisedStr = getValue(record, "Nat");
142
        String dudStr = getValue(record, "Dud P");
143
        String advStr = getValue(record, "Adv");
144
        String cultStr = getValue(record, "Cult C");
145

  
146
        if (endemicStr != null){
147
            boolean allNull = checkAllNull(indigenousStr, indigenousDoubtStr, naturalisedStr, dudStr, advStr, cultStr);
148
            if (!endemicStr.equals("+")){
149
                logger.warn("Endemic not recognized: " + endemicStr);
150
                return null;
151
            }else if (! allNull){
152
                logger.warn("Cuban state is endemic but others exist");
153
                return null;
154
            }else{
155
                return PresenceAbsenceTerm.ENDEMIC_FOR_THE_RELEVANT_AREA();
156
            }
157
        }else if (indigenousStr != null){
158
            boolean allNull = checkAllNull(indigenousDoubtStr, naturalisedStr, dudStr, advStr, cultStr);
159
            if (!checkPlusMinus(indigenousStr)){
160
                logger.warn("Indigenous not recognized: " + indigenousStr);
161
                return null;
162
            }else if (! allNull){
163
                //TODO may this exist?
164
                logger.warn("Cuban state is indigenous but others exist");
165
                return null;
166
            }else if(indigenousStr.equals("+")){
167
                UUID indigenousUuid = state.getTransformer().getPresenceTermUuid("Ind.");
168
                PresenceAbsenceTerm indigenousState = getPresenceTerm(state, indigenousUuid, null, null, null);
169
                return indigenousState;
170
            }else if(indigenousStr.equals("-") || indigenousStr.equals("–")){
171
                logger.warn("Indigenous status '-' not yet handled)");
172
                return PresenceAbsenceTerm.ABSENT();
173
            }else{
174
                logger.warn("Indigenous not recognized: " + indigenousStr);
175
                return null;
176
            }
177
        }else if(indigenousDoubtStr != null){
178

  
179
        }
180

  
181
        return null;
182
    }
183

  
184

  
185
    /**
186
     * @param indigenousStr
187
     * @return
188
     */
189
    private boolean checkPlusMinus(String str) {
190
        return str.equals("+") || str.equals("-") || str.equals("–");
191
    }
192

  
193

  
194
    /**
195
     * @param indigenousStr
196
     * @param indigenousDoubtStr
197
     * @param naturalisedStr
198
     * @param dudStr
199
     * @param advStr
200
     * @param cultStr
201
     */
202
    private boolean checkAllNull(String ... others) {
203
        for (String other : others){
204
            if (other != null){
205
                return false;
206
            }
207
        }
208
        return true;
209
    }
210

  
211

  
212
    /**
213
     * @param record
214
     * @param state
215
     * @param taxon
216
     */
217
    private void makeSynonyms(HashMap<String, String> record, CubaImportState state, Taxon taxon) {
218
        // TODO Auto-generated method stub
219

  
220
    }
221

  
222

  
223
    /**
224
     * @param record
225
     * @param state
226
     * @param taxon
227
     */
228
    private void makeNotes(HashMap<String, String> record, CubaImportState state, Taxon taxon) {
229
        String notesStr = getValue(record, "(Notas)");
230
        if (notesStr == null){
231
            return;
232
        }else{
233
            Annotation annotation = Annotation.NewDefaultLanguageInstance(notesStr);
234
            //TODO
235
            annotation.setAnnotationType(AnnotationType.EDITORIAL());
236
            taxon.addAnnotation(annotation);
237
        }
238
    }
239

  
240

  
241
    /**
242
     * @param record
243
     * @param state
244
     * @param familyTaxon
245
     * @return
246
     */
247
    private Taxon makeTaxon(HashMap<String, String> record, CubaImportState state, TaxonNode familyNode) {
248
        String taxonStr = getValue(record, "Taxón");
249
        if (taxonStr == null){
250
            return null;
251
        }
252
        boolean isAbsent = false;
253
        if (taxonStr.startsWith("[") && taxonStr.endsWith("]")){
254
            taxonStr = taxonStr.substring(1, taxonStr.length() - 1);
255
            isAbsent = true;
256
        }
257

  
258
        TaxonNameBase<?,?> botanicalName = nameParser.parseFullName(taxonStr, nc, Rank.SPECIES());
259
        if (botanicalName.isProtectedTitleCache()){
260
            logger.warn("Taxon could not be parsed: " + taxonStr);
261
        }
262
        Reference<?> sec = null;
263
        Taxon taxon = Taxon.NewInstance(botanicalName, sec);
264
        familyNode.addChildTaxon(taxon, null, null);
265

  
266
        return taxon;
267
    }
268

  
269

  
270
    /**
271
     * @param record
272
     * @param state
273
     * @return
274
     */
275
    private TaxonNode getFamilyTaxon(HashMap<String, String> record, CubaImportState state) {
276
        String familyStr = getValue(record, "Fam.");
277
        if (familyStr == null){
278
            return null;
279
        }
280
        Taxon family = state.getHigherTaxon(familyStr);
281
        TaxonNode familyNode;
282
        if (family != null){
283
            familyNode = family.getTaxonNodes().iterator().next();
284
        }else{
285
            BotanicalName name = BotanicalName.NewInstance(Rank.FAMILY());
286
            name.setGenusOrUninomial(familyStr);
287
            Reference<?> sec = null;
288
            Taxon taxon = Taxon.NewInstance(name, sec);
289
            Classification classification = getClassification(state);
290
            familyNode = classification.addChildTaxon(taxon, sec, null);
291
        }
292

  
293
        return familyNode;
294
    }
295

  
296

  
297
    /**
298
     * @param state
299
     * @return
300
     */
301
    private Classification getClassification(CubaImportState state) {
302
        Classification classification = state.getClassification();
303
        if (classification == null){
304
            String name = state.getConfig().getClassificationName();
305
            //TODO
306
            Reference<?> sec = null;
307
            Language language = Language.DEFAULT();
308
            classification = Classification.NewInstance(name, sec, language);
309
            state.setClassification(classification);
310
            getClassificationService().save(classification);
311
        }
312
        return classification;
313
    }
314

  
315

  
316
    /**
317
     * @param record
318
     * @param originalKey
319
     * @return
320
     */
321
    private String getValue(HashMap<String, String> record, String originalKey) {
322
        String value = record.get(originalKey);
323
        if (! StringUtils.isBlank(value)) {
324
        	if (logger.isDebugEnabled()) { logger.debug(originalKey + ": " + value); }
325
        	value = CdmUtils.removeDuplicateWhitespace(value.trim()).toString();
326
        	return value;
327
        }else{
328
        	return null;
329
        }
330
    }
331

  
332

  
333
	private Feature redBookCategory;
334
	private Feature endemism;
335

  
336

  
337

  
338
	/**
339
	 *  Stores taxa records in DB
340
	 */
341
	@Override
342
    protected void firstPass(CubaImportState state) {
343

  
344
		CyprusRow taxonLight = null; //state.getCyprusRow();
345
		Reference<?> citation = null;
346
		String microCitation = null;
347

  
348
//		//species name
349
//		String speciesStr = taxonLight.getSpecies();
350
//		String subSpeciesStr = taxonLight.getSubspecies();
351
//		String homotypicSynonymsString = taxonLight.getHomotypicSynonyms();
352
//		List<String> homotypicSynonymList = Arrays.asList(homotypicSynonymsString.split(";"));
353
//		String heterotypicSynonymsString = taxonLight.getHeterotypicSynonyms();
354
//		List<String> heterotypicSynonymList = Arrays.asList(heterotypicSynonymsString.split(";"));
355
//
356
//		String systematicsString = taxonLight.getSystematics();
357
//		String endemismString = taxonLight.getEndemism();
358
//		String statusString = taxonLight.getStatus();
359
//		String redBookCategory = taxonLight.getRedDataBookCategory();
360
//
361
//		if (StringUtils.isNotBlank(speciesStr)) {
362
//			boolean speciesIsExisting = false;
363
//			Taxon mainTaxon = null;
364
//			//species
365
//			Taxon speciesTaxon = (Taxon)createTaxon(state, Rank.SPECIES(), speciesStr, Taxon.class, nc);
366
//			mainTaxon = speciesTaxon;
367
//
368
//			//subspecies
369
//			if (StringUtils.isNotBlank(subSpeciesStr)){
370
//				Taxon existingSpecies = state.getHigherTaxon(speciesStr);
371
//				if (existingSpecies != null){
372
//					speciesIsExisting = true;
373
//					speciesTaxon = existingSpecies;
374
//				}
375
//
376
//				Taxon subSpeciesTaxon = (Taxon)createTaxon(state, Rank.SUBSPECIES(), subSpeciesStr, Taxon.class, nc);
377
//
378
//				if (subSpeciesTaxon != null){
379
//					makeParent(state, speciesTaxon, subSpeciesTaxon, citation, microCitation);
380
//				}
381
//				mainTaxon = subSpeciesTaxon;
382
//				state.putHigherTaxon(speciesStr, speciesTaxon);
383
//			}
384
//
385
//			if (! speciesIsExisting){
386
//				makeHigherTaxa(state, taxonLight, speciesTaxon, citation, microCitation);
387
//			}
388
//			makeHomotypicSynonyms(state, citation, microCitation, homotypicSynonymList, mainTaxon);
389
//			makeHeterotypicSynonyms(state, citation, microCitation, heterotypicSynonymList, mainTaxon);
390
//			makeSystematics(systematicsString, mainTaxon);
391
//			makeEndemism(endemismString, mainTaxon);
392
//			makeStatus(statusString, mainTaxon);
393
//			makeRedBookCategory(redBookCategory, mainTaxon);
394
//
395
////			state.putHigherTaxon(higherName, uuid);//(speciesStr, mainTaxon);
396
//			getTaxonService().save(mainTaxon);
397
//		}
398
		return;
399
    }
400

  
401

  
402
	private void makeHigherTaxa(CubaImportState state, CyprusRow taxonLight, Taxon speciesTaxon, Reference citation, String microCitation) {
403
		String divisionStr = taxonLight.getDivision();
404
		String genusStr = taxonLight.getGenus();
405
		String familyStr = taxonLight.getFamily();
406

  
407
		Taxon division = getTaxon(state, divisionStr, Rank.DIVISION(), null, citation, microCitation);
408
		Taxon family = getTaxon(state, familyStr, Rank.FAMILY(), division, citation, microCitation);
409
		Taxon genus = getTaxon(state, genusStr, Rank.GENUS(), family, citation, microCitation);
410
		makeParent(state, genus, speciesTaxon, citation, microCitation)	;
411
	}
412

  
413

  
414
	private Taxon getTaxon(CubaImportState state, String taxonNameStr, Rank rank, Taxon parent, Reference citation, String microCitation) {
415
		Taxon result;
416
		if (state.containsHigherTaxon(taxonNameStr)){
417
			result = state.getHigherTaxon(taxonNameStr);
418
		}else{
419
			result = (Taxon)createTaxon(state, rank, taxonNameStr, Taxon.class, nc);
420
			state.putHigherTaxon(taxonNameStr, result);
421
			if (parent == null){
422
				makeParent(state, null,result, citation, microCitation);
423
			}else{
424
				makeParent(state, parent, result, citation, microCitation);
425
			}
426

  
427
		}
428
		return result;
429
	}
430

  
431

  
432
	private void makeHomotypicSynonyms(CubaImportState state,
433
			Reference citation, String microCitation, List<String> homotypicSynonymList, Taxon mainTaxon) {
434
		for (String homotypicSynonym: homotypicSynonymList){
435
			if (StringUtils.isNotBlank(homotypicSynonym)){
436
				Synonym synonym = (Synonym)createTaxon(state, null, homotypicSynonym, Synonym.class, nc);
437
				mainTaxon.addHomotypicSynonym(synonym, citation, microCitation);
438
			}
439
		}
440
	}
441

  
442

  
443
	private void makeHeterotypicSynonyms(CubaImportState state, Reference citation, String microCitation, List<String> heterotypicSynonymList, Taxon mainTaxon) {
444
		for (String heterotypicSynonym: heterotypicSynonymList){
445
			if (StringUtils.isNotBlank(heterotypicSynonym)){
446
				Synonym synonym = (Synonym)createTaxon(state, null, heterotypicSynonym, Synonym.class, nc);
447
				mainTaxon.addSynonym(synonym, SynonymRelationshipType.HETEROTYPIC_SYNONYM_OF(), citation, microCitation);
448
			}
449
		}
450
	}
451

  
452

  
453
	private void makeSystematics(String systematicsString, Taxon mainTaxon) {
454
		//Systematics
455
		if (StringUtils.isNotBlank(systematicsString)){
456
			TaxonDescription td = this.getTaxonDescription(mainTaxon, false, true);
457
			TextData textData = TextData.NewInstance(Feature.SYSTEMATICS());
458
			textData.putText(Language.UNDETERMINED(), systematicsString);
459
			td.addElement(textData);
460
		}
461
	}
462

  
463

  
464
	private void makeEndemism(String endemismString, Taxon mainTaxon) {
465
		//endemism
466
		if (StringUtils.isNotBlank(endemismString)){
467
			//OLD - not wanted as marker
468
//			boolean flag;
469
//			if (endemismString.trim().equalsIgnoreCase("not endemic") || endemismString.trim().equalsIgnoreCase("ne?")){
470
//				flag = false;
471
//			}else if (endemismString.trim().equalsIgnoreCase("endemic")){
472
//				flag = true;
473
//			}else{
474
//				throw new RuntimeException(endemismString + " is not a valid value for endemism");
475
//			}
476
//			Marker marker = Marker.NewInstance(MarkerType.ENDEMIC(), flag);
477
//			mainTaxon.addMarker(marker);
478
			//text data
479
			TaxonDescription td = this.getTaxonDescription(mainTaxon, false, true);
480
			TextData textData = TextData.NewInstance(endemism);
481
			textData.putText(Language.ENGLISH(), endemismString);
482
			td.addElement(textData);
483
		}
484
	}
485

  
486

  
487
	private void makeRedBookCategory(String redBookCategory, Taxon mainTaxon) {
488
		//red data book category
489
		if (StringUtils.isNotBlank(redBookCategory)){
490
			TaxonDescription td = this.getTaxonDescription(mainTaxon, false, true);
491
			TextData textData = TextData.NewInstance(this.redBookCategory);
492
			textData.putText(Language.ENGLISH(), redBookCategory);
493
			td.addElement(textData);
494
		}
495
	}
496

  
497

  
498

  
499

  
500
	/**
501
	 *  Stores parent-child, synonym and common name relationships
502
	 */
503
	@Override
504
    protected void secondPass(CubaImportState state) {
505
//		CyprusRow cyprusRow = state.getCyprusRow();
506
		return;
507
	}
508

  
509

  
510

  
511
	/**
512
	 * @param state
513
	 * @param rank
514
	 * @param taxonNameStr
515
	 * @param authorStr
516
	 * @param nameStatus
517
	 * @param nc
518
	 * @return
519
	 */
520
	private TaxonBase createTaxon(CubaImportState state, Rank rank, String taxonNameStr,
521
			Class statusClass, NomenclaturalCode nc) {
522
		TaxonBase taxonBase;
523
		NonViralName taxonNameBase = null;
524
		if (nc == NomenclaturalCode.ICVCN){
525
			logger.warn("ICVCN not yet supported");
526

  
527
		}else{
528
			taxonNameBase =(NonViralName) nc.getNewTaxonNameInstance(rank);
529
			//NonViralName nonViralName = (NonViralName)taxonNameBase;
530
			INonViralNameParser parser = nameParser;//NonViralNameParserImpl.NewInstance();
531
			taxonNameBase = (NonViralName<BotanicalName>)parser.parseFullName(taxonNameStr, nc, rank);
532

  
533
			//taxonNameBase.setNameCache(taxonNameStr);
534

  
535
		}
536

  
537
		//Create the taxon
538
		Reference sec = state.getConfig().getSourceReference();
539
		// Create the status
540
		if (statusClass.equals(Taxon.class)){
541
			taxonBase = Taxon.NewInstance(taxonNameBase, sec);
542
		}else if (statusClass.equals(Synonym.class)){
543
			taxonBase = Synonym.NewInstance(taxonNameBase, sec);
544
		}else {
545
			Taxon taxon = Taxon.NewInstance(taxonNameBase, sec);
546
			taxon.setTaxonStatusUnknown(true);
547
			taxonBase = taxon;
548
		}
549
		return taxonBase;
550
	}
551

  
552
	private boolean makeParent(CubaImportState state, Taxon parentTaxon, Taxon childTaxon, Reference citation, String microCitation){
553
		boolean success = true;
554
		Reference sec = state.getConfig().getSourceReference();
555

  
556
//		Reference sec = parentTaxon.getSec();
557
		Classification tree = state.getTree(sec);
558
		if (tree == null){
559
			tree = makeTree(state, sec);
560
			tree.setTitleCache(state.getConfig().getSourceReferenceTitle(), true);
561
		}
562
		if (sec.equals(childTaxon.getSec())){
563
			success &=  (null !=  tree.addParentChild(parentTaxon, childTaxon, citation, microCitation));
564
		}else{
565
			logger.warn("No relationship added for child " + childTaxon.getTitleCache());
566
		}
567
		return success;
568
	}
569

  
570

  
571
    @Override
572
    protected boolean isIgnore(CubaImportState state) {
573
        return ! state.getConfig().isDoTaxa();
574
    }
575

  
576
    @Override
577
    protected boolean doCheck(CubaImportState state) {
578
        logger.warn("DoCheck not yet implemented for CubaExcelImport");
579
        return true;
580
    }
581

  
582
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaImportConfigurator.java
1
/**
2
* Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.io.cuba;
11

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

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.database.ICdmDataSource;
18
import eu.etaxonomy.cdm.io.common.ImportStateBase;
19
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
20
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
21
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
24

  
25

  
26
/**
27
 * @author a.mueller
28
 * @created 20.03.2008
29
 */
30
public class CubaImportConfigurator extends ExcelImportConfiguratorBase {
31

  
32
    private static final long serialVersionUID = 5590553979984931651L;
33

  
34
    @SuppressWarnings("unused")
35
	private static Logger logger = Logger.getLogger(CubaImportConfigurator.class);
36

  
37
    private String cubaReferenceTitle;
38

  
39
    private UUID uuidCyprusReference = UUID.fromString("b5281cd3-9d5d-4ae2-8d55-b62a592ce846");
40

  
41
	private boolean isDoTaxa;
42

  
43
	private static IInputTransformer defaultTransformer = new CubaTransformer();
44

  
45
	public static CubaImportConfigurator NewInstance(URI source, ICdmDataSource destination){
46
		return new CubaImportConfigurator(source, destination);
47
	}
48

  
49
	@Override
50
    protected void makeIoClassList(){
51
		ioClassList = new Class[]{
52
		        CubaVocabularyImport.class,
53
				CubaExcelImport.class
54
		};
55
	}
56

  
57
	@Override
58
    public ImportStateBase getNewState() {
59
		return new CubaImportState(this);
60
	}
61

  
62

  
63

  
64
	private CubaImportConfigurator(URI source, ICdmDataSource destination) {
65
	   super(source, destination, defaultTransformer);
66
	   setNomenclaturalCode(NomenclaturalCode.ICNAFP);
67
	   setSource(source);
68
	   setDestination(destination);
69
	}
70

  
71

  
72
	@Override
73
    public URI getSource() {
74
		return super.getSource();
75
	}
76
	@Override
77
    public void setSource(URI source) {
78
		super.setSource(source);
79
	}
80

  
81
	@Override
82
    public Reference<?> getSourceReference() {
83
		if (sourceReference == null){
84
			sourceReference =  ReferenceFactory.newDatabase();
85
			if (getSource() != null){
86
				sourceReference.setTitleCache(getCubaReferenceTitle(), true);
87
			}
88
		}
89
		return sourceReference;
90
	}
91

  
92
	@Override
93
    public String getSourceNameString() {
94
		return getSource().toString();
95
	}
96

  
97

  
98
	public void setUuidCyprusReference(UUID uuidCyprusReference) {
99
		this.uuidCyprusReference = uuidCyprusReference;
100
	}
101

  
102

  
103
	public UUID getUuidCyprusReference() {
104
		return uuidCyprusReference;
105
	}
106

  
107

  
108
	public void setCubaReferenceTitle(String cyprusReferenceTitle) {
109
		this.cubaReferenceTitle = cyprusReferenceTitle;
110
	}
111

  
112

  
113
	public String getCubaReferenceTitle() {
114
		return cubaReferenceTitle;
115
	}
116

  
117
	public void setDoTaxa(boolean isDoTaxa) {
118
		this.isDoTaxa = isDoTaxa;
119
	}
120

  
121
	public boolean isDoTaxa() {
122
		return isDoTaxa;
123
	}
124

  
125

  
126

  
127
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaImportState.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.io.cuba;
12

  
13
import java.util.HashMap;
14
import java.util.Map;
15
import java.util.UUID;
16

  
17
import org.apache.log4j.Logger;
18

  
19
import eu.etaxonomy.cdm.io.excel.common.ExcelImportState;
20
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
21
import eu.etaxonomy.cdm.model.taxon.Classification;
22
import eu.etaxonomy.cdm.model.taxon.Taxon;
23

  
24
/**
25
 * @author a.mueller
26
 * @created 11.05.2009
27
 */
28
public class CubaImportState extends ExcelImportState<CubaImportConfigurator, ExcelRowBase>{
29
	@SuppressWarnings("unused")
30
	private static final Logger logger = Logger.getLogger(CubaImportState.class);
31

  
32
	private final Map<String, Taxon> higherTaxonTaxonMap = new HashMap<String, Taxon>();
33
	private final Map<String, UUID> higherTaxonUuidMap = new HashMap<String, UUID>();
34

  
35
//	private CyprusRow cyprusRow;
36
//	private CyprusDistributionRow cyprusDistributionRow;
37

  
38
	private Classification classification;
39

  
40

  
41
	public CubaImportState(CubaImportConfigurator config) {
42
		super(config);
43
	}
44

  
45

  
46
	public boolean containsHigherTaxon(String higherName) {
47
		return higherTaxonTaxonMap.containsKey(higherName);
48
	}
49

  
50
	public Taxon putHigherTaxon(String higherName, Taxon taxon) {
51
		return higherTaxonTaxonMap.put(higherName, taxon);
52
	}
53

  
54
	public Taxon removeHigherTaxon(String higherName) {
55
		return higherTaxonTaxonMap.remove(higherName);
56
	}
57

  
58
	public Taxon getHigherTaxon(String higherName) {
59
		return higherTaxonTaxonMap.get(higherName);
60
	}
61

  
62

  
63
	public boolean containsHigherTaxonUuid(String higherName) {
64
		return higherTaxonUuidMap.containsKey(higherName);
65
	}
66

  
67
	public UUID putHigherTaxon(String higherName, UUID uuid) {
68
		return higherTaxonUuidMap.put(higherName, uuid);
69
	}
70

  
71
	public UUID removeHigherTaxonUuid(String higherName) {
72
		return higherTaxonUuidMap.remove(higherName);
73
	}
74

  
75
	public UUID getHigherTaxonUuid(String higherName) {
76
		return higherTaxonUuidMap.get(higherName);
77
	}
78

  
79

  
80
    /**
81
     * @return
82
     */
83
    public Classification getClassification() {
84
        return classification;
85
    }
86

  
87

  
88
    /**
89
     * @param classification the classification to set
90
     */
91
    public void setClassification(Classification classification) {
92
        this.classification = classification;
93
    }
94

  
95

  
96

  
97

  
98

  
99
//	/**
100
//	 * @return the cyprusRow
101
//	 */
102
//	public CyprusRow getCyprusRow() {
103
//		return cyprusRow;
104
//	}
105
//
106
//	/**
107
//	 * @param cyprusRow the normalExplicitRow to set
108
//	 */
109
//	public void setCyprusRow(CyprusRow cyprusRow) {
110
//		this.cyprusRow = cyprusRow;
111
//	}
112

  
113

  
114
//	/**
115
//	 * @return the cyprusRow
116
//	 */
117
//	public CyprusDistributionRow getCyprusDistributionRow() {
118
//		return cyprusDistributionRow;
119
//	}
120
//
121
//	/**
122
//	 * @param cyprusRow the normalExplicitRow to set
123
//	 */
124
//	public void setCyprusDistributionRow(CyprusDistributionRow cyprusRow) {
125
//		this.cyprusDistributionRow = cyprusRow;
126
//	}
127

  
128

  
129

  
130

  
131
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaTransformer.java
1
// $Id$
2
/**
3
* Copyright (C) 2007 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10

  
11
package eu.etaxonomy.cdm.io.cuba;
12

  
13
import java.util.UUID;
14

  
15
import org.apache.commons.lang.StringUtils;
16
import org.apache.log4j.Logger;
17

  
18
import eu.etaxonomy.cdm.io.common.mapping.InputTransformerBase;
19
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
20
import eu.etaxonomy.cdm.io.cyprus.CyprusTransformer;
21
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
22

  
23
/**
24
 * @author a.mueller
25
 * @created 01.03.2010
26
 */
27
public final class CubaTransformer extends InputTransformerBase {
28
    private static final long serialVersionUID = 1070018208741186271L;
29

  
30
    @SuppressWarnings("unused")
31
	private static final Logger logger = Logger.getLogger(CubaTransformer.class);
32

  
33
    //presenceTerm
34
    public static final UUID nonNativeDoubtfullyNaturalisedUuid = UUID.fromString("a1e26234-831e-4190-9fe3-011aca09ddba");
35
    public static final UUID nonAdventiveAlienUuid = UUID.fromString("06e48a0b-3e48-4ef8-9bdd-0755880e99ce");
36
    public static final UUID cultivatedOnlyUuid = UUID.fromString("9cca5c3b-aced-41c4-accc-f800b67168f8");
37

  
38

  
39
    //Named Areas
40
    public static final UUID uuidCubaVocabulary = UUID.fromString("2119f610-1f93-4d87-af28-40aeefaca100");
41
//    public static final UUID uuidCyprusDivisionsAreaLevel = UUID.fromString("ff52bbd9-f73d-4476-af39-f3991fa892bd");
42

  
43
    public static final UUID uuidCuba = UUID.fromString("d0144a6e-0e17-4a1d-bce5-d464a2aa7229");
44

  
45
    public static final UUID uuidWesternCuba = UUID.fromString("53ee35a5-03dd-4c1e-9b23-1a0d08489684");
46
    public static final UUID uuidPinarDelRio = UUID.fromString("ee1bae89-b6a8-4b89-a864-238fe3c4dbf3");
47
    public static final UUID uuidHabana = UUID.fromString("ff906b63-6e74-4a38-b492-73d32817ad3a");
48
    public static final UUID uuidMatanzas = UUID.fromString("bc280278-1b67-4766-ba28-e3a5c215d6a9");
49
    public static final UUID uuidIslaDeLaJuventud = UUID.fromString("0e0683d6-90d4-4b0f-834e-05737ca9b2b4");
50

  
51
    public static final UUID uuidCentralCuba = UUID.fromString("25eb5879-358e-4ff7-837d-101569d5d843");
52
    public static final UUID uuidVillaClara = UUID.fromString("4de5e35d-fdad-49d0-a5c8-dc44e4e844a0");
53
    public static final UUID uuidCienfuegos = UUID.fromString("c4189205-4543-4f4d-b211-6f899734a2f1");
54
    public static final UUID uuidSanctiSpiritus = UUID.fromString("70ee99b9-d006-4a08-a8c2-19269d60865f");
55
    public static final UUID uuidCiegoDeAvila = UUID.fromString("2ce7f4bc-4142-4866-b156-cf5300973c6d");
56
    public static final UUID uuidCamaguey = UUID.fromString("4a4e2ab9-bce1-4018-8654-e7dfe6ea9a0f");
57
    public static final UUID uuidLasTunas = UUID.fromString("6e0e9c28-23fe-4ea7-8ae1-75e1dce385e9");
58

  
59
    public static final UUID uuidEastCuba = UUID.fromString("6a9ed0e2-7d3a-4620-9376-720c166674ee");
60
    public static final UUID uuidGranma = UUID.fromString("7098418f-992a-4888-b4a0-722870bc7c69");
61
    public static final UUID uuidHolguin = UUID.fromString("1595e1f2-5ae6-4db7-982c-552c26130051");
62
    public static final UUID uuidSantiagoDeCuba = UUID.fromString("838a2e44-f3cc-4d89-83a8-6f83c6f9726d");
63
    public static final UUID uuidGuantanamo = UUID.fromString("3a76b1af-da3a-44a3-859f-eeba5ad6f58b");
64

  
65
    public static final UUID uuidEspanola = UUID.fromString("27d9d0f3-cd5f-4f3e-979d-64e47b6b5768");
66
    public static final UUID uuidJamaica = UUID.fromString("2825a0ee-0bd1-49d5-afb4-bac80db5551f");
67
    public static final UUID uuidPuertoRico = UUID.fromString("9fca701d-4899-4266-a29f-0d136670c795");
68
    public static final UUID uuidSmallerAntilles = UUID.fromString("9720309a-2467-4aad-992e-b3c34b95d8d7");
69
    public static final UUID uuidBahamas = UUID.fromString("23615e27-e916-48f4-8d49-8c148106216c");
70
    public static final UUID uuidCaymanIslands = UUID.fromString("f53ea0b5-3bca-4e95-9a10-2d13edcd7501");
71
    public static final UUID uuidNorthAmerica = UUID.fromString("5ab08324-baa2-4121-8c37-e1d558b51f2f");
72
    public static final UUID uuidCentralAmerica = UUID.fromString("4d972402-5ef8-43d8-a377-f0b6dd88d32e");
73
    public static final UUID uuidSouthAmerica = UUID.fromString("0fccc041-ce9d-40d5-8b9b-d7d833feed38");
74
    public static final UUID uuidOldWorld = UUID.fromString("c6b45544-01df-4c97-bb29-9058964c5b57");
75

  
76
//    public static final UUID uuid = UUID.fromString("");
77
//    public static final UUID uuid = UUID.fromString("");
78
//    public static final UUID uuid = UUID.fromString("");
79

  
80

  
81
    @Override
82
    public UUID getNamedAreaUuid(String key) throws UndefinedTransformerMethodException {
83
        if (StringUtils.isBlank(key)){return null;
84
        }else if (key.equalsIgnoreCase("C")){return uuidCuba;
85
        }else if (key.equalsIgnoreCase("CuW")){return uuidWesternCuba;
86
        }else if (key.equalsIgnoreCase("PR")){return uuidPinarDelRio;
87
        }else if (key.equalsIgnoreCase("Hab")){return uuidHabana;
88
        }else if (key.equalsIgnoreCase("Mat")){return uuidMatanzas;
89
        }else if (key.equalsIgnoreCase("IJ")){return uuidIslaDeLaJuventud;
90

  
91
        }else if (key.equalsIgnoreCase("CuC")){return uuidCentralCuba;
92
        }else if (key.equalsIgnoreCase("VC")){return uuidVillaClara;
93
        }else if (key.equalsIgnoreCase("Ci")){return uuidCienfuegos;
94
        }else if (key.equalsIgnoreCase("SS")){return uuidSanctiSpiritus;
95
        }else if (key.equalsIgnoreCase("CA")){return uuidCiegoDeAvila;
96
        }else if (key.equalsIgnoreCase("Cam")){return uuidCamaguey;
97
        }else if (key.equalsIgnoreCase("LT")){return uuidLasTunas;
98

  
99
        }else if (key.equalsIgnoreCase("CuE")){return uuidEastCuba;
100
        }else if (key.equalsIgnoreCase("Gr")){return uuidGranma;
101
        }else if (key.equalsIgnoreCase("Ho")){return uuidHolguin;
102
        }else if (key.equalsIgnoreCase("SC")){return uuidSantiagoDeCuba;
103
        }else if (key.equalsIgnoreCase("Gu")){return uuidGuantanamo;
104

  
105
        }else if (key.equalsIgnoreCase("Esp")){return uuidEspanola;
106
        }else if (key.equalsIgnoreCase("Ja")){return uuidJamaica;
107
        }else if (key.equalsIgnoreCase("PR")){return uuidPuertoRico;
108
        //TODO same as Pinar del Rio
109
        }else if (key.equalsIgnoreCase("Men")){return uuidSmallerAntilles;
110
        }else if (key.equalsIgnoreCase("Bah")){return uuidBahamas;
111
        }else if (key.equalsIgnoreCase("Cay")){return uuidCaymanIslands;
112
        }else if (key.equalsIgnoreCase("AmN")){return uuidNorthAmerica;
113
        }else if (key.equalsIgnoreCase("AmC")){return uuidCentralAmerica;
114
        }else if (key.equalsIgnoreCase("AmS")){return uuidSouthAmerica;
115
        }else if (key.equalsIgnoreCase("VM")){return uuidOldWorld;
116
        }else{
117
            return null;
118
        }
119
    }
120

  
121

  
122

  
123
    @Override
124
    public UUID getPresenceTermUuid(String key) throws UndefinedTransformerMethodException {
125
        if (StringUtils.isBlank(key)){return null;
126
        }else if (key.equalsIgnoreCase("Ind.")){return CyprusTransformer.indigenousUuid;
127
        }else if (key.equalsIgnoreCase("Ind?")){return CyprusTransformer.indigenousDoubtfulUuid;
128
        }else if (key.equalsIgnoreCase("Dud.")){return nonNativeDoubtfullyNaturalisedUuid;
129
        }else if (key.equalsIgnoreCase("Adv.")){return nonAdventiveAlienUuid;
130
        }else if (key.equalsIgnoreCase("Cult.")){return cultivatedOnlyUuid;
131
        }else{
132
            return null;
133
        }
134
    }
135

  
136
    @Override
137
    public PresenceAbsenceTerm getPresenceTermByKey(String key) throws UndefinedTransformerMethodException {
138
        if (StringUtils.isBlank(key)){return null;
139
        }else if (key.equalsIgnoreCase("Nat.")){return PresenceAbsenceTerm.NATURALISED();
140
        }else if (key.equalsIgnoreCase("Cult.")){return PresenceAbsenceTerm.CULTIVATED();
141
        }else{
142
            return null;
143
        }
144
    }
145

  
146

  
147

  
148

  
149

  
150

  
151
}
app-import/src/main/java/eu/etaxonomy/cdm/io/cuba/CubaVocabularyImport.java
1
/**
2
 * Copyright (C) 2007 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

  
10
package eu.etaxonomy.cdm.io.cuba;
11

  
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.io.common.CdmImportBase;
19
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
20
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
21
import eu.etaxonomy.cdm.model.common.TermType;
22
import eu.etaxonomy.cdm.model.common.TermVocabulary;
23
import eu.etaxonomy.cdm.model.location.NamedArea;
24
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
25
import eu.etaxonomy.cdm.model.location.NamedAreaType;
26

  
27
/**
28
 * @author a.mueller
29
 * @created 05.01.2016
30
 */
31

  
32
@Component
33
public class CubaVocabularyImport extends CdmImportBase<CubaImportConfigurator, CubaImportState> {
34
    private static final long serialVersionUID = -747486709409732371L;
35

  
36
    private static final Logger logger = Logger.getLogger(CubaVocabularyImport.class);
37

  
38
    /**
39
     * {@inheritDoc}
40
     */
41
    @Override
42
    protected void doInvoke(CubaImportState state) {
43
        try {
44
            makeAreas(state);
45
            makePresenceAbsenceTerms(state);
46
        } catch (UndefinedTransformerMethodException e) {
47
           e.printStackTrace();
48
        }
49
    }
50

  
51
    /**
52
     * @param state
53
     */
54
    private void makePresenceAbsenceTerms(CubaImportState state) {
55
        TransactionStatus tx = startTransaction();
56
        commitTransaction(tx);
57
    }
58

  
59
    private boolean makeAreas(CubaImportState state) throws UndefinedTransformerMethodException{
60
        TransactionStatus tx = startTransaction();
61

  
62
        IInputTransformer transformer = state.getTransformer();
63

  
64
        //vocabulary
65
        UUID cubaAreasVocabularyUuid = UUID.fromString("c81e3c7b-3c01-47d1-87cf-388de4b1908c");
66
        String label = "Cuba Areas";
67
        String abbrev = null;
68
        boolean isOrdered = true;
69
        NamedArea anyArea = NamedArea.ARCTICOCEAN();  //just any
70
        TermVocabulary<NamedArea> cubaAreasVocabualary = getVocabulary(TermType.NamedArea, cubaAreasVocabularyUuid, label, label, abbrev, null, isOrdered, anyArea);
71

  
72
        TermMatchMode matchMode = null;
73

  
74
        NamedAreaType areaType = null;  //TODO
75
        NamedAreaLevel level = null;  //TODO
76

  
77
        //Cuba
78
        level = NamedAreaLevel.COUNTRY();
79
        label = "Cuba";
80
        abbrev = "C";
81
        UUID cubaUuid = transformer.getNamedAreaUuid(abbrev);
82
        NamedArea cuba = getNamedArea(state, cubaUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
83

  
84
        //Regions
85
        level = null;
86

  
87
        //Western Cuba
88
        label = "Western Cuba";
89
        abbrev = "CuW";
90
        UUID cubaWestUuid = transformer.getNamedAreaUuid(abbrev);
91
        NamedArea westernCuba = getNamedArea(state, cubaWestUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
92
        cuba.addIncludes(westernCuba);
93

  
94
        //Central Cuba
95
        label = "Central Cuba";
96
        abbrev = "CuC";
97
        UUID cubaCentralUuid = transformer.getNamedAreaUuid(abbrev);
98
        NamedArea centralCuba = getNamedArea(state, cubaCentralUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
99
        cuba.addIncludes(centralCuba);
100

  
101
        //East Cuba
102
        label = "East Cuba";
103
        abbrev = "CuE";
104
        UUID cubaEastUuid = transformer.getNamedAreaUuid(abbrev);
105
        NamedArea eastCuba = getNamedArea(state, cubaEastUuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
106
        cuba.addIncludes(eastCuba);
107

  
108
        //Provinces - West
109
        level = NamedAreaLevel.PROVINCE();
110

  
111
        //Pinar del Río PR
112
        label = "Pinar del Río";
113
        abbrev = "PR";
114
        UUID uuid = transformer.getNamedAreaUuid(abbrev);
115
        NamedArea area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
116
        westernCuba.addIncludes(area);
117

  
118
        //Habana Hab
119
        label = "Habana"; //including Ciudad de la Habana, Mayabeque, Artemisa
120
        abbrev = "Hab";
121
        uuid = transformer.getNamedAreaUuid(abbrev);
122
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
123
        westernCuba.addIncludes(area);
124

  
125
        //Matanzas Mat
126
        label = "Matanzas";
127
        abbrev = "Mat";
128
        uuid = transformer.getNamedAreaUuid(abbrev);
129
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
130
        westernCuba.addIncludes(area);
131

  
132
        //Isla de la Juventud IJ
133
        label = "Isla de la Juventud";
134
        abbrev = "IJ";
135
        uuid = transformer.getNamedAreaUuid(abbrev);
136
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
137
        westernCuba.addIncludes(area);
138

  
139
        //Provinces - Central
140
        //Villa Clara VC
141
        label = "Villa Clara";
142
        abbrev = "VC";
143
        uuid = transformer.getNamedAreaUuid(abbrev);
144
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
145
        centralCuba.addIncludes(area);
146

  
147
        //Cienfuegos Ci VC
148
        label = "Cienfuegos";
149
        abbrev = "Ci";
150
        uuid = transformer.getNamedAreaUuid(abbrev);
151
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
152
        centralCuba.addIncludes(area);
153

  
154
        //Sancti Spiritus SS
155
        label = "Sancti Spiritus";
156
        abbrev = "SS";
157
        uuid = transformer.getNamedAreaUuid(abbrev);
158
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
159
        centralCuba.addIncludes(area);
160

  
161
        //Ciego de Ávila CA
162
        label = "Ciego de Ávila";
163
        abbrev = "CA";
164
        uuid = transformer.getNamedAreaUuid(abbrev);
165
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
166
        centralCuba.addIncludes(area);
167

  
168
        //Camagüey Cam
169
        label = "Camagüey";
170
        abbrev = "Cam";
171
        uuid = transformer.getNamedAreaUuid(abbrev);
172
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
173
        centralCuba.addIncludes(area);
174

  
175
        //Las Tunas LT
176
        label = "Las Tunas";
177
        abbrev = "LT";
178
        uuid = transformer.getNamedAreaUuid(abbrev);
179
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
180
        centralCuba.addIncludes(area);
181

  
182
        //Provinces - East
183
        //Granma Gr
184
        label = "Granma";
185
        abbrev = "Gr";
186
        uuid = transformer.getNamedAreaUuid(abbrev);
187
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
188
        eastCuba.addIncludes(area);
189

  
190
        //Holguín Ho
191
        label = "Holguín";
192
        abbrev = "Ho";
193
        uuid = transformer.getNamedAreaUuid(abbrev);
194
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
195
        eastCuba.addIncludes(area);
196

  
197
        //Santiago de Cuba SC
198
        label = "Santiago de Cuba";
199
        abbrev = "SC";
200
        uuid = transformer.getNamedAreaUuid(abbrev);
201
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
202
        eastCuba.addIncludes(area);
203

  
204
        //Guantánamo Gu
205
        label = "Guantánamo";
206
        abbrev = "Gu";
207
        uuid = transformer.getNamedAreaUuid(abbrev);
208
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
209
        eastCuba.addIncludes(area);
210

  
211
        //Surrounding
212
        //Española Esp
213
        label = "Española";
214
        abbrev = "Esp";
215
        uuid = transformer.getNamedAreaUuid(abbrev);
216
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
217

  
218
        //Jamaica Ja
219
        label = "Jamaica";
220
        abbrev = "Ja";
221
        uuid = transformer.getNamedAreaUuid(abbrev);
222
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
223

  
224
        //Puerto Rico PR
225
        label = "Puerto Rico";  //Greater Antilles
226
        abbrev = "PR";
227
        uuid = transformer.getNamedAreaUuid(abbrev);
228
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
229

  
230
        //Smaller Antilles Men
231
        label = "Smaller Antilles";
232
        abbrev = "Men";
233
        uuid = transformer.getNamedAreaUuid(abbrev);
234
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
235

  
236
        //Bahamas
237
        label = "Bahamas";
238
        abbrev = "Bah";
239
        uuid = transformer.getNamedAreaUuid(abbrev);
240
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
241

  
242
        //Cayman Islands
243
        label = "Cayman Islands"; //[Trinidad, Tobago, Curaçao, Margarita, ABC Isl. = S. America];
244
        abbrev = "Cay";
245
        uuid = transformer.getNamedAreaUuid(abbrev);
246
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
247

  
248
        //World
249
        //N America
250
        label = "N America"; //(incl. Mexico)
251
        abbrev = "AmN";
252
        uuid = transformer.getNamedAreaUuid(abbrev);
253
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
254

  
255
        //Central America
256
        label = "Central America";
257
        abbrev = "AmC";
258
        uuid = transformer.getNamedAreaUuid(abbrev);
259
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
260

  
261
        //S America
262
        label = "S America";
263
        abbrev = "AmS";
264
        uuid = transformer.getNamedAreaUuid(abbrev);
265
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
266

  
267
        //Old World
268
        label = "Old World ";
269
        abbrev = "VM";
270
        uuid = transformer.getNamedAreaUuid(abbrev);
271
        area = getNamedArea(state, uuid, label, label, abbrev, areaType, level, cubaAreasVocabualary, matchMode);
272

  
273
        commitTransaction(tx);
274
        return true;
275
    }
276

  
277

  
278
    @Override
279
    protected boolean isIgnore(CubaImportState state) {
280
        return ! state.getConfig().isDoTaxa();
281
    }
282

  
283

  
284
    @Override
285
    protected boolean doCheck(CubaImportState state) {
286
        logger.warn("DoCheck not yet implemented for CubaVocabularyImport");
287
        return true;
288
    }
289

  
290

  
291

  
292
}

Also available in: Unified diff