Project

General

Profile

« Previous | Next » 

Revision a2c424c2

Added by Patrick Plitzner over 7 years ago

#5488 Improve import of family taxa

  • Load families in related object methods

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
15 15
import java.util.HashMap;
16 16
import java.util.HashSet;
17 17
import java.util.Map;
18
import java.util.Map.Entry;
18 19
import java.util.Set;
19 20
import java.util.UUID;
20 21

  
......
80 81
    protected void doInvoke(RedListGefaesspflanzenImportState state) {
81 82
        Classification gesamtListe = makeClassification("Gesamtliste", state.getConfig().getClassificationUuid(), "Gesamtliste", null, RedListUtil.gesamtListeReferenceUuid, state);
82 83
        Classification checkliste = makeClassification("Checkliste", RedListUtil.checkListClassificationUuid, "Checkliste", null, RedListUtil.checkListReferenceUuid, state);
83
        makeClassification("E", RedListUtil.uuidClassificationE, "Ehrendorfer", null, RedListUtil.uuidClassificationReferenceE, state);
84
        makeClassification("W", RedListUtil.uuidClassificationW, "Wisskirchen (Standardliste)", 1998, RedListUtil.uuidClassificationReferenceW, state);
85
        makeClassification("K", RedListUtil.uuidClassificationK, "Korneck (Rote Liste)", 1996, RedListUtil.uuidClassificationReferenceK, state);
86
        makeClassification("AW", RedListUtil.uuidClassificationAW, "Atlas (Westdeutschland)", 1988, RedListUtil.uuidClassificationReferenceAW, state);
87
        makeClassification("AO", RedListUtil.uuidClassificationAO, "Atlas (Ostdeutschland)", 1996, RedListUtil.uuidClassificationReferenceAO, state);
88
        makeClassification("R", RedListUtil.uuidClassificationR, "Rothmaler", 2011, RedListUtil.uuidClassificationReferenceR, state);
89
        makeClassification("O", RedListUtil.uuidClassificationO, "Oberdorfer", 2001, RedListUtil.uuidClassificationReferenceO, state);
90
        makeClassification("S", RedListUtil.uuidClassificationS, "Schmeil-Fitschen", 2011, RedListUtil.uuidClassificationReferenceS, state);
84
        makeClassification("Ehrendorfer", RedListUtil.uuidClassificationE, "Ehrendorfer", null, RedListUtil.uuidClassificationReferenceE, state);
85
        makeClassification("Wisskirchen (Standardliste)", RedListUtil.uuidClassificationW, "Wisskirchen (Standardliste)", 1998, RedListUtil.uuidClassificationReferenceW, state);
86
        makeClassification("Korneck (Rote Liste)", RedListUtil.uuidClassificationK, "Korneck (Rote Liste)", 1996, RedListUtil.uuidClassificationReferenceK, state);
87
        makeClassification("Atlas (Westdeutschland)", RedListUtil.uuidClassificationAW, "Atlas (Westdeutschland)", 1988, RedListUtil.uuidClassificationReferenceAW, state);
88
        makeClassification("Atlas (Ostdeutschland)", RedListUtil.uuidClassificationAO, "Atlas (Ostdeutschland)", 1996, RedListUtil.uuidClassificationReferenceAO, state);
89
        makeClassification("Rothmaler", RedListUtil.uuidClassificationR, "Rothmaler", 2011, RedListUtil.uuidClassificationReferenceR, state);
90
        makeClassification("Oberdorfer", RedListUtil.uuidClassificationO, "Oberdorfer", 2001, RedListUtil.uuidClassificationReferenceO, state);
91
        makeClassification("Schmeil-Fitschen", RedListUtil.uuidClassificationS, "Schmeil-Fitschen", 2011, RedListUtil.uuidClassificationReferenceS, state);
91 92
        importFamilies(gesamtListe, checkliste, state);
92 93
        super.doInvoke(state);
93 94
    }
......
139 140
        logger.info("Update classification (1000 nodes)");
140 141
        getClassificationService().saveOrUpdate(gesamtListeClassification);
141 142
        getClassificationService().saveOrUpdate(checklistClassification);
143
        getClassificationService().saveOrUpdate(classificationE);
144
        getClassificationService().saveOrUpdate(classificationW);
145
        getClassificationService().saveOrUpdate(classificationK);
146
        getClassificationService().saveOrUpdate(classificationAW);
147
        getClassificationService().saveOrUpdate(classificationAO);
148
        getClassificationService().saveOrUpdate(classificationR);
149
        getClassificationService().saveOrUpdate(classificationO);
150
        getClassificationService().saveOrUpdate(classificationS);
142 151
        return true;
143 152
    }
144 153

  
......
165 174

  
166 175
        //Gesamtliste
167 176
        TaxonBase<?> taxonBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class);
168
        TaxonBase<?> parentBaseGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
169
        if(parentBaseGL!=null && !parentBaseGL.isInstanceOf(Taxon.class)){
170
            RedListUtil.logMessage(id, parentBaseGL+" is no taxon but is a parent of "+taxonBaseGL+" (Gesamtliste)", logger);
177
        Taxon parentGL = state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, Taxon.class);
178
        if(parentGL!=null && !parentGL.isInstanceOf(Taxon.class)){
179
            RedListUtil.logMessage(id, parentGL+" is no taxon but is a parent of "+taxonBaseGL+" (Gesamtliste)", logger);
171 180
        }
172
        Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
173 181
        //add to family if no parent found
174
        if(parentBaseGL==null){
182
        if(parentGL==null){
175 183
            if(!taxonBaseGL.isInstanceOf(Taxon.class)){
176 184
                RedListUtil.logMessage(id, taxonBaseGL+" has no parent but is not a taxon.", logger);
177 185
            }
178 186
            else{
179
                Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
187
                Taxon family = (Taxon) state.getRelatedObject(RedListUtil.FAMILY_NAMESPACE, familieString);
180 188
                gesamtListeClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseGL, Taxon.class), null, null);
181 189
            }
182 190
        }
......
187 195

  
188 196
        //Checkliste
189 197
        TaxonBase<?> taxonBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class);
190
        TaxonBase<?> parentBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
191
        if(parentBaseCL!=null && !parentBaseCL.isInstanceOf(Taxon.class)){
192
            RedListUtil.logMessage(id, parentBaseCL+" is no taxon but is a parent of "+taxonBaseCL+" (Checkliste)", logger);
198
        Taxon parentCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, Taxon.class);
199
        if(parentCL!=null && !parentCL.isInstanceOf(Taxon.class)){
200
            RedListUtil.logMessage(id, parentCL+" is no taxon but is a parent of "+taxonBaseCL+" (Checkliste)", logger);
193 201
        }
194
        Taxon parentCL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
195 202
        if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
196 203
            //add to family if no parent found
197 204
            if(parentCL==null){
......
199 206
                    RedListUtil.logMessage(id, taxonBaseCL+" has no parent but is not a taxon.", logger);
200 207
                }
201 208
                else{
202
                    Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
209
                    Taxon family = (Taxon) state.getRelatedObject(RedListUtil.FAMILY_NAMESPACE, familieString);
203 210
                    checklistClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseCL, Taxon.class), null, null);
204 211
                }
205 212
            }
......
229 236
        addTaxonToClassification(classificationS, RedListUtil.CLASSIFICATION_NAMESPACE_S, relationS, taxonBaseGL, taxonBaseCL, id, state);
230 237
    }
231 238

  
239

  
240

  
232 241
    private void addTaxonToClassification(Classification classification, String classificationNamespace, String relationString, final TaxonBase<?> gesamtListeTaxon, final TaxonBase<?> checklisteTaxon, long id, RedListGefaesspflanzenImportState state){
233 242
        Taxon taxon = HibernateProxyHelper.deproxy(state.getRelatedObject(classificationNamespace, String.valueOf(id), TaxonBase.class), Taxon.class);
234 243
        //add concept relation to gesamtliste and checkliste
......
356 365
        } catch (SQLException e) {
357 366
            e.printStackTrace();
358 367
        }
368
        //add taxa and their parent taxa
359 369
        result.put(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_GESAMTLISTE_NAMESPACE));
360 370
        result.put(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.TAXON_CHECKLISTE_NAMESPACE));
361 371
        result.put(RedListUtil.CLASSIFICATION_NAMESPACE_E, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.CLASSIFICATION_NAMESPACE_E));
......
366 376
        result.put(RedListUtil.CLASSIFICATION_NAMESPACE_R, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.CLASSIFICATION_NAMESPACE_R));
367 377
        result.put(RedListUtil.CLASSIFICATION_NAMESPACE_O, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.CLASSIFICATION_NAMESPACE_O));
368 378
        result.put(RedListUtil.CLASSIFICATION_NAMESPACE_S, (Map<String, TaxonBase>) getCommonService().getSourcedObjectsByIdInSource(TaxonBase.class, idSet, RedListUtil.CLASSIFICATION_NAMESPACE_S));
379

  
380
        //add families
381
        Map<String, Taxon> familyMap = new HashMap<String, Taxon>();
382
        for (Entry<String, UUID> entry: state.getFamilyMap().entrySet()) {
383
            familyMap.put(entry.getKey(), HibernateProxyHelper.deproxy(getTaxonService().load(entry.getValue()), Taxon.class));
384
        }
385
        result.put(RedListUtil.FAMILY_NAMESPACE, familyMap);
369 386
        return result;
370 387
    }
371 388

  
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
57 57
    public static final String CLASSIFICATION_NAMESPACE_R = "classification_namespace_r";
58 58
    public static final String CLASSIFICATION_NAMESPACE_O = "classification_namespace_o";
59 59
    public static final String CLASSIFICATION_NAMESPACE_S = "classification_namespace_s";
60
    public static final String FAMILY_NAMESPACE = "family_namespace";
60 61

  
61 62

  
62 63
    //cell content

Also available in: Unified diff