Project

General

Profile

Revision e3cf774c

IDe3cf774c9af8227add3ca10ddc9aa80addba8938
Parent c8c58de5
Child 9e2583cf

Added by Patrick Plitzner about 5 years ago

#5448 Fix import of families

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
78 78

  
79 79
    @Override
80 80
    protected void doInvoke(RedListGefaesspflanzenImportState state) {
81
        makeClassification("Gesamtliste", state.getConfig().getClassificationUuid(), "Gesamtliste", null, RedListUtil.gesamtListeReferenceUuid, state);
82
        makeClassification("Checkliste", RedListUtil.checkListClassificationUuid, "Checkliste", null, RedListUtil.checkListReferenceUuid, state);
81
        Classification gesamtListe = makeClassification("Gesamtliste", state.getConfig().getClassificationUuid(), "Gesamtliste", null, RedListUtil.gesamtListeReferenceUuid, state);
82
        Classification checkliste = makeClassification("Checkliste", RedListUtil.checkListClassificationUuid, "Checkliste", null, RedListUtil.checkListReferenceUuid, state);
83 83
        makeClassification("E", RedListUtil.uuidClassificationE, "Ehrendorfer", null, RedListUtil.uuidClassificationReferenceE, state);
84 84
        makeClassification("W", RedListUtil.uuidClassificationW, "Wisskirchen (Standardliste)", 1998, RedListUtil.uuidClassificationReferenceW, state);
85 85
        makeClassification("K", RedListUtil.uuidClassificationK, "Korneck (Rote Liste)", 1996, RedListUtil.uuidClassificationReferenceK, state);
......
88 88
        makeClassification("R", RedListUtil.uuidClassificationR, "Rothmaler", 2011, RedListUtil.uuidClassificationReferenceR, state);
89 89
        makeClassification("O", RedListUtil.uuidClassificationO, "Oberdorfer", 2001, RedListUtil.uuidClassificationReferenceO, state);
90 90
        makeClassification("S", RedListUtil.uuidClassificationS, "Schmeil-Fitschen", 2011, RedListUtil.uuidClassificationReferenceS, state);
91
        importFamilies(state);
91
        importFamilies(gesamtListe, checkliste, state);
92 92
        super.doInvoke(state);
93 93
    }
94 94

  
95 95

  
96
    private void importFamilies(RedListGefaesspflanzenImportState state) {
97
        Classification gesamtListe = getClassificationService().load(state.getConfig().getClassificationUuid(), Arrays.asList(new String[]{"*, rootNode.childNodes"}));
98
        Classification checkliste = getClassificationService().load(RedListUtil.checkListClassificationUuid, Arrays.asList(new String[]{"*, rootNode.childNodes"}));
96
    private void importFamilies(Classification gesamtListe, Classification checkliste, RedListGefaesspflanzenImportState state) {
99 97
        for(UUID uuid:state.getFamilyMap().values()){
100
            Taxon familyGL = HibernateProxyHelper.deproxy(getTaxonService().load(uuid, Arrays.asList(new String[]{"*, taxon"})), Taxon.class);
98
            Taxon familyGL = HibernateProxyHelper.deproxy(getTaxonService().load(uuid, Arrays.asList(new String[]{"*"})), Taxon.class);
101 99
            Taxon familyCL = (Taxon) familyGL.clone();
102 100
            getTaxonService().saveOrUpdate(familyCL);
103 101

  
......
173 171
        }
174 172
        Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
175 173
        //add to family if no parent found
176
        if(taxonBaseGL.getName().getRank()!=null && taxonBaseGL.getName().getRank().isGenus()){
177
            if(parentBaseGL!=null){
178
                RedListUtil.logMessage(id, taxonBaseGL+" is genus but already had a parent when trying to add to family", logger);
174
        if(parentBaseGL==null){
175
            if(!taxonBaseGL.isInstanceOf(Taxon.class)){
176
                RedListUtil.logMessage(id, taxonBaseGL+" has no parent but is not a taxon.", logger);
179 177
            }
180
            if(taxonBaseGL.isInstanceOf(Taxon.class)){
178
            else{
181 179
                Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
182 180
                gesamtListeClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseGL, Taxon.class), null, null);
183 181
            }
184
            else{
185
                RedListUtil.logMessage(id, taxonBaseGL+" has no parent but is not a taxon.", logger);
186
            }
187 182
        }
183
        //add to higher taxon
188 184
        else{
189 185
            createParentChildNodes(gesamtListeClassification, id, gueltString, taxZusatzString, taxonBaseGL, parentGL);
190 186
        }
......
196 192
            RedListUtil.logMessage(id, parentBaseCL+" is no taxon but is a parent of "+taxonBaseCL+" (Checkliste)", logger);
197 193
        }
198 194
        Taxon parentCL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
199
        //add to family if no parent found
200
        if(parentCL==null){
201

  
202
        }
203
        else{
204
            if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
195
        if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
196
            //add to family if no parent found
197
            if(parentCL==null){
198
                if(!taxonBaseCL.isInstanceOf(Taxon.class)){
199
                    RedListUtil.logMessage(id, taxonBaseCL+" has no parent but is not a taxon.", logger);
200
                }
201
                else{
202
                    Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
203
                    checklistClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseCL, Taxon.class), null, null);
204
                }
205
            }
206
            //add to higher taxon
207
            else{
205 208
                createParentChildNodes(checklistClassification, id, gueltString, taxZusatzString, taxonBaseCL, parentCL);
206 209
            }
207 210
        }
......
366 369
        return result;
367 370
    }
368 371

  
369
    private void makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
372
    private Classification makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
370 373
        Classification classification = Classification.NewInstance(classificationName, Language.DEFAULT());
371 374
        classification.setUuid(classificationUuid);
372 375
        Reference reference = ReferenceFactory.newGeneric();
......
376 379
        if(yearPublished!=null){
377 380
            reference.setDatePublished(TimePeriod.NewInstance(yearPublished));
378 381
        }
379
        getClassificationService().save(classification);
382
        return getClassificationService().save(classification);
380 383
    }
381 384

  
382 385
    @Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)