Project

General

Profile

Revision d5e984f6

IDd5e984f632ef89be3023090f09c6f038dede2b21
Parent 6375d175
Child ae538f84

Added by Patrick Plitzner about 5 years ago

#5448 Fix potential NPEs

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListGefaesspflanzenImportClassification.java
70 70
    @Override
71 71
    protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
72 72
        String result = "select e.*, f.FAMILIE "
73
                + "from V_TAXATLAS_D20_EXPORT e, V_TAXATLAS_D20_FAMILIEN f "
74
                + "where e.NAMNR = f.NAMNR and e.NAMNR IN (@IDSET)";
73
                + "from V_TAXATLAS_D20_EXPORT e, GATTUNG_FAMILIE f "
74
                + "where e.EPI1 = f.GATTUNG and e.NAMNR IN (@IDSET)";
75 75
        result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
76 76
        return result;
77 77
    }
78 78

  
79 79
    @Override
80 80
    protected void doInvoke(RedListGefaesspflanzenImportState 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);
81
        makeClassification("Gesamtliste", state.getConfig().getClassificationUuid(), "Gesamtliste", null, RedListUtil.gesamtListeReferenceUuid, state);
82
        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(gesamtListe, checkliste, state);
91
        importFamilies(state);
92 92
        super.doInvoke(state);
93 93
    }
94 94

  
95 95

  
96
    private void importFamilies(Classification gesamtListe, Classification checkliste,
97
            RedListGefaesspflanzenImportState state) {
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"}));
98 99
        for(UUID uuid:state.getFamilyMap().values()){
99
            Taxon familyGL = HibernateProxyHelper.deproxy(getTaxonService().load(uuid, Arrays.asList(new String[]{"*"})), Taxon.class);
100
            Taxon familyGL = HibernateProxyHelper.deproxy(getTaxonService().load(uuid, Arrays.asList(new String[]{"*, taxon"})), Taxon.class);
100 101
            Taxon familyCL = (Taxon) familyGL.clone();
102
            getTaxonService().saveOrUpdate(familyCL);
101 103

  
102 104
            gesamtListe.addChildTaxon(familyGL, null, null);
103 105
            familyGL.setSec(gesamtListe.getReference());
......
106 108
            checkliste.addChildTaxon(familyCL, null, null);
107 109
            familyCL.setSec(checkliste.getReference());
108 110
            familyCL.setTitleCache(null);
111

  
112
            getClassificationService().saveOrUpdate(gesamtListe);
113
            getClassificationService().saveOrUpdate(checkliste);
109 114
        }
110 115
    }
111 116

  
......
168 173
        }
169 174
        Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
170 175
        //add to family if no parent found
171
        if(parentGL==null){
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);
179
            }
172 180
            if(taxonBaseGL.isInstanceOf(Taxon.class)){
173 181
                Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
174 182
                gesamtListeClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseGL, Taxon.class), null, null);
......
358 366
        return result;
359 367
    }
360 368

  
361
    private Classification makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
369
    private void makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
362 370
        Classification classification = Classification.NewInstance(classificationName, Language.DEFAULT());
363 371
        classification.setUuid(classificationUuid);
364 372
        Reference reference = ReferenceFactory.newGeneric();
......
369 377
            reference.setDatePublished(TimePeriod.NewInstance(yearPublished));
370 378
        }
371 379
        getClassificationService().save(classification);
372
        return classification;
373 380
    }
374 381

  
375 382
    @Override

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)