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
|
|
10
|
package eu.etaxonomy.cdm.io.tcsrdf;
|
11
|
|
12
|
import java.util.HashSet;
|
13
|
import java.util.Set;
|
14
|
|
15
|
import org.apache.log4j.Logger;
|
16
|
import org.jdom.Namespace;
|
17
|
import org.springframework.stereotype.Component;
|
18
|
|
19
|
import com.hp.hpl.jena.rdf.model.Model;
|
20
|
|
21
|
import eu.etaxonomy.cdm.api.service.INameService;
|
22
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
23
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
24
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
|
27
|
/**
|
28
|
* @author a.mueller
|
29
|
* @created 29.05.2008
|
30
|
* @version 1.0
|
31
|
*/
|
32
|
@Component
|
33
|
public class TcsRdfTaxonNameRelationsImport extends TcsRdfImportBase implements ICdmIO<TcsRdfImportState> {
|
34
|
private static final Logger logger = Logger.getLogger(TcsRdfTaxonNameRelationsImport.class);
|
35
|
|
36
|
private static int modCount = 5000;
|
37
|
|
38
|
public TcsRdfTaxonNameRelationsImport(){
|
39
|
super();
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public boolean doCheck(TcsRdfImportState state){
|
44
|
boolean result = true;
|
45
|
logger.warn("Checking for TaxonNameRelations not yet implemented");
|
46
|
//result &= checkArticlesWithoutJournal(tcsConfig);
|
47
|
//result &= checkPartOfJournal(tcsConfig);
|
48
|
|
49
|
return result;
|
50
|
}
|
51
|
|
52
|
@Override
|
53
|
public void doInvoke(TcsRdfImportState state){
|
54
|
|
55
|
MapWrapper<TaxonNameBase> taxonNameMap = (MapWrapper<TaxonNameBase>)state.getStore(ICdmIO.TAXONNAME_STORE);
|
56
|
MapWrapper<Reference> referenceMap = (MapWrapper<Reference>)state.getStore(ICdmIO.REFERENCE_STORE);
|
57
|
|
58
|
String tcsElementName;
|
59
|
Namespace tcsNamespace;
|
60
|
String cdmAttrName;
|
61
|
String value;
|
62
|
|
63
|
Set<TaxonNameBase> nameStore = new HashSet<TaxonNameBase>();
|
64
|
TcsRdfImportConfigurator config = state.getConfig();
|
65
|
//Model source = config.getSourceRoot();
|
66
|
|
67
|
logger.info("start makeNameRelationships ...");
|
68
|
INameService nameService = getNameService();
|
69
|
|
70
|
// <tn:hasBasionym rdf:resource="palm_tn_14530"/>
|
71
|
|
72
|
Model root = config.getSourceRoot();
|
73
|
|
74
|
String rdfNamespace = config.getRdfNamespaceURIString();
|
75
|
String taxonNameNamespace = config.getTnNamespaceURIString();
|
76
|
/*
|
77
|
List<Element> elTaxonNames = root.getChildren("TaxonName", taxonNameNamespace);
|
78
|
|
79
|
int i = 0;
|
80
|
int nameRelCount = 0;
|
81
|
//for each taxonName
|
82
|
for (Element elTaxonName : elTaxonNames){
|
83
|
|
84
|
TaxonNameBase fromName = null;
|
85
|
if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
|
86
|
|
87
|
//Basionyms
|
88
|
tcsElementName = "hasBasionym";
|
89
|
tcsNamespace = taxonNameNamespace;
|
90
|
List<Element> elBasionymList = elTaxonName.getChildren(tcsElementName, tcsNamespace);
|
91
|
|
92
|
for (Element elBasionym: elBasionymList){
|
93
|
nameRelCount++;
|
94
|
logger.debug("BASIONYM "+ nameRelCount);
|
95
|
tcsElementName = "resource";
|
96
|
tcsNamespace = rdfNamespace;
|
97
|
Attribute attrResource = elBasionym.getAttribute(tcsElementName, tcsNamespace);
|
98
|
if (attrResource == null){
|
99
|
logger.warn("Basionym rdf:resource is missing ! Basionym not set!");
|
100
|
continue;
|
101
|
}
|
102
|
String basionymId = attrResource.getValue();
|
103
|
TaxonNameBase basionym = taxonNameMap.get(basionymId);
|
104
|
if (basionym == null){
|
105
|
logger.warn("Basionym name ("+basionymId+") not found in Map! Basionym not set!");
|
106
|
continue;
|
107
|
}
|
108
|
if (fromName == null){
|
109
|
Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
|
110
|
if (about != null){
|
111
|
fromName = taxonNameMap.get(about.getValue() );
|
112
|
}
|
113
|
if (fromName == null){
|
114
|
logger.warn("From name ("+about+") not found in Map! Basionym not set!");
|
115
|
continue;
|
116
|
}
|
117
|
}
|
118
|
String ruleConcidered = null; //TODO
|
119
|
String microCitation = null; //TODO;
|
120
|
Reference citation = null; //TODO;
|
121
|
fromName.addBasionym(basionym, citation, microCitation, ruleConcidered);
|
122
|
nameStore.add(fromName);
|
123
|
|
124
|
}
|
125
|
}// end Basionyms
|
126
|
|
127
|
//Other Relations
|
128
|
//TODO
|
129
|
|
130
|
logger.info(nameRelCount + " nameRelations handled");
|
131
|
nameService.save(nameStore);
|
132
|
logger.info("end makeNameRelationships ...");
|
133
|
*/
|
134
|
return;
|
135
|
}
|
136
|
|
137
|
/* (non-Javadoc)
|
138
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
139
|
*/
|
140
|
protected boolean isIgnore(TcsRdfImportState state){
|
141
|
return ! state.getConfig().isDoRelNames();
|
142
|
}
|
143
|
|
144
|
}
|