Project

General

Profile

« Previous | Next » 

Revision f3f4d328

Added by Patrick Plitzner almost 8 years ago

Refactor names and taxa creation #5448

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportNames.java
120 120
        String hybString = rs.getString(RedListUtil.HYB);
121 121

  
122 122
        //---NAME---
123
        if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
124
            RedListUtil.logMessage(id, "No name found!", logger);
125
        }
123
        BotanicalName name = importName(state, id, taxNameString, rangString, ep1String, ep2String, ep3String,
124
                nomZusatzString, hybString, namesToSave);
126 125

  
127
        Rank rank = makeRank(id, state, rangString);
128
        BotanicalName name = BotanicalName.NewInstance(rank);
129 126

  
130
        //ep1 should always be present
131
        if(CdmUtils.isBlank(ep1String)){
132
            RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
127
        //--- AUTHORS ---
128
        importAuthors(state, rs, id, nomZusatzString, taxZusatzString, zusatzString, authorKombString,
129
                authorBasiString, name);
130

  
131
        //---TAXON---
132
        TaxonBase taxonBase = importTaxon(id, taxNameString, gueltString, authorBasiString, hybString, name);
133
        if(taxonBase==null){
134
            RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
135
            return;
133 136
        }
134
        name.setGenusOrUninomial(ep1String);
135
        if(CdmUtils.isNotBlank(ep2String)){
136
            name.setSpecificEpithet(ep2String);
137

  
138
        /*check if taxon/synonym is also in checklist
139
         * 1. create new taxon with the same name (in the checklist classification)
140
         * 2. create congruent concept relationship between both
141
         */
142
        String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
143
        if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
144
            cloneToClassification(taxonBase, name, TaxonRelationshipType.CONGRUENT_TO(), taxaToSave, id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE, state);
137 145
        }
138
        if(CdmUtils.isNotBlank(ep3String)){
139
            if(rank==Rank.SUBSPECIES() ||
140
                    rank==Rank.VARIETY()){
141
                name.setInfraSpecificEpithet(ep3String);
146

  
147
        //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
148
        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
149
        taxaToSave.add(taxonBase);
150
    }
151

  
152
    private void cloneToClassification(TaxonBase taxonBase, TaxonNameBase name, TaxonRelationshipType taxonRelationshipType, Set<TaxonBase> taxaToSave, long id, String sourceNameSpace, RedListGefaesspflanzenImportState state){
153
            TaxonBase clone = (TaxonBase) taxonBase.clone();
154
            clone.setName(name);
155
            if(taxonBase.isInstanceOf(Taxon.class)){
156
                TaxonRelationship taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, taxonRelationshipType, null, null);
157
                taxonRelation.setDoubtful(true);//TODO Ist das mit " mit Fragezeichen" gemeint?
142 158
            }
159
            ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, sourceNameSpace);
160
            taxaToSave.add(clone);
161
    }
162

  
163
    private TaxonBase importTaxon(long id, String taxNameString, String gueltString, String authorBasiString,
164
            String hybString, BotanicalName name) {
165
        TaxonBase taxonBase = null;
166
        if(authorBasiString.trim().contains(RedListUtil.AUCT)){
167
            taxonBase = Taxon.NewInstance(name, null);
168
            taxonBase.setAppendedPhrase(RedListUtil.AUCT);
143 169
        }
144
        //nomenclatural status
145
        if(CdmUtils.isNotBlank(nomZusatzString)){
146
            NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
147
            if(status!=null){
148
                name.addStatus(NomenclaturalStatus.NewInstance(status));
149
            }
170
        else if(gueltString.equals(RedListUtil.GUELT_ACCEPTED_TAXON)){
171
            taxonBase = Taxon.NewInstance(name, null);
150 172
        }
151
        //hybrid
152
        if(hybString.equals(RedListUtil.HYB_X)){
153
            name.setBinomHybrid(true);
173
        else if(gueltString.equals(RedListUtil.GUELT_SYNONYM) || gueltString.equals(RedListUtil.GUELT_BASIONYM)){
174
            taxonBase = Synonym.NewInstance(name, null);
154 175
        }
155
        else if(hybString.equals(RedListUtil.HYB_XF)){
156
            name.setTrinomHybrid(true);
176
        else{
177
            return null;
157 178
        }
158 179

  
180
        //check taxon name consistency
181
        checkTaxonNameConsistency(id, taxNameString, hybString, taxonBase);
182
        return taxonBase;
183
    }
159 184

  
160
        //--- AUTHORS ---
185
    private void importAuthors(RedListGefaesspflanzenImportState state, ResultSet rs, long id, String nomZusatzString,
186
            String taxZusatzString, String zusatzString, String authorKombString, String authorBasiString,
187
            BotanicalName name) throws SQLException {
161 188
        //combination author
162 189
        if(authorKombString.contains(RedListUtil.EX)){
163 190
            //TODO: what happens with multiple ex authors??
......
225 252
        //check authorship consistency
226 253
        String authorString = rs.getString(RedListUtil.AUTOR);
227 254
        String authorshipCache = name.getAuthorshipCache();
255
        checkAuthorShipConsistency(id, nomZusatzString, taxZusatzString, zusatzString, authorString, authorshipCache);
256
    }
257

  
258
    private BotanicalName importName(RedListGefaesspflanzenImportState state, long id, String taxNameString,
259
            String rangString, String ep1String, String ep2String, String ep3String, String nomZusatzString,
260
            String hybString, Set<TaxonNameBase> namesToSave) {
261
        if(CdmUtils.isBlank(taxNameString) && CdmUtils.isBlank(ep1String)){
262
            RedListUtil.logMessage(id, "No name found!", logger);
263
        }
264

  
265
        Rank rank = makeRank(id, state, rangString);
266
        BotanicalName name = BotanicalName.NewInstance(rank);
267

  
268
        //ep1 should always be present
269
        if(CdmUtils.isBlank(ep1String)){
270
            RedListUtil.logMessage(id, RedListUtil.EPI1+" is empty!", logger);
271
        }
272
        name.setGenusOrUninomial(ep1String);
273
        if(CdmUtils.isNotBlank(ep2String)){
274
            name.setSpecificEpithet(ep2String);
275
        }
276
        if(CdmUtils.isNotBlank(ep3String)){
277
            if(rank==Rank.SUBSPECIES() ||
278
                    rank==Rank.VARIETY()){
279
                name.setInfraSpecificEpithet(ep3String);
280
            }
281
        }
282
        //nomenclatural status
283
        if(CdmUtils.isNotBlank(nomZusatzString)){
284
            NomenclaturalStatusType status = makeNomenclaturalStatus(id, state, nomZusatzString);
285
            if(status!=null){
286
                name.addStatus(NomenclaturalStatus.NewInstance(status));
287
            }
288
        }
289
        //hybrid
290
        if(hybString.equals(RedListUtil.HYB_X)){
291
            name.setBinomHybrid(true);
292
        }
293
        else if(hybString.equals(RedListUtil.HYB_XF)){
294
            name.setTrinomHybrid(true);
295
        }
296
        //add source
297
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
228 298

  
299
        namesToSave.add(name);
300
        return name;
301
    }
302

  
303
    private void checkAuthorShipConsistency(long id, String nomZusatzString, String taxZusatzString,
304
            String zusatzString, String authorString, String authorshipCache) {
229 305
        if(CdmUtils.isNotBlank(zusatzString)){
230 306
            authorString = authorString.replace(", "+zusatzString, "");
231 307
        }
......
241 317
        if(!authorString.equals(authorshipCache)){
242 318
            RedListUtil.logMessage(id, "Authorship inconsistent! name.authorhshipCache <-> Column "+RedListUtil.AUTOR+": "+authorshipCache+" <-> "+authorString, logger);
243 319
        }
320
    }
244 321

  
245
        //id
246
        ImportHelper.setOriginalSource(name, state.getTransactionalSourceReference(), id, RedListUtil.NAME_NAMESPACE);
247
        state.getNameMap().put(id, name.getUuid());
248

  
249
        namesToSave.add(name);
250

  
251
        //---TAXON---
252
        TaxonBase taxonBase = null;
253
        if(authorBasiString.trim().contains(RedListUtil.AUCT)){
254
            taxonBase = Taxon.NewInstance(name, null);
255
            taxonBase.setAppendedPhrase(RedListUtil.AUCT);
256
        }
257
        else if(gueltString.equals(RedListUtil.GUELT_ACCEPTED_TAXON)){
258
            taxonBase = Taxon.NewInstance(name, null);
259
        }
260
        else if(gueltString.equals(RedListUtil.GUELT_SYNONYM) || gueltString.equals(RedListUtil.GUELT_BASIONYM)){
261
            taxonBase = Synonym.NewInstance(name, null);
262
        }
263
        if(taxonBase==null){
264
            RedListUtil.logMessage(id, "Taxon for name "+name+" could not be created.", logger);
265
            return;
266
        }
267

  
268
        //check taxon name consistency
322
    private void checkTaxonNameConsistency(long id, String taxNameString, String hybString, TaxonBase taxonBase) {
269 323
        String nameCache = ((BotanicalName)taxonBase.getName()).getNameCache().trim();
270 324

  
271 325
        if(taxNameString.endsWith("agg.")){
......
283 337
        if(!taxNameString.trim().equals(nameCache)){
284 338
            RedListUtil.logMessage(id, "Taxon name inconsistent! taxon.titleCache <-> Column "+RedListUtil.TAXNAME+": "+nameCache+" <-> "+taxNameString, logger);
285 339
        }
286

  
287
        /*check if taxon/synonym is also in checklist
288
         * 1. create new taxon with the same name (in the checklist classification)
289
         * 2. create congruent concept relationship between both
290
         */
291
        String clTaxonString = rs.getString(RedListUtil.CL_TAXON);
292
        if(CdmUtils.isNotBlank(clTaxonString) && !clTaxonString.trim().equals("-")){
293
            TaxonBase clone = (TaxonBase) taxonBase.clone();
294
            clone.setName(name);
295
            if(taxonBase.isInstanceOf(Taxon.class)){
296
                TaxonRelationship taxonRelation = ((Taxon) taxonBase).addTaxonRelation((Taxon) clone, TaxonRelationshipType.CONGRUENT_TO(), null, null);
297
                taxonRelation.setDoubtful(true);//TODO Ist das mit " mit Fragezeichen" gemeint?
298
            }
299
            ImportHelper.setOriginalSource(clone, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_CHECKLISTE_NAMESPACE);
300
            taxaToSave.add(clone);
301
        }
302

  
303
        //NOTE: the source has to be added after cloning or otherwise the clone would also get the source
304
        ImportHelper.setOriginalSource(taxonBase, state.getTransactionalSourceReference(), id, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE);
305
        taxaToSave.add(taxonBase);
306

  
307 340
    }
308 341

  
309 342
    private Rank makeRank(long id, RedListGefaesspflanzenImportState state, String rankStr) {

Also available in: Unified diff