Project

General

Profile

Revision 11b06c28

ID11b06c287d546ef6727ce7d96a9f515fd692415a
Parent 842835ee
Child 4066cdd4

Added by Andreas Müller over 5 years ago

First version of Mexico import #5822

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java
193 193
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
194 194
	}
195 195

  
196
	public static ICdmDataSource cdm_pesi_euromed(){
197
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
198
		String cdmServer = "160.45.63.175";
199
		String cdmDB = "cdm_pesi_euromed";
200
		String cdmUserName = "edit";
201
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
202
	}
203

  
204 196
	public static ICdmDataSource cdm_corvidae_dev(){
205 197
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
206 198
		String cdmServer = "160.45.63.175";
......
267 259
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
268 260
	}
269 261

  
270
	   public static ICdmDataSource cdm_cuba_production(){
271
	        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
272
	        String cdmServer = "160.45.63.171";
273
	        String cdmDB = "cdm_production_flora_cuba";
274
	        String cdmUserName = "edit";
275
	        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
276
	    }
262
    public static ICdmDataSource cdm_cuba_production(){
263
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
264
        String cdmServer = "160.45.63.171";
265
        String cdmDB = "cdm_production_flora_cuba";
266
        String cdmUserName = "edit";
267
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
268
    }
269

  
270
    public static ICdmDataSource cdm_mexico_rubiaceae_production(){
271
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
272
        String cdmServer = "160.45.63.171";
273
        String cdmDB = "cdm_production_rubiaceae_mexico";
274
        String cdmUserName = "edit";
275
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
276
    }
277 277

  
278 278
	public static ICdmDataSource cdm_cyprus_production_tunnel(){
279 279
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
......
301 301
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
302 302
	}
303 303

  
304
	public static ICdmDataSource cdm_flora_malesiana_preview(){
305
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
306
		String cdmServer = "160.45.63.175";
307
		String cdmDB = "cdm_edit_flora_malesiana";
308
		String cdmUserName = "edit";
309
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
310
	}
311

  
312
	public static ICdmDataSource cdm_flora_malesiana_production(){
313
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
314
		String cdmServer = "160.45.63.171";
315
		String cdmDB = "cdm_production_flora_malesiana";
316
		String cdmUserName = "edit";
317
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
318
	}
319

  
320 304
	public static ICdmDataSource cdm_portal_test_localhost(){
321 305
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
322 306
		String cdmServer = "127.0.0.1";
......
399 383
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
400 384
	}
401 385

  
402
	public static ICdmDataSource cdm_local_tdwg2010(){
403
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
404
		String cdmServer = "127.0.0.1";
405
		String cdmDB = "cdm_tdwg2010";
406
		String cdmUserName = "edit";
407
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
408
	}
409

  
410 386

  
411 387
	public static ICdmDataSource NULL(){
412 388
		return null;
......
519 495
		String cdmUserName = "edit";
520 496
		return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
521 497
	}
522
	
498

  
523 499
	public static ICdmDataSource cdm_production_redlist_gefaesspflanzen(){
524 500
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
525 501
		String cdmServer = "160.45.63.171";
app-import/src/main/java/eu/etaxonomy/cdm/app/mexico/MexicoBorhidiActivator.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.app.mexico;
11

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

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.app.common.CdmDestinations;
18
import eu.etaxonomy.cdm.database.DbSchemaValidation;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
21
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
22
import eu.etaxonomy.cdm.io.mexico.MexicoBorhidiImportConfigurator;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
26
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
27

  
28
/**
29
 * Activator for import of Borhidi Rubiaceae (Mexico)
30
 * @author a.mueller
31
 * @date 16.06.2016
32
 *
33
 */
34
public class MexicoBorhidiActivator {
35
    private static final Logger logger = Logger.getLogger(MexicoBorhidiActivator.class);
36

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

  
40
    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
41
//  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
42
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_mexico_rubiaceae_production();
43

  
44
    static boolean invers = true;
45

  
46
//    boolean doRubiaceae = include;
47

  
48
//    static boolean include = !invers;
49

  
50

  
51
    //feature tree uuid
52
    public static final UUID featureTreeUuid = UUID.fromString("d1f4ed29-9aae-4f6e-aa1e-4a3bf780e11d");
53

  
54
    //classification
55
    static final UUID classificationUuid = UUID.fromString("8ebb2076-d849-47e0-ad32-4fe08ca61cac");
56
    private static final String classificationName = "Rubiaceae Borhidi";
57

  
58
    static final String sourceReferenceTitle = "Rubiáceas de México";
59

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

  
63
    boolean doVocabularies = (hbm2dll == DbSchemaValidation.CREATE);
64
//    static final boolean doTaxa = false;
65
//    static final boolean doDeduplicate = true;
66

  
67
    private void doImport(ICdmDataSource cdmDestination){
68

  
69
        URI source = borhidi();
70

  
71
        //make Source
72
        MexicoBorhidiImportConfigurator config= MexicoBorhidiImportConfigurator.NewInstance(source, cdmDestination);
73
        config.setClassificationUuid(classificationUuid);
74
        config.setClassificationName(classificationName);
75
        config.setCheck(check);
76
//        config.setDoTaxa(doTaxa);
77
        config.setDbSchemaValidation(hbm2dll);
78
        config.setSourceReferenceTitle(sourceReferenceTitle);
79
//        config.setDoVocabularies(doVocabularies);
80

  
81
        config.setSource(source);
82
        String fileName = source.toString();
83
        fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
84

  
85
        String message = "Start import from ("+ fileName + ") ...";
86
        System.out.println(message);
87
        logger.warn(message);
88

  
89
        config.setSourceReference(getSourceReference(sourceReferenceTitle));
90
//        config.setDoVocabularies(doVocabularies);
91

  
92
        CdmDefaultImport<MexicoBorhidiImportConfigurator> myImport = new CdmDefaultImport<MexicoBorhidiImportConfigurator>();
93

  
94
        myImport.invoke(config);
95

  
96
//        if (makeFeatureTree){
97
//            FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
98
//            myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
99
//        }
100

  
101
        System.out.println("End import from ("+ source.toString() + ")...");
102

  
103
    }
104

  
105

  
106
    //Borhidi
107
    public static URI borhidi() {
108
        return URI.create("file:////BGBM-PESIHPC/Mexico/Borhidi_2012.xlsx");
109
    }
110

  
111
    private Reference getSourceReference(@SuppressWarnings("unused") String string) {
112
        Reference result = ReferenceFactory.newBook();
113
//        result.setTitleCache(string, true);
114
        result.setTitle("Rubiáceas de México");
115
        result.setPlacePublished("Budapest");
116
        result.setPublisher("Akadémiai Kiadó");
117
        result.setPages("512 pp.");
118
        result.setDatePublished(TimePeriodParser.parseString("2006"));
119
        Person borhidi = Person.NewTitledInstance("Borhidi");
120
        borhidi.setFirstname("Attila");
121
        result.setAuthorship(borhidi);
122
        return result;
123
    }
124

  
125
    /**
126
     * @param args
127
     */
128
    public static void main(String[] args) {
129
        MexicoBorhidiActivator me = new MexicoBorhidiActivator();
130
        me.doImport(cdmDestination);
131
        System.exit(0);
132
    }
133
}
app-import/src/main/java/eu/etaxonomy/cdm/app/mexico/MexicoConabioActivator.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.app.mexico;
11

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

  
15
import org.apache.log4j.Logger;
16

  
17
import eu.etaxonomy.cdm.app.common.CdmDestinations;
18
import eu.etaxonomy.cdm.database.DbSchemaValidation;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.cdm.io.common.CdmDefaultImport;
21
import eu.etaxonomy.cdm.io.common.IImportConfigurator.CHECK;
22
import eu.etaxonomy.cdm.io.mexico.MexicoConabioImportConfigurator;
23
import eu.etaxonomy.cdm.model.reference.Reference;
24
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
25

  
26
/**
27
 * @author a.mueller
28
 * @date 16.06.2016
29
 *
30
 */
31
public class MexicoConabioActivator {
32
    private static final Logger logger = Logger.getLogger(MexicoConabioActivator.class);
33

  
34
    //database validation status (create, update, validate ...)
35
    static DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
36

  
37
//    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
38
  static final ICdmDataSource cdmDestination = CdmDestinations.cdm_test_local_mysql_test();
39
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_mexico_production();
40

  
41
    static boolean invers = true;
42

  
43
//    boolean doRubiaceae = include;
44

  
45
//    static boolean include = !invers;
46

  
47

  
48
    //feature tree uuid
49
    public static final UUID featureTreeUuid = UUID.fromString("d1f4ed29-9aae-4f6e-aa1e-4a3bf780e11d");
50

  
51
    //classification
52
    static final UUID classificationUuid = UUID.fromString("61968b43-e881-4043-b5c2-ba192e8f72dc");
53
    private static final String classificationName = "Rubiaceae Conabio";
54

  
55
    static final String sourceReferenceTitle = "Conabio XXX";
56

  
57
    //check - import
58
    static final CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
59

  
60
    boolean doVocabularies = (hbm2dll == DbSchemaValidation.CREATE);
61
    static final boolean doTaxa = true;
62
    static final boolean doDistributions = false;
63
    static final boolean doCommonNames = false;
64
//    static final boolean doDeduplicate = true;
65

  
66
    private void doImport(ICdmDataSource cdmDestination){
67

  
68
        URI source = conabio_rubiaceae();
69

  
70
        //make Source
71
        MexicoConabioImportConfigurator config= MexicoConabioImportConfigurator.NewInstance(source, cdmDestination);
72
        config.setClassificationUuid(classificationUuid);
73
        config.setClassificationName(classificationName);
74
        config.setCheck(check);
75
        config.setDoTaxa(doTaxa);
76
        config.setDoDistributions(doDistributions);
77
        config.setDoCommonNames(doCommonNames);
78
        config.setDbSchemaValidation(hbm2dll);
79
        config.setSourceReferenceTitle(sourceReferenceTitle);
80
//        config.setDoVocabularies(doVocabularies);
81

  
82
        config.setSource(source);
83
        String fileName = source.toString();
84
        fileName = fileName.substring(fileName.lastIndexOf("/") + 1 );
85

  
86
        String message = "Start import from ("+ fileName + ") ...";
87
        System.out.println(message);
88
        logger.warn(message);
89

  
90
        config.setSourceReference(getSourceReference(sourceReferenceTitle));
91
//        config.setDoVocabularies(doVocabularies);
92

  
93
        CdmDefaultImport<MexicoConabioImportConfigurator> myImport = new CdmDefaultImport<MexicoConabioImportConfigurator>();
94

  
95
        myImport.invoke(config);
96

  
97
//        if (makeFeatureTree){
98
//            FeatureTree tree = makeFeatureNodes(myImport.getCdmAppController().getTermService());
99
//            myImport.getCdmAppController().getFeatureTreeService().saveOrUpdate(tree);
100
//        }
101

  
102
        System.out.println("End import from ("+ source.toString() + ")...");
103

  
104
    }
105

  
106

  
107
    //Conabio Rubiaceae
108
    public static URI conabio_rubiaceae() {
109
        return URI.create("file:////BGBM-PESIHPC/Mexico/CONABIO-Rubiaceae.xlsx");
110
    }
111

  
112
    private Reference getSourceReference(String string) {
113
        Reference result = ReferenceFactory.newGeneric();
114
        result.setTitleCache(string, true);
115
//        result.setInReference(inRef);
116
//        inRef.setTitleCache(sourceReferenceTitle, true);
117
        return result;
118
    }
119

  
120
    /**
121
     * @param args
122
     */
123
    public static void main(String[] args) {
124
        MexicoConabioActivator me = new MexicoConabioActivator();
125
        me.doImport(cdmDestination);
126
        System.exit(0);
127
    }
128
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoBorhidiExcelImport.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

  
12
import java.net.URI;
13
import java.net.URISyntaxException;
14
import java.util.Arrays;
15
import java.util.HashMap;
16
import java.util.List;
17
import java.util.Set;
18
import java.util.UUID;
19

  
20
import org.apache.log4j.Logger;
21
import org.springframework.stereotype.Component;
22

  
23
import eu.etaxonomy.cdm.common.CdmUtils;
24
import eu.etaxonomy.cdm.model.common.DefinedTerm;
25
import eu.etaxonomy.cdm.model.common.Extension;
26
import eu.etaxonomy.cdm.model.common.ExtensionType;
27
import eu.etaxonomy.cdm.model.common.Identifier;
28
import eu.etaxonomy.cdm.model.common.TermVocabulary;
29
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
30
import eu.etaxonomy.cdm.model.description.Feature;
31
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
32
import eu.etaxonomy.cdm.model.description.TextData;
33
import eu.etaxonomy.cdm.model.media.Media;
34
import eu.etaxonomy.cdm.model.name.BotanicalName;
35
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
36
import eu.etaxonomy.cdm.model.name.Rank;
37
import eu.etaxonomy.cdm.model.reference.Reference;
38
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
39
import eu.etaxonomy.cdm.model.taxon.Classification;
40
import eu.etaxonomy.cdm.model.taxon.Taxon;
41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
43

  
44
/**
45
 * @author a.mueller
46
 * @date 16.06.2016
47
 *
48
 */
49
@Component
50
public class MexicoBorhidiExcelImport<CONFIG extends MexicoBorhidiImportConfigurator>
51
        extends SimpleExcelTaxonImport<CONFIG>{
52
    private static final Logger logger = Logger.getLogger(MexicoBorhidiExcelImport.class);
53
    private static final long serialVersionUID = -3607776356577606657L;
54

  
55
    private  static List<String> expectedKeys= Arrays.asList(new String[]{
56
            "FullnameNoAuthors","OutputNameID","OutputFullNameWithAuthors"
57
            ,"OutputAbbreviatedTitle","OutputCollation","OutputVolume",
58
            "OutputIssue","OutputPage","OutputTitlePageYear","OutputYearPublished",
59
            "OutputBHLLink"});
60

  
61

  
62
    @Override
63
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
64
        String line = state.getCurrentLine() + ": ";
65
        HashMap<String, String> record = state.getOriginalRecord();
66

  
67
        Set<String> keys = record.keySet();
68
        checkAllKeysExist(line, keys, expectedKeys);
69

  
70
        if (record.get("FullnameNoAuthors") == null ){
71
            logger.warn("No FullnameNoAuthors given: " + line);
72
            return;
73
        }
74

  
75
        //Name
76
        BotanicalName speciesName = makeName(record, state);
77

  
78
        //Taxon
79
        Reference sec = state.getConfig().getSourceReference();
80
        Taxon taxon = Taxon.NewInstance(speciesName, sec);
81
        TaxonNode rubiaceae = getHighestNode(state);
82
//        rubiaceae.addChildTaxon(taxon, null, null);
83

  
84
        //make genus
85
        makeGenus(state, speciesName, sec, taxon, rubiaceae);
86

  
87
        //add tropicos identifier
88
        String tropicosId = record.get("OutputNameID");
89
        if (isNotBlank(tropicosId)){
90
            String tropicosIdTypeLabel = "Tropicos Name Identifier";
91
            UUID uuid = MexicoBorhidiTransformer.uuidTropicosNameIdentifier;
92
            TermVocabulary<DefinedTerm> voc = null;  //for now it goes to user defined voc
93
            DefinedTerm identifierType = this.getIdentiferType(state, uuid, tropicosIdTypeLabel, tropicosIdTypeLabel, null, voc);
94
            Identifier<Taxon> identifier = Identifier.NewInstance(tropicosId, identifierType);
95
            taxon.addIdentifier(identifier);
96
        }
97

  
98
    }
99

  
100

  
101
    private Classification classification;
102
    private TaxonNode rubiaceaeNode;
103
    /**
104
     * @return
105
     */
106
    private TaxonNode getHighestNode(SimpleExcelTaxonImportState<CONFIG> state) {
107
        if (rubiaceaeNode == null){
108
            MexicoBorhidiImportConfigurator config = state.getConfig();
109
            classification = Classification.NewInstance(state.getConfig().getClassificationName());
110
            classification.setUuid(config.getClassificationUuid());
111
            classification.setReference(config.getSourceReference());
112
            BotanicalName nameRubiaceae = BotanicalName.NewInstance(Rank.FAMILY());
113
            nameRubiaceae.setGenusOrUninomial("Rubiaceae");
114
            Taxon rubiaceaeTaxon = Taxon.NewInstance(nameRubiaceae, classification.getReference());
115
            rubiaceaeNode = classification.addChildTaxon(rubiaceaeTaxon, null, null);
116
            getClassificationService().save(classification);
117
        }
118
        return rubiaceaeNode;
119
    }
120

  
121
    /**
122
     * @param record
123
     * @param state
124
     * @return
125
     */
126
    private BotanicalName makeName(HashMap<String, String> record, SimpleExcelTaxonImportState<CONFIG> state) {
127
        String line = state.getCurrentLine() + ": ";
128

  
129
        String fullNameStr = getValue(record, "OutputFullNameWithAuthors");
130
        String volume = getValue(record, "OutputVolume");
131
        String issue = getValue(record, "OutputIssue");
132
        String page = getValue(record, "OutputPage");
133
        String titleYear = getValue(record, "OutputTitlePageYear");
134
        String publishedYear = getValue(record, "OutputYearPublished");
135
        String refAbbrevTitle = getValue(record, "OutputAbbreviatedTitle");
136
        String outputCollation = getValue(record, "OutputCollation");
137

  
138
        BotanicalName name = (BotanicalName)nameParser.parseFullName(fullNameStr, NomenclaturalCode.ICNAFP, Rank.SPECIES());
139
        if (name.isProtectedTitleCache()){
140
            logger.warn(line + "Name could not be parsed: " + fullNameStr );
141
        }else{
142
            replaceAuthorNames(state, name);
143
        }
144

  
145
        String[] volumeDetail = makeVolumeDetail(outputCollation);
146

  
147
        if (refAbbrevTitle != null){
148
            if (volume != null){
149
                Reference journal = state.getReference(refAbbrevTitle);
150
                if (journal == null){
151
                    journal = ReferenceFactory.newJournal();
152
                    journal.setAbbrevTitle(refAbbrevTitle);
153
                    state.putReference(refAbbrevTitle, journal);
154
                }
155
                Reference article = ReferenceFactory.newArticle();
156

  
157
                //volume + issue
158
    //            if (isNotBlank(issue)){
159
    //                volume = volume + "(" + issue + ")";
160
    //            }
161
                volume = volumeDetail[0];
162
                String detail = volumeDetail.length > 1 ? volumeDetail[1] : null;
163

  
164
                //            String detail = page;
165
                name.setNomenclaturalMicroReference(detail);
166

  
167
                article.setVolume(CdmUtils.Ne(volume));
168
                article.setInReference(journal);
169

  
170
                titleYear = (isBlank(publishedYear)? titleYear : "\"" + titleYear + "\"[" + publishedYear + "]");
171
                article.setDatePublished(TimePeriodParser.parseString(titleYear));
172

  
173
                Reference existingArticle = state.getReference(article.getTitleCache());
174
                if (existingArticle != null){
175
                    name.setNomenclaturalReference(existingArticle);
176
                }else{
177
                    name.setNomenclaturalReference(article);
178
                    state.putReference(article.getTitleCache(), article);
179
                }
180
            }else{
181

  
182
                Reference book = ReferenceFactory.newBook();
183
                book.setAbbrevTitle(refAbbrevTitle);
184

  
185
                if (volumeDetail.length > 1){
186
                    logger.warn(line + "Book outputCollation has volume part");
187
                }
188

  
189
                //year
190
                titleYear = (isBlank(publishedYear)? titleYear : "\"" + titleYear + "\"[" + publishedYear + "]");
191
                book.setDatePublished(TimePeriodParser.parseString(titleYear));
192

  
193
                //deduplicate
194
                Reference existingBook = state.getReference(book.getTitleCache());
195
                if (existingBook != null){
196
                    name.setNomenclaturalReference(existingBook);
197
                }else{
198
                    name.setNomenclaturalReference(book);
199
                    state.putReference(book.getTitleCache(), book);
200
                }
201

  
202
                //micro ref
203
                String detail = outputCollation;
204
                //String detail = page;
205
                name.setNomenclaturalMicroReference(detail);
206
            }
207
        }
208

  
209
        addNomRefExtension(state, name);
210

  
211

  
212
        //add protologue
213
        String bhlLink = record.get("OutputBHLLink");
214
        if (isNotBlank(bhlLink)){
215
            URI uri;
216
            try {
217
                uri = new URI(bhlLink);
218
                Media media = Media.NewInstance(uri, null, null, null);
219
                TaxonNameDescription desc = TaxonNameDescription.NewInstance(name);
220
                desc.setTitleCache("Protologue for " + name.getNameCache(), true);
221
                DescriptionElementBase elem = TextData.NewInstance(Feature.PROTOLOGUE());
222
                elem.addMedia(media);
223
                desc.addElement(elem);
224
            } catch (URISyntaxException e) {
225
                logger.warn(line + "URI could not be parsed: " + e.getMessage());
226
            }
227
        }
228

  
229
        return name;
230
    }
231

  
232
    /**
233
     * @param outputCollation
234
     * @return
235
     */
236
    private String[] makeVolumeDetail(String outputCollation) {
237
        if (outputCollation == null){
238
            return new String[0];
239
        }else{
240
            String[] split = outputCollation.split(":");
241
            return split;
242
        }
243
    }
244

  
245
    /**
246
     * @param state
247
     * @param referencedName
248
     */
249
    private void addNomRefExtension(SimpleExcelTaxonImportState<CONFIG> state, BotanicalName name) {
250
        String newExtensionStr = name.getFullTitleCache() + " - BORHIDI";
251
        UUID uuidNomRefExtension = MexicoConabioTransformer.uuidNomRefExtension;
252
        for (Extension extension : name.getExtensions()){
253
            if (extension.getType().getUuid().equals(uuidNomRefExtension)){
254
                extension.setValue(extension.getValue() + "\n" + newExtensionStr);
255
                return;
256
            }
257
        }
258
        String label = "Nomenclatural reference in Sources";
259
        String abbrev = "Nom. ref. src.";
260
        ExtensionType extensionType = getExtensionType(state, uuidNomRefExtension, label, label, abbrev);
261
        Extension.NewInstance(name, newExtensionStr, extensionType);
262
    }
263

  
264

  
265
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoBorhidiImportConfigurator.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

  
12
import java.net.URI;
13

  
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15
import eu.etaxonomy.cdm.io.common.ImportStateBase;
16
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
17
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
18
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19

  
20
/**
21
 * @author a.mueller
22
 * @date 16.06.2016
23
 *
24
 */
25
public class MexicoBorhidiImportConfigurator extends ExcelImportConfiguratorBase{
26
    private static final long serialVersionUID = -4793138681632122831L;
27

  
28
    private static IInputTransformer defaultTransformer = new MexicoBorhidiTransformer();
29

  
30
    /**
31
     * @param source
32
     * @param cdmDestination
33
     * @return
34
     */
35
    public static MexicoBorhidiImportConfigurator NewInstance(URI source, ICdmDataSource destination) {
36
        return new MexicoBorhidiImportConfigurator(source, destination);
37
    }
38

  
39

  
40
    private MexicoBorhidiImportConfigurator(URI source, ICdmDataSource destination) {
41
        super(source, destination, defaultTransformer);
42
        setNomenclaturalCode(NomenclaturalCode.ICNAFP);
43
        setSource(source);
44
        setDestination(destination);
45
     }
46

  
47
    @Override
48
    public ImportStateBase getNewState() {
49
        return new SimpleExcelTaxonImportState<>(this);
50
    }
51

  
52
    @Override
53
    protected void makeIoClassList() {
54
        ioClassList = new Class[]{
55
                MexicoBorhidiExcelImport.class
56
        };
57
    }
58

  
59
}
60

  
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoBorhidiTransformer.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

  
12
import java.util.UUID;
13

  
14
import eu.etaxonomy.cdm.io.common.mapping.InputTransformerBase;
15

  
16
/**
17
 * @author a.mueller
18
 * @date 16.06.2016
19
 *
20
 */
21
public class MexicoBorhidiTransformer extends InputTransformerBase{
22
    private static final long serialVersionUID = 4308493883009041513L;
23

  
24
    public static UUID uuidTropicosNameIdentifier = UUID.fromString("6205e531-75b0-4f2a-9a9c-b1247fb080ab");
25

  
26
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioCommonNamesImport.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

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

  
17
import org.apache.commons.lang3.StringUtils;
18
import org.apache.log4j.Logger;
19
import org.springframework.stereotype.Component;
20

  
21
import eu.etaxonomy.cdm.model.common.Language;
22
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
23
import eu.etaxonomy.cdm.model.common.TermType;
24
import eu.etaxonomy.cdm.model.common.TermVocabulary;
25
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
26
import eu.etaxonomy.cdm.model.description.TaxonDescription;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
29
import eu.etaxonomy.cdm.model.taxon.Taxon;
30

  
31
/**
32
 * @author a.mueller
33
 * @date 16.06.2016
34
 *
35
 */
36
@Component
37
public class MexicoConabioCommonNamesImport<CONFIG extends MexicoConabioImportConfigurator>
38
            extends SimpleExcelTaxonImport<CONFIG>{
39

  
40
    private static final long serialVersionUID = 3579868489510261569L;
41

  
42
    private static final Logger logger = Logger.getLogger(MexicoConabioCommonNamesImport.class);
43

  
44
    private TermVocabulary<Language> languagesVoc;
45
    private Map<String, Language> languagesMap = new HashMap<>();
46

  
47

  
48
    @Override
49
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
50
        initLanguageVocabulary(state);
51

  
52
        String line = state.getCurrentLine() + ": ";
53
        HashMap<String, String> record = state.getOriginalRecord();
54

  
55
        String idCat = getValue(record, "IdCAT");
56
        Taxon taxon = state.getHigherTaxon(idCat);
57
        if (taxon == null){
58
            logger.warn(line + "Taxon could not be found: " + idCat);
59
        }else{
60
            TaxonDescription desc = getTaxonDescription(taxon);
61
            String nomComunStr = getValue(record, "NomComun");
62
            String langStr = getValue(record, "Lengua");
63
            Language language = languagesMap.get(langStr);
64
            if (language == null){
65
                logger.warn("Language not found: " + langStr);
66
            }
67

  
68
            String refStr = getValue(record, "ReferenciasNombreComun");
69
            CommonTaxonName commonName = CommonTaxonName.NewInstance(nomComunStr,
70
                    language, null);
71

  
72
            Reference ref = getReference(state, refStr);
73
            if (ref != null){
74
                commonName.addSource(OriginalSourceType.PrimaryTaxonomicSource,
75
                        null, null, ref, null);
76
            }
77

  
78

  
79
            getTaxonService().save(taxon);
80
        }
81
    }
82

  
83
    /**
84
     * @param state
85
     */
86
    @SuppressWarnings("unchecked")
87
    private void initLanguageVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
88
        if (languagesVoc == null){
89
            languagesVoc = this.getVocabularyService().find(MexicoConabioTransformer.uuidMexicanLanguagesVoc);
90
            if (languagesVoc == null){
91
                createLanguagesVoc(state);
92
            }
93
        }
94
    }
95

  
96
    /**
97
     * @param state
98
     * @return
99
     */
100
    private void createLanguagesVoc(SimpleExcelTaxonImportState<CONFIG> state) {
101
        URI termSourceUri = null;
102
        String label = "Mexican States";
103
        String description = "Mexican States as used by the CONABIO Rubiaceae database";
104
        languagesVoc = TermVocabulary.NewInstance(TermType.Language,
105
                description, label, null, termSourceUri);
106
        languagesVoc.setUuid(MexicoConabioTransformer.uuidMexicanLanguagesVoc);
107

  
108
        addLanguage(state, "Aguascalientes", MexicoConabioTransformer.uuidAguascalientes);
109

  
110
        this.getVocabularyService().save(languagesVoc);
111

  
112
        return;
113
    }
114

  
115
    /**
116
     * @param state
117
     * @param string
118
     * @param uuidaguascalientes
119
     */
120
    private void addLanguage(SimpleExcelTaxonImportState<CONFIG> state, String label, UUID uuid) {
121
        String abbrev = null;
122
        Language language = Language.NewInstance(
123
                label, label, abbrev);
124
        language.setUuid(uuid);
125
        languagesVoc.addTerm(language);
126
        languagesMap.put(label, language);
127
    }
128

  
129
    /**
130
     * @param state
131
     * @param refStr
132
     * @return
133
     */
134
    private Reference getReference(SimpleExcelTaxonImportState<CONFIG> state, String refStr) {
135
        if (StringUtils.isNoneBlank(refStr)){
136
            return null;
137
        }
138
        Reference ref = state.getReference(refStr);
139
        if (ref == null){
140
            ref = ReferenceFactory.newBook();
141
            ref.setTitleCache(refStr, true);
142
            state.putReference(refStr, ref);
143
        }
144
        return ref;
145
    }
146

  
147
    /**
148
     * @param taxon
149
     * @return
150
     */
151
    private TaxonDescription getTaxonDescription(Taxon taxon) {
152
        if (!taxon.getDescriptions().isEmpty()){
153
            return taxon.getDescriptions().iterator().next();
154
        }else{
155
            TaxonDescription desc = TaxonDescription.NewInstance(taxon);
156
            return desc;
157
        }
158
    }
159

  
160
    @Override
161
    protected boolean isIgnore(SimpleExcelTaxonImportState<CONFIG> state) {
162
        return ! state.getConfig().isDoCommonNames();
163
    }
164

  
165
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioDistributionImport.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

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

  
16
import org.apache.commons.lang3.StringUtils;
17
import org.apache.log4j.Logger;
18
import org.springframework.stereotype.Component;
19

  
20
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
21
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary;
22
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
23
import eu.etaxonomy.cdm.model.common.TermType;
24
import eu.etaxonomy.cdm.model.description.Distribution;
25
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
26
import eu.etaxonomy.cdm.model.description.TaxonDescription;
27
import eu.etaxonomy.cdm.model.location.NamedArea;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
30
import eu.etaxonomy.cdm.model.taxon.Taxon;
31

  
32
/**
33
 * @author a.mueller
34
 * @date 16.06.2016
35
 *
36
 */
37
@Component
38
public class MexicoConabioDistributionImport<CONFIG extends MexicoConabioImportConfigurator>
39
            extends SimpleExcelTaxonImport<CONFIG> {
40

  
41
    private static final long serialVersionUID = -1733208053395372094L;
42

  
43
    private static final Logger logger = Logger.getLogger(MexicoConabioDistributionImport.class);
44

  
45
    private OrderedTermVocabulary<NamedArea> stateAreasVoc;
46
    private NamedArea mexico;
47

  
48
    @Override
49
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
50
        initAreaVocabulary(state);
51

  
52
        String line = state.getCurrentLine() + ": ";
53
        HashMap<String, String> record = state.getOriginalRecord();
54

  
55
        String idCat = getValue(record, "IdCAT");
56
        Taxon taxon = state.getHigherTaxon(idCat);
57
        if (taxon == null){
58
            logger.warn(line + "Taxon could not be found: " + idCat);
59
        }else{
60
            TaxonDescription desc = getTaxonDescription(taxon);
61

  
62
            String distrStatusStr = getValue(record, "TipoDistribucion");
63
            try {
64
                PresenceAbsenceTerm mexicanDistributionStatus = state.getTransformer().getPresenceTermByKey(distrStatusStr);
65
                if (mexicanDistributionStatus != null){
66
                    Distribution mexicanDistribution = Distribution.NewInstance(mexico, mexicanDistributionStatus);
67
                    desc.addElement(mexicanDistribution);
68
                    String refStr = getValue(record, "ReferenciaTipoDistribucion");
69
                    Reference ref = getReference(state, refStr);
70
                    if (ref != null){
71
                        mexicanDistribution.addSource(OriginalSourceType.PrimaryTaxonomicSource,
72
                                null, null, ref, null);
73
                    }
74

  
75
                }
76
            } catch (UndefinedTransformerMethodException e) {}
77

  
78

  
79
            handleDistribution(state, desc, "AGUASCALIENTES", MexicoConabioTransformer.uuidAguascalientes, line);
80
            handleDistribution(state, desc, "BAJA CALIFORNIA", MexicoConabioTransformer.uuidBaja_california, line);
81
            handleDistribution(state, desc, "BAJA CALIFORNIA SUR", MexicoConabioTransformer.uuidBaja_california_sur, line);
82
            handleDistribution(state, desc, "CAMPECHE", MexicoConabioTransformer.uuidCampeche, line);
83
            handleDistribution(state, desc, "COAHUILA DE ZARAGOZA", MexicoConabioTransformer.uuidCoahuila_de_zaragoza, line);
84
            handleDistribution(state, desc, "COLIMA", MexicoConabioTransformer.uuidColima, line);
85
            handleDistribution(state, desc, "CHIAPAS", MexicoConabioTransformer.uuidChiapas, line);
86
            handleDistribution(state, desc, "CHIHUAHUA", MexicoConabioTransformer.uuidChihuahua, line);
87
            handleDistribution(state, desc, "DISTRITO FEDERAL", MexicoConabioTransformer.uuidDistrito_federal, line);
88
            handleDistribution(state, desc, "DURANGO", MexicoConabioTransformer.uuidDurango, line);
89
            handleDistribution(state, desc, "GUANAJUATO", MexicoConabioTransformer.uuidGuanajuato, line);
90
            handleDistribution(state, desc, "GUERRERO", MexicoConabioTransformer.uuidGuerrero, line);
91
            handleDistribution(state, desc, "HIDALGO", MexicoConabioTransformer.uuidHidalgo, line);
92
            handleDistribution(state, desc, "JALISCO", MexicoConabioTransformer.uuidJalisco, line);
93
            handleDistribution(state, desc, "MEXICO", MexicoConabioTransformer.uuidMexico, line);
94
            handleDistribution(state, desc, "MICHOACAN DE OCAMPO", MexicoConabioTransformer.uuidMichoacan_de_ocampo, line);
95
            handleDistribution(state, desc, "MORELOS", MexicoConabioTransformer.uuidMorelos, line);
96
            handleDistribution(state, desc, "NAYARIT", MexicoConabioTransformer.uuidNayarit, line);
97
            handleDistribution(state, desc, "NUEVO LEON", MexicoConabioTransformer.uuidNuevo_leon, line);
98
            handleDistribution(state, desc, "OAXACA", MexicoConabioTransformer.uuidOaxaca, line);
99
            handleDistribution(state, desc, "PUEBLA", MexicoConabioTransformer.uuidPuebla, line);
100
            handleDistribution(state, desc, "QUERETARO DE ARTEAGA", MexicoConabioTransformer.uuidQueretaro_de_arteaga, line);
101
            handleDistribution(state, desc, "QUINTANA ROO", MexicoConabioTransformer.uuidQuintana_roo, line);
102
            handleDistribution(state, desc, "SAN LUIS POTOSI", MexicoConabioTransformer.uuidSan_luis_potosi, line);
103
            handleDistribution(state, desc, "SINALOA", MexicoConabioTransformer.uuidSinaloa, line);
104
            handleDistribution(state, desc, "SONORA", MexicoConabioTransformer.uuidSonora, line);
105
            handleDistribution(state, desc, "TABASCO", MexicoConabioTransformer.uuidTabasco, line);
106
            handleDistribution(state, desc, "TAMAULIPAS", MexicoConabioTransformer.uuidTamaulipas, line);
107
            handleDistribution(state, desc, "TLAXCALA", MexicoConabioTransformer.uuidTlaxcala, line);
108
            handleDistribution(state, desc, "VERACRUZ DE IGNACIO DE LA LLAVE", MexicoConabioTransformer.uuidVeracruz_de_ignacio_de_la_llave, line);
109
            handleDistribution(state, desc, "YUCATAN", MexicoConabioTransformer.uuidYucatan, line);
110
            handleDistribution(state, desc, "ZACATECAS", MexicoConabioTransformer.uuidZacatecas, line);
111

  
112
            getTaxonService().save(taxon);
113
        }
114

  
115

  
116
    }
117

  
118
    /**
119
     * @param state
120
     * @param refStr
121
     * @return
122
     */
123
    private Reference getReference(SimpleExcelTaxonImportState<CONFIG> state, String refStr) {
124
        if (StringUtils.isNoneBlank(refStr)){
125
            return null;
126
        }
127
        Reference ref = state.getReference(refStr);
128
        if (ref == null){
129
            ref = ReferenceFactory.newBook();
130
            ref.setTitleCache(refStr, true);
131
            state.putReference(refStr, ref);
132
        }
133
        return ref;
134
    }
135

  
136
    /**
137
     * @param desc
138
     * @param string
139
     * @param uuidUserDefinedAnnotationTypeVocabulary
140
     */
141
    private void handleDistribution(SimpleExcelTaxonImportState<CONFIG> state, TaxonDescription desc, String key,
142
            UUID uuid, String line) {
143
        HashMap<String, String> record = state.getOriginalRecord();
144
        String value = getValue(record, key);
145
        if ("1".equals(value)){
146
            NamedArea area = getNamedArea(state, uuid, null, null, null, null, null);
147
            Distribution dist = Distribution.NewInstance(area, PresenceAbsenceTerm.PRESENT());
148
            desc.addElement(dist);
149
        }else if (value != null){
150
            logger.warn(line + "Unrecognized distribution status '"+value+"' for " + key);
151
        }
152
    }
153

  
154
    /**
155
     * @param taxon
156
     * @return
157
     */
158
    private TaxonDescription getTaxonDescription(Taxon taxon) {
159
        if (!taxon.getDescriptions().isEmpty()){
160
            return taxon.getDescriptions().iterator().next();
161
        }else{
162
            TaxonDescription desc = TaxonDescription.NewInstance(taxon);
163
            return desc;
164
        }
165
    }
166

  
167
    /**
168
     * @param state
169
     */
170
    @SuppressWarnings("unchecked")
171
    private void initAreaVocabulary(SimpleExcelTaxonImportState<CONFIG> state) {
172
        if (stateAreasVoc == null){
173
            stateAreasVoc = (OrderedTermVocabulary<NamedArea>)this.getVocabularyService().find(MexicoConabioTransformer.uuidMexicanStatesVoc);
174
            if (stateAreasVoc == null){
175
                createStateAreasVoc(state);
176
            }
177
        }
178
    }
179

  
180
    /**
181
     * @param state
182
     * @return
183
     */
184
    private void createStateAreasVoc(SimpleExcelTaxonImportState<CONFIG> state) {
185
        URI termSourceUri = null;
186
        String label = "Mexican States";
187
        String description = "Mexican States as used by the CONABIO Rubiaceae database";
188
        stateAreasVoc = OrderedTermVocabulary.NewInstance(TermType.NamedArea,
189
                description, label, null, termSourceUri);
190
        stateAreasVoc.setUuid(MexicoConabioTransformer.uuidMexicanStatesVoc);
191

  
192
        String mexicoLabel = "Mexico (Country)";
193
        NamedArea newArea = NamedArea.NewInstance(
194
                mexicoLabel, mexicoLabel, null);
195
        newArea.setUuid(MexicoConabioTransformer.uuidMexicoCountry);
196
        stateAreasVoc.addTerm(newArea);
197

  
198
        addArea(state, "Aguascalientes", MexicoConabioTransformer.uuidAguascalientes);
199
        addArea(state, "Baja California", MexicoConabioTransformer.uuidBaja_california);
200
        addArea(state, "Baja California Sur", MexicoConabioTransformer.uuidBaja_california_sur);
201
        addArea(state, "Campeche", MexicoConabioTransformer.uuidCampeche);
202
        addArea(state, "Coahuila de Zaragoza", MexicoConabioTransformer.uuidCoahuila_de_zaragoza);
203
        addArea(state, "Colima", MexicoConabioTransformer.uuidColima);
204
        addArea(state, "Chiapas", MexicoConabioTransformer.uuidChiapas);
205
        addArea(state, "Chihuahua", MexicoConabioTransformer.uuidChihuahua);
206
        addArea(state, "Distrito ederal", MexicoConabioTransformer.uuidDistrito_federal);
207
        addArea(state, "Durango", MexicoConabioTransformer.uuidDurango);
208
        addArea(state, "Guanajuato", MexicoConabioTransformer.uuidGuanajuato);
209
        addArea(state, "Guerrero", MexicoConabioTransformer.uuidGuerrero);
210
        addArea(state, "Hidalgo", MexicoConabioTransformer.uuidHidalgo);
211
        addArea(state, "Jalisco", MexicoConabioTransformer.uuidJalisco);
212
        addArea(state, "Mexico", MexicoConabioTransformer.uuidMexico);
213
        addArea(state, "Michoacan de Ocampo", MexicoConabioTransformer.uuidMichoacan_de_ocampo);
214
        addArea(state, "Morelos", MexicoConabioTransformer.uuidMorelos);
215
        addArea(state, "Nayarit", MexicoConabioTransformer.uuidNayarit);
216
        addArea(state, "Nuevo Leon", MexicoConabioTransformer.uuidNuevo_leon);
217
        addArea(state, "Oaxaca", MexicoConabioTransformer.uuidOaxaca);
218
        addArea(state, "Puebla", MexicoConabioTransformer.uuidPuebla);
219
        addArea(state, "Queretaro de Arteaga", MexicoConabioTransformer.uuidQueretaro_de_arteaga);
220
        addArea(state, "Quintana Roo", MexicoConabioTransformer.uuidQuintana_roo);
221
        addArea(state, "San luis Potosi", MexicoConabioTransformer.uuidSan_luis_potosi);
222
        addArea(state, "Sinaloa", MexicoConabioTransformer.uuidSinaloa);
223
        addArea(state, "Sonora", MexicoConabioTransformer.uuidSonora);
224
        addArea(state, "Tabasco", MexicoConabioTransformer.uuidTabasco);
225
        addArea(state, "Tamaulipas", MexicoConabioTransformer.uuidTamaulipas);
226
        addArea(state, "Tlaxcala", MexicoConabioTransformer.uuidTlaxcala);
227
        addArea(state, "Veracruz de Ignacio de la Llave", MexicoConabioTransformer.uuidVeracruz_de_ignacio_de_la_llave);
228
        addArea(state, "Yucatan", MexicoConabioTransformer.uuidYucatan);
229
        addArea(state, "Zacatecas", MexicoConabioTransformer.uuidZacatecas);
230

  
231
        this.getVocabularyService().save(stateAreasVoc);
232

  
233
        return;
234
    }
235

  
236
    /**
237
     * @param state
238
     * @param string
239
     * @param uuidaguascalientes
240
     */
241
    private void addArea(SimpleExcelTaxonImportState<CONFIG> state, String areaLabel, UUID uuid) {
242
        String abbrev = null;
243
        NamedArea newArea = NamedArea.NewInstance(
244
                areaLabel, areaLabel, abbrev);
245
        newArea.setUuid(uuid);
246
        newArea.setPartOf(mexico);
247
        stateAreasVoc.addTerm(newArea);
248
    }
249

  
250
    @Override
251
    protected boolean isIgnore(SimpleExcelTaxonImportState<CONFIG> state) {
252
        return ! state.getConfig().isDoDistributions();
253
    }
254

  
255
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioImportConfigurator.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

  
12
import java.net.URI;
13

  
14
import eu.etaxonomy.cdm.database.ICdmDataSource;
15
import eu.etaxonomy.cdm.io.common.ImportStateBase;
16
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
17
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
18
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
19

  
20
/**
21
 * @author a.mueller
22
 * @date 16.06.2016
23
 *
24
 */
25
public class MexicoConabioImportConfigurator extends ExcelImportConfiguratorBase{
26
    private static final long serialVersionUID = -2795059530001736347L;
27

  
28
    private boolean doTaxa = true;
29
    private boolean doDistributions = true;
30
    private boolean doCommonNames = true;
31

  
32
    private static IInputTransformer defaultTransformer = new MexicoConabioTransformer();
33

  
34
    public static MexicoConabioImportConfigurator NewInstance(URI source, ICdmDataSource destination) {
35
        return new MexicoConabioImportConfigurator(source, destination);
36
    }
37

  
38
    private MexicoConabioImportConfigurator(URI source, ICdmDataSource destination) {
39
        super(source, destination, defaultTransformer);
40
        setNomenclaturalCode(NomenclaturalCode.ICNAFP);
41
        setSource(source);
42
        setDestination(destination);
43
     }
44

  
45
    @SuppressWarnings({ "unchecked", "rawtypes" })
46
    @Override
47
    public ImportStateBase getNewState() {
48
        return new SimpleExcelTaxonImportState<>(this);
49
    }
50

  
51
    @SuppressWarnings("unchecked")
52
    @Override
53
    protected void makeIoClassList() {
54
        ioClassList = new Class[]{
55
                MexicoConabioTaxonImport.class
56
        };
57
    }
58

  
59
    /**
60
     * @return the doTaxa
61
     */
62
    public boolean isDoTaxa() {
63
        return doTaxa;
64
    }
65

  
66
    /**
67
     * @param doTaxa the doTaxa to set
68
     */
69
    public void setDoTaxa(boolean doTaxa) {
70
        this.doTaxa = doTaxa;
71
    }
72

  
73
    /**
74
     * @return the doDistributions
75
     */
76
    public boolean isDoDistributions() {
77
        return doDistributions;
78
    }
79

  
80
    /**
81
     * @param doDistributions the doDistributions to set
82
     */
83
    public void setDoDistributions(boolean doDistributions) {
84
        this.doDistributions = doDistributions;
85
    }
86

  
87
    /**
88
     * @return the doCommonNames
89
     */
90
    public boolean isDoCommonNames() {
91
        return doCommonNames;
92
    }
93

  
94
    /**
95
     * @param doCommonNames the doCommonNames to set
96
     */
97
    public void setDoCommonNames(boolean doCommonNames) {
98
        this.doCommonNames = doCommonNames;
99
    }
100

  
101
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioImportState.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

  
12
import org.apache.log4j.Logger;
13

  
14
import eu.etaxonomy.cdm.io.excel.common.ExcelImportState;
15
import eu.etaxonomy.cdm.io.excel.common.ExcelRowBase;
16

  
17
/**
18
 * @author a.mueller
19
 * @date 16.06.2016
20
 *
21
 */
22
public class MexicoConabioImportState extends ExcelImportState<MexicoConabioImportConfigurator, ExcelRowBase>{
23

  
24
    @SuppressWarnings("unused")
25
    private static final Logger logger = Logger.getLogger(MexicoConabioImportState.class);
26

  
27
    /**
28
     * @param config
29
     */
30
    public MexicoConabioImportState(MexicoConabioImportConfigurator config) {
31
        super(config);
32
    }
33

  
34
}
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/MexicoConabioTaxonImport.java
1
// $Id$
2
/**
3
* Copyright (C) 2016 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
package eu.etaxonomy.cdm.io.mexico;
11

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

  
19
import org.apache.log4j.Logger;
20
import org.springframework.stereotype.Component;
21

  
22
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.common.Annotation;
26
import eu.etaxonomy.cdm.model.common.AnnotationType;
27
import eu.etaxonomy.cdm.model.common.Extension;
28
import eu.etaxonomy.cdm.model.common.ExtensionType;
29
import eu.etaxonomy.cdm.model.common.Language;
30
import eu.etaxonomy.cdm.model.common.TimePeriod;
31
import eu.etaxonomy.cdm.model.name.BotanicalName;
32
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
33
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
34
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
35
import eu.etaxonomy.cdm.model.name.NonViralName;
36
import eu.etaxonomy.cdm.model.name.Rank;
37
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
38
import eu.etaxonomy.cdm.model.reference.Reference;
39
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
40
import eu.etaxonomy.cdm.model.taxon.Classification;
41
import eu.etaxonomy.cdm.model.taxon.Synonym;
42
import eu.etaxonomy.cdm.model.taxon.SynonymRelationshipType;
43
import eu.etaxonomy.cdm.model.taxon.Taxon;
44
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
45
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
46
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
47

  
48
/**
49
 * @author a.mueller
50
 * @date 16.06.2016
51
 *
52
 */
53
@Component
54
public class MexicoConabioTaxonImport<CONFIG extends MexicoConabioImportConfigurator>
55
        extends SimpleExcelTaxonImport<CONFIG>{
56

  
57
    private static final long serialVersionUID = 3691221053127007258L;
58

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

  
61
    private final Map<String, TaxonBase<?>> taxonIdMap = new HashMap<>();
62

  
63
    private Classification classification;
64

  
65

  
66
    private  static List<String> expectedKeys= Arrays.asList(new String[]{
67
            "IdCAT","IdCATRel","IdCAT_AscendenteInmediato"
68
            ,"IdCAT_AscendenteObligatorio","CategoriaTaxonomica","Nombre",
69
            "EstatusNombre","AutorNombre","AutorSinAnio","Anio",
70
            "ReferenciaNombre",
71
            "Division","AutorDivision","ReferenciaClasificacionDivision",
72
            "Clase","AutorClase","ReferenciaClasificacionClase",
73
            "Subclase","AutorSubclase","ReferenciaClasificacionSubclase",
74
            "Superorden","AutorSuperorden","ReferenciaClasificacionSuperorden",
75
            "Orden","AutorOrden","ReferenciaClasificacionOrden",
76
            "Familia",     "EstatusFamilia","AutorFamilia","ReferenciaClasificacionFamilia",
77
            "Tribu",  "EstatusTribu","AutorTribu","ReferenciaNombreTribu",
78
            "Genero","EstatusGenero","AutorGenero","","ReferenciaNombreGenero",
79
            "Epiteto_especifico","EstatusEspecie","AutorEpiteto_especifico","ReferenciaNombreEspecie",
80
            "CategoriaInfraespecifica","NombreInfraespecifico","EstatusInfraespecie","AutorInfraespecie","ReferenciaNombreInfraespecifico",
81
            "CitaNomenclatural","Anotacion al Taxon","Fuente_BDs",
82
            "FamAceptada","GenAceptado","CategoriaTaxAceptada","NombreAceptado","AutorNombreAceptado","AutorSinAnioAceptado","AnioAceptado",
83
            "TipoRelacion","ReferenciaSinonimia","ComentariosRevisor",
84
            "CompareID","IdCAT_OLD","Nombre_OLD","AutorSinAnio_OLD",
85
            "CitaNomenclatural_OLD","ReferenceType","IsUpdated"
86
        });
87

  
88

  
89
    @Override
90
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
91
        String line = state.getCurrentLine() + ": ";
92
        HashMap<String, String> record = state.getOriginalRecord();
93

  
94
        Set<String> keys = record.keySet();
95

  
96
        checkAllKeysExist(line, keys, expectedKeys);
97

  
98
        if (getValue(record, "Nombre") == null ){
99
            logger.warn("No FullnameNoAuthors given: " + line);
100
            return;
101
        }
102

  
103
        //Name
104
        BotanicalName speciesName = makeName(line, record, state);
105
        String statusStr = getValue(record, "EstatusNombre");
106

  
107
        String secRefStr = getValueNd(record, "ReferenciaNombre");
108
        Reference sec = getSecRef(state, secRefStr, line);
109

  
110
        TaxonBase<?> taxonBase;
111
        if ("aceptado".equals(statusStr)){
112
            taxonBase = Taxon.NewInstance(speciesName, sec);
113
        }else if (statusStr.startsWith("sin")){
114
            taxonBase = Synonym.NewInstance(speciesName, sec);
115
        }else{
116
            throw new RuntimeException(line + " Status not recognized: " + statusStr);
117
        }
118

  
119
        String annotation = getValue(record, "Anotacion al Taxon");
120
        if (annotation != null && (!annotation.equals("nom. illeg.") || !annotation.equals("nom. cons."))){
121
            taxonBase.addAnnotation(Annotation.NewInstance(annotation, AnnotationType.EDITORIAL(), Language.SPANISH_CASTILIAN()));
122
        }
123

  
124
        String idCat = getValue(record, "IdCAT");
125
        this.addOriginalSource(taxonBase, idCat, "IdCAT", state.getConfig().getSourceReference());
126

  
127
        getTaxonService().save(taxonBase);
128
        taxonIdMap.put(idCat, taxonBase);
129
        if (taxonBase instanceof Taxon){
130
            state.putHigherTaxon(idCat, (Taxon)taxonBase);
131
        }
132

  
133
    }
134

  
135

  
136

  
137
    /**
138
     * @param state
139
     * @param secRefStr
140
     * @return
141
     */
142
    private Reference getSecRef(SimpleExcelTaxonImportState<CONFIG> state, String secRefStr, String line) {
143
        Reference result = state.getReference(secRefStr);
144
        if (result == null && secRefStr != null){
145
            result = ReferenceFactory.newBook();
146
            TimePeriod tp = TimePeriodParser.parseString(secRefStr.substring(secRefStr.length()-4));
147
            String authorStr = secRefStr.substring(0, secRefStr.length()-6);
148
            if (! (authorStr + ", " + tp.getYear()).equals(secRefStr)){
149
                logger.warn(line + "Sec ref could not be parsed: " + secRefStr);
150
            }else{
151
                result.setDatePublished(tp);
152
            }
153

  
154
            if (authorStr.contains(",") || authorStr.contains("&")){
155
                //TODO split
156
                Team team = Team.NewTitledInstance(authorStr, null);
157
                result.setAuthorship(team);
158
            }else if (authorStr.equals("Tropicos") || authorStr.equals("The plant list")
159
                    || authorStr.equals("APG IV")){
160
                result.setTitle(authorStr);
161

  
162
            }else{
163
                Person person = Person.NewTitledInstance(authorStr);
164
                result.setAuthorship(person);
165
            }
166

  
167
        }else if(secRefStr == null){
168
            logger.warn(line + "Empty secRefStr not yet implemented");
169
        }
170

  
171
        return result;
172
    }
173

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)