Project

General

Profile

« Previous | Next » 

Revision c98ea2df

Added by Patrick Plitzner almost 7 years ago

#5448 Add taxa to their respective families

View differences:

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

  
69 69
    @Override
70 70
    protected String getRecordQuery(RedListGefaesspflanzenImportConfigurator config) {
71
        String result = " SELECT * "
72
                + " FROM V_TAXATLAS_D20_EXPORT t "
73
                + " WHERE t.NAMNR IN (@IDSET)";
71
        String result = "select e.*, f.FAMILIE "
72
                + "from V_TAXATLAS_D20_EXPORT e, V_TAXATLAS_D20_FAMILIEN f "
73
                + "where e.NAMNR = f.NAMNR and e.NAMNR IN (@IDSET)";
74 74
        result = result.replace("@IDSET", IPartitionedIO.ID_LIST_TOKEN);
75 75
        return result;
76 76
    }
77 77

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

  
93 94

  
95
    private void importFamilies(Classification gesamtListe, Classification checkliste,
96
            RedListGefaesspflanzenImportState state) {
97
        for(UUID uuid:state.getFamilyMap().values()){
98
            Taxon familyGL = HibernateProxyHelper.deproxy(getTaxonService().load(uuid), Taxon.class);
99
            Taxon familyCL = (Taxon) familyGL.clone();
100

  
101
            gesamtListe.addChildTaxon(familyGL, null, null);
102
            familyGL.setSec(gesamtListe.getReference());
103

  
104
            checkliste.addChildTaxon(familyCL, null, null);
105
            familyCL.setSec(checkliste.getReference());
106
        }
107
    }
108

  
94 109
    @Override
95 110
    public boolean doPartition(ResultSetPartitioner partitioner, RedListGefaesspflanzenImportState state) {
96 111
        ResultSet rs = partitioner.getResultSet();
......
131 146
        String parentId = String.valueOf(rs.getLong(RedListUtil.LOWER));
132 147
        String gueltString = rs.getString(RedListUtil.GUELT);
133 148
        String taxZusatzString = rs.getString(RedListUtil.TAX_ZUSATZ);
149
        String familieString = rs.getString(RedListUtil.FAMILIE);
134 150

  
135 151
        String relationE = rs.getString(RedListUtil.E);
136 152
        String relationW = rs.getString(RedListUtil.W);
......
148 164
            RedListUtil.logMessage(id, parentBaseGL+" is no taxon but is a parent of "+taxonBaseGL+" (Gesamtliste)", logger);
149 165
        }
150 166
        Taxon parentGL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_GESAMTLISTE_NAMESPACE, parentId, TaxonBase.class);
151
        createParentChildNodes(gesamtListeClassification, id, gueltString, taxZusatzString, taxonBaseGL, parentGL);
167
        //add to family if no parent found
168
        if(parentGL==null){
169
            if(taxonBaseGL.isInstanceOf(Taxon.class)){
170
                Taxon family = HibernateProxyHelper.deproxy(getTaxonService().load(state.getFamilyMap().get(familieString)), Taxon.class);
171
                gesamtListeClassification.addParentChild(family, HibernateProxyHelper.deproxy(taxonBaseGL, Taxon.class), null, null);
172
            }
173
            else{
174
                RedListUtil.logMessage(id, taxonBaseGL+" has no parent but is not a taxon.", logger);
175
            }
176
        }
177
        else{
178
            createParentChildNodes(gesamtListeClassification, id, gueltString, taxZusatzString, taxonBaseGL, parentGL);
179
        }
152 180

  
153 181
        //Checkliste
154 182
        TaxonBase<?> taxonBaseCL = state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, String.valueOf(id), TaxonBase.class);
......
157 185
            RedListUtil.logMessage(id, parentBaseCL+" is no taxon but is a parent of "+taxonBaseCL+" (Checkliste)", logger);
158 186
        }
159 187
        Taxon parentCL = (Taxon) state.getRelatedObject(RedListUtil.TAXON_CHECKLISTE_NAMESPACE, parentId, TaxonBase.class);
160
        if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
161
            createParentChildNodes(checklistClassification, id, gueltString, taxZusatzString, taxonBaseCL, parentCL);
188
        //add to family if no parent found
189
        if(parentCL==null){
190

  
191
        }
192
        else{
193
            if(taxonBaseCL!=null){//null check necessary because not all taxa exist in the checklist
194
                createParentChildNodes(checklistClassification, id, gueltString, taxZusatzString, taxonBaseCL, parentCL);
195
            }
162 196
        }
163 197

  
198
        //check uuids
164 199
        if(taxonBaseGL!= null && taxonBaseCL!=null
165 200
                && taxonBaseGL.getUuid().equals(taxonBaseCL.getUuid())){
166 201
            RedListUtil.logMessage(id, "Same UUID for "+taxonBaseGL+ " (Gesamtliste) and "+taxonBaseCL+" (Checkliste)", logger);
......
320 355
        return result;
321 356
    }
322 357

  
323
    private void makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
358
    private Classification makeClassification(String classificationName, UUID classificationUuid, String referenceName, Integer yearPublished, UUID referenceUuid, RedListGefaesspflanzenImportState state) {
324 359
        Classification classification = Classification.NewInstance(classificationName, Language.DEFAULT());
325 360
        classification.setUuid(classificationUuid);
326 361
        Reference reference = ReferenceFactory.newGeneric();
......
331 366
            reference.setDatePublished(TimePeriod.NewInstance(yearPublished));
332 367
        }
333 368
        getClassificationService().save(classification);
369
        return classification;
334 370
    }
335 371

  
336 372
    @Override
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/gefaesspflanzen/RedListUtil.java
106 106
    public static final String EHRD = "EHRD";
107 107
    public static final String WISSK = "WISSK";
108 108

  
109
    public static final String FAMILIE = "FAMILIE";
110

  
109 111
    public static final String E = "E";
110 112
    public static final String W = "W";
111 113
    public static final String K = "K";

Also available in: Unified diff