Project

General

Profile

« Previous | Next » 

Revision c5e2b66a

Added by Andreas Müller 8 months ago

ref #10242 first version of Sileneae import

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/SileneaeImportActivator.java
1
/**
2
* Copyright (C) 2023 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.caryophyllales;
10

  
11
import java.io.File;
12
import java.util.UUID;
13

  
14
import org.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16

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

  
27
/**
28
 * @author a.mueller
29
 * @date 01.02.2023
30
 */
31
public class SileneaeImportActivator {
32

  
33
    @SuppressWarnings("unused")
34
    private static final Logger logger = LogManager.getLogger();
35

  
36
    //database validation status (create, update, validate ...)
37
    private static final DbSchemaValidation hbm2dll = DbSchemaValidation.VALIDATE;
38
    private static final URI source = sileneae();
39

  
40
    private static final ICdmDataSource cdmDestination = CdmDestinations.cdm_local_caryo_spp();
41
    //private static final ICdmDataSource cdmDestination = CdmDestinations.cdm_production_caryophyllales_spp();
42

  
43
    private static final UUID acceptedUuid = UUID.fromString("8ac4a182-1281-4473-b6a1-c4f681f7dea3");
44
    private static final UUID unresolvedUuid = UUID.fromString("99ab0e67-4214-4bc7-884d-6af8c2e60c38");
45
    private static final UUID classificationUuid = UUID.fromString("9edc58b5-de3b-43aa-9f31-1ede7c009c2b");
46
    private static final UUID secUuid = UUID.fromString("770bf23b-68ab-4074-8241-3ed6899694af");
47

  
48
    //check - import
49
    static CHECK check = CHECK.IMPORT_WITHOUT_CHECK;
50

  
51
    private void doImport(ICdmDataSource cdmDestination){
52

  
53
        //make Source
54
        CaryoSileneaeImportConfigurator config = CaryoSileneaeImportConfigurator.NewInstance(source, cdmDestination);
55
        config.setClassificationUuid(classificationUuid);
56
        config.setAcceptedNodeUuid(acceptedUuid);
57
        config.setUnresolvedNodeUuid(unresolvedUuid);
58
        config.setCheck(check);
59
//      config.setDoTaxa(doTaxa);
60
        config.setDbSchemaValidation(hbm2dll);
61
        config.setSecUuid(secUuid);
62
        config.setSourceReferenceTitle("Sileneae.xlsx");
63

  
64
        CdmDefaultImport<CaryoSileneaeImportConfigurator> myImport = new CdmDefaultImport<>();
65

  
66
        //...
67
        if (true){
68
            System.out.println("Start import from ("+ source.toString() + ") ...");
69
            config.setSourceReference(getSourceReference(config.getSourceReferenceTitle()));
70
            myImport.invoke(config);
71
            System.out.println("End import from ("+ source.toString() + ")...");
72
        }
73
    }
74

  
75
    private Reference getSourceReference(String string) {
76
        Reference result = ReferenceFactory.newGeneric();
77
        result.setTitleCache(string, true);
78
        return result;
79
    }
80

  
81
    public static URI sileneae(){
82
        String fileName = "Sileneae.xlsx";
83
        File file = new File("E://data/Caryophyllales/" +  fileName);
84
        if (!file.exists()) {
85
            System.exit(0);
86
        }
87
        URI uri = URI.fromFile(file);
88
        return uri;
89
    }
90

  
91
    public static void main(String[] args) {
92
        SileneaeImportActivator me = new SileneaeImportActivator();
93
        me.doImport(cdmDestination);
94
        System.exit(0);
95
    }
96
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeImportBase.java
1
/**
2
* Copyright (C) 2023 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.caryo;
10

  
11
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport;
12
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
13
import eu.etaxonomy.cdm.model.name.TaxonName;
14
import eu.etaxonomy.cdm.model.reference.Reference;
15
import eu.etaxonomy.cdm.model.taxon.Taxon;
16

  
17
/**
18
 * @author a.mueller
19
 * @date 02.02.2023
20
 */
21
public abstract class CaryoSileneaeImportBase extends SimpleExcelTaxonImport<CaryoSileneaeImportConfigurator> {
22

  
23
    private static final long serialVersionUID = -299606747509423614L;
24

  
25
    private Reference secRef = null;
26

  
27
    protected Taxon getTaxon(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state, Integer taxonLinkId) {
28
        // TODO Auto-generated method stub
29
        return null;
30
    }
31

  
32
    protected TaxonName getName(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state, Integer nameLinkID) {
33
        // TODO Auto-generated method stub
34
        return null;
35
    }
36

  
37
    protected Reference getSecRef(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
38
        if (secRef == null){
39
            secRef = getReferenceService().find(state.getConfig().getSecUuid());
40
        }
41
        return secRef;
42
    }
43

  
44
    protected void newTransaction(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
45
        commitTransaction(state.getTransactionStatus());
46
        secRef = null;
47
        state.getDeduplicationHelper().reset();
48
        state.setSourceReference(null);
49
        System.gc();
50
        state.setTransactionStatus(startTransaction());
51
    }
52

  
53
    protected Integer getInt(String value) {
54
        return isBlank(value) ? null : Integer.valueOf(value);
55
    }
56
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeImportConfigurator.java
1
/**
2
* Copyright (C) 2020 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.caryo;
10

  
11
import java.util.UUID;
12

  
13
import eu.etaxonomy.cdm.common.URI;
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.io.mexico.SimpleExcelTaxonImportState;
19
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
20

  
21
/**
22
 * @author a.mueller
23
 * @since 17.02.2020
24
 */
25
public class CaryoSileneaeImportConfigurator extends ExcelImportConfiguratorBase{
26

  
27
    private static final long serialVersionUID = -3833210622605834032L;
28

  
29
    private boolean doDeduplicate = true;
30

  
31
    private UUID acceptedNodeUuid;
32
    private UUID unresolvedNodeUuid;
33

  
34
    private static IInputTransformer defaultTransformer = new CaryoAizoaceaeTransformer();
35

  
36
    public static CaryoSileneaeImportConfigurator NewInstance(URI source, ICdmDataSource destination) {
37
        return new CaryoSileneaeImportConfigurator(source, destination);
38
    }
39

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

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

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

  
61
    public boolean isDoDeduplicate() {
62
        return this.doDeduplicate;
63
    }
64
    public void setDoDeduplicate(boolean doDeduplicate) {
65
        this.doDeduplicate = doDeduplicate;
66
    }
67

  
68
    public UUID getAcceptedNodeUuid() {
69
        return acceptedNodeUuid;
70
    }
71
    public void setAcceptedNodeUuid(UUID acceptedNodeUuid) {
72
        this.acceptedNodeUuid = acceptedNodeUuid;
73
    }
74

  
75
    public UUID getUnresolvedNodeUuid() {
76
        return unresolvedNodeUuid;
77
    }
78
    public void setUnresolvedNodeUuid(UUID unresolvedNodeUuid) {
79
        this.unresolvedNodeUuid = unresolvedNodeUuid;
80
    }
81

  
82
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeNameImport.java
1
/**
2
* Copyright (C) 2020 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.caryo;
10

  
11
import java.util.HashMap;
12
import java.util.List;
13
import java.util.Map;
14
import java.util.UUID;
15

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

  
20
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
21
import eu.etaxonomy.cdm.common.CdmUtils;
22
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
23
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
24
import eu.etaxonomy.cdm.model.common.Annotation;
25
import eu.etaxonomy.cdm.model.common.AnnotationType;
26
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
27
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
28
import eu.etaxonomy.cdm.model.name.Rank;
29
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
30
import eu.etaxonomy.cdm.model.name.TaxonName;
31
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
32
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
33
import eu.etaxonomy.cdm.model.reference.Reference;
34
import eu.etaxonomy.cdm.model.term.DefinedTerm;
35
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
36
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
37

  
38
/**
39
 * @author a.mueller
40
 * @since 02.02.2023
41
 */
42
@Component
43
public class CaryoSileneaeNameImport extends CaryoSileneaeImportBase {
44

  
45
    private static final long serialVersionUID = 8931253645038029899L;
46
    private static final Logger logger = LogManager.getLogger();
47

  
48
    private static final String NOMEN_ID = "nomen_id";
49
    private static final String RANK = "rank";
50
    private static final String GENUS = "Genus";
51
    private static final String INFRAGEN_NAME = "Infragen_name";
52
    private static final String SPECIES = "Species";
53
    private static final String INFRASP_EPITHET = "Infrasp_epithet";
54
    private static final String AUTHORS = "Authors";
55

  
56
    private static final String BASIONYM_LINK = "Basionym_link";
57
    private static final String IPNI_ID = "IPNI_ID";
58
    private static final String NOTES = "Notes";
59
    private static final String NOMINVAL_FLAG = "NomInval_Flag";
60
    private static final String TYPE_SPECIMEN = "Type_specimen";
61
    private static final String TYPE_SPECIES_LINK = "TypeSpecies_link";
62

  
63
    //maybe not used
64
    private static final String PUBLICATION = "Publication";
65
    private static final String PUBL_DATE = "PublDate";
66

  
67
    //not used
68
    @SuppressWarnings("unused")
69
    private static final String HOMONYM_FLAG = "Homonym_Flag";
70
    @SuppressWarnings("unused")
71
    private static final String MISAPPLIED_FLAG = "Misapplied_Flag";
72
    @SuppressWarnings("unused")
73
    private static final String SynonymyReference_link = "SynonymyReference_link";
74

  
75
    private Map<Integer, UUID> nameMapping = new HashMap<>();
76

  
77
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
78

  
79
    @Override
80
    protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
81
        int line = state.getCurrentLine();
82
        if ((line % 500) == 0){
83
            newTransaction(state);
84
            System.out.println(line);
85
        }
86

  
87
        this.state = state;
88
        Map<String, String> record = state.getOriginalRecord();
89

  
90
        Integer nomenId = Integer.valueOf(getValue(record, NOMEN_ID));
91
        String rankStr = getValue(record, RANK);
92
        String genusStr = getValue(record, GENUS);
93
        String infragenStr = getValue(record, INFRAGEN_NAME);
94
        String speciesStr = getValue(record, SPECIES);
95
        String infraspStr = getValue(record, INFRASP_EPITHET);
96
        String authorsStr = getValue(record, AUTHORS);
97
        String ipniId = getValue(record, IPNI_ID);
98
        String notes = getValue(record, NOTES);
99
        String nomInvalFlag = getValue(record, NOMINVAL_FLAG);
100
        String typeSpecimenStr = getValue(record, TYPE_SPECIMEN);
101

  
102
        String row = String.valueOf(line) + "("+nomenId+"): ";
103

  
104
        try {
105
            //create name
106
            Rank rank = state.getTransformer().getRankByKey(rankStr);
107
            TaxonName name = TaxonNameFactory.NewBotanicalInstance(rank);
108

  
109
            //fill simple
110
            name.setGenusOrUninomial(Ne(genusStr));
111
            name.setInfraGenericEpithet(Ne(infragenStr));
112
            name.setSpecificEpithet(Ne(speciesStr));
113
            name.setInfraSpecificEpithet(Ne(infraspStr));
114
            NonViralNameParserImpl.NewInstance().parseAuthors(name, authorsStr);
115

  
116
            //TODO ??publication + PublDate
117

  
118
            //ipni ID
119
            if (isNotBlank(ipniId)) {
120
                name.addIdentifier(ipniId, DefinedTerm.IDENTIFIER_NAME_IPNI());
121
            }
122

  
123
            //notes
124
            if (isNotBlank(notes)) {
125
                Annotation annotation = Annotation.NewDefaultLanguageInstance(notes);
126
                annotation.setAnnotationType(AnnotationType.TECHNICAL());
127
                name.addAnnotation(annotation);
128
            }
129

  
130
            //nominval flag
131
            if (nomInvalFlag != null && nomInvalFlag.trim().equalsIgnoreCase("yes")) {
132
                Reference ref = null;
133
                name.addStatus(NomenclaturalStatusType.INVALID(), ref, null);
134
            }
135

  
136
            //type specimen
137
            if (isNotBlank(typeSpecimenStr)) {
138
                DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
139
                facade.setCollector(null);  //just to create field unit and gathering event
140
                facade.innerDerivedUnit().setTitleCache(typeSpecimenStr, true);
141
                SpecimenTypeDesignationStatus status = null; //TODO
142
                Reference ref = null;
143
                String originalInfo = null;
144
                name.addSpecimenTypeDesignation(facade.innerDerivedUnit(), status, ref, null, originalInfo, false, false);
145
                // save ??
146
            }
147

  
148

  
149
        } catch (UndefinedTransformerMethodException | StringNotParsableException e) {
150
            e.printStackTrace();
151
        }
152
    }
153

  
154
    private String Ne(String genusStr) {
155
        return CdmUtils.Ne(genusStr);
156
    }
157

  
158
    private TaxonName dedupliateNameParts(TaxonName name) {
159
        if (state.getConfig().isDoDeduplicate()){
160
            state.getDeduplicationHelper().replaceAuthorNamesAndNomRef(name);
161
        }
162
        return name;
163
    }
164

  
165
    private String getOtherAuthors(List<TaxonName> otherNames) {
166
        String result = "";
167
        for (TaxonName name : otherNames){
168
            result = CdmUtils.concat(";", result, name.getAuthorshipCache());
169
        }
170
        return result;
171
    }
172

  
173

  
174
    private void handleNomenclRemarkAndNameStatus(String nomenclaturalRemarks, String row, boolean isNewName, TaxonName name,
175
            List<NomenclaturalStatusType> statusTypes) {
176

  
177
        NomenclaturalStatusType remarkType = null;
178
        NomenclaturalStatusType statusType = statusTypes.isEmpty()? null: statusTypes.iterator().next();
179
        if (nomenclaturalRemarks == null){
180
           //nothing to do
181
        }else if (", nom. illeg.".equals(nomenclaturalRemarks)){
182
            remarkType = NomenclaturalStatusType.ILLEGITIMATE();
183
        }else if (", nom. cons.".equals(nomenclaturalRemarks)){
184
            remarkType = NomenclaturalStatusType.CONSERVED();
185
        }else if (", nom. nud.".equals(nomenclaturalRemarks)){
186
            remarkType = NomenclaturalStatusType.NUDUM();
187
        }else if (", nom. provis.".equals(nomenclaturalRemarks)){
188
            remarkType = NomenclaturalStatusType.PROVISIONAL();
189
        }else if (", nom. rej.".equals(nomenclaturalRemarks)){
190
            remarkType = NomenclaturalStatusType.REJECTED();
191
        }else if (", nom. subnud.".equals(nomenclaturalRemarks)){
192
            remarkType = NomenclaturalStatusType.SUBNUDUM();
193
        }else if (", nom. superfl.".equals(nomenclaturalRemarks)){
194
            remarkType = NomenclaturalStatusType.SUPERFLUOUS();
195
        }else if (", not validly publ.".equals(nomenclaturalRemarks)){
196
            statusTypes.add(NomenclaturalStatusType.INVALID());
197
        }else if (", opus utique oppr.".equals(nomenclaturalRemarks)){
198
            statusTypes.add(NomenclaturalStatusType.OPUS_UTIQUE_OPPR());
199
        }else {
200
            logger.warn(row + "Unhandled nomenclatural remark: " + nomenclaturalRemarks);
201
        }
202

  
203
        NomenclaturalStatusType kewType = remarkType != null? remarkType : statusType;
204
        if (isNewName){
205
            if(remarkType != null && statusType != null && !remarkType.equals(statusType)){
206
                logger.warn(row + "Kew suggests 2 different nom. status. types for new name. The status from nomenclatural_remarks was taken.");
207
            }
208
            if (kewType != null){
209
                name.addStatus(kewType, getSecRef(state), null);
210
            }
211
        }else{
212
            NomenclaturalStatusType existingType = null;
213
            if (!name.getStatus().isEmpty()){
214
                existingType = name.getStatus().iterator().next().getType();
215
            }
216
            if (existingType != null && kewType != null){
217
                if (!existingType.equals(kewType)){
218
                    logger.warn(row + "Existing name status "+existingType.getTitleCache()+" differs from Kew status " + kewType.getTitleCache() + ". Key status ignored");
219
                }
220
            }else if (existingType != null && kewType == null){
221
                logger.warn(row + "Info: Existing name has a name status "+existingType.getTitleCache()+" but Kew name has no status. Existing status kept.");
222
            }else if (existingType == null && kewType != null){
223
                if(remarkType != null && statusType != null && !remarkType.equals(statusType)){
224
                    logger.warn(row + "Existing name has no status while Kew name suggests a status (but 2 different status form status and nomenclatural_remarks field).");
225
                }else{
226
                    logger.warn(row + "Existing name has no status while Kew name suggests a status ("+kewType.getTitleCache()+"). Kew status ignored.");
227
                }
228
            }
229
        }
230
    }
231

  
232
    @Override
233
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
234
        Map<String, String> record = state.getOriginalRecord();
235
        int line = state.getCurrentLine();
236

  
237
        Integer nomenId = Integer.valueOf(getValue(record, NOMEN_ID));
238
        Integer basionymId = getInt(getValue(record, BASIONYM_LINK));
239
        Integer typeSpeciesId = getInt(getValue(record, TYPE_SPECIES_LINK));
240

  
241
        String row = String.valueOf(line) + "("+nomenId+"): ";
242
        if ((line % 500) == 0){
243
            newTransaction(state);
244
            System.out.println(line);
245
        }
246

  
247
        TaxonName name = getName(state, nomenId);
248
        if (name == null) {
249
            logger.warn(row + "Name does not exist");
250
            return;
251
        }
252

  
253
        //basionym
254
        if (basionymId != null) {
255
            TaxonName basionym = getName(state, basionymId);
256
            if (basionym == null) {
257
                logger.warn(row + "basionym does not exist");
258
            }else {
259
                name.addBasionym(basionym);
260
            }
261
        }
262

  
263
        //type name
264
        if (typeSpeciesId != null) {
265
            TaxonName typeSpecies = getName(state, typeSpeciesId);
266
            if (typeSpecies == null) {
267
                logger.warn(row + "typeSpecies does not exist");
268
            }else {
269
                Reference ref = null;
270
                NameTypeDesignationStatus status = null; //TODO
271
                name.addNameTypeDesignation(typeSpecies, ref, null, null, status, false);
272
            }
273
        }
274
    }
275
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeNomRefImport.java
1
/**
2
* Copyright (C) 2020 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.caryo;
10

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

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

  
22
import eu.etaxonomy.cdm.common.CdmUtils;
23
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
24
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
25
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
26
import eu.etaxonomy.cdm.model.common.CdmBase;
27
import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
28
import eu.etaxonomy.cdm.model.name.TaxonName;
29
import eu.etaxonomy.cdm.model.reference.Reference;
30
import eu.etaxonomy.cdm.model.reference.ReferenceType;
31
import eu.etaxonomy.cdm.model.taxon.Synonym;
32
import eu.etaxonomy.cdm.model.taxon.Taxon;
33
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
34

  
35
/**
36
 * @author a.mueller
37
 * @since 02.02.2023
38
 */
39
@Component
40
public class CaryoSileneaeNomRefImport extends CaryoSileneaeImportBase {
41

  
42
    private static final long serialVersionUID = 7227226331297614469L;
43
    private static final Logger logger = LogManager.getLogger();
44

  
45
    private static final String NOMEN_ID = "nomen_id";
46
    private static final String NAME = "name";
47
    private static final String PUBLICATION = "Publication";
48
    private static final String PUB_TYPE_ED = "PubTypeEd";
49
    private static final String PUB_TYPE_KEW = "PubTypeKew";
50
    private static final String PUB_KEW = "PubKew";
51
    private static final String NIMM_KEW = "NimmKew";
52
    private static final String ORIG_SPELLING = "Original spelling";
53
    private static final String NOM_STATUS = "Nom. Status";
54

  
55
    private static final String SECOND_PUBLICATION = "SecondPublication";
56
    private static final String IMPORT = "import";
57
    private static final String DUPL = "dupl";
58

  
59

  
60
    private Map<Integer, Reference> nameMapping = new HashMap<>();
61
    private Set<String> neglectedRecords = new HashSet<>();
62
    private Set<UUID> createdNames = new HashSet<>();
63

  
64
    private static final NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
65

  
66
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
67

  
68
    @Override
69
    protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
70
        int line = state.getCurrentLine();
71
        if ((line % 500) == 0){
72
            newTransaction(state);
73
            System.out.println(line);
74
        }
75

  
76
        this.state = state;
77
        Map<String, String> record = state.getOriginalRecord();
78

  
79
        Integer nomenId = Integer.valueOf(getValue(record, NOMEN_ID));
80
        String nameStr = getValue(record, NAME);
81
        String origPublication = getValue(record, PUBLICATION);
82
        String pubTypeEd = getValue(record, PUB_TYPE_ED);
83
        String pubTypeKew = getValue(record, PUB_TYPE_KEW);
84
        String pubKew = getValue(record, PUB_KEW);
85

  
86
        String nimmKew = getValue(record, NIMM_KEW);
87
        String origSpelling = getValue(record, ORIG_SPELLING);
88
        //TODO erstmal nicht importieren laut NaK
89
        @SuppressWarnings("unused")
90
        String nomStatus = getValue(record, NOM_STATUS);
91

  
92
        String row = String.valueOf(line) + "("+nameStr+"): ";
93

  
94
        TaxonName name = getName(state, nomenId);
95
        if (name == null) {
96
            return;   //record did not exist
97
            //TODO check if it is really a duplicate
98
        }
99

  
100
        boolean isKew = isNotBlank(nimmKew) && "x".equals(nimmKew);
101

  
102
        String publication = isKew ? pubKew : origPublication;
103
        String pubType = isKew ? pubTypeEd : pubTypeKew;
104

  
105
        ReferenceType refType = getRefType(pubType);
106
        if (refType == null) {
107
            logger.warn(row + "reference type not found");
108
        }else if (refType == ReferenceType.Article) {
109
            publication = "in " + publication;
110
        }else if (refType == ReferenceType.Book) {
111
            //
112
        }else {
113
            logger.warn(row + "reference type not handled: " + refType);
114
        }
115
        String referenceName = name.getTitleCache()+ " " + publication;
116
        TaxonName parsedName = parser.parseReferencedName(referenceName);
117
        if (parsedName.isProtectedFullTitleCache() || parsedName.isProtectedTitleCache() ) {
118
            logger.warn(row + "name could not be parsed");
119
        }else {
120
            Reference ref = parsedName.getNomenclaturalReference();
121
            name.setNomenclaturalReference(ref);
122
            String microRef = parsedName.getNomenclaturalMicroReference();
123
            name.setNomenclaturalMicroReference(microRef);
124
        }
125

  
126
        //validateName (name);
127
        validateName(name, nameStr, row);
128
        //deduplicate
129
        dedupliateNameParts(name);
130

  
131
        //orig spelling
132
        if (isNotBlank(origSpelling)) {
133
            TaxonName origName = (TaxonName)parser.parseFullName(origSpelling);
134
            if (origName.isProtectedTitleCache()) {
135
                logger.warn(row + "orig name could not be parsed");
136
            }
137
            name.getNomenclaturalSource().setNameUsedInSource(origName);
138
        }
139
    }
140

  
141
    private void validateName(TaxonName name, String nameStr, String row) {
142
        if (name.getTitleCache().equals(nameStr)) {
143
            logger.warn(row+ "name titleCache does not match");
144
        }
145
    }
146

  
147
    private ReferenceType getRefType(String pubType) {
148
        if ("A".equals(pubType)){
149
            return ReferenceType.Article;
150
        }else if ("B".equals(pubType)) {
151
            return ReferenceType.Book;
152
        }
153
        return null;
154
    }
155

  
156
    private TaxonName dedupliateNameParts(TaxonName name) {
157
        if (state.getConfig().isDoDeduplicate()){
158
            state.getDeduplicationHelper().replaceAuthorNamesAndNomRef(name);
159
        }
160
        return name;
161
    }
162

  
163
    private void makeStatus(String status, String sourceId,
164
            String accId, String row, List<NomenclaturalStatusType> statusTypes) {
165

  
166
        Class<? extends CdmBase> clazz;
167
        if ("Accepted".equals(status) || "Unplaced".equals(status) || "Artificial Hybrid".equals(status) ){
168
            clazz = Taxon.class;
169
        }else if ("Synonym".equals(status) || "Orthographic".equals(status)){
170
            clazz = (accId == null)? Taxon.class : Synonym.class;
171
            if("Orthographic".equals(status)){
172
                statusTypes.add(NomenclaturalStatusType.SUPERFLUOUS());
173
            }
174
        }else if("Illegitimate".equals(status)){
175
            statusTypes.add(NomenclaturalStatusType.ILLEGITIMATE());
176
        }else if ("Invalid".equals(status)){
177
            statusTypes.add(NomenclaturalStatusType.INVALID());
178
        }else{
179
            logger.warn(row + "Unhandled status: " + status);
180
        }
181
        return;
182
    }
183

  
184
    private void handleNomenclRemarkAndNameStatus(String nomenclaturalRemarks, String row, boolean isNewName, TaxonName name,
185
            List<NomenclaturalStatusType> statusTypes) {
186

  
187
        NomenclaturalStatusType remarkType = null;
188
        NomenclaturalStatusType statusType = statusTypes.isEmpty()? null: statusTypes.iterator().next();
189
        if (nomenclaturalRemarks == null){
190
           //nothing to do
191
        }else if (", nom. illeg.".equals(nomenclaturalRemarks)){
192
            remarkType = NomenclaturalStatusType.ILLEGITIMATE();
193
        }else if (", nom. cons.".equals(nomenclaturalRemarks)){
194
            remarkType = NomenclaturalStatusType.CONSERVED();
195
        }else if (", nom. nud.".equals(nomenclaturalRemarks)){
196
            remarkType = NomenclaturalStatusType.NUDUM();
197
        }else if (", nom. provis.".equals(nomenclaturalRemarks)){
198
            remarkType = NomenclaturalStatusType.PROVISIONAL();
199
        }else if (", nom. rej.".equals(nomenclaturalRemarks)){
200
            remarkType = NomenclaturalStatusType.REJECTED();
201
        }else if (", nom. subnud.".equals(nomenclaturalRemarks)){
202
            remarkType = NomenclaturalStatusType.SUBNUDUM();
203
        }else if (", nom. superfl.".equals(nomenclaturalRemarks)){
204
            remarkType = NomenclaturalStatusType.SUPERFLUOUS();
205
        }else if (", not validly publ.".equals(nomenclaturalRemarks)){
206
            statusTypes.add(NomenclaturalStatusType.INVALID());
207
        }else if (", opus utique oppr.".equals(nomenclaturalRemarks)){
208
            statusTypes.add(NomenclaturalStatusType.OPUS_UTIQUE_OPPR());
209
        }else {
210
            logger.warn(row + "Unhandled nomenclatural remark: " + nomenclaturalRemarks);
211
        }
212

  
213
        NomenclaturalStatusType kewType = remarkType != null? remarkType : statusType;
214
        if (isNewName){
215
            if(remarkType != null && statusType != null && !remarkType.equals(statusType)){
216
                logger.warn(row + "Kew suggests 2 different nom. status. types for new name. The status from nomenclatural_remarks was taken.");
217
            }
218
            if (kewType != null){
219
                name.addStatus(kewType, getSecRef(state), null);
220
            }
221
        }else{
222
            NomenclaturalStatusType existingType = null;
223
            if (!name.getStatus().isEmpty()){
224
                existingType = name.getStatus().iterator().next().getType();
225
            }
226
            if (existingType != null && kewType != null){
227
                if (!existingType.equals(kewType)){
228
                    logger.warn(row + "Existing name status "+existingType.getTitleCache()+" differs from Kew status " + kewType.getTitleCache() + ". Key status ignored");
229
                }
230
            }else if (existingType != null && kewType == null){
231
                logger.warn(row + "Info: Existing name has a name status "+existingType.getTitleCache()+" but Kew name has no status. Existing status kept.");
232
            }else if (existingType == null && kewType != null){
233
                if(remarkType != null && statusType != null && !remarkType.equals(statusType)){
234
                    logger.warn(row + "Existing name has no status while Kew name suggests a status (but 2 different status form status and nomenclatural_remarks field).");
235
                }else{
236
                    logger.warn(row + "Existing name has no status while Kew name suggests a status ("+kewType.getTitleCache()+"). Kew status ignored.");
237
                }
238
            }
239
        }
240
    }
241

  
242
    private void testParsedName(SimpleExcelTaxonImportState<CaryoAizoaceaeExcelImportConfigurator> state, TaxonName name,
243
            String row, String fullCitation) throws UndefinedTransformerMethodException {
244
        Map<String, String> record = state.getOriginalRecord();
245

  
246
        String nameCache = getValue(record, NAME);
247
        String pubType = getValue(record, "PubType");
248
        String place_of_publication = getValue(record, "place_of_publication");
249
        String volume_and_page = getValue(record, "volume_and_page");
250

  
251
//        if (!CdmUtils.nullSafeEqual(name.getNameCache(), nameCache)){
252
//            logger.warn(row + "Unexpected nameCache: " + nameCache);
253
//        }
254
//        if (!CdmUtils.nullSafeEqual(name.getTitleCache(), fullName)){
255
//            logger.warn(row + "Unexpected titleCache: <->" + name.getTitleCache());
256
//        }
257
//        if (isBlank(genusHybrid) == name.isMonomHybrid()){
258
//            logger.warn(row + "Unexpected genus hybrid: " + genusHybrid);
259
//        }
260
//        if (!CdmUtils.nullSafeEqual(name.getGenusOrUninomial(),genus)){
261
//            logger.warn(row + "Unexpected genus: " + genus);
262
//        }if (isBlank(speciesHybrid) == name.isBinomHybrid()){
263
//            logger.warn(row + "Unexpected species hybrid: " + speciesHybrid);
264
//        }
265
//        if (!CdmUtils.nullSafeEqual(name.getSpecificEpithet(),species)){
266
//            logger.warn(row + "Unexpected species epithet: " + name.getSpecificEpithet() +"<->"+ species);
267
//        }
268
//        if (!CdmUtils.nullSafeEqual(name.getInfraSpecificEpithet(), infraspecies)){
269
//            logger.warn(row + "Unexpected infraspecific epithet: " + name.getInfraSpecificEpithet() +"<->"+ infraspecies);
270
//        }
271
//        if (!CdmUtils.nullSafeEqual(name.getAuthorshipCache(),authors)){
272
//            logger.warn(row + "Unexpected authors: " + name.getAuthorshipCache() +"<->"+ authors);
273
//        }
274
//        String combinationAndExAuthor = authorTitle(name.getCombinationAuthorship(), name.getExCombinationAuthorship());
275
//        if (!CdmUtils.nullSafeEqual(combinationAndExAuthor, combinationAuthor)){
276
//            logger.warn(row + "Unexpected combination author: " + combinationAndExAuthor +"<->"+ combinationAuthor);
277
//        }
278
//        String basionymAndExAuthor = authorTitle(name.getBasionymAuthorship(), name.getExBasionymAuthorship());
279
//        if (!CdmUtils.nullSafeEqual(basionymAndExAuthor, basionymAuthor)){
280
//            logger.warn(row + "Unexpected basionym author: " + basionymAndExAuthor +"<->"+ basionymAuthor);
281
//        }
282
//        Rank rank = state.getTransformer().getRankByKey(rankStr);
283
//        if (!rank.equals(name.getRank())){
284
//            logger.warn(row + "Unexpected rank: " + rankStr);
285
//        }
286
//
287
//        Reference nomRef = name.getNomenclaturalReference();
288
//        if (nomRef == null){
289
//            if (fullCitation != null){
290
//                NonViralNameParserImpl parser = new NonViralNameParserImpl();
291
//                TaxonName parsedName = parser.parseReferencedName(fullCitation, NomenclaturalCode.ICNAFP, rank);
292
//                if (parsedName.getNomenclaturalReference() != null){
293
//                    name.setNomenclaturalReference(parsedName.getNomenclaturalReference());
294
//                    logger.warn(row + "Nom.ref. was missing. Taken from Kew");
295
//                }else{
296
//                    logger.warn(row + "Nom. ref. is missing or can not be parsed");
297
//                }
298
//            }else{
299
//                logger.warn(row + "NomRef is missing.");
300
//            }
301
//        }else{
302
//            if ("A".equals(pubType) && nomRef.getType() != ReferenceType.Article){
303
//                logger.warn(row + "Unexpected nomref type: " + pubType + "<->" + nomRef.getType().toString());
304
//            }
305
//            if ("B".equals(pubType) && nomRef.getType() != ReferenceType.Book){
306
//                logger.warn(row + "Unexpected nomref type: " + pubType + "<->" + nomRef.getType().toString());
307
//            }
308
//            year = normalizeYear(year);
309
//            if (!CdmUtils.nullSafeEqual(year, nomRef.getDatePublishedString())){
310
//                logger.warn(row + "Unexpected year: " + year + "<->" + nomRef.getDatePublishedString());
311
//            }
312
//            if (volume_and_page != null && !name.getFullTitleCache().contains(volume_and_page)){
313
//                logger.warn(row + "volume_and_page not found in fullTitleCache: " + name.getFullTitleCache() +"<->"+ volume_and_page);
314
//            }
315
//            if (place_of_publication != null && !name.getFullTitleCache().contains(place_of_publication)){
316
//                logger.warn(row + "place_of_publication not found in fullTitleCache: " + name.getFullTitleCache() +"<->"+ place_of_publication);
317
//            }
318
//        }
319
//        if ("subsp.".equals(infraSpecRank) && !rank.equals(Rank.SUBSPECIES())){
320
//            logger.warn(row + "Unexpected infraspec marker: " + infraSpecRank);
321
//        }else if ("var.".equals(infraSpecRank) && !rank.equals(Rank.VARIETY())){
322
//            logger.warn(row + "Unexpected infraspec marker: " + infraSpecRank);
323
//        }else if ("f.".equals(infraSpecRank) && !rank.equals(Rank.FORM())){
324
//            logger.warn(row + "Unexpected infraspec marker: " + infraSpecRank);
325
//        }
326
    }
327

  
328
    private String authorTitle(TeamOrPersonBase<?> author, TeamOrPersonBase<?> exAuthor) {
329
        String authorStr = author == null? null: author.getNomenclaturalTitleCache();
330
        String exAuthorStr = exAuthor == null? null: exAuthor.getNomenclaturalTitleCache();
331
        return CdmUtils.concat(" ex ", exAuthorStr, authorStr);
332
    }
333

  
334
    private String normalizeYear(String year) {
335
        if (year == null){
336
            return null;
337
        }else if (year.contains("\" [")){
338
            String[] split = year.split("\" \\[");
339
            year = split[1].replace("]","") + " [" + split[0]+"\"]";
340
        }else if ("?".equals(year)){
341
            return null;
342
        }
343
        return year;
344
    }
345

  
346
    @Override
347
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
348
//        Map<String, String> record = state.getOriginalRecord();
349
//        int line = state.getCurrentLine();
350
//        String accName = getValue(record, "AcceptedName");
351
//        String basionymId = getValue(record, "basionym_plant_name_id");
352
//        String homotypicSynonym = getValue(record, "homotypic_synonym");
353
//
354
//        String row = String.valueOf(line) + "("+fullName+"): ";
355
//
356
//        if ((line % 500) == 0){
357
//            newTransaction(state);
358
//            System.out.println(line);
359
//        }
360
    }
361
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeSynonymImport.java
1
/**
2
* Copyright (C) 2020 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.caryo;
10

  
11
import java.util.HashSet;
12
import java.util.Map;
13
import java.util.Set;
14

  
15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
import org.springframework.stereotype.Component;
18

  
19
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
20
import eu.etaxonomy.cdm.model.common.CdmBase;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.model.taxon.Synonym;
23
import eu.etaxonomy.cdm.model.taxon.SynonymType;
24
import eu.etaxonomy.cdm.model.taxon.Taxon;
25
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
26

  
27
/**
28
 * @author a.mueller
29
 * @since 02.02.2023
30
 */
31
@Component
32
public class CaryoSileneaeSynonymImport extends CaryoSileneaeImportBase {
33

  
34
    private static final long serialVersionUID = 7967768097472488888L;
35
    private static final Logger logger = LogManager.getLogger();
36

  
37
    private static final String NOMTAX_ID = "NomTax_ID";
38
    private static final String NOMEN_LINK = "Nomen_link";
39
    private static final String TAXON_LINK = "Taxon_link";
40

  
41
    private Set<String> neglectedRecords = new HashSet<>();
42

  
43
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
44

  
45
    @Override
46
    protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
47
        int line = state.getCurrentLine();
48
        if ((line % 500) == 0){
49
            newTransaction(state);
50
            System.out.println(line);
51
        }
52

  
53
        this.state = state;
54
        Map<String, String> record = state.getOriginalRecord();
55

  
56
        Integer nomTaxId = Integer.valueOf(getValue(record, NOMTAX_ID));
57
        Integer nameLinkID = Integer.valueOf(getValue(record, NOMEN_LINK));
58
        Integer taxonLinkId = Integer.valueOf(getValue(record, TAXON_LINK));
59

  
60

  
61
        String row = String.valueOf(line) + "("+nomTaxId+"): ";
62

  
63
        TaxonName name = getName(state, nameLinkID);
64

  
65
        if (name == null) {
66
            logger.warn(row + "Name does not exist");
67
            return;
68
        }
69

  
70
        Synonym synonym = Synonym.NewInstance(name, getSecRef(state));
71

  
72
        Taxon taxon = getTaxon(state, taxonLinkId);
73
        if (taxon == null) {
74
            logger.warn(row + "Taxon does not exist");
75
            return;
76
        }
77
        //TODO type (compute homotypics)
78
        taxon.addSynonym(synonym, SynonymType.SYNONYM_OF);
79
    }
80

  
81
    @Override
82
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
83
    }
84

  
85
    private boolean hasSameAcceptedTaxon(TaxonBase<?> taxonBase, TaxonBase<?> basionymTaxon) {
86
        if (taxonBase.isInstanceOf(Synonym.class)){
87
            taxonBase = CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon();
88
        }
89
        if (basionymTaxon.isInstanceOf(Synonym.class)){
90
            basionymTaxon = CdmBase.deproxy(basionymTaxon, Synonym.class).getAcceptedTaxon();
91
        }
92
        return taxonBase != null && basionymTaxon != null && taxonBase.equals(basionymTaxon);
93
    }
94
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeTaxonImport.java
1
/**
2
* Copyright (C) 2020 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.caryo;
10

  
11
import java.util.HashMap;
12
import java.util.HashSet;
13
import java.util.Map;
14
import java.util.Set;
15
import java.util.UUID;
16

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

  
21
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
22
import eu.etaxonomy.cdm.model.common.CdmBase;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.taxon.Classification;
25
import eu.etaxonomy.cdm.model.taxon.Synonym;
26
import eu.etaxonomy.cdm.model.taxon.Taxon;
27
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
28
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
29

  
30
/**
31
 * @author a.mueller
32
 * @since 02.02.2023
33
 */
34
@Component
35
public class CaryoSileneaeTaxonImport extends CaryoSileneaeImportBase {
36

  
37
    private static final long serialVersionUID = 5594951908819469636L;
38
    private static final Logger logger = LogManager.getLogger();
39

  
40
    private static final String ACCEPTED_TAXON_ID = "AcceptedTaxon_ID";
41
    private static final String NOMEN_LINK = "nomen_link";
42
    private static final String PARENT = "parent";
43

  
44
    private Map<String, UUID> taxonMapping = new HashMap<>();
45
    private Set<String> neglectedRecords = new HashSet<>();
46

  
47
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
48

  
49
    @Override
50
    protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
51
        int line = state.getCurrentLine();
52
        if ((line % 500) == 0){
53
            newTransaction(state);
54
            System.out.println(line);
55
        }
56

  
57
        this.state = state;
58
        Map<String, String> record = state.getOriginalRecord();
59

  
60
        Integer accTaxonId = Integer.valueOf(getValue(record, ACCEPTED_TAXON_ID));
61
        Integer nameLinkID = Integer.valueOf(getValue(record, NOMEN_LINK));
62

  
63
        String row = String.valueOf(line) + "("+accTaxonId+"): ";
64

  
65
        TaxonName name = getName(state, nameLinkID);
66

  
67
        if (name == null) {
68
            logger.warn(row + "Name does not exist");
69
            return;
70
        }
71

  
72
        Taxon taxon = Taxon.NewInstance(name, getSecRef(state));
73

  
74
        getTaxonService().saveOrUpdate(taxon);
75
    }
76

  
77
    @Override
78
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
79
        int line = state.getCurrentLine();
80
        if ((line % 500) == 0){
81
            newTransaction(state);
82
            System.out.println(line);
83
        }
84

  
85
        this.state = state;
86
        Map<String, String> record = state.getOriginalRecord();
87

  
88
        Integer accTaxonId = Integer.valueOf(getValue(record, ACCEPTED_TAXON_ID));
89
        Integer parentId = Integer.valueOf(getValue(record, PARENT));
90

  
91
        String row = String.valueOf(line) + "("+accTaxonId+"): ";
92

  
93
        Taxon taxon = getTaxon(state, accTaxonId);
94
        if (taxon == null) {
95
            logger.warn(row + "Taxon does not exist");
96
            return;
97
        }
98

  
99
        Taxon parent = getTaxon(state, parentId);
100
        if (parent == null) {
101
            logger.warn(row + "Taxon does not exist");
102
            return;
103
        }
104

  
105
        Classification classification = getClassification(state);
106

  
107
        //TODO ref needed?
108
        TaxonNode node = classification.addParentChild(parent, taxon, null, null);
109

  
110
        getTaxonNodeService().saveOrUpdate(node);
111
    }
112

  
113
    private Classification getClassification(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state2) {
114
        // TODO Auto-generated method stub
115
        return null;
116
    }
117

  
118
    private boolean hasSameAcceptedTaxon(TaxonBase<?> taxonBase, TaxonBase<?> basionymTaxon) {
119
        if (taxonBase.isInstanceOf(Synonym.class)){
120
            taxonBase = CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon();
121
        }
122
        if (basionymTaxon.isInstanceOf(Synonym.class)){
123
            basionymTaxon = CdmBase.deproxy(basionymTaxon, Synonym.class).getAcceptedTaxon();
124
        }
125
        return taxonBase != null && basionymTaxon != null && taxonBase.equals(basionymTaxon);
126
    }
127

  
128
    private TaxonNode getFamily(){
129
        UUID uuid = UUID.fromString("0334809a-aa20-447d-add9-138194f80f56");
130
        TaxonNode aizoaceae = getTaxonNodeService().find(uuid);
131
        return aizoaceae;
132
    }
133

  
134
    private TaxonNode hybridParent(){
135
        UUID uuid = UUID.fromString("2fae0fa1-758a-4fcb-bb6c-a2bd11f40641");
136
        TaxonNode hybridParent = getTaxonNodeService().find(uuid);
137
        return hybridParent;
138
    }
139
    private TaxonNode unresolvedParent(){
140
        UUID uuid = UUID.fromString("accb1ff6-5748-4b18-b529-9368c331a38d");
141
        TaxonNode unresolvedParent = getTaxonNodeService().find(uuid);
142
        return unresolvedParent;
143
    }
144
}

Also available in: Unified diff