Project

General

Profile

« Previous | Next » 

Revision 95fb00f9

Added by Andreas Müller almost 4 years ago

ref #8996 import Uzbekistan taxonomy (first version)

View differences:

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

  
99
    public static ICdmDataSource cdm_local_uzbekistan(){
100
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
101
        String cdmServer = "127.0.0.1";
102
        String cdmDB = "cdm_uzbekistan";
103
        String cdmUserName = "root";
104
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
105
    }
106

  
99 107
	public static ICdmDataSource cdm_local_redlist_gefaesspflanzen(){
100 108
		DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
101 109
		String cdmServer = "127.0.0.1";
app-import/src/main/java/eu/etaxonomy/cdm/app/uzbekistan/UzbekistanTaxonActivator.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.app.uzbekistan;
10

  
11
import java.io.File;
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.uzbekistan.UzbekistanTaxonImportConfigurator;
23
import eu.etaxonomy.cdm.model.agent.Person;
24
import eu.etaxonomy.cdm.model.agent.Team;
25
import eu.etaxonomy.cdm.model.reference.Reference;
26
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
27
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
28

  
29
/**
30
 *
31
 * Import for Flora of Uzbekistan taxa.
32
 *
33
 * https://dev.e-taxonomy.eu/redmine/issues/8996
34
 *
35
 * @author a.mueller
36
 * @since 05.05.2020
37
 */
38
public class UzbekistanTaxonActivator {
39
    @SuppressWarnings("unused")
40
    private static final Logger logger = Logger.getLogger(UzbekistanTaxonActivator.class);
41

  
42
    //database validation status (create, update, validate ...)
43
    static DbSchemaValidation hbm2dll = DbSchemaValidation.CREATE;
44

  
45
    static final ICdmDataSource cdmDestination = CdmDestinations.localH2();
46
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_cdmtest_mysql();
47
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_uzbekistan();
48
//    static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_uzbekistan();
49

  
50

  
51
    //classification
52
    static final UUID classificationUuid = UUID.fromString("230ca922-bf63-4297-b631-aed87f553107");
53
    private static final String classificationName = "Flora of Uzbekistan";
54

  
55
    static final UUID secRefUuid = UUID.fromString("09b9b07a-a501-49d0-877c-14dd738537bb");
56
    static final UUID sourceRefUuid = UUID.fromString("295e0b9c-c637-45db-8e71-ca664f128221");
57

  
58
    static final String fileName = "FoU_taxonomy_2020_05_12.xlsx";
59

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

  
63
    private void doImport(ICdmDataSource cdmDestination){
64

  
65
        //make Source
66
        URI source = uzbekistanChecklist();
67
//        URI source = uzbekistanChecklist_local();
68

  
69
        UzbekistanTaxonImportConfigurator config = UzbekistanTaxonImportConfigurator.NewInstance(source, cdmDestination);
70
        config.setClassificationUuid(classificationUuid);
71
        config.setClassificationName(classificationName);
72
        config.setCheck(check);
73
        config.setDbSchemaValidation(hbm2dll);
74
//        config.setUuidFeatureTree(featureTreeUuid);
75
//        config.setFeatureTreeTitle(featureTreeTitle);
76
        config.setSecReference(getSecReference());
77
        config.setSourceReference(getSourceReference());
78

  
79
        CdmDefaultImport<UzbekistanTaxonImportConfigurator> myImport = new CdmDefaultImport<>();
80
        myImport.invoke(config);
81
    }
82

  
83

  
84
    private URI uzbekistanChecklist(){
85
        return URI.create("file:////BGBM-PESIHPC/Uzbekistan/" + fileName);
86
    }
87
    @SuppressWarnings("unused")
88
    private URI uzbekistanChecklist_local(){
89
        File file = new File("C:\\Users\\a.mueller\\BGBM\\Data\\Uzbekistan\\" + fileName);
90
    	return file.toURI();
91
    }
92

  
93
    private Reference secRef;
94
    private Reference getSecReference(){
95
        if (secRef != null){
96
            return secRef;
97
        }
98
        Reference result = ReferenceFactory.newArticle();
99
        result.setTitle("Corrections and amendments to the 2016 classification of lichenized fungi in the Ascomycota and Basidiomycota");
100
        result.setDatePublished(TimePeriodParser.parseStringVerbatim("2016"));
101

  
102
        Team team = Team.NewInstance();
103

  
104
        Person person = Person.NewInstance();
105
        person.setInitials("R.");
106
        person.setFamilyName("Lücking");
107
        team.addTeamMember(person);
108

  
109
        person = Person.NewInstance();
110
        person.setInitials("B.P.");
111
        person.setFamilyName("Hodkinson");
112
        team.addTeamMember(person);
113

  
114
        person = Person.NewInstance();
115
        person.setInitials("S.D.");
116
        person.setFamilyName("Leavitt");
117
        team.addTeamMember(person);
118

  
119
        result.setAuthorship(team);
120

  
121
//        result.setPublisher("Berlin: Botanic Garden and Botanical Museum Berlin-Dahlem; Athens: Hellenic Botanical Society.");
122

  
123
        result.setVolume("120(1)");
124
        Reference journal = ReferenceFactory.newJournal();
125
        journal.setTitle("The Bryologist");
126
        result.setInReference(journal);
127
        secRef = result;
128

  
129
        secRef.setUuid(secRefUuid);
130
        return result;
131
    }
132

  
133
    private Reference getSourceReference(){
134
        Reference result = ReferenceFactory.newGeneric();
135
        result.setTitle("Excelfile (FoU_taxonomy_template.xlsx) derived from ");
136
        result.setInReference(getSecReference());
137
        result.setUuid(sourceRefUuid);
138

  
139
        return result;
140
    }
141

  
142
    public static void main(String[] args) {
143
        UzbekistanTaxonActivator me = new UzbekistanTaxonActivator();
144
        me.doImport(cdmDestination);
145
        System.exit(0);
146
    }
147
}
app-import/src/main/java/eu/etaxonomy/cdm/io/greece/GreeceStatusUpdaterImport.java
74 74
    protected void firstPass(SimpleExcelTaxonImportState<GreeceStatusUpdaterConfigurator> state) {
75 75

  
76 76
    	Map<String, String> record = state.getOriginalRecord();
77
    	String line = "line " + state.getCurrentLine() + ": ";
78
    	if ((state.getCurrentLine() % 50) == 0){
79
    	    System.out.println(line);
80
    	}
77
        String line = getLine(state, 50);
81 78

  
82 79
    	String row = getValue(record, "line");
83 80
    	TaxonBase<?> taxonBase = getTaxon(state, record, line);
app-import/src/main/java/eu/etaxonomy/cdm/io/lichenes/LichenesGeneraTaxonImport.java
75 75
    @Override
76 76
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
77 77

  
78
        String line = state.getCurrentLine() + ": ";
78
        String line = getLine(state, 100);
79 79
        Map<String, String> record = state.getOriginalRecord();
80 80

  
81 81
        Set<String> keys = record.keySet();
app-import/src/main/java/eu/etaxonomy/cdm/io/mexico/SimpleExcelTaxonImport.java
215 215
            }
216 216
        }
217 217
    }
218

  
219
    /**
220
     * Returns the line string and prints it on syso for each count-th line
221
     */
222
    protected String getLine(SimpleExcelTaxonImportState<CONFIG> state, Integer count) {
223
        String line = state.getCurrentLine() + ": ";
224
        if (count != null && (state.getCurrentLine() % count) == 0){
225
            System.out.println(line);
226
        }
227
        return line;
228
    }
218 229
}
app-import/src/main/java/eu/etaxonomy/cdm/io/uzbekistan/UzbekistanTaxonImport.java
1
/**
2
* Copyright (C) 2016 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.uzbekistan;
10

  
11
import java.util.Arrays;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.Set;
15
import java.util.UUID;
16

  
17
import org.apache.log4j.Logger;
18
import org.springframework.stereotype.Component;
19

  
20
import eu.etaxonomy.cdm.io.common.utils.ImportDeduplicationHelper;
21
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport;
22
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
23
import eu.etaxonomy.cdm.model.common.CdmBase;
24
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
25
import eu.etaxonomy.cdm.model.common.Language;
26
import eu.etaxonomy.cdm.model.description.CommonTaxonName;
27
import eu.etaxonomy.cdm.model.name.INonViralName;
28
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
29
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
30
import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
31
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
32
import eu.etaxonomy.cdm.model.name.Rank;
33
import eu.etaxonomy.cdm.model.name.TaxonName;
34
import eu.etaxonomy.cdm.model.reference.Reference;
35
import eu.etaxonomy.cdm.model.reference.ReferenceType;
36
import eu.etaxonomy.cdm.model.taxon.Classification;
37
import eu.etaxonomy.cdm.model.taxon.Synonym;
38
import eu.etaxonomy.cdm.model.taxon.SynonymType;
39
import eu.etaxonomy.cdm.model.taxon.Taxon;
40
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
41
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
42
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
43

  
44
/**
45
 * Uzbekistan taxon import.
46
 *
47
 * @author a.mueller
48
 * @since 05.05.2020
49
 */
50
@Component
51
public class UzbekistanTaxonImport<CONFIG extends UzbekistanTaxonImportConfigurator>
52
            extends SimpleExcelTaxonImport<CONFIG>{
53

  
54
    private static final long serialVersionUID = 7793140600785382094L;
55
    private static final Logger logger = Logger.getLogger(UzbekistanTaxonImport.class);
56

  
57
    private static final String COMMON_NAME = "common name";
58
    private static final String PARENT_TAXON_UUID = "parentTaxonUuid";
59
    private static final String ACCEPTED_TAXON_UUID = "acceptedTaxonUuid";
60
    private static final String NAME_TYPE_UUID = "nameTypeUuid";
61
    private static final String REPLACED_SYNONYM_UUID = "replacedSynonymUuid";
62
    private static final String BASIONYM_UUID = "basionymUuid";
63
    private static final String TAXON_UUID = "taxonUuid";
64
    private static final String NAME_STATUS = "nameStatus";
65
    private static final String STATUS = "status";
66
    private static final String RANK = "rank";
67
    private static final String FULL_NAME = "fullName";
68
    private static final String FULL_TITLE = "fullTitle";
69
    private static final String REFERENCE_TYPE = "referenceType";
70

  
71
	private static UUID rootUuid = UUID.fromString("3ee689d2-17c2-4f02-9905-7092a45aa1b9");
72

  
73
    private  static List<String> expectedKeys= Arrays.asList(new String[]{
74
            TAXON_UUID,FULL_TITLE,FULL_NAME,"pureName",
75
            RANK,STATUS,REFERENCE_TYPE,PARENT_TAXON_UUID,"parenTaxonName",
76
            ACCEPTED_TAXON_UUID,"acceptedTaxonName","homotypicGroupUuid",BASIONYM_UUID,
77
            REPLACED_SYNONYM_UUID,NAME_STATUS,NAME_TYPE_UUID,COMMON_NAME
78
    });
79

  
80
    private Reference sourceReference;
81
    private Reference secReference;
82

  
83
    private NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
84

  
85
//    @Override
86
//    protected String getWorksheetName(CONFIG config) {
87
//        return "valid taxa names";
88
//    }
89

  
90
    @Override
91
    protected void firstPass(SimpleExcelTaxonImportState<CONFIG> state) {
92

  
93
        String line = getLine(state, 50);
94
        System.out.println(line);
95
        Map<String, String> record = state.getOriginalRecord();
96

  
97
        Set<String> keys = record.keySet();
98
        for (String key: keys) {
99
            if (! expectedKeys.contains(key)){
100
                logger.warn(line + "Unexpected Key: " + key);
101
            }
102
        }
103

  
104
        makeTaxon(state, line, record);
105
    }
106

  
107
    private void makeTaxon(SimpleExcelTaxonImportState<CONFIG> state, String line, Map<String, String> record) {
108

  
109
        Reference sec = getSecReference(state);
110

  
111
        String fullTitle = getValue(record, FULL_TITLE);
112
        String fullName = getValue(record, FULL_NAME);
113
        Rank rank = makeRank(line, record);
114

  
115
        //name
116
        TaxonName taxonName = parser.parseReferencedName(fullTitle, NomenclaturalCode.ICNAFP, rank);
117

  
118
        //TODO validation, deduplication, source, ...
119

  
120
        //taxon
121
        TaxonBase<?> taxonBase = makeTaxonBase(state, line, record, taxonName, sec);
122

  
123
        //name status
124
        makeNameStatus(line, record, taxonName);
125

  
126
        //common name
127
        makeCommonName(line, record, taxonBase);
128

  
129
        taxonName = TaxonName.castAndDeproxy(taxonName);
130
       //TODO
131
        checkParsed(TaxonName.castAndDeproxy(taxonName), fullTitle, fullName, line);
132
        checkReference(record, line, taxonName, fullTitle);
133
        replaceNameAuthorsAndReferences(state, taxonName);
134
        taxonName.addSource(makeOriginalSource(state));
135

  
136
        getNameService().saveOrUpdate(taxonName);
137
        if (taxonBase != null){
138
            getTaxonService().saveOrUpdate(taxonBase);
139
        }
140

  
141
        return;
142
    }
143

  
144
    private void checkReference(Map<String, String> record, String line,
145
            TaxonName taxonName, String fullTitle) {
146
        String refTypeStr = getValue(record, REFERENCE_TYPE);
147
        String statusStr = getValue(record, STATUS);
148
        Reference ref = taxonName.getNomenclaturalReference();
149
        if(ref == null){
150
            if (isNotBlank(refTypeStr)){
151
                logger.warn(line + "RefType given but no nom. ref. parsed: " + fullTitle);
152
            }
153
            if(isNotBlank(statusStr)){
154
                logger.warn(line+"Taxon status exist but name has no nom. ref.: " + fullTitle);
155
            }
156
        }else{
157
            if ("A".equals(refTypeStr)){
158
                if (!ref.getType().equals(ReferenceType.Article)){
159
                    logger.warn(line+"RefType should be article but was not: " + ref.getType().getMessage() + ";" + fullTitle);
160
                }
161
            }else if ("B".equals(refTypeStr)){
162
                if (!ref.getType().equals(ReferenceType.Book)){
163
                    logger.warn(line+"RefType should be book but was not: " + ref.getType().getMessage() + ";" + fullTitle);
164
                }
165
            }else if ("BS".equals(refTypeStr)){
166
                if (!ref.getType().equals(ReferenceType.BookSection)){
167
                    logger.warn(line+"RefType should be book section but was not: " + ref.getType().getMessage() + ";" + fullTitle) ;
168
                }
169
            }else{
170
                logger.warn(line+"Name has nom. ref. but ref type could not be recognized/was empty: " + refTypeStr + ";" + fullTitle);
171
            }
172
        }
173
    }
174

  
175
    private void makeCommonName(String line,
176
            Map<String, String> record,
177
            TaxonBase<?> taxonBase) {
178
        String commonNameStr = getValue(record, COMMON_NAME);
179
        if(isBlank(commonNameStr)){
180
            return;
181
        }else if(taxonBase == null){
182
            logger.warn(line + "No taxon exists for common name: " + commonNameStr);
183
        }else if(! (taxonBase instanceof Taxon)){
184
            logger.warn(line + "Taxon is not accepted for common name: " + commonNameStr);
185
        }else{
186
            Taxon taxon = (Taxon)taxonBase;
187
            CommonTaxonName commonName = CommonTaxonName.NewInstance(commonNameStr, Language.RUSSIAN());
188
            getTaxonDescription(taxon, false, true).addElement(commonName);
189
        }
190
    }
191

  
192
    private void makeNameStatus(String line, Map<String, String> record,
193
            TaxonName taxonName) {
194
        String nameStatus = getValue(record, NAME_STATUS);
195
        NomenclaturalStatusType status;
196
        if (isBlank(nameStatus)){
197
            status = null;
198
        }else if ("nom. cons.".equals(nameStatus)){
199
            status = NomenclaturalStatusType.CONSERVED();
200
        }else if ("nom. inval.".equals(nameStatus)){
201
            status = NomenclaturalStatusType.INVALID();
202
        }else if ("nom. illeg.".equals(nameStatus)){
203
            status = NomenclaturalStatusType.ILLEGITIMATE();
204
        }else if ("nom. rej.".equals(nameStatus)){
205
            status = NomenclaturalStatusType.REJECTED();
206
        }else{
207
            logger.warn(line + "Nom. status not recognized: " + nameStatus);
208
            status = null;
209
        }
210
        if (status != null){
211
            taxonName.addStatus(NomenclaturalStatus.NewInstance(status));
212
        }
213
    }
214

  
215

  
216
    private TaxonBase<?> makeTaxonBase(SimpleExcelTaxonImportState<CONFIG> state, String line,
217
            Map<String, String> record, TaxonName taxonName, Reference sec) {
218
        TaxonBase<?> taxonBase;
219
        String statusStr = getValue(record, STATUS);
220
        String taxonUuidStr = getValue(record, TAXON_UUID);
221
        UUID taxonUuid = UUID.fromString(taxonUuidStr);
222
        if ("A".equals(statusStr)){
223
            taxonBase = Taxon.NewInstance(taxonName, sec);
224
        }else if ("S".equals(statusStr)){
225
            taxonBase = Synonym.NewInstance(taxonName, sec);
226
        }else if (statusStr == null){
227
            taxonName.setUuid(taxonUuid);
228
            return null;
229
        }else{
230
            logger.warn(line + "Status not handled: " + statusStr);
231
            return null;
232
        }
233
        taxonBase.setUuid(taxonUuid);
234
        taxonBase.addSource(makeOriginalSource(state));
235
        return taxonBase;
236
    }
237

  
238
    private Rank makeRank(String line, Map<String, String> record) {
239
        String rankStr = getValue(record, RANK);
240
        if (rankStr.equals("family")){
241
            return Rank.FAMILY();
242
        }else if(rankStr.equals("genus")){
243
            return Rank.GENUS();
244
        }else if(rankStr.equals("species")){
245
            return Rank.SPECIES();
246
        }else if(rankStr.equals("section")){
247
            return Rank.SECTION_BOTANY();
248
        }else if(rankStr.equals("subsection")){
249
            return Rank.SUBSECTION_BOTANY();
250
        }else if(rankStr.equals("series")){
251
            return Rank.SERIES();
252
        }else if(rankStr.equals("subgenus")){
253
            return Rank.SUBGENUS();
254
        }else if(rankStr.equals("subspecies")){
255
            return Rank.SUBSPECIES();
256
        }else if(rankStr.equals("variety")){
257
            return Rank.VARIETY();
258
        }else if(rankStr.equals("unranked infrageneric")){
259
            return Rank.UNRANKED_INFRAGENERIC();
260
        }else{
261
            logger.warn(line + "Unknown rank: " + rankStr);
262
        }
263
        return null;
264
    }
265

  
266
    @Override
267
    protected void secondPass(SimpleExcelTaxonImportState<CONFIG> state) {
268
        String line = state.getCurrentLine() + ": ";
269
        System.out.println(line);
270
        Map<String, String> record = state.getOriginalRecord();
271

  
272
        String statusStr = getValue(record, STATUS);
273
        String rankStr = getValue(record, RANK);
274

  
275
        UUID taxonUuid = getUuid(record, TAXON_UUID, true, line);
276
        TaxonBase<?> taxonBase = getTaxonService().find(taxonUuid);
277
        TaxonName taxonName;
278
        if (taxonBase == null){
279
            taxonName = getNameService().find(taxonUuid);
280
        }else{
281
            taxonName = taxonBase.getName();
282
        }
283

  
284
        UUID parentUuid = getUuid(record, PARENT_TAXON_UUID, false, line);
285
        if (parentUuid != null){
286
            TaxonBase<?> parentBase = getTaxonService().find(parentUuid);
287
            if(!parentBase.isInstanceOf(Taxon.class)){
288
                logger.warn(line + "Parent taxon is not accepted: " + parentUuid);
289
            }else if (taxonBase == null || (!taxonBase.isInstanceOf(Taxon.class))){
290
                logger.warn(line + "Taxon has parent uuid but has not status accepted");
291
            }else{
292
                Taxon child = CdmBase.deproxy(taxonBase, Taxon.class);
293
                Taxon parentTaxon = CdmBase.deproxy(parentBase, Taxon.class);
294
                Classification classification = getClassification(state).getClassification();
295
                TaxonNode node = classification.addParentChild(parentTaxon, child, null, null);
296
                getTaxonNodeService().saveOrUpdate(node);
297
            }
298
        }else if("A".equals(statusStr) && !"family".equals(rankStr)){
299
            logger.warn(line + "No parent given for accepted non-family taxon");
300
        }
301

  
302
        UUID acceptedUuid = getUuid(record, ACCEPTED_TAXON_UUID, false, line);
303
        if (acceptedUuid != null){
304
            TaxonBase<?> acceptedBase = getTaxonService().find(acceptedUuid);
305
            if(!acceptedBase.isInstanceOf(Taxon.class)){
306
                logger.warn(line + "Accepted taxon is not accepted: " + acceptedUuid);
307
            }else if (taxonBase == null || (!taxonBase.isInstanceOf(Synonym.class))){
308
                logger.warn(line + "Synonym has accepted uuid but has not status accepted");
309
            }else{
310
                Synonym syn = CdmBase.deproxy(taxonBase, Synonym.class);
311
                Taxon acc = CdmBase.deproxy(acceptedBase, Taxon.class);
312
                //TODO synType
313
                acc.addSynonym(syn, SynonymType.HETEROTYPIC_SYNONYM_OF());
314
            }
315
        }else if("S".equals(statusStr)){
316
            logger.warn(line + "No accepted taxon given for synonym");
317
        }
318

  
319
        UUID basionymUuid = getUuid(record, BASIONYM_UUID, false, line);
320
        if (basionymUuid != null){
321
            TaxonBase<?> basionymTaxon = getTaxonService().find(basionymUuid);
322
            if(basionymTaxon == null){
323
                logger.warn(line + "Basionym does not exist as taxon but only as name: " + basionymUuid);
324
            }else{
325
                TaxonName basionymName = basionymTaxon.getName();
326
                taxonName.addBasionym(basionymName);
327
                taxonName.mergeHomotypicGroups(basionymName);  //just in case this is not automatically done
328
                adjustSynonymType(taxonBase, basionymTaxon, line);
329
            }
330
        }
331

  
332
        UUID replacedSynonymUuid = getUuid(record, REPLACED_SYNONYM_UUID, false, line);
333
        if (replacedSynonymUuid != null){
334
            TaxonBase<?> replacedTaxon = getTaxonService().find(replacedSynonymUuid);
335
            if(replacedTaxon == null){
336
                logger.warn(line + "Replaced synonym does not exist as taxon but only as name: " + replacedSynonymUuid);
337
            }else{
338
                TaxonName replacedName = replacedTaxon.getName();
339
                taxonName.addBasionym(replacedName);
340
                taxonName.mergeHomotypicGroups(replacedName);  //just in case this is not automatically done
341
                adjustSynonymType(taxonBase, replacedTaxon, line);
342
            }
343
        }
344

  
345
        UUID nameTypeUuid = getUuid(record, NAME_TYPE_UUID, false, line);
346
        if (nameTypeUuid != null){
347
            TaxonBase<?> typeTaxon = getTaxonService().find(nameTypeUuid);
348
            TaxonName typeName;
349
            if (typeTaxon == null){
350
                typeName = getNameService().find(nameTypeUuid);
351
            }else{
352
                typeName = typeTaxon.getName();
353
            }
354
            //TODO
355
            NameTypeDesignationStatus status = null; //NameTypeDesignationStatus.
356
            taxonName.addNameTypeDesignation(typeName, null, null, null, status, false);
357
        }
358
    }
359

  
360
    private void adjustSynonymType(TaxonBase<?> taxonBase, TaxonBase<?> homotypicTaxon, String line) {
361
        adjustSynonymTypeOrdered(taxonBase, homotypicTaxon, line);
362
        adjustSynonymTypeOrdered(homotypicTaxon, taxonBase, line);
363
    }
364

  
365
    private void adjustSynonymTypeOrdered(TaxonBase<?> firstTaxon, TaxonBase<?> secondTaxon, String line) {
366
        if (firstTaxon == null){
367
            logger.warn(line + "first taxon is null for adjust synonym type");
368
        }else if (secondTaxon == null){
369
            logger.warn(line + "second taxon is null for adjust synonym type");
370
        }else if (secondTaxon.isInstanceOf(Synonym.class)){
371
            Synonym syn = CdmBase.deproxy(secondTaxon, Synonym.class);
372
            if (firstTaxon.equals(syn.getAcceptedTaxon())){
373
                syn.setType(SynonymType.HOMOTYPIC_SYNONYM_OF());
374
            }
375
        }
376
    }
377

  
378
    protected UUID getUuid(Map<String, String> record, String columnName, boolean required, String line) {
379
        String uuidStr = getValue(record, columnName);
380
        if (isNotBlank(uuidStr)){
381
            UUID uuid;
382
            try {
383
                uuid = UUID.fromString(uuidStr);
384
                return uuid;
385
            } catch (Exception e) {
386
                logger.warn(line + "UUID could not be parsed: " + uuidStr);
387
                return null;
388
            }
389
        }else{
390
            if (required){
391
                logger.warn(line + "UUID required but does not exist");
392
            }
393
            return null;
394
        }
395
    }
396

  
397
	private void checkParsed(TaxonName name, String fullName, String nameStr, String line) {
398
		if (name.isProtectedTitleCache() || name.isProtectedFullTitleCache() || name.isProtectedNameCache()) {
399
			logger.warn(line + "Name could not be parsed: " + fullName);
400
		}
401
		if (name.getNomenclaturalReference() != null && name.getNomenclaturalReference().isProtectedTitleCache()){
402
		    logger.warn(line + "Nom ref could not be parsed: " + fullName);
403
		}
404
		if (!name.getTitleCache().equals(nameStr)){
405
            logger.warn(line + "Name part not parsed correctly: " + name.getTitleCache() + "<-> expected: " + nameStr);
406
        }
407
	}
408

  
409
    private TaxonNode rootNode;
410

  
411
    private TaxonNode getClassification(SimpleExcelTaxonImportState<CONFIG> state) {
412
        if (rootNode == null){
413
            Reference sec = getSecReference(state);
414
            String classificationName = state.getConfig().getClassificationName();
415
            Language language = Language.DEFAULT();
416
            Classification classification = Classification.NewInstance(classificationName, sec, language);
417
            classification.setUuid(state.getConfig().getClassificationUuid());
418
            classification.getRootNode().setUuid(rootUuid);
419
            getClassificationService().save(classification);
420

  
421
            rootNode = classification.getRootNode();
422
        }
423
        return rootNode;
424
    }
425

  
426
    private Reference getSecReference(SimpleExcelTaxonImportState<CONFIG> state) {
427
        if (this.secReference == null){
428
            this.secReference = getPersistentReference(state.getConfig().getSecReference());
429
        }
430
        return this.secReference;
431
    }
432

  
433
    protected Reference getSourceCitation(SimpleExcelTaxonImportState<CONFIG> state) {
434
        if (this.sourceReference == null){
435
            this.sourceReference = getPersistentReference(state.getConfig().getSourceReference());
436
        }
437
        return this.sourceReference;
438
    }
439

  
440
    private Reference getPersistentReference(Reference reference) {
441
        Reference result = getReferenceService().find(reference.getUuid());
442
        if (result == null){
443
            result = reference;
444
        }
445
        return result;
446
    }
447

  
448
    private void replaceNameAuthorsAndReferences(SimpleExcelTaxonImportState<CONFIG> state, INonViralName name) {
449
        dedupHelper().replaceAuthorNamesAndNomRef(state, name);
450
    }
451

  
452
    private ImportDeduplicationHelper<SimpleExcelTaxonImportState<CONFIG>> dedupHelper;
453
	private ImportDeduplicationHelper<SimpleExcelTaxonImportState<CONFIG>> dedupHelper() {
454
    	if (dedupHelper == null) {
455
    		dedupHelper = (ImportDeduplicationHelper)ImportDeduplicationHelper.NewInstance(this);
456
    	}
457
    	return dedupHelper;
458
    }
459

  
460
    @Override
461
    protected IdentifiableSource makeOriginalSource(SimpleExcelTaxonImportState<CONFIG> state) {
462
    	String noStr = getValue(state.getOriginalRecord(), "taxonUuid");
463
        return IdentifiableSource.NewDataImportInstance(noStr, "taxonUuid", state.getConfig().getSourceReference());
464
    }
465

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

  
11
import java.net.URI;
12

  
13
import eu.etaxonomy.cdm.database.ICdmDataSource;
14
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer;
15
import eu.etaxonomy.cdm.io.excel.common.ExcelImportConfiguratorBase;
16
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19

  
20
/**
21
 * Configurator for Uzbekistan taxon import.
22
 *
23
 * @author a.mueller
24
 * @since 05.05.2020
25
 */
26
public class UzbekistanTaxonImportConfigurator
27
        extends ExcelImportConfiguratorBase{
28

  
29
    private static final long serialVersionUID = -8829443434339585263L;
30

  
31
    private static IInputTransformer defaultTransformer = null;
32
    private Reference secReference;
33

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

  
38
    private UzbekistanTaxonImportConfigurator(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 SimpleExcelTaxonImportState getNewState() {
48
        return new SimpleExcelTaxonImportState<>(this);
49
    }
50

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

  
59
    public Reference getSecReference() {
60
        return secReference;
61
    }
62
    public void setSecReference(Reference secReference) {
63
        this.secReference = secReference;
64
    }
65
}

Also available in: Unified diff