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
|
}
|