Project

General

Profile

« Previous | Next » 

Revision 2fedea5a

Added by Andreas Müller 8 months ago

ref #10242 final version of Sileneae import (before synonym cleanup=

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/app/caryophyllales/SileneaeImportActivator.java
38 38
    private static final URI source = sileneae();
39 39

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

  
43 44
    private static final UUID acceptedUuid = UUID.fromString("8ac4a182-1281-4473-b6a1-c4f681f7dea3");
44 45
    private static final UUID unresolvedUuid = UUID.fromString("99ab0e67-4214-4bc7-884d-6af8c2e60c38");
app-import/src/main/java/eu/etaxonomy/cdm/app/common/CdmDestinations.java
611 611
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
612 612
    }
613 613

  
614
    public static ICdmDataSource cdm_local_caryo_spp2(){
614
    public static ICdmDataSource cdm_local_caryo_spp1(){
615 615
        DatabaseTypeEnum dbType = DatabaseTypeEnum.MySQL;
616 616
        String cdmServer = "127.0.0.1";
617
        String cdmDB = "cdm_caryo_spp2";
617
        String cdmDB = "cdm_local_caryophyllales_spp1";
618 618
        String cdmUserName = "edit";
619 619
        return makeDestination(dbType, cdmServer, cdmDB, -1, cdmUserName, null);
620 620
    }
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeImportBase.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.caryo;
10 10

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

  
16
import eu.etaxonomy.cdm.common.DoubleResult;
11 17
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImport;
12 18
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
13 19
import eu.etaxonomy.cdm.model.name.TaxonName;
......
24 30

  
25 31
    private Reference secRef = null;
26 32

  
27
    protected Taxon getTaxon(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state, Integer taxonLinkId) {
28
        // TODO Auto-generated method stub
29
        return null;
33
    protected static Map<Integer,TaxonName> nameMap = new HashMap<>();
34

  
35
    private static Map<Integer,Taxon> taxonMap = new HashMap<>();
36

  
37
    protected static Map<Integer,TaxonName> origNameMap = new HashMap<>();
38
    protected static Map<Integer,TaxonName> orphanedNameMap = new HashMap<>();
39
    protected static Set<TaxonName> origSpellingNames = new HashSet<>();
40

  
41
    protected static Map<Integer, Integer> accIdMap = new HashMap<>();
42

  
43
    protected static Map<Integer,DoubleResult<String,String>> origPublicationMap = new HashMap<>();
44

  
45

  
46

  
47
    protected Taxon getTaxon(Integer taxonLinkId) {
48
        return taxonMap.get(taxonLinkId);
30 49
    }
31 50

  
32
    protected TaxonName getName(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state, Integer nameLinkID) {
33
        // TODO Auto-generated method stub
34
        return null;
51
    protected TaxonName getName(Integer nameLinkId) {
52
        return nameMap.get(nameLinkId);
53
    }
54

  
55
    protected void putToNameMap(Integer id, TaxonName name) {
56
        nameMap.put(id, name);
57
        origNameMap.put(id, name);
58
        orphanedNameMap.put(id, name);
59
    }
60
    protected void putToTaxonMap(Integer id, Taxon taxon) {
61
        taxonMap.put(id, taxon);
35 62
    }
36 63

  
37 64
    protected Reference getSecRef(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeImportConfigurator.java
31 31
    private UUID acceptedNodeUuid;
32 32
    private UUID unresolvedNodeUuid;
33 33

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

  
36 36
    public static CaryoSileneaeImportConfigurator NewInstance(URI source, ICdmDataSource destination) {
37 37
        return new CaryoSileneaeImportConfigurator(source, destination);
......
54 54
    @Override
55 55
    protected void makeIoClassList() {
56 56
        ioClassList = new Class[]{
57
                CaryoSileneaeNameImport.class
57
                CaryoSileneaeNameImport.class,
58
                CaryoSileneaeNomRefImport.class,
59
                CaryoSileneaeTaxonImport.class,
60
                CaryoSileneaeSynonymImport.class
58 61
        };
59 62
    }
60 63

  
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeNameImport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.caryo;
10 10

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

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

  
20
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
21 18
import eu.etaxonomy.cdm.common.CdmUtils;
19
import eu.etaxonomy.cdm.common.DoubleResult;
20
import eu.etaxonomy.cdm.facade.DerivedUnitFacade;
22 21
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
23 22
import eu.etaxonomy.cdm.io.mexico.SimpleExcelTaxonImportState;
24 23
import eu.etaxonomy.cdm.model.common.Annotation;
......
32 31
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
33 32
import eu.etaxonomy.cdm.model.reference.Reference;
34 33
import eu.etaxonomy.cdm.model.term.DefinedTerm;
35
import eu.etaxonomy.cdm.strategy.exceptions.StringNotParsableException;
36 34
import eu.etaxonomy.cdm.strategy.parser.NonViralNameParserImpl;
37 35

  
38 36
/**
......
45 43
    private static final long serialVersionUID = 8931253645038029899L;
46 44
    private static final Logger logger = LogManager.getLogger();
47 45

  
48
    private static final String NOMEN_ID = "nomen_id";
49
    private static final String RANK = "rank";
46
    private static final UUID uuidSileneaeInfoNameIdType = UUID.fromString("95ecbf6d-521d-447f-bae5-d82585ff3617");
47

  
48
    private static final String NOMEN_ID = "nomen_ID";
49
    private static final String RANK = "Rank";
50 50
    private static final String GENUS = "Genus";
51 51
    private static final String INFRAGEN_NAME = "Infragen_name";
52 52
    private static final String SPECIES = "Species";
......
72 72
    @SuppressWarnings("unused")
73 73
    private static final String SynonymyReference_link = "SynonymyReference_link";
74 74

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

  
77
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
75
    @Override
76
    protected String getWorksheetName(CaryoSileneaeImportConfigurator config) {
77
        return "Names";
78
    }
78 79

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

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

  
90 90
        Integer nomenId = Integer.valueOf(getValue(record, NOMEN_ID));
......
93 93
        String infragenStr = getValue(record, INFRAGEN_NAME);
94 94
        String speciesStr = getValue(record, SPECIES);
95 95
        String infraspStr = getValue(record, INFRASP_EPITHET);
96
        String publicationStr = getValue(record, PUBLICATION);
97
        String publDateStr = getValue(record, PUBL_DATE);
96 98
        String authorsStr = getValue(record, AUTHORS);
97 99
        String ipniId = getValue(record, IPNI_ID);
98 100
        String notes = getValue(record, NOTES);
......
104 106
        try {
105 107
            //create name
106 108
            Rank rank = state.getTransformer().getRankByKey(rankStr);
109
            if (rank == null) {
110
                logger.warn(row + "rank not recognized: " + rankStr);
111
            }
107 112
            TaxonName name = TaxonNameFactory.NewBotanicalInstance(rank);
108 113

  
109 114
            //fill simple
110 115
            name.setGenusOrUninomial(Ne(genusStr));
111 116
            name.setInfraGenericEpithet(Ne(infragenStr));
117
            if (speciesStr != null && speciesStr.startsWith("×")) {
118
                name.setBinomHybrid(true);
119
                speciesStr = speciesStr.replace("×", "").trim();
120
            }
112 121
            name.setSpecificEpithet(Ne(speciesStr));
113 122
            name.setInfraSpecificEpithet(Ne(infraspStr));
114
            NonViralNameParserImpl.NewInstance().parseAuthors(name, authorsStr);
123
            try {
124
                NonViralNameParserImpl.NewInstance().parseAuthors(name, authorsStr);
125
            } catch (Exception e) {
126
                name.setAuthorshipCache(authorsStr, true);
127
                logger.warn(row + "authorship not parsable: " + authorsStr);
128
            }
115 129

  
116
            //TODO ??publication + PublDate
130
            //publication
131
            publicationStr = normalizePublication(publicationStr);
132
            if (isNotBlank(publicationStr) || isNotBlank(publDateStr)) {
133
                DoubleResult<String, String> publ = new DoubleResult<>(publicationStr, publDateStr);
134
                origPublicationMap.put(nomenId, publ);
135
            }
117 136

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

  
142
            //add ID
143
            DefinedTerm sileneaeInfoNameIdType = getIdentiferType(state,
144
                    uuidSileneaeInfoNameIdType, null, null, null, null);
145
            name.addIdentifier(nomenId.toString(), sileneaeInfoNameIdType);
146

  
123 147
            //notes
124 148
            if (isNotBlank(notes)) {
125
                Annotation annotation = Annotation.NewDefaultLanguageInstance(notes);
126
                annotation.setAnnotationType(AnnotationType.TECHNICAL());
127
                name.addAnnotation(annotation);
149
                handleNotes(name, notes, row);
128 150
            }
129 151

  
130
            //nominval flag
152
            //nom.inval flag
131 153
            if (nomInvalFlag != null && nomInvalFlag.trim().equalsIgnoreCase("yes")) {
132 154
                Reference ref = null;
133 155
                name.addStatus(NomenclaturalStatusType.INVALID(), ref, null);
......
137 159
            if (isNotBlank(typeSpecimenStr)) {
138 160
                DerivedUnitFacade facade = DerivedUnitFacade.NewInstance(SpecimenOrObservationType.PreservedSpecimen);
139 161
                facade.setCollector(null);  //just to create field unit and gathering event
162
                facade.innerFieldUnit().setTitleCache("Field Unit for: " + typeSpecimenStr, true);
140 163
                facade.innerDerivedUnit().setTitleCache(typeSpecimenStr, true);
141
                SpecimenTypeDesignationStatus status = null; //TODO
164
                SpecimenTypeDesignationStatus status = SpecimenTypeDesignationStatus.UNSPECIFIC();
142 165
                Reference ref = null;
143 166
                String originalInfo = null;
144 167
                name.addSpecimenTypeDesignation(facade.innerDerivedUnit(), status, ref, null, originalInfo, false, false);
145 168
                // save ??
146 169
            }
147 170

  
171
            Reference sourceRef = getSourceReference(state);
172
            name.addImportSource(nomenId.toString(), "Names.nomen_ID", sourceRef, "row " + String.valueOf(line));
173

  
174
            putToNameMap(nomenId, name);
148 175

  
149
        } catch (UndefinedTransformerMethodException | StringNotParsableException e) {
176
        } catch (UndefinedTransformerMethodException e) {
150 177
            e.printStackTrace();
151 178
        }
152 179
    }
153 180

  
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);
181
    private String normalizePublication(String publicationStr) {
182
        if (isBlank(publicationStr)) {
183
            return null;
161 184
        }
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());
185
        if ("-".equalsIgnoreCase(publicationStr)) {
186
            return null;
187
        }
188
        if ("?".equalsIgnoreCase(publicationStr)) {
189
            return null;
169 190
        }
170
        return result;
191
        if ("??".equalsIgnoreCase(publicationStr)) {
192
            return null;
193
        }
194
        if ("none".equalsIgnoreCase(publicationStr)) {
195
            return null;
196
        }
197
        return publicationStr;
171 198
    }
172 199

  
200
    private String Ne(String genusStr) {
201
        return CdmUtils.Ne(genusStr);
202
    }
173 203

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

  
177 206
        NomenclaturalStatusType remarkType = null;
178
        NomenclaturalStatusType statusType = statusTypes.isEmpty()? null: statusTypes.iterator().next();
179
        if (nomenclaturalRemarks == null){
207
        if (notes == null){
180 208
           //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)){
209
        }else if ("ined".equals(notes)){
210
            remarkType = NomenclaturalStatusType.INED();
211
            notes = null;
212
        }else if ("nom. utique rej.".equals(notes)){
213
            remarkType = NomenclaturalStatusType.UTIQUE_REJECTED();
214
            notes = null;
215
        }else if ("nomen nudum".equalsIgnoreCase(notes)){
216
            remarkType = NomenclaturalStatusType.NUDUM();
217
            notes = null;
218
        }else if (notes.startsWith("nomen nudum") || notes.startsWith("Nomen nudum") ){
186 219
            remarkType = NomenclaturalStatusType.NUDUM();
187
        }else if (", nom. provis.".equals(nomenclaturalRemarks)){
188
            remarkType = NomenclaturalStatusType.PROVISIONAL();
189
        }else if (", nom. rej.".equals(nomenclaturalRemarks)){
220
        }else if (notes.startsWith("nom. illeg.")){
221
            remarkType = NomenclaturalStatusType.ILLEGITIMATE();
222
        }else if (notes.startsWith("nom. inval")){
223
            remarkType = NomenclaturalStatusType.INVALID();
224
        }else if ("Nom. rej.".equals(notes)){
190 225
            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);
226
            notes = null;
201 227
        }
202 228

  
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.");
229
        //annotation
230
        if (isNotBlank(notes)) {
231
            Annotation annotation = Annotation.NewDefaultLanguageInstance(notes);
232
            annotation.setAnnotationType(AnnotationType.TECHNICAL());
233
            name.addAnnotation(annotation);
234
        }
235

  
236
        //nom. status.
237
        if (remarkType != null) {
238
            if (!name.hasStatus(remarkType)) {
239

  
240
                Reference ref = null;
241
                name.addStatus(remarkType, ref, null);
242
                if (name.getStatus().size() > 1) {
243
                    logger.warn(row + "name has >1 status: " + name.getFullTitleCache());
227 244
                }
228 245
            }
229 246
        }
247

  
248
        return notes;
230 249
    }
231 250

  
232 251
    @Override
......
239 258
        Integer typeSpeciesId = getInt(getValue(record, TYPE_SPECIES_LINK));
240 259

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

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

  
253 272
        //basionym
254
        if (basionymId != null) {
255
            TaxonName basionym = getName(state, basionymId);
273
        if (basionymId != null && !basionymId.equals(nomenId)) {
274
            TaxonName basionym = getName(basionymId);
256 275
            if (basionym == null) {
257 276
                logger.warn(row + "basionym does not exist");
258 277
            }else {
......
262 281

  
263 282
        //type name
264 283
        if (typeSpeciesId != null) {
265
            TaxonName typeSpecies = getName(state, typeSpeciesId);
284
            TaxonName typeSpecies = getName(typeSpeciesId);
266 285
            if (typeSpecies == null) {
267 286
                logger.warn(row + "typeSpecies does not exist");
268 287
            }else {
269 288
                Reference ref = null;
270
                NameTypeDesignationStatus status = null; //TODO
289
                NameTypeDesignationStatus status = null; // NameTypeDesignationStatus.NOT_APPLICABLE(); //TODO minor NameTypeDesignationStatus
271 290
                name.addNameTypeDesignation(typeSpecies, ref, null, null, status, false);
272 291
            }
273 292
        }
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeNomRefImport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.caryo;
10 10

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

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

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

  
35 31
/**
36 32
 * @author a.mueller
......
42 38
    private static final long serialVersionUID = 7227226331297614469L;
43 39
    private static final Logger logger = LogManager.getLogger();
44 40

  
45
    private static final String NOMEN_ID = "nomen_id";
41
    private static final String NOMEN_ID = "nomen_ID";
46 42
    private static final String NAME = "name";
47 43
    private static final String PUBLICATION = "Publication";
48 44
    private static final String PUB_TYPE_ED = "PubTypeEd";
......
52 48
    private static final String ORIG_SPELLING = "Original spelling";
53 49
    private static final String NOM_STATUS = "Nom. Status";
54 50

  
51
    @SuppressWarnings("unused")
55 52
    private static final String SECOND_PUBLICATION = "SecondPublication";
53
    @SuppressWarnings("unused")
56 54
    private static final String IMPORT = "import";
55
    @SuppressWarnings("unused")
57 56
    private static final String DUPL = "dupl";
58 57

  
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 58
    private static final NonViralNameParserImpl parser = NonViralNameParserImpl.NewInstance();
65 59

  
66 60
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
67 61

  
62
    @Override
63
    protected String getWorksheetName(CaryoSileneaeImportConfigurator config) {
64
        return "NomRef";
65
    }
66

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

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

  
86 85
        String nimmKew = getValue(record, NIMM_KEW);
87 86
        String origSpelling = getValue(record, ORIG_SPELLING);
88
        //TODO erstmal nicht importieren laut NaK
87

  
89 88
        @SuppressWarnings("unused")
90 89
        String nomStatus = getValue(record, NOM_STATUS);
91 90

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

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

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

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

  
105
        DoubleResult<String, String> origPubl = origPublicationMap.get(nomenId);
106
        boolean useOrigPubl = false;
107
        if (isBlank(publication) && origPubl != null) {
108
            publication = origPubl.getFirstResult();
109
            useOrigPubl = true;
110
            logger.warn(row + "use original (Nomen.xlsx) publication and/or year");
111
        }
112

  
113
        if ("ined.".equals(publication)) {
114
            publication = null;
115
            NomenclaturalStatusType type = NomenclaturalStatusType.INED();
116
            if (name.hasStatus(type)) {
117
                name.addStatus(type, null, null);
118
            }
119
        }
104 120

  
105 121
        ReferenceType refType = getRefType(pubType);
106
        if (refType == null) {
107
            logger.warn(row + "reference type not found");
122
        if (refType == null && isNotBlank(publication)) {
123
            logger.warn(row + "reference type not found for: " + publication);
124
        }else if (publication == null) {
125
            if (!name.isAutonym()) {
126
                logger.warn(row + "no publication");
127
            }
108 128
        }else if (refType == ReferenceType.Article) {
109
            publication = "in " + publication;
129
            if (!publication.startsWith("in ")) {
130
                publication = " in " + publication;
131
            }else {
132
                publication = " " + publication;
133
            }
110 134
        }else if (refType == ReferenceType.Book) {
111
            //
135
            if (publication.startsWith("in ")) {
136
                publication = " " + publication;
137
            }else if (publication.contains(",")) {
138
//                logger.warn(row + "book with ',': " + publication);
139
                String[] split = publication.split(",");
140
                String potentialAuthor = split[0];
141
                if (potentialAuthor.split(" ").length <= 2) {
142
                    boolean noAbbrev = true;
143
                    for(String str : potentialAuthor.split(" ")) {
144
                        if (str.endsWith(".")) {
145
                            noAbbrev = false;
146
                            break;
147
                        }
148
                    }
149
                    if (noAbbrev) {
150
                        refType = ReferenceType.BookSection;
151
                        publication = " in " + publication;
152
                    }else {
153
//                        logger.warn(row + "probably only abbrev title");
154
                        publication = ", " + publication;
155
                    }
156
                } else {
157
//                    logger.warn(row + "probably not booksection");
158
                    publication = ", " + publication;
159
                }
160
            }else {
161
                publication = ", " + publication;
162
            }
112 163
        }else {
113 164
            logger.warn(row + "reference type not handled: " + refType);
165
            publication = ", " + publication;
114 166
        }
115
        String referenceName = name.getTitleCache()+ " " + publication;
116
        TaxonName parsedName = parser.parseReferencedName(referenceName);
167
        String referenceName = CdmUtils.concat("", name.getTitleCache(), publication);
168
        TaxonName parsedName = parser.parseReferencedName(referenceName, NomenclaturalCode.ICNAFP, null);
117 169
        if (parsedName.isProtectedFullTitleCache() || parsedName.isProtectedTitleCache() ) {
118
            logger.warn(row + "name could not be parsed");
170
            logger.warn(row + "name could not be parsed: " + referenceName);
119 171
        }else {
120 172
            Reference ref = parsedName.getNomenclaturalReference();
173
            if (useOrigPubl && origPubl != null && origPubl.getSecondResult() != null) {
174
                if (ref != null) {
175
                    ref.setDatePublished(TimePeriodParser.parseStringVerbatim(origPubl.getSecondResult()));
176
                }else {
177
                    ref = ReferenceFactory.newGeneric();
178
                    ref.setDatePublished(TimePeriodParser.parseStringVerbatim(origPubl.getSecondResult()));
179
                }
180
                logger.warn(row + "set original (Nomen.xlsx) year");
181
            }
121 182
            name.setNomenclaturalReference(ref);
122 183
            String microRef = parsedName.getNomenclaturalMicroReference();
123 184
            name.setNomenclaturalMicroReference(microRef);
......
125 186

  
126 187
        //validateName (name);
127 188
        validateName(name, nameStr, row);
189

  
128 190
        //deduplicate
129 191
        dedupliateNameParts(name);
130 192

  
......
134 196
            if (origName.isProtectedTitleCache()) {
135 197
                logger.warn(row + "orig name could not be parsed");
136 198
            }
137
            name.getNomenclaturalSource().setNameUsedInSource(origName);
199
            if (name.getNomenclaturalSource() == null) {
200
                logger.warn(row + "no nomsource yet");
201
            }
202
            name.getNomenclaturalSource(true).setNameUsedInSource(origName);
203
            origSpellingNames.add(origName);
138 204
        }
139 205
    }
140 206

  
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");
207
    private void validateName(TaxonName name, String nomRefStr, String row) {
208
        nomRefStr = nomRefStr.replace("× ", "×");
209
        nomRefStr = nomRefStr.replace(" unranked ", " [unranked] ");
210
        nomRefStr = nomRefStr.replace(" [infrasp.unranked] ", " [infraspec.] ");
211

  
212
        if (!name.getTitleCache().equals(nomRefStr)) {
213
            TaxonName nomRefName = (TaxonName)parser.parseFullName(nomRefStr, NomenclaturalCode.ICNAFP, null);
214
            if (!nomRefName.getNameCache().equals(name.getNameCache())) {
215
                logger.warn(row+ "nameCache does not match: " + name.getNameCache() + "<->" + nomRefName.getNameCache());
216
                if (!CdmUtils.Nz(name.getAuthorshipCache()).equals(nomRefName.getAuthorshipCache())) {
217
                    logger.warn(row+ "also authorship differs: " + name.getAuthorshipCache() + "<->" + nomRefName.getAuthorshipCache());
218
                }
219
            }else {
220
                logger.warn(row+ "authors/titleCache do not match: " + name.getTitleCache() + "<->" + nomRefStr);
221
            }
222
            if (!CdmUtils.Nz(name.getAuthorshipCache()).equals(nomRefName.getAuthorshipCache())) {
223
                if (isBlank(nomRefName.getAuthorshipCache())) {
224
                    logger.warn(row + "'NomRef' authorship is empty but differs. Kept 'Nomen' authorship");
225
                }else {
226
                    name.setCombinationAuthorship(nomRefName.getCombinationAuthorship());
227
                    name.setExCombinationAuthorship(nomRefName.getExCombinationAuthorship());
228
                    name.setBasionymAuthorship(nomRefName.getBasionymAuthorship());
229
                    name.setExBasionymAuthorship(nomRefName.getExBasionymAuthorship());
230
                }
231
            }
144 232
        }
145 233
    }
146 234

  
......
160 248
        return name;
161 249
    }
162 250

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

  
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
        }
252
    private boolean first = true;
253
    @Override
254
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
212 255

  
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.");
256
         if (first) {
257
            if (origNameMap.size() > 0) {
258
                logger.warn("There are " +  origNameMap.size() + " unhandled names");
259
                for (Integer key : origNameMap.keySet()) {
260
                    System.out.println(key + ": " + origNameMap.get(key).getTitleCache());
237 261
                }
238 262
            }
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 263

  
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;
264
            Set<TaxonName> commonSet = new HashSet<>(nameMap.values());
265
            commonSet.addAll(origNameMap.values());
266
            commonSet.addAll(origSpellingNames);
267
            try {
268
                getNameService().saveOrUpdate(commonSet);
269
            } catch (Exception e) {
270
                e.printStackTrace();
271
            }
272
            first = false;
342 273
        }
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 274
    }
361 275
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeSynonymImport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.caryo;
10 10

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

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

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

  
27 24
/**
28 25
 * @author a.mueller
......
38 35
    private static final String NOMEN_LINK = "Nomen_link";
39 36
    private static final String TAXON_LINK = "Taxon_link";
40 37

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

  
43
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
38
    @Override
39
    protected String getWorksheetName(CaryoSileneaeImportConfigurator config) {
40
        return "Synonyms";
41
    }
44 42

  
45 43
    @Override
46 44
    protected void firstPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
......
50 48
            System.out.println(line);
51 49
        }
52 50

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

  
56 53
        Integer nomTaxId = Integer.valueOf(getValue(record, NOMTAX_ID));
......
60 57

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

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

  
65 62
        if (name == null) {
66 63
            logger.warn(row + "Name does not exist");
......
69 66

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

  
72
        Taxon taxon = getTaxon(state, taxonLinkId);
69
        Taxon taxon = getTaxon(taxonLinkId);
73 70
        if (taxon == null) {
74 71
            logger.warn(row + "Taxon does not exist");
75 72
            return;
76 73
        }
74

  
77 75
        //TODO type (compute homotypics)
76

  
78 77
        taxon.addSynonym(synonym, SynonymType.SYNONYM_OF);
78
        orphanedNameMap.remove(nameLinkID);
79
        getTaxonService().saveOrUpdate(taxon);  //TODO does with work with session handling? I forgot it for the final import
79 80
    }
80 81

  
82
    boolean first = true;
81 83
    @Override
82 84
    protected void secondPass(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
85
        if (first) {
86
            for (TaxonName taxonName : orphanedNameMap.values()) {
87
                Taxon taxon = Taxon.NewInstance(taxonName, getSecRef(state));
88
                TaxonNode node = getUnresolvedNode(state).addChildTaxon(taxon, null);
89
                getTaxonNodeService().saveOrUpdate(node);
90
            }
91
            first = false;
92
        }
83 93
    }
84 94

  
85
    private boolean hasSameAcceptedTaxon(TaxonBase<?> taxonBase, TaxonBase<?> basionymTaxon) {
86
        if (taxonBase.isInstanceOf(Synonym.class)){
87
            taxonBase = CdmBase.deproxy(taxonBase, Synonym.class).getAcceptedTaxon();
95
    private TaxonNode unresolvedNode;
96
    private TaxonNode getUnresolvedNode(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
97
        if (unresolvedNode == null) {
98
            unresolvedNode = getTaxonNodeService().find(state.getConfig().getUnresolvedNodeUuid());
88 99
        }
89
        if (basionymTaxon.isInstanceOf(Synonym.class)){
90
            basionymTaxon = CdmBase.deproxy(basionymTaxon, Synonym.class).getAcceptedTaxon();
91
        }
92
        return taxonBase != null && basionymTaxon != null && taxonBase.equals(basionymTaxon);
100
        return unresolvedNode;
93 101
    }
102

  
94 103
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeTaxonImport.java
8 8
*/
9 9
package eu.etaxonomy.cdm.io.caryo;
10 10

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

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

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

  
30 23
/**
......
41 34
    private static final String NOMEN_LINK = "nomen_link";
42 35
    private static final String PARENT = "parent";
43 36

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

  
47
    private SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state;
37
    @Override
38
    protected String getWorksheetName(CaryoSileneaeImportConfigurator config) {
39
        return "Taxa";
40
    }
48 41

  
49 42
    @Override
50 43
    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();
44
        try {
45
            int line = state.getCurrentLine();
46
//            if ((line % 500) == 0){
47
//                newTransaction(state);
48
//                System.out.println(line);
49
//            }
59 50

  
60
        Integer accTaxonId = Integer.valueOf(getValue(record, ACCEPTED_TAXON_ID));
61
        Integer nameLinkID = Integer.valueOf(getValue(record, NOMEN_LINK));
51
            Map<String, String> record = state.getOriginalRecord();
62 52

  
63
        String row = String.valueOf(line) + "("+accTaxonId+"): ";
53
            Integer accTaxonId = Integer.valueOf(getValue(record, ACCEPTED_TAXON_ID));
54
            Integer nameLinkID = Integer.valueOf(getValue(record, NOMEN_LINK));
64 55

  
65
        TaxonName name = getName(state, nameLinkID);
56
            String row = String.valueOf(line) + "("+accTaxonId+"): ";
66 57

  
67
        if (name == null) {
68
            logger.warn(row + "Name does not exist");
69
            return;
70
        }
58
            TaxonName name = getName(nameLinkID);
59
            if (name == null) {
60
                logger.warn(row + "Name does not exist");
61
                return;
62
            }
71 63

  
72
        Taxon taxon = Taxon.NewInstance(name, getSecRef(state));
64
            orphanedNameMap.remove(nameLinkID);
65
            Taxon taxon = Taxon.NewInstance(name, getSecRef(state));
73 66

  
74
        getTaxonService().saveOrUpdate(taxon);
67
            putToTaxonMap(accTaxonId, taxon);
68
            getTaxonService().saveOrUpdate(taxon);
69
        } catch (Exception e) {
70
            e.printStackTrace();
71
        }
75 72
    }
76 73

  
77 74
    @Override
78 75
    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;
76
        try {
77
            int line = state.getCurrentLine();
78
//            if ((line % 500) == 0){
79
//                newTransaction(state);
80
//                System.out.println(line);
81
//            }
82

  
83
            Map<String, String> record = state.getOriginalRecord();
84

  
85
            Integer accTaxonId = Integer.valueOf(getValue(record, ACCEPTED_TAXON_ID));
86
            Integer parentId = getInt(getValue(record, PARENT));
87

  
88
            String row = String.valueOf(line) + "("+accTaxonId+"): ";
89

  
90
            Taxon taxon = getTaxon(accTaxonId);
91
            if (taxon == null) {
92
                logger.warn(row + "Taxon does not exist");
93
                return;
94
            }
95

  
96
            Taxon parent;
97
            if (parentId == null) {
98
                TaxonNode rootNode = getRootNode(state);
99
                parent = rootNode.getTaxon();
100
            }else {
101
                parent = getTaxon(parentId);
102

  
103
            }
104
            if (parent == null) {
105
                logger.warn(row + "Taxon does not exist");
106
                return;
107
            }
108
            Classification classification = getClassification(state);
109

  
110
            TaxonNode node = classification.addParentChild(parent, taxon, null, null);
111

  
112
            getTaxonNodeService().saveOrUpdate(node);
113
        } catch (Exception e) {
114
            e.printStackTrace();
97 115
        }
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 116
    }
117 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();
118
    private TaxonNode rootNode;
119
    private TaxonNode getRootNode(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
120
        if (rootNode == null) {
121
            rootNode = getTaxonNodeService().find(state.getConfig().getAcceptedNodeUuid());
124 122
        }
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;
123
        return rootNode;
132 124
    }
133 125

  
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;
126
    private Classification classification;
127
    private Classification getClassification(SimpleExcelTaxonImportState<CaryoSileneaeImportConfigurator> state) {
128
        if (classification == null) {
129
            classification = getClassificationService().find(state.getConfig().getClassificationUuid());
130
        }
131
        return classification;
143 132
    }
144 133
}
app-import/src/main/java/eu/etaxonomy/cdm/io/caryo/CaryoSileneaeTransformer.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.caryo;
10

  
11
import org.apache.commons.lang3.StringUtils;
12
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.Logger;
14

  
15
import eu.etaxonomy.cdm.io.common.mapping.InputTransformerBase;
16
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
18
import eu.etaxonomy.cdm.model.name.Rank;
19
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
20

  
21
/**
22
 * @author a.mueller
23
 * @since 16.06.2016
24
 */
25
public class CaryoSileneaeTransformer extends InputTransformerBase{
26

  
27
    private static final long serialVersionUID = 4635704148993246218L;
28

  
29
    private static final Logger logger = LogManager.getLogger();
30

  
31
     @Override
32
    public Rank getRankByKey(String key) throws UndefinedTransformerMethodException {
33
        if (StringUtils.isBlank(key)){
34
            return null;
35
        }
36
        try {
37
            Rank rank = Rank.getRankByIdInVoc(key, NomenclaturalCode.ICNAFP);
38
            return rank;
39
        } catch (UnknownCdmTypeException e) {
40
            if (key.equals("gen.")) {return Rank.GENUS();
41
            } else if (key.equals("spec.")) {return Rank.SPECIES();
42
            } else if (key.equals("unranked")) {return Rank.UNRANKED_INFRAGENERIC();
43
            } else if (key.equals("[infrasp.unranked]")) {return Rank.UNRANKED_INFRASPECIFIC();
44
            } else{
45
                logger.warn("Rank not defined: " + key);
46
                return null;
47
            }
48
        }
49

  
50
    }
51
}

Also available in: Unified diff