Project

General

Profile

« Previous | Next » 

Revision 0b2466d9

Added by Patrick Plitzner almost 8 years ago

Ordering of XML elements and some refactoring #5452

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/BfnXmlConstants.java
175 175
    public static final UUID vocRLFeatures =  UUID.fromString("74091f30-faa0-487b-bd7e-c82eed05d3c9");
176 176

  
177 177
    public static final UUID UUID_TAX_NR_IDENTIFIER_TYPE =  UUID.fromString("7d12de50-0db7-47b3-bb8e-703ad1d54fbc");
178
    public static final UUID UUID_REIHENFOLGE_IDENTIFIER_TYPE =  UUID.fromString("97961851-b1c1-41fb-adfd-2961b48f7efe");
178 179

  
179 180
    //redList state Vocabularies
180 181
    public static final UUID vocStateRLKat =  UUID.fromString("66bbb391-af8a-423b-9506-a235b61af922");
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/in/BfnXmlImportTaxonName.java
220 220
		for (Element elTaxon : elTaxonList){
221 221
			//create Taxon
222 222
			String taxonId = elTaxon.getAttributeValue(BfnXmlConstants.ATT_TAXNR);
223
			String reihenfolge = elTaxon.getAttributeValue(BfnXmlConstants.ATT_REIHENFOLGE);
223 224
			childName = BfnXmlConstants.EL_WISSNAME;
224 225
			Element elWissName = XmlHelp.getSingleChildElement(success, elTaxon, childName, bfnNamespace, obligatory);
225 226
			String childElementName = BfnXmlConstants.EL_NANTEIL;
226
			Taxon taxon = createOrUpdateTaxon(success, taxonId, config, bfnNamespace, elWissName, childElementName, state);
227
			Taxon taxon = createOrUpdateTaxon(success, taxonId, reihenfolge, config, bfnNamespace, elWissName, childElementName, state);
227 228

  
228 229
			//for each synonym
229 230
			childName = "SYNONYME";
......
322 323
	 *
323 324
	 * @param success
324 325
	 * @param taxonId
326
	 * @param reihenfolge
325 327
	 * @param config
326 328
	 * @param bfnNamespace
327 329
	 * @param elTaxonName
......
333 335
	@SuppressWarnings({ "unchecked" })
334 336
	private Taxon createOrUpdateTaxon(
335 337
			ResultWrapper<Boolean> success, String taxonId,
336
			BfnXmlImportConfigurator config, Namespace bfnNamespace,
338
			String reihenfolge, BfnXmlImportConfigurator config, Namespace bfnNamespace,
337 339
			Element elTaxonName, String childElementName, BfnXmlImportState state) {
338 340

  
339 341
		List<Element> elWissNameList = elTaxonName.getChildren(childElementName, bfnNamespace);
......
409 411
					taxon.addImportSource(uniqueID, namespace, state.getCompleteSourceRef(), microRefStr);
410 412

  
411 413
					taxon.addIdentifier(taxonId, getIdentiferType(state, BfnXmlConstants.UUID_TAX_NR_IDENTIFIER_TYPE, "taxNr", "TaxNr attribute of Bfn Xml file", "taxNr", null));
414
					taxon.addIdentifier(reihenfolge, getIdentiferType(state, BfnXmlConstants.UUID_REIHENFOLGE_IDENTIFIER_TYPE, "reihenfolge", "reihenfolge attribute of Bfn Xml file", "reihenfolge", null));
412 415
				} catch (UnknownCdmTypeException e) {
413 416
					success.setValue(false);
414 417
				}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/in/BfnXmlTransformer.java
42 42
	    //species group
43 43
	    rankMap.put(BfnXmlConstants.RNK_SUBSP_AGGR, Rank.SUBSPECIFICAGGREGATE());
44 44
	    rankMap.put(BfnXmlConstants.RNK_SSP, Rank.SUBSPECIES());
45
	    rankMap.put(BfnXmlConstants.RNK_SP, Rank.SPECIES());
45
	    rankMap.put(BfnXmlConstants.RNK_SPEZIES, Rank.SPECIES());
46 46
	    //below subspecies
47 47
	    rankMap.put(BfnXmlConstants.RNK_CAND, Rank.CANDIDATE());
48 48
	    rankMap.put(BfnXmlConstants.RNK_TAXINFRASP, Rank.INFRASPECIFICTAXON());
......
92 92
        }else if (rankCode.equals(BfnXmlConstants.RNK_SUBSP)){return Rank.SUBSPECIES();
93 93
        }else if (rankCode.equals(BfnXmlConstants.RNK_SUBSP_DOT)){return Rank.SUBSPECIES();
94 94
        }else if (rankCode.equals(BfnXmlConstants.RNK_INFRAGEN)){return Rank.INFRAGENUS();
95
        }else if (rankCode.equals(BfnXmlConstants.RNK_SPEZIES)){return Rank.SPECIES();
95
        }else if (rankCode.equals(BfnXmlConstants.RNK_SP)){return Rank.SPECIES();
96 96
        }else if (rankCode.equals(BfnXmlConstants.RNK_F)){return Rank.FORM();
97 97
        }else if (rankCode.equals(BfnXmlConstants.RNK_VAR_DOT)){return Rank.VARIETY();
98 98
        }else if (rankCode.equals(BfnXmlConstants.RNK_SUBFAM)){return Rank.FAMILY();
......
102 102
        }else if (rankCode.equals(BfnXmlConstants.RNK_SUBTRIB)){return Rank.FAMILY();
103 103
        }else if (rankCode.equals(BfnXmlConstants.RNK_TRIB)){return Rank.FAMILY();
104 104
        }else if (rankCode.equals(BfnXmlConstants.RNK_SUPERTRIB)){return Rank.FAMILY();
105
        }else {return rankMap.get(rankCode);
105
        }else {
106
            return rankMap.get(rankCode);
106 107
        }
107 108
    }
108 109

  
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlTaxonNameExport.java
11 11
import java.util.Comparator;
12 12
import java.util.List;
13 13
import java.util.Set;
14
import java.util.UUID;
14 15

  
15 16
import org.jdom2.Attribute;
16 17
import org.jdom2.Document;
......
83 84
        Element taxonyme = new Element(BfnXmlConstants.EL_TAXONYME);
84 85
        roteListeDaten.addContent(taxonyme);
85 86
        List<TaxonNode> childNodes = classification.getChildNodes();
86
        java.util.Collections.sort(childNodes, new OriginalSourceComparator());
87
        java.util.Collections.sort(childNodes, new TaxonComparator());
87 88
        for (TaxonNode taxonNode : childNodes) {
88 89
            exportTaxon(taxonNode.getTaxon(), taxonyme, state);
89 90
        }
......
154 155
        Element taxonym = new Element(BfnXmlConstants.EL_TAXONYM);
155 156
        parent.addContent(taxonym);
156 157

  
157
        DefinedTerm taxNrIdentifierType = HibernateProxyHelper.deproxy(getTermService().load(BfnXmlConstants.UUID_TAX_NR_IDENTIFIER_TYPE), DefinedTerm.class);
158
        Set<String> identifiers = taxon.getIdentifiers(taxNrIdentifierType);
159
        if(identifiers.size()==1){
160
            String taxNr = identifiers.iterator().next();
161
            taxonym.setAttribute(BfnXmlConstants.ATT_TAXNR, taxNr);
162
        }
163
        else{
164
            logger.error("Taxon "+taxon.getTitleCache()+" has none or multiple identifiers of type 'taxNr'");
165
        }
158
        //reihenfolge attribute
159
        taxonym.setAttribute(BfnXmlConstants.ATT_REIHENFOLGE, getIdentifier(taxon, BfnXmlConstants.UUID_REIHENFOLGE_IDENTIFIER_TYPE));
160

  
161
        //taxNr attribute
162
        taxonym.setAttribute(BfnXmlConstants.ATT_TAXNR, getIdentifier(taxon, BfnXmlConstants.UUID_TAX_NR_IDENTIFIER_TYPE));
163

  
166 164

  
167 165
        exportWissName(taxon, taxonym);
168 166

  
......
187 185

  
188 186
    }
189 187

  
188
    private String getIdentifier(Taxon taxon, UUID identifierUuid) {
189
        DefinedTerm identifierType = HibernateProxyHelper.deproxy(getTermService().load(identifierUuid), DefinedTerm.class);
190
        Set<String> identfiers = taxon.getIdentifiers(identifierType);
191
        if(identfiers.size()==1){
192
            return identfiers.iterator().next();
193
        }
194
        else{
195
            logger.error("Taxon "+taxon.getTitleCache()+" has none or multiple identifiers of type '"+identifierType.getLabel()+"'");
196
            return null;
197
        }
198
    }
199

  
190 200
    private void exportWissName(TaxonBase<?> taxon, Element parent) {
191 201
        Element wissName = new Element(BfnXmlConstants.EL_WISSNAME);
192 202
        parent.addContent(wissName);
193 203

  
194 204
        NonViralName<?> name = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
195 205
        Rank rank = name.getRank();
196
        //wissName
197
        addNanteil(wissName, BfnXmlConstants.BEREICH_WISSNAME, name.getTitleCache());
198 206
        //epithet 1,2,3
199 207
        exportEpithet(taxon, wissName, name, rank);
200 208

  
......
203 211

  
204 212
        //authors
205 213
        addNanteil(wissName, BfnXmlConstants.BEREICH_AUTOREN, name.getAuthorshipCache());
214

  
215
        //wissName
216
        addNanteil(wissName, BfnXmlConstants.BEREICH_WISSNAME, name.getTitleCache());
206 217
    }
207 218

  
208 219
    private void exportEpithet(TaxonBase<?> taxon, Element wissName, NonViralName<?> name, Rank rank) {
220
        //eindeutiger Code
221
        Set<IdentifiableSource> sources = taxon.getSources();
222
        for (IdentifiableSource identifiableSource : sources) {
223
            if(identifiableSource.getType().equals(OriginalSourceType.Import)
224
                    && identifiableSource.getIdNamespace().equals(BfnXmlConstants.EL_TAXONYM+":"
225
                            +BfnXmlConstants.EL_WISSNAME+":"+BfnXmlConstants.EL_NANTEIL+":"+BfnXmlConstants.BEREICH_EINDEUTIGER_CODE)){
226
                addNanteil(wissName, BfnXmlConstants.BEREICH_EINDEUTIGER_CODE, identifiableSource.getIdInSource());
227
            }
228
        }
229

  
230
        //epitheton1-2
209 231
        addNanteil(wissName, BfnXmlConstants.BEREICH_EPITHETON1, name.getGenusOrUninomial());
210 232
        if(rank.isLower(Rank.GENUS())){
211 233
            String epitheton2 = name.getInfraGenericEpithet();
......
214 236
            }
215 237
            addNanteil(wissName, BfnXmlConstants.BEREICH_EPITHETON2, epitheton2);
216 238
        }
239
        //epitheton3
217 240
        if(rank.isLower(Rank.SPECIES())){
218 241
            String epitheton3 = name.getInfraSpecificEpithet();
219 242
            if(epitheton3==null){
......
221 244
            }
222 245
            addNanteil(wissName, BfnXmlConstants.BEREICH_EPITHETON3, epitheton3);
223 246
        }
224
        Set<IdentifiableSource> sources = taxon.getSources();
225
        for (IdentifiableSource identifiableSource : sources) {
226
            if(identifiableSource.getType().equals(OriginalSourceType.Import)
227
                    && identifiableSource.getIdNamespace().equals(BfnXmlConstants.EL_TAXONYM+":"
228
            +BfnXmlConstants.EL_WISSNAME+":"+BfnXmlConstants.EL_NANTEIL+":"+BfnXmlConstants.BEREICH_EINDEUTIGER_CODE)){
229
                addNanteil(wissName, BfnXmlConstants.BEREICH_EINDEUTIGER_CODE, identifiableSource.getIdInSource());
230
            }
231
        }
232 247
    }
233 248

  
234 249
    private void exportCommonName(Taxon taxon, Element taxonym) {
......
274 289
        return false;
275 290
    }
276 291

  
277
    private final class OriginalSourceComparator implements Comparator<TaxonNode> {
292
    private final class TaxonComparator implements Comparator<TaxonNode> {
278 293
        @Override
279 294
        public int compare(TaxonNode o1, TaxonNode o2) {
280 295
            Taxon taxon1 = o1.getTaxon();
281 296
            Taxon taxon2 = o2.getTaxon();
282
            int id1 = 0;
283
            int id2 = 0;
284

  
285
            Set<IdentifiableSource> sources1 = taxon1.getSources();
286
            for (IdentifiableSource identifiableSource : sources1) {
287
                if(identifiableSource.getType().equals(OriginalSourceType.Import)
288
                        && identifiableSource.getIdNamespace().equals(BfnXmlConstants.EL_TAXONYM+":"
289
                +BfnXmlConstants.EL_WISSNAME+":"+BfnXmlConstants.EL_NANTEIL+":"+BfnXmlConstants.BEREICH_EINDEUTIGER_CODE)){
290
                    id1 = Integer.parseInt(identifiableSource.getIdInSource());
291
                }
292
            }
293
            Set<IdentifiableSource> sources2 = taxon2.getSources();
294
            for (IdentifiableSource identifiableSource : sources2) {
295
                if(identifiableSource.getType().equals(OriginalSourceType.Import)
296
                        && identifiableSource.getIdNamespace().equals(BfnXmlConstants.EL_TAXONYM+":"
297
                                +BfnXmlConstants.EL_WISSNAME+":"+BfnXmlConstants.EL_NANTEIL+":"+BfnXmlConstants.BEREICH_EINDEUTIGER_CODE)){
298
                    id2 = Integer.parseInt(identifiableSource.getIdInSource());
299
                }
300
            }
301
            return id1-id2;
297

  
298
            int reihenfolge1 = Integer.parseInt(getIdentifier(taxon1, BfnXmlConstants.UUID_REIHENFOLGE_IDENTIFIER_TYPE));
299
            int reihenfolge2 = Integer.parseInt(getIdentifier(taxon2, BfnXmlConstants.UUID_REIHENFOLGE_IDENTIFIER_TYPE));
300

  
301
            return reihenfolge1-reihenfolge2;
302 302
        }
303 303
    }
304 304

  

Also available in: Unified diff