Project

General

Profile

« Previous | Next » 

Revision 4ed5c440

Added by Patrick Plitzner almost 8 years ago

Export concept relationships

View differences:

app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/BfnXmlConstants.java
52 52
    public static final String EL_TAXONYME = "TAXONYME";
53 53
    public static final String EL_TAXONYM = "TAXONYM";
54 54
    public static final String ATT_TAXNR = "taxNr";
55
    public static final String ATT_QUELLE = "quelle";
55 56

  
56 57
    public static final String EL_WISSNAME = "WISSNAME";
57 58
    public static final String EL_NANTEIL = "NANTEIL";
......
77 78

  
78 79
    public static final String EL_KONZEPTBEZIEHUNGEN = "KONZEPTBEZIEHUNGEN";
79 80
    public static final String EL_KONZEPTBEZIEHUNG = "KONZEPTBEZIEHUNG";
81
    public static final String EL_TAXONYM1 = "TAXONYM1";
82
    public static final String EL_TAXONYM2 = "TAXONYM2";
80 83

  
81 84

  
82 85
    public static final String BEREICH_WISSNAME = "wissName";
......
169 172

  
170 173
    //redList feature vocabulary
171 174
    public static final UUID vocRLFeatures =  UUID.fromString("74091f30-faa0-487b-bd7e-c82eed05d3c9");
172
   
175

  
173 176
    public static final UUID UUID_TAX_NR_IDENTIFIER_TYPE =  UUID.fromString("7d12de50-0db7-47b3-bb8e-703ad1d54fbc");
174 177

  
175 178
    //redList state Vocabularies
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/in/BfnXmlTransformer.java
26 26
    @SuppressWarnings("unused")
27 27
	private static final Logger logger = Logger.getLogger(BfnXmlTransformer.class);
28 28

  
29

  
29 30
	private static final BiMap<Rank, String> rankMap = HashBiMap.create();
30 31
	static {
31 32
	    rankMap.put(Rank.INFRAGENUS(), BfnXmlConstants.RNK_INFRAGEN);
......
92 93
        return rankMap;
93 94
    }
94 95

  
96
    private static final BiMap<TaxonRelationshipType, String> relationshipTypeMap = HashBiMap.create();
97
    static {
98
        relationshipTypeMap.put(TaxonRelationshipType.CONGRUENT_TO(), "!=");
99
        relationshipTypeMap.put(TaxonRelationshipType.CONGRUENT_OR_INCLUDES(), "!=,>");
100
        relationshipTypeMap.put(TaxonRelationshipType.CONGRUENT_OR_INCLUDED_OR_INCLUDES(), "!=,<");
101
        relationshipTypeMap.put(TaxonRelationshipType.INCLUDES(), ">");
102
        relationshipTypeMap.put(TaxonRelationshipType.INCLUDES_OR_OVERLAPS(), ">,><");
103
        relationshipTypeMap.put(TaxonRelationshipType.INCLUDED_OR_INCLUDES_OR_OVERLAPS(), ">,><");//TODO: should be Included In Or Overlaps
104
        relationshipTypeMap.put(TaxonRelationshipType.OVERLAPS(), "><");
105
        relationshipTypeMap.put(TaxonRelationshipType.CONGRUENT_OR_INCLUDES_OR_OVERLAPS(), "~");//TODO Included in not here
106
        relationshipTypeMap.put(TaxonRelationshipType.ALL_RELATIONSHIPS(), "?");
107
        relationshipTypeMap.put(TaxonRelationshipType.EXCLUDES(), "/=");
108
        relationshipTypeMap.put(TaxonRelationshipType.CONGRUENT_TO(), "!=");
109
    }
110

  
111
    public static BiMap<TaxonRelationshipType, String> getRelationshipTypeMap() {
112
        return relationshipTypeMap;
113
    }
114

  
95 115

  
96 116
	public static TaxonRelationshipType concept2TaxonRelation(String conceptStatus) throws UnknownCdmTypeException{
97 117
		if(conceptStatus == null) {
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlExportBase.java
10 10
package eu.etaxonomy.cdm.io.redlist.bfnXml.out;
11 11

  
12 12
import org.apache.log4j.Logger;
13
import org.jdom2.Attribute;
14
import org.jdom2.Element;
13 15

  
14 16
import eu.etaxonomy.cdm.io.common.CdmExportBase;
15 17
import eu.etaxonomy.cdm.io.common.mapping.out.IExportTransformer;
18
import eu.etaxonomy.cdm.io.redlist.bfnXml.BfnXmlConstants;
16 19

  
17 20
/**
18 21
 *
......
29 32
	public BfnXmlExportBase() {
30 33
		super();
31 34
	}
35

  
36
    protected void addIwert(Element parent, String standardNameValue, String wertString) {
37
        Element iwert = new Element(BfnXmlConstants.EL_IWERT);
38
        iwert.setAttribute(new Attribute(BfnXmlConstants.ATT_STANDARDNAME, standardNameValue));
39
        parent.addContent(iwert);
40
    
41
        Element wert = new Element(BfnXmlConstants.EL_WERT);
42
        wert.addContent(wertString);
43
        iwert.addContent(wert);
44
    }
32 45
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlExportConceptRelations.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.cdm.io.redlist.bfnXml.out;
10

  
11
import java.util.List;
12
import java.util.Set;
13
import java.util.UUID;
14

  
15
import org.jdom2.Document;
16
import org.jdom2.Element;
17
import org.springframework.stereotype.Component;
18

  
19
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
20
import eu.etaxonomy.cdm.io.redlist.bfnXml.BfnXmlConstants;
21
import eu.etaxonomy.cdm.model.common.DefinedTerm;
22
import eu.etaxonomy.cdm.model.taxon.Classification;
23
import eu.etaxonomy.cdm.model.taxon.Taxon;
24
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
25
import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
26

  
27

  
28

  
29
/**
30
 *
31
 * @author pplitzner
32
 * @date May 3, 2016
33
 *
34
 */
35
@Component
36
public class BfnXmlExportConceptRelations extends BfnXmlExportBase {
37

  
38
    private static final long serialVersionUID = -931703660108981011L;
39

  
40

  
41
	public BfnXmlExportConceptRelations(){
42
		super();
43
	}
44

  
45
	@Override
46
    protected void doInvoke(BfnXmlExportState state){
47
	    startTransaction(true);
48

  
49
	    Document document = state.getConfig().getDocument();
50
	    Element konzeptbeziehungen = null;
51
	    List<Classification> list = getClassificationService().list(Classification.class, null, null, null, null);
52
	    DefinedTerm taxNrIdentifierType = HibernateProxyHelper.deproxy(getTermService().load(BfnXmlConstants.UUID_TAX_NR_IDENTIFIER_TYPE), DefinedTerm.class);
53
	    for (Classification classification : list) {
54
            List<TaxonNode> childNodes = classification.getChildNodes();
55
            for (TaxonNode taxonNode : childNodes) {
56
                Set<TaxonRelationship> relationsFromThisTaxon = taxonNode.getTaxon().getRelationsFromThisTaxon();
57
                for (TaxonRelationship taxonRelationship : relationsFromThisTaxon) {
58
                    UUID uuid = taxonRelationship.getUuid();
59
                    //all of the relationships should have been processed
60
                    //when iterating over the taxa of the first classification
61
                    //if there are only 2 of them
62
                    if(!state.getKnownConceptRelations().contains(uuid)) {
63
                        if(konzeptbeziehungen==null){
64
                            konzeptbeziehungen = new Element(BfnXmlConstants.EL_KONZEPTBEZIEHUNGEN);
65
                            document.addContent(konzeptbeziehungen);
66
                        }
67
                        Element konzeptbeziehung = new Element(BfnXmlConstants.EL_KONZEPTBEZIEHUNG);
68
                        konzeptbeziehungen.addContent(konzeptbeziehung);
69

  
70
                        state.getKnownConceptRelations().add(uuid);
71

  
72
                        //fromTaxon = TAXONYM1
73
                        Taxon fromTaxon = taxonRelationship.getFromTaxon();
74
                        Element taxonym1 = new Element(BfnXmlConstants.EL_TAXONYM1);
75
                        konzeptbeziehung.addContent(taxonym1);
76
                        addConceptTaxonym(taxNrIdentifierType, taxonym1, fromTaxon);
77

  
78
                        //toTaxon = TAXONYM2
79
                        Taxon toTaxon = taxonRelationship.getToTaxon();
80
                        Element taxonym2 = new Element(BfnXmlConstants.EL_TAXONYM2);
81
                        konzeptbeziehung.addContent(taxonym2);
82
                        addConceptTaxonym(taxNrIdentifierType, taxonym2, toTaxon);
83

  
84
                        //relation type
85

  
86
                    }
87
                }
88
            }
89
        }
90

  
91
	}
92

  
93
    private void addConceptTaxonym(DefinedTerm taxNrIdentifierType, Element taxonym, Taxon taxon) {
94
        String taxNr = getTaxNr(taxon, taxNrIdentifierType);
95
        if(taxon.getTaxonNodes().size()>1){
96
            logger.error(taxon+" has more than one taxon node. First one is used");
97
        }
98
        Classification classification = taxon.getTaxonNodes().iterator().next().getClassification();
99
        taxonym.setAttribute(BfnXmlConstants.ATT_QUELLE, classification.getTitleCache());
100
        taxonym.setAttribute(BfnXmlConstants.ATT_TAXNR, taxNr);
101
        addIwert(taxonym, BfnXmlConstants.ATT_NAME, taxon.getName().getTitleCache());
102
    }
103

  
104
    private String getTaxNr(Taxon taxon, DefinedTerm taxNrIdentifierType) {
105
        String taxNr = null;
106
        Set<String> identifiers = taxon.getIdentifiers(taxNrIdentifierType);
107
        if(identifiers.size()==1){
108
            taxNr = identifiers.iterator().next();
109
        }
110
        else{
111
            logger.error("Taxon "+taxon.getTitleCache()+" has none or multiple identifiers of type 'taxNr'");
112
        }
113
        return taxNr;
114
    }
115

  
116
    /**
117
     * {@inheritDoc}
118
     */
119
    @Override
120
    protected boolean doCheck(BfnXmlExportState state) {
121
        return false;
122
    }
123

  
124
    /**
125
     * {@inheritDoc}
126
     */
127
    @Override
128
    protected boolean isIgnore(BfnXmlExportState state) {
129
        return false;
130
    }
131

  
132
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlExportState.java
10 10

  
11 11
package eu.etaxonomy.cdm.io.redlist.bfnXml.out;
12 12

  
13
import java.util.HashMap;
14
import java.util.Map;
13
import java.util.HashSet;
14
import java.util.Set;
15 15
import java.util.UUID;
16 16

  
17 17
import org.apache.log4j.Logger;
......
29 29
	@SuppressWarnings("unused")
30 30
	private static final Logger logger = Logger.getLogger(BfnXmlExportState.class);
31 31

  
32
	private Map<String, UUID> taxNrMap = new HashMap<String, UUID>();
32
	private Set<UUID> knownConceptRelations = new HashSet<UUID>();
33 33

  
34 34
	public BfnXmlExportState(BfnXmlExportConfigurator config) {
35 35
		super(config);
36 36
	}
37 37

  
38
    public Map<String, UUID> getTaxNrMap() {
39
        return taxNrMap;
38
    public Set<UUID> getKnownConceptRelations() {
39
        return knownConceptRelations;
40 40
    }
41 41

  
42 42
}
app-import/src/main/java/eu/etaxonomy/cdm/io/redlist/bfnXml/out/BfnXmlTaxonNameExport.java
109 109
                        logger.error("StateData does not have a size of 1 for feature "+feature.getLabel()+" in taxon "+taxon.getTitleCache());
110 110
                        continue;
111 111
                    }
112
                    exportIwert(bezugsraum, feature, stateData.iterator().next().getState().getLabel());
112
                    addIwert(bezugsraum, feature.getLabel(), stateData.iterator().next().getState().getLabel());
113 113
                }
114 114
                else if(descriptionElementBase.isInstanceOf(TextData.class)){
115 115
                    TextData textData = HibernateProxyHelper.deproxy(descriptionElementBase, TextData.class);
116
                    exportIwert(bezugsraum, textData.getFeature(), textData.getLanguageText(Language.GERMAN()).getText());
116
                    addIwert(bezugsraum, textData.getFeature().getLabel(), textData.getLanguageText(Language.GERMAN()).getText());
117 117
                }
118 118
            }
119 119
        }
120 120
    }
121 121

  
122
    private void exportIwert(Element parent, Feature feature, String wertString) {
123
        Element iwert = new Element(BfnXmlConstants.EL_IWERT);
124
        iwert.setAttribute(new Attribute(BfnXmlConstants.ATT_STANDARDNAME, feature.getLabel()));
125
        parent.addContent(iwert);
126

  
127
        Element wert = new Element(BfnXmlConstants.EL_WERT);
128
        wert.addContent(wertString);
129
        iwert.addContent(wert);
130
    }
131

  
132 122
    private void exportFeatures(Element roteListeDaten) {
133 123
        Element eigenschaften = new Element(BfnXmlConstants.EL_EIGENSCHAFTEN);
134 124
        roteListeDaten.addContent(eigenschaften);
......
169 159
        if(identifiers.size()==1){
170 160
            String taxNr = identifiers.iterator().next();
171 161
            taxonym.setAttribute(BfnXmlConstants.ATT_TAXNR, taxNr);
172
            state.getTaxNrMap().put(taxNr, taxon.getUuid());
173 162
        }
174 163
        else{
175 164
            logger.error("Taxon "+taxon.getTitleCache()+" has none or multiple identifiers of type 'taxNr'");

Also available in: Unified diff