Project

General

Profile

Revision c52b7e11

IDc52b7e11fed2fe91e9bba84831a6edc91c6d4129
Parent c90de46b
Child 0f7d2058

Added by Katja Luther about 7 years ago

adapted tcs rdf and xml import, using apache jena for rdf import
tcs import for caryophylales
minor

View differences:

cdmlib-commons/src/main/java/eu/etaxonomy/cdm/common/XmlHelp.java
145 145
		}
146 146
		return childAttribute.getValue();
147 147
	}
148
	
149
	public static String getChildContent(Element element, String childElementName, Namespace childElementNamespace, String childAttributeName, Namespace childAttributeNamespace){
150
		Element child = element.getChild(childElementName, childElementNamespace);
151
		if (child == null){
152
			return null;
153
		}
154
		List childContent = child.getContent();
155
		if (childContent.isEmpty()){
156
			return null;
157
		}
158
		for (Object content:childContent){
159
			if (content instanceof Element){
160
				Element contentEl = (Element)content;
161
				if (contentEl.getName().equals(childAttributeName)){
162
					return contentEl.getText();
163
				}
164
			}
165
		}
166
		return null;
167
	}
148 168

  
149 169
	/**
150 170
	 * @param parent
......
331 351
			success.setValue(false);
332 352
			return null;	
333 353
		}else if (elList.size() == 0){
354
			elList = getChildren(parentElement, childName, null);
334 355
			logger.info("There is no '" + childName + "' element");
335 356
			if (obligatory){
336 357
				success.setValue(false);
337 358
			}
338 359
			return null;
339 360
		}
361
		
340 362
		Element childElement = elList.get(0);		
341 363
		return childElement;
342 364
	}	
......
355 377
			return null;
356 378
		}
357 379
		return elList;
380
	}
381

  
382
	public static String getChildContentAttributeValue(Element element,
383
			String childAttributeName, Namespace taxonNameNamespace, String childElementName,
384
			Namespace childElementNamespace) {
385
		Element child = element.getChild(childAttributeName, taxonNameNamespace);
386
		if (child == null){
387
			return null;
388
		}
389
		List childContent = child.getContent();
390
		if (childContent.isEmpty()){
391
			return null;
392
		}
393
		for (Object content:childContent){
394
			if (content instanceof Element){
395
				Element contentEl = (Element)content;
396
				if (contentEl == null){
397
					return null;
398
				}
399
				if (!(contentEl.getAttributeValue(childElementName) == null)){
400
					Attribute at = contentEl.getAttribute("ressource");
401
					if (at != null)return at.getValue();
402
				}
403
			}
404
		}
405
		return null;
358 406
	}	
359 407
	
360 408
}
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/ipni/IIpniService.java
9 9
*/
10 10
package eu.etaxonomy.cdm.ext.ipni;
11 11

  
12
import java.io.InputStream;
12 13
import java.net.URL;
13 14
import java.util.List;
14 15
import java.util.UUID;
......
51 52
	public static final String SIMPLE_NAME_SERVICE_URL = "http://www.uk.ipni.org/ipni/simplePlantNameSearch.do";
52 53
	public static final String ADVANCED_NAME_SERVICE_URL = "http://www.uk.ipni.org/ipni/advPlantNameSearch.do";
53 54
	public static final String PUBLICATION_SERVICE_URL = "http://www.uk.ipni.org/ipni/advPublicationSearch.do";
54
	
55
	public static final String ID_PUBLICATION_SERVICE_URL = "http://www.uk.ipni.org/ipni/idPublicationSearch.do";
56
	public static final String ID_NAMESEARCH_SERVICE_URL = "http://www.ipni.org/ipni/idPlantNameSearch.do";
55 57
	
56 58
	 /**
57 59
	 * Enumeration of the four return delimited data formats provided by IPNI.<BR/>
......
125 127
	 * @return
126 128
	 */
127 129
	public List<BotanicalName> getNamesSimple(String wholeName, ICdmApplicationConfiguration services, IpniServiceNamesConfigurator config);
128

  
130
	
131
	/**
132
	 * Returns the name matching the id parameter according to the IPNI Quick search function.
133
	 * See {@link http://www.uk.ipni.org/sample_searches.html#name_quick} for further explanation about the IPNI Quick search.
134
	 * <BR/><BR/>
135
	 * 
136
	 * Please be aware that not all data returned by IPNI are transformed into CDM data as some of the data types are not available in the
137
	 * CDM and some types are just not yet implemented.
138
	 *  
139
	 * @param id
140
	 * @return
141
	 */
142
	public InputStream getNamesById(String id);
143
	
144
	
145
	/**
146
	 * Returns the publication matching the id parameter according to the IPNI Quick search function.
147
	 * See {@link http://www.uk.ipni.org/sample_searches.html#name_quick} for further explanation about the IPNI Quick search.
148
	 * <BR/><BR/>
149
	 * 
150
	 * Please be aware that not all data returned by IPNI are transformed into CDM data as some of the data types are not available in the
151
	 * CDM and some types are just not yet implemented.
152
	 *  
153
	 * @param id
154
	 * @return
155
	 */
156
	public InputStream getPublicationsById(String id);
129 157
	
130 158
	/**
131 159
	 * Returns a list of names matching the relevant parameters according to the IPNI full search function.
cdmlib-ext/src/main/java/eu/etaxonomy/cdm/ext/ipni/IpniService.java
54 54
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
55 55
import eu.etaxonomy.cdm.strategy.parser.TimePeriodParser;
56 56

  
57

  
58 57
/**
59 58
* @author a.mueller
60 59
* @created Aug 16, 2010
......
167 166
		 AUTHOR,
168 167
		 NAME,
169 168
		 PUBLICATION,
169
		 ID
170 170
	}
171 171
	
172 172
	public enum IpniRank{
......
277 277
            	result = buildAuthorList(content, services, config);
278 278
            }else if (serviceType.equals(ServiceType.NAME)){
279 279
            	result = buildNameList(content, services, config);
280
            }else{
280
            }else {
281 281
            	result = buildPublicationList(content, services, config);
282 282
            }
283 283
            if(responseCode == HttpURLConnection.HTTP_OK){
......
296 296
        // error
297 297
        return null;
298 298
    }
299
	
300
	public InputStream queryServiceForID (String request, URL serviceUrl){
301
		
302
		try {
303
			
304
            // create the request url
305
            URL newUrl = new URL(serviceUrl.getProtocol(),
306
                                                     serviceUrl.getHost(),
307
                                                     serviceUrl.getPort(),
308
                                                     serviceUrl.getPath() 
309
                                                     + "?" + request);
310
            
311
            
312
            URI newUri = newUrl.toURI();
313
                       
314
            logger.info("Firing request for URI: " + newUri);
315
                
316
            HttpResponse response = UriUtils.getResponse(newUri, null);
317
            
318
            int responseCode = response.getStatusLine().getStatusCode();
319
            
320
            // get the content at the resource
321
            InputStream content = response.getEntity().getContent();
322
            return content;
323
           
324
		   } catch (IOException e) {
325
	            logger.error("No content for request: " + request);
326
	        } catch (URISyntaxException e) {
327
				logger.error("Given URL could not be transformed into URI", e);
328
			}
329
         
330
		return null;
331
	
332
	}
333

  
334
	
335

  
299 336

  
300 337
	private List<Reference> buildPublicationList( InputStream content, ICdmApplicationConfiguration services, IIpniServiceConfigurator iConfig) throws IOException {
301 338
		IpniServicePublicationConfigurator config = (IpniServicePublicationConfigurator)iConfig;
......
407 444
		
408 445
		String line = reader.readLine();
409 446
		while (StringUtils.isNotBlank(line)){
447
			
410 448
			BotanicalName name = getNameFromLine(line,parameterMap, appConfig);
411 449
			result.add(name);
412 450
			line = reader.readLine();
451
			
413 452
		}
414 453

  
415 454
		
......
884 923
		return serviceUrl;
885 924
	}
886 925

  
926

  
927
	@Override
928
	public InputStream getNamesById(String id) {
929
		
930
	
931
		String request = "id="+id + "&output_format=lsid-metadata";
932
		return queryServiceForID(request, getServiceUrl(IIpniService.ID_NAMESEARCH_SERVICE_URL));
933
		
934
	}
935
	
936
	@Override
937
	public InputStream getPublicationsById(String id) {
938
		
939
	
940
		String request = "id="+id ;
941
		return queryServiceForID(request, getServiceUrl(IIpniService.ID_PUBLICATION_SERVICE_URL));
942
		
943
	}
944

  
887 945
		
888 946
	
889 947
}
cdmlib-ext/src/test/java/eu/etaxonomy/cdm/ext/ipni/IpniServiceTest.java
3 3
 */
4 4
package eu.etaxonomy.cdm.ext.ipni;
5 5

  
6
import java.io.InputStream;
6 7
import java.util.List;
7 8

  
8 9
import org.apache.log4j.Logger;
......
197 198

  
198 199
	}	
199 200
	
201
	@Test
202
	//@Ignore
203
	public void testNameID(){
204
		ICdmApplicationConfiguration services = null;
205
		IpniServiceNamesConfigurator config = null;
206
		InputStream content = service1.getNamesById("416415-1");
207
		
208
		
209
		Assert.assertNotNull(content);
210
	}
211
	
212
	
200 213
	/**
201 214
	 * Test method for {@link eu.etaxonomy.cdm.ext.ipni.IpniService#getServiceUrl()}.
202 215
	 */
cdmlib-io/pom.xml
127 127
			<groupId>identificationKeyAPI</groupId>
128 128
			<artifactId>identificationKeyAPI</artifactId>
129 129
		</dependency>
130
		<dependency>
131
 			<groupId>org.apache.jena</groupId>
132
 			<artifactId>apache-jena-libs</artifactId>
133
 			<type>pom</type>
134
 			<version>2.12.0</version>
135
		</dependency>
130 136

  
131 137
	</dependencies>
132 138
</project>
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/CdmTextElementMapper.java
14 14
import org.jdom.Element;
15 15
import org.jdom.Namespace;
16 16

  
17
import com.hp.hpl.jena.rdf.model.Resource;
18
import com.hp.hpl.jena.rdf.model.Statement;
19

  
17 20
/**
18 21
 * @author a.mueller
19 22
 * @created 29.07.2008
20 23
 * @version 1.0
21 24
 */
22 25

  
23
public class CdmTextElementMapper extends CdmSingleAttributeXmlMapperBase {
26
public class CdmTextElementMapper extends CdmSingleAttributeRDFMapperBase {
24 27
	@SuppressWarnings("unused")
25 28
	private static final Logger logger = Logger.getLogger(CdmTextElementMapper.class);
26 29
	
......
28 31
	 * @param dbValue
29 32
	 * @param cdmValue
30 33
	 */
31
	public CdmTextElementMapper(String sourceElementString,Namespace sourceNamespace, String cdmAttributeString) {
34
	public CdmTextElementMapper(String sourceElementString, String sourceNamespace, String cdmAttributeString) {
32 35
		super(sourceElementString, cdmAttributeString);
33
		this.sourceNamespace = sourceNamespace;
36
		this.sourceNameSpace = sourceNamespace;
34 37
	}
35 38

  
36 39
	/**
......
41 44
		super(dbAttributString, cdmAttributeString);
42 45
	}
43 46
	
44
	public Namespace getSourceNamespace(){
45
		return sourceNamespace;
47
	public String getSourceNamespace(){
48
		return sourceNameSpace;
46 49
	}
47 50
		
48 51
	public Class getTypeClass(){
49 52
		return String.class;
50 53
	}
51 54
	
52
	public boolean mapsSource(Content content, Element parentElement){
55
	public boolean mapsSource(Resource content, Statement parentElement){
53 56
		return super.mapsSource(content, parentElement);	
54 57
	}
58

  
59
	
60

  
61
	
62

  
63
	
55 64
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/CdmUnclearMapper.java
14 14
import org.jdom.Element;
15 15
import org.jdom.Namespace;
16 16

  
17
import com.hp.hpl.jena.rdf.model.Resource;
18
import com.hp.hpl.jena.rdf.model.Statement;
19

  
17 20

  
18 21
/**
19 22
 * @author a.mueller
20 23
 * @created 29.07.2008
21 24
 * @version 1.0
22 25
 */
23
public class CdmUnclearMapper extends CdmSingleAttributeXmlMapperBase {
26
public class CdmUnclearMapper extends CdmSingleAttributeRDFMapperBase {
24 27
	private static final Logger logger = Logger.getLogger(CdmUnclearMapper.class);
25 28
	
26 29
	
......
28 31
	 * @param dbValue
29 32
	 * @param cdmValue
30 33
	 */
31
	public CdmUnclearMapper(String sourceElementString, Namespace sourceNamespace) {
34
	public CdmUnclearMapper(String sourceElementString, String sourceNamespace) {
32 35
		super(sourceElementString, null);
33
		this.sourceNamespace = sourceNamespace;
36
		this.sourceNameSpace = sourceNamespace;
34 37
	}
35 38

  
36 39
	/**
......
41 44
		super(dbAttributString, null);
42 45
	}
43 46
	
44
	public Namespace getSourceNamespace(){
45
		return sourceNamespace;
47
	public String getSourceNamespace(){
48
		return sourceNameSpace;
46 49
	}
47 50
	
48 51
	public Class getTypeClass(){
49 52
		return String.class;
50 53
	}
51 54
	
52
	public boolean mapsSource(Content content, Element parentElement){
55
	public boolean mapsSource(Resource content, Statement parentElement){
53 56
		return super.mapsSource(content, parentElement);
54 57
	}
55 58
	
......
57 60
		return this.getSourceElement();
58 61
	}
59 62

  
63
	
64

  
60 65

  
61 66
}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfImportBase.java
19 19
import java.util.Set;
20 20

  
21 21
import org.apache.log4j.Logger;
22
import org.apache.poi.hpsf.Property;
23
import org.apache.jena.*;
22 24
import org.jdom.Content;
23 25
import org.jdom.Element;
24 26
import org.jdom.Namespace;
25 27
import org.jdom.Text;
26 28

  
29
import com.hp.hpl.jena.rdf.model.Resource;
30
import com.hp.hpl.jena.rdf.model.Statement;
31

  
27 32
import eu.etaxonomy.cdm.io.common.CdmImportBase;
28 33
import eu.etaxonomy.cdm.io.common.ImportHelper;
29 34
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
......
37 42
public abstract class TcsRdfImportBase  extends CdmImportBase<TcsRdfImportConfigurator, TcsRdfImportState> {
38 43
	private static final Logger logger = Logger.getLogger(TcsRdfImportBase.class);
39 44

  
40
	protected static Namespace nsTcom = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/Common#");
41
	protected static Namespace nsTn = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonName#");
42
	protected static Namespace nsTgeo = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/GeographicRegion#");
43
	protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
44
	protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
45
	protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
45
	protected static String nsTcom = "http://rs.tdwg.org/ontology/voc/Common#";
46
	protected static String nsTn = "http://rs.tdwg.org/ontology/voc/TaxonName#";
47
	protected static String nsTgeo = "http://rs.tdwg.org/ontology/voc/GeographicRegion#";
48
	protected static String nsTc = "http://rs.tdwg.org/ontology/voc/TaxonConcept#";
49
	protected static String nsTpub = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
50
	protected static String nsTm = "http://rs.tdwg.org/ontology/voc/Team";
51
	protected static String nsTpalm = "http://wp5.e-taxonomy.eu/import/palmae/common";
46 52
	
47 53
	
48 54
	protected abstract void doInvoke(TcsRdfImportState state);
......
58 64
//		return doInvoke(state);
59 65
//	}
60 66
	
61
	protected boolean makeStandardMapper(Element parentElement, CdmBase ref, Set<String> omitAttributes, CdmSingleAttributeXmlMapperBase[] classMappers){
67
	protected boolean makeStandardMapper(Statement resource, CdmBase ref, Set<String> omitAttributes, CdmSingleAttributeRDFMapperBase[] classMappers){
62 68
		if (omitAttributes == null){
63 69
			omitAttributes = new HashSet<String>();
64 70
		}
65 71
		boolean result = true;	
66
		for (CdmSingleAttributeXmlMapperBase mapper : classMappers){
67
			Object value = getValue(mapper, parentElement);
72
		for (CdmSingleAttributeRDFMapperBase mapper : classMappers){
73
			Object value = getValue(mapper, resource);
68 74
			//write to destination
69 75
			if (value != null){
70 76
				String destinationAttribute = mapper.getDestinationAttribute();
......
76 82
		return result;
77 83
	}
78 84
	
79
	private Object getValue(CdmSingleAttributeXmlMapperBase mapper, Element parentElement){
85
	public Object getValue(CdmSingleAttributeRDFMapperBase mapper, Statement resource){
80 86
		String sourceAttribute = mapper.getSourceAttribute();
81
		Namespace sourceNamespace = mapper.getSourceNamespace(parentElement);
82
		Element child = parentElement.getChild(sourceAttribute, sourceNamespace);
83
		if (child == null){
84
			return null;
85
		}
86
		if (child.getContentSize() > 1){
87
			logger.warn("Element is not String");
88
		}
89
		Object value = child.getTextTrim();
87
		String sourceNamespace = mapper.getSourceNameSpace(resource);
88
		String value = resource.getProperty(resource.getModel().createProperty(sourceNamespace+sourceAttribute)).getString();
89
		
90 90
		return value;
91 91
	}
92 92
	
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfImportConfigurator.java
13 13
import java.net.MalformedURLException;
14 14
import java.net.URI;
15 15
import java.net.URL;
16
import java.util.Map;
16 17

  
17 18
import org.apache.log4j.Logger;
18 19
import org.jdom.Element;
19 20
import org.jdom.Namespace;
20 21

  
22
import com.hp.hpl.jena.rdf.model.Model;
23
import com.hp.hpl.jena.rdf.model.ModelFactory;
24
import com.hp.hpl.jena.rdf.model.NsIterator;
25

  
21 26
import eu.etaxonomy.cdm.common.XmlHelp;
22 27
import eu.etaxonomy.cdm.database.ICdmDataSource;
23 28
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
......
51 56
	private boolean doTaxa = true;
52 57
	private boolean doRelTaxa = true;
53 58
	private boolean doFacts = true;
54

  
55
	//rdfNamespace
59
	Map<String, String> nsPrefixMap;
60
	/*//rdfNamespace
56 61
	private Namespace rdfNamespace;
57
	//TaxonConcept namespace
58
	private Namespace tcNamespace;
62
	//Team namespace
63
	private Namespace tmNamespace;
64
	//Person namespace
65
	private Namespace personNamespace;
59 66
	//TaxonName namespace
60 67
	private Namespace tnNamespace;
68
	//TaxonConcept namespace
69
	private Namespace tcNamespace;
61 70
	//TDWG common namespace
62 71
	private Namespace commonNamespace;
63 72
	//TDWG geoNamespace
64 73
	private Namespace geoNamespace;
65 74
	//publicationNamespace
66 75
	private Namespace publicationNamespace;
76
	//owlNamespace
77
	private Namespace owlNamespace;
78
	//dcNamespace
79
	private Namespace dcNamespace;
80
	//dcTermsNamespace
81
	private Namespace dcTermsNamespace;
67 82
	//palmNamespace
68 83
	private Namespace palmNamespace;
69 84

  
......
74 89
	protected static Namespace nsTc = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/TaxonConcept#");
75 90
	protected static Namespace nsTpub = Namespace.getNamespace("http://rs.tdwg.org/ontology/voc/PublicationCitation#");
76 91
	protected static Namespace nsTpalm = Namespace.getNamespace("http://wp5.e-taxonomy.eu/import/palmae/common");
77

  
92
	
93
	String[] prefixArray = {"rdf", "tm", "p","tc","tcom", "tgeo","owl","dc","dcterms","tn"};
94
*/
78 95
	@Override
79 96
    protected void makeIoClassList(){
80 97
		ioClassList = new Class[]{
......
111 128
	/**
112 129
	 * @return
113 130
	 */
114
	public Element getSourceRoot(){
131
	public Model getSourceRoot(){
115 132
		URI source = getSource();
116 133
		try {
117 134
			URL url;
118 135
			url = source.toURL();
119 136
			Object o = url.getContent();
120 137
			InputStream is = (InputStream)o;
138
			Model model = ModelFactory.createDefaultModel();
139
			model.read(is, null);
140
			makeNamespaces(model);
141
			return model;
142
		} catch (MalformedURLException e) {
143
			e.printStackTrace();
144
		}catch (Exception e) {
145
			// TODO Auto-generated catch block
146
			e.printStackTrace();
147
		}
148
		return null;
149
	}
150
public Element getSourceRoot(InputStream is){
151
		
152
		try {
121 153
			Element root = XmlHelp.getRoot(is);
122 154
			makeNamespaces(root);
123 155
			return root;
124 156
		} catch (MalformedURLException e) {
125 157
			e.printStackTrace();
126 158
		}catch (Exception e) {
127
			// TODO Auto-generated catch block
128
			e.printStackTrace();
159
			System.err.println("The InputStream does not contain an rdf file.");
160
			//e.printStackTrace();
129 161
		}
130 162
		return null;
131 163
	}
132

  
133
	private boolean makeNamespaces(Element root){
134
		//String strTnNamespace = "http://rs.tdwg.org/ontology/voc/TaxonName#";
135
		//Namespace taxonNameNamespace = Namespace.getNamespace("tn", strTnNamespace);
136

  
137
		String prefix;
138
		rdfNamespace = root.getNamespace();
164
	
165
	
166
	private void makeNamespaces(Element root){
167
		
168
		String prefix = "rdf";
169
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
139 170
		prefix = "tc";
140
		tcNamespace = root.getNamespace(prefix);
171
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
141 172
		prefix = "tn";
142
		tnNamespace = root.getNamespace(prefix);
173
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
143 174
		prefix = "tcom";
144
		commonNamespace = root.getNamespace(prefix);
175
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
145 176
		prefix = "tgeo";
146
		geoNamespace = root.getNamespace(prefix);
177
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
147 178
		prefix = "tpub";
148
		publicationNamespace = root.getNamespace(prefix);
179
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
149 180

  
150 181
		prefix = "tpalm";
151
		palmNamespace = root.getNamespace(prefix);
152

  
153
		if (rdfNamespace == null || tcNamespace == null || tnNamespace == null ||
154
				commonNamespace == null ||	geoNamespace == null || publicationNamespace == null
155
				|| palmNamespace == null){
156
			logger.warn("At least one Namespace is NULL");
157
		}
158
		return true;
182
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
183
		prefix = "tm";
184
		nsPrefixMap.put(prefix, root.getNamespace().getURI().toString());
185
	}
186
	public void makeNamespaces(Model model){
187
		nsPrefixMap = model.getNsPrefixMap();
188
		
159 189
	}
160 190

  
161 191

  
......
186 216
		}
187 217
	}
188 218

  
189
	public Namespace getRdfNamespace() {
190
		return rdfNamespace;
219
	public String getRdfNamespaceURIString() {
220
		return nsPrefixMap.get("rdf");
191 221
	}
192

  
193
	public void setRdfNamespace(Namespace rdfNamespace) {
194
		this.rdfNamespace = rdfNamespace;
222
	
223
	public String getTeamNamespaceURIString() {
224
		return nsPrefixMap.get("tm");
195 225
	}
196 226

  
197
	public Namespace getTcNamespace() {
198
		return tcNamespace;
227
	public void setNamespace(Namespace namespace) {
228
		this.nsPrefixMap.put(namespace.getPrefix(), namespace.getURI());
199 229
	}
200 230

  
201
	public void setTcNamespace(Namespace tcNamespace) {
202
		this.tcNamespace = tcNamespace;
231
	public String getTcNamespaceURIString() {
232
		return nsPrefixMap.get("tc");
203 233
	}
204 234

  
205
	public Namespace getTnNamespace() {
206
		return tnNamespace;
207
	}
235
	
208 236

  
209
	public void setTnNamespace(Namespace tnNamespace) {
210
		this.tnNamespace = tnNamespace;
237
	public String getTnNamespaceURIString() {
238
		return nsPrefixMap.get("tn");
211 239
	}
212 240

  
213
	public Namespace getCommonNamespace() {
214
		return commonNamespace;
215
	}
241
	
216 242

  
217
	public void setCommonNamespace(Namespace commonNamespace) {
218
		this.commonNamespace = commonNamespace;
243
	public String getCommonNamespaceURIString() {
244
		return nsPrefixMap.get("tcom");
219 245
	}
220 246

  
221
	public Namespace getGeoNamespace() {
222
		return geoNamespace;
223
	}
247
	
224 248

  
225
	public void setGeoNamespace(Namespace geoNamespace) {
226
		this.geoNamespace = geoNamespace;
249
	public String getGeoNamespaceURIString() {
250
		return nsPrefixMap.get("tgeo");
227 251
	}
228 252

  
229
	public Namespace getPublicationNamespace() {
230
		return publicationNamespace;
231
	}
253
	
232 254

  
233
	public void setPublicationNamespace(Namespace publicationNamespace) {
234
		this.publicationNamespace = publicationNamespace;
255
	public String getPublicationNamespaceURI() {
256
		return nsPrefixMap.get("tpub");
235 257
	}
258

  
259
	
236 260
	/**
237 261
	 * @return the palmNamespace
238 262
	 */
239
	public Namespace getPalmNamespace() {
240
		return palmNamespace;
263
	public String getPalmNamespaceURIString() {
264
		return nsPrefixMap.get("tpalm");
241 265
	}
242 266

  
243
	/**
244
	 * @param palmNamespace the palmNamespace to set
245
	 */
246
	public void setPalmNamespace(Namespace palmNamespace) {
247
		this.palmNamespace = palmNamespace;
248
	}
267
	
249 268

  
250 269
	/**
251 270
	 * if false references in this rdf file are not published in the bibliography list
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfReferenceImport.java
23 23
import org.jdom.Namespace;
24 24
import org.springframework.stereotype.Component;
25 25

  
26
import com.hp.hpl.jena.rdf.model.Model;
27
import com.hp.hpl.jena.rdf.model.Resource;
28
import com.hp.hpl.jena.rdf.model.Statement;
29

  
26 30
import eu.etaxonomy.cdm.common.CdmUtils;
27 31
import eu.etaxonomy.cdm.common.XmlHelp;
28 32
import eu.etaxonomy.cdm.io.common.mapping.berlinModel.CdmOneToManyMapper;
......
31 35
import eu.etaxonomy.cdm.io.common.ImportHelper;
32 36
import eu.etaxonomy.cdm.io.common.MapWrapper;
33 37
import eu.etaxonomy.cdm.io.common.mapping.CdmSingleAttributeMapperBase;
38
import eu.etaxonomy.cdm.io.common.mapping.IRdfMapper;
34 39
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
35 40
import eu.etaxonomy.cdm.model.agent.Team;
36 41
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
......
83 88
	}
84 89

  
85 90

  
86
	protected static IXmlMapper[] standardMappers = new IXmlMapper[]{
91
	protected static IRdfMapper[] standardMappers = new IRdfMapper[]{
87 92
		//new CdmTextElementMapper("edition", "edition"),
88 93
		new CdmTextElementMapper("volume", "volume"),
89 94
		new CdmTextElementMapper("placePublished", "placePublished"),
......
95 100
		//new CdmTextElementMapper("url", "uri")
96 101
	};
97 102

  
98
	protected static CdmSingleAttributeXmlMapperBase[] operationalMappers = new CdmSingleAttributeXmlMapperBase[]{
103
	protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
99 104
		new CdmUnclearMapper("year")
100 105
		, new CdmUnclearMapper("title")
101 106
		, new CdmUnclearMapper("shortTitle")
......
115 120

  
116 121

  
117 122

  
118
	private boolean makeStandardMapper(Element parentElement, Reference ref, Set<String> omitAttributes){
123
	private boolean makeStandardMapper(Statement resource, Reference ref, Set<String> omitAttributes){
119 124
		if (omitAttributes == null){
120 125
			omitAttributes = new HashSet<String>();
121 126
		}
122 127
		boolean result = true;
123
		for (IXmlMapper mapper : standardMappers){
128
		for (IRdfMapper mapper : standardMappers){
124 129
			if (mapper instanceof CdmSingleAttributeMapperBase){
125
				makeSingleAttributeMapper((CdmSingleAttributeXmlMapperBase)mapper, parentElement, ref, omitAttributes);
130
				makeSingleAttributeMapper((CdmSingleAttributeRDFMapperBase)mapper, resource, ref, omitAttributes);
126 131
			}else if (mapper instanceof CdmOneToManyMapper){
127
				makeMultipleAttributeMapper((CdmOneToManyMapper)mapper, parentElement, ref, omitAttributes);
132
				makeMultipleAttributeMapper((CdmOneToManyMapper)mapper, resource, ref, omitAttributes);
128 133
			}else{
129 134
				logger.error("Unrecognized mapper type");
130 135
				return false;
......
135 140
		return true;
136 141
	}
137 142

  
138
	private boolean makeSingleAttributeMapper(CdmSingleAttributeXmlMapperBase mapper, Element parentElement, Reference ref, Set<String> omitAttributes){
143
	private boolean makeSingleAttributeMapper(CdmSingleAttributeRDFMapperBase mapper, Statement resource, Reference ref, Set<String> omitAttributes){
139 144
		boolean result = true;
140
		Object value = getValue(mapper, parentElement);
145
		Object value = getValue(mapper, resource);
141 146
		//write to destination
142 147
		if (value != null){
143 148
			String destinationAttribute = mapper.getDestinationAttribute();
......
148 153
		return result;
149 154
	}
150 155

  
151
	private boolean makeMultipleAttributeMapper(CdmOneToManyMapper<?,?,CdmTextElementMapper> mapper, Element parentElement, Reference ref, Set<String> omitAttributes){
156
	private boolean makeMultipleAttributeMapper(CdmOneToManyMapper<?,?,CdmTextElementMapper> mapper, Statement parentElement, Reference ref, Set<String> omitAttributes){
152 157
		if (omitAttributes == null){
153 158
			omitAttributes = new HashSet<String>();
154 159
		}
......
169 174
		return result;
170 175
	}
171 176

  
172
	private Object getValue(CdmSingleAttributeXmlMapperBase mapper, Element parentElement){
173
		String sourceAttribute = mapper.getSourceAttribute().toLowerCase();
174
		Namespace sourceNamespace = mapper.getSourceNamespace(parentElement);
175
		Element child = parentElement.getChild(sourceAttribute, sourceNamespace);
176
		if (child == null){
177
			return null;
178
		}
179
		if (child.getContentSize() > 1){
180
			logger.warn("Element is not String");
181
		}
182
		Object value = child.getTextTrim();
183
		return value;
184
	}
177
//	private Object getValue(CdmSingleAttributeRDFMapperBase mapper, Element parentElement){
178
//		String sourceAttribute = mapper.getSourceAttribute().toLowerCase();
179
//		Namespace sourceNamespace = mapper.getSourceNamespace(parentElement);
180
//		Element child = parentElement.getChild(sourceAttribute, sourceNamespace);
181
//		if (child == null){
182
//			return null;
183
//		}
184
//		if (child.getContentSize() > 1){
185
//			logger.warn("Element is not String");
186
//		}
187
//		Object value = child.getTextTrim();
188
//		return value;
189
//	}
185 190

  
186 191
	@Override
187 192
    protected void doInvoke(TcsRdfImportState state){
......
189 194
		MapWrapper<Reference> nomRefMap = (MapWrapper<Reference>)state.getStore(ICdmIO.NOMREF_STORE);
190 195

  
191 196
		TcsRdfImportConfigurator config = state.getConfig();
192
		Element root = config.getSourceRoot();
197
		Model root = config.getSourceRoot();
193 198
		logger.info("start makeReferences ...");
194 199

  
195 200
		String tcsElementName;
196 201
		Namespace tcsNamespace;
197 202

  
198
		Namespace rdfNamespace = config.getRdfNamespace();
199
		Namespace publicationNamespace = config.getPublicationNamespace();
203
		String rdfNamespace = config.getRdfNamespaceURIString();
204
		String publicationNamespace = config.getPublicationNamespaceURI();
200 205

  
201 206
		String idNamespace = "PublicationCitation";
202 207
		tcsElementName = "PublicationCitation";
203
		tcsNamespace = publicationNamespace;
204
		List<Element> elPublicationCitations = root.getChildren(tcsElementName, tcsNamespace);
208
		
209
		/*List<Element> elPublicationCitations = root.l
205 210

  
206 211
		int nomRefCount = 0;
207 212
		int biblioRefsCount = 0;
......
321 326
		getReferenceService().save(referenceMap.objects());
322 327

  
323 328
		//referenceService.saveReferenceAll(referenceMap.objects());
324
		logger.info("end makeReferences ...");
329
		logger.info("end makeReferences ...");*/
325 330
		return;
326 331

  
327 332
	}
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfTaxonImport.java
21 21
import org.jdom.filter.Filter;
22 22
import org.springframework.stereotype.Component;
23 23

  
24
import com.hp.hpl.jena.rdf.model.Model;
25

  
24 26
import eu.etaxonomy.cdm.api.service.ITaxonService;
25 27
import eu.etaxonomy.cdm.common.XmlHelp;
26 28
import eu.etaxonomy.cdm.io.common.ICdmIO;
......
68 70
		return result;
69 71
	}
70 72
	
71
	protected static CdmSingleAttributeXmlMapperBase[] standardMappers = new CdmSingleAttributeXmlMapperBase[]{
73
	protected static CdmSingleAttributeRDFMapperBase[] standardMappers = new CdmSingleAttributeRDFMapperBase[]{
72 74
//		new CdmTextElementMapper("genusPart", "genusOrUninomial")
73 75
	
74 76
	};
75 77

  
76 78
	
77
	protected static CdmSingleAttributeXmlMapperBase[] operationalMappers = new CdmSingleAttributeXmlMapperBase[]{
79
	protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
78 80
		 new CdmUnclearMapper("hasName")
79 81
		,new CdmUnclearMapper("hasName")
80 82
		, new CdmUnclearMapper("accordingTo")
......
82 84
		, new CdmUnclearMapper("code", nsTgeo)	
83 85
	};
84 86
	
85
	protected static CdmSingleAttributeXmlMapperBase[] unclearMappers = new CdmSingleAttributeXmlMapperBase[]{
87
	protected static CdmSingleAttributeRDFMapperBase[] unclearMappers = new CdmSingleAttributeRDFMapperBase[]{
86 88
		new CdmUnclearMapper("primary")
87 89
		, new CdmUnclearMapper("note", nsTcom)	
88 90
		, new CdmUnclearMapper("taxonStatus", nsTpalm)
......
103 105
		
104 106
		String xmlElementName;
105 107
		String xmlAttributeName;
106
		Namespace elementNamespace;
107
		Namespace attributeNamespace;
108
		String elementNamespace;
109
		String attributeNamespace;
108 110
		
109 111
		logger.info("start makeTaxa ...");
110 112
		
111 113
		TcsRdfImportConfigurator config = state.getConfig();
112
		Element root = config.getSourceRoot();
114
		Model root = config.getSourceRoot();
113 115
		
114
		Namespace rdfNamespace = config.getRdfNamespace();
116
		String rdfNamespace = config.getRdfNamespaceURIString();
115 117
		
116 118
		String idNamespace = "TaxonConcept";
117 119
		xmlElementName = "TaxonConcept";
118
		elementNamespace = config.getTcNamespace();
119
		List<Element> elTaxonConcepts = root.getChildren(xmlElementName, elementNamespace);
120
		elementNamespace = config.getTcNamespaceURIString();
121
		/*List<Element> elTaxonConcepts = root.getChildren(xmlElementName, elementNamespace);
120 122

  
121 123
		ITaxonService taxonService = getTaxonService();
122 124
		
......
137 139
			
138 140
			//hasName
139 141
			xmlElementName = "hasName";
140
			elementNamespace = config.getTcNamespace();
142
			String conceptNamespace = config.getTcNamespaceURIString();
141 143
			xmlAttributeName = "resource";
142 144
			attributeNamespace = rdfNamespace;
143 145
			String strNameResource= XmlHelp.getChildAttributeValue(elTaxonConcept, xmlElementName, elementNamespace, xmlAttributeName, attributeNamespace);
......
205 207
		logger.info("saving " + taxonMap.size()+ " taxa ...");
206 208
		taxonService.save(taxonMap.objects());
207 209
		logger.info("end makeTaxa ...");
210
		*/
208 211
		return;
209 212
	}
210 213
	
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/tcsrdf/TcsRdfTaxonNameImport.java
9 9

  
10 10
package eu.etaxonomy.cdm.io.tcsrdf;
11 11

  
12
import java.io.IOException;
13
import java.io.InputStream;
12 14
import java.util.List;
13 15
import java.util.Set;
14 16

  
......
18 20
import org.jdom.Namespace;
19 21
import org.springframework.stereotype.Component;
20 22

  
23
import com.hp.hpl.jena.rdf.model.Model;
24
import com.hp.hpl.jena.rdf.model.ModelFactory;
25
import com.hp.hpl.jena.rdf.model.RDFNode;
26
import com.hp.hpl.jena.rdf.model.ResIterator;
27
import com.hp.hpl.jena.rdf.model.Resource;
28
import com.hp.hpl.jena.rdf.model.Selector;
29
import com.hp.hpl.jena.rdf.model.SimpleSelector;
30
import com.hp.hpl.jena.rdf.model.Statement;
31
import com.hp.hpl.jena.rdf.model.StmtIterator;
32
import com.hp.hpl.jena.vocabulary.*;
33
import com.hp.hpl.jena.rdf.model.Property;
34

  
35
import org.apache.commons.io.IOUtils;
36
import org.apache.jena.iri.IRIFactory;
37

  
21 38
import eu.etaxonomy.cdm.common.XmlHelp;
22 39
import eu.etaxonomy.cdm.io.common.ICdmIO;
23 40
import eu.etaxonomy.cdm.io.common.ImportHelper;
......
34 51
import eu.etaxonomy.cdm.model.name.NonViralName;
35 52
import eu.etaxonomy.cdm.model.name.Rank;
36 53
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
54
import eu.etaxonomy.cdm.model.name.ViralName;
37 55
import eu.etaxonomy.cdm.model.reference.IGeneric;
38 56
import eu.etaxonomy.cdm.model.reference.Reference;
39 57
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
......
65 83
		return result;
66 84
	}
67 85

  
68
	protected static CdmSingleAttributeXmlMapperBase[] standardMappers = new CdmSingleAttributeXmlMapperBase[]{
86
	protected static CdmSingleAttributeRDFMapperBase[] standardMappers = new CdmSingleAttributeRDFMapperBase[]{
69 87
		new CdmTextElementMapper("genusPart", "genusOrUninomial")
70 88
		, new CdmTextElementMapper("uninomial", "genusOrUninomial")  //TODO make it a more specific Mapper for both attributes
71 89
		, new CdmTextElementMapper("specificEpithet", "specificEpithet")
......
75 93

  
76 94
	};
77 95

  
78
	protected static CdmSingleAttributeXmlMapperBase[] operationalMappers = new CdmSingleAttributeXmlMapperBase[]{
96
	protected static CdmSingleAttributeRDFMapperBase[] operationalMappers = new CdmSingleAttributeRDFMapperBase[]{
79 97
		new CdmUnclearMapper("basionymAuthorship")
80 98
		, new CdmUnclearMapper("combinationAuthorship")
81 99
		, new CdmUnclearMapper("hasAnnotation")
......
85 103
		, new CdmUnclearMapper("year")
86 104
	};
87 105

  
88
	protected static CdmSingleAttributeXmlMapperBase[] unclearMappers = new CdmSingleAttributeXmlMapperBase[]{
106
	protected static CdmSingleAttributeRDFMapperBase[] unclearMappers = new CdmSingleAttributeRDFMapperBase[]{
89 107
		new CdmUnclearMapper("authorship")
90 108
		, new CdmUnclearMapper("rankString")
91 109
		, new CdmUnclearMapper("nameComplete")
......
106 124

  
107 125
		logger.info("start makeTaxonNames ...");
108 126
		TcsRdfImportConfigurator config = state.getConfig();
109
		Element root = config.getSourceRoot();
127
		Model root = config.getSourceRoot();
110 128

  
111
		Namespace rdfNamespace = config.getRdfNamespace();
112
		Namespace taxonNameNamespace = config.getTnNamespace();
129
		String rdfNamespace = config.getRdfNamespaceURIString();
130
		String taxonNameNamespace = config.getTnNamespaceURIString();
113 131

  
114 132
		String idNamespace = "TaxonName";
115 133

  
116
		List<Element> elTaxonNames = root.getChildren("TaxonName", taxonNameNamespace);
134
		Resource elTaxonName = root.getResource(taxonNameNamespace);
117 135

  
118 136
		int i = 0;
119
		//for each taxonName
120
		for (Element elTaxonName : elTaxonNames){
121

  
122
			if ((++i % modCount) == 0){ logger.info("Names handled: " + (i-1));}
123

  
124
			Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
137
		
138
		TaxonNameBase name;
139
		Property property = root.getProperty(taxonNameNamespace+"authorship");
140
		
141
		ResIterator iterator = root.listSubjectsWithProperty(property, (RDFNode) null);
142
		String id ;
143
		while (iterator.hasNext()){
144
			
145
			Resource resource = iterator.next();
146
			
147
			name = handleNameResource(resource, config);
148
			id = resource.getNameSpace();
149
			taxonNameMap.put(id, name);
150
		}
151
		
152
		logger.info(i + " names handled");
153
		getNameService().save(taxonNameMap.objects());
154
//		makeNameSpecificData(nameMap);
155
		logger.info("end makeTaxonNames ...");
156
		return;
125 157

  
126
			//create TaxonName element
127
			String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace);
128
			String strRank = XmlHelp.getChildAttributeValue(elTaxonName, "rank", taxonNameNamespace, "resource", rdfNamespace);
129
			String strNomenclaturalCode = XmlHelp.getChildAttributeValue(elTaxonName, "nomenclaturalCode", taxonNameNamespace, "resource", rdfNamespace);
158
	}
159
	/* (non-Javadoc)
160
	 * @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
161
	 */
162
	@Override
163
    protected boolean isIgnore(TcsRdfImportState state){
164
		return ! state.getConfig().isDoTaxonNames();
165
	}
166
	
167
	protected TaxonNameBase handleNameModel(Model model, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap, String uri){
168
		Resource nameAbout = model.getResource(uri);
169
		TaxonNameBase result = handleNameResource(nameAbout, config);
170
		taxonNameMap.put(uri, result);
171
		return result;
172
		
173
	}
174
	
175
	private TaxonNameBase handleNameResource(Resource nameAbout, TcsRdfImportConfigurator config){
176
		String idNamespace = "TaxonName";
177
		//Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
178
		
179
		//create TaxonName element
180
		
181
		
182
		System.out.println("name about "+nameAbout.getLocalName());
183
		
184
		
185
		StmtIterator stmts = nameAbout.listProperties();
186
		while ( stmts.hasNext() ) {
187
            System.out.println( stmts.next() );
188
        }
189
		Property prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nomenclaturalCode");
190
		Statement stateNomenclaturalCode = nameAbout.getProperty(prop);
191
		String strNomenclaturalCode = stateNomenclaturalCode.getObject().toString();
192
		//Rank
193
		prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"rankString");
194
		String strRank = nameAbout.getProperty(prop).getString();
195
		
196
		
197
		
198
		try {
199
			
200
			Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
201
			NomenclaturalCode nomCode;
202
			if (strNomenclaturalCode != null){
203
				nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
204
			}else{
205
				nomCode = NomenclaturalCode.ICNAFP;
206
			}
207
				
208
			TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
209

  
210
			Set<String> omitAttributes = null;
211
			//makeStandardMapper(nameAbout, nameBase, omitAttributes, standardMappers);
212
			
213
			prop = nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"nameComplete");
214
			String strNameComplete = nameAbout.getProperty(prop).getString();
215
			nameBase.setTitleCache(strNameComplete, true);
216
			
217
			prop =  nameAbout.getModel().getProperty(config.getCommonNamespaceURIString()+"publishedIn");
218
			String strPublishedIn = nameAbout.getProperty(prop).getString();
219
			if (strPublishedIn != null && strPublishedIn != ""){
220
				IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
221
				nomRef.setTitleCache(strPublishedIn, true);
222
				nameBase.setNomenclaturalReference(nomRef);
223
				try{
224
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"year");
225
				String strYear = nameAbout.getProperty(prop).getString();
226
				Integer year = null;
227
				if (strYear != null){
228
					try {
229
						year = Integer.valueOf(strYear);
230
						TimePeriod timeP = TimePeriod.NewInstance(year);
231
						nomRef.setDatePublished(timeP);
232
					} catch (RuntimeException e) {
233
						logger.warn("year could not be parsed");
234
					}
235
				}
236
				}catch(NullPointerException e){
237
				}
238
				if (config.isPublishReferences()){
239
					((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
240
				}
241
			}
242
			
243
			if (nameBase instanceof NonViralName){
244
				NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
245
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"genusPart");
246
				String strGenusPart;
247
				try{
248
					strGenusPart = nameAbout.getProperty(prop).getString();
249
				}catch(NullPointerException e){
250
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"uninomial");
251
					strGenusPart = nameAbout.getProperty(prop).getString();
252
				}
253
				
254
				nonViralName.setGenusOrUninomial(strGenusPart);
255
				
256
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infragenericEpithet");
257
				try{
258
					String strInfragenericEpithet = nameAbout.getProperty(prop).getString();
259
					nonViralName.setInfraGenericEpithet(strInfragenericEpithet);
260
				}catch(NullPointerException e){
261
					
262
				}
263
				try {
264
					prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"specificEpithet");
265
					String strSpecificEpithet = nameAbout.getProperty(prop).getString();
266
					nonViralName.setSpecificEpithet(strSpecificEpithet);
267
				}catch(NullPointerException e){
268
					
269
				}
270
				try{
271
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"infraspecificEpithet");
272
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
273
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
274
				}catch(NullPointerException e){
275
					
276
				}
277
				//AuthorTeams
278
				//TODO
279
				prop =  nameAbout.getModel().getProperty(config.getTnNamespaceURIString()+"authorship");
280
				Statement stateAuthorship = nameAbout.getProperty(prop);
281
				prop =  nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"name");
282
				Team authorTeam = new Team();
283
				authorTeam.setTitleCache(stateAuthorship.getObject().toString(), true);
284
				prop =  nameAbout.getModel().getProperty(config.getTeamNamespaceURIString()+"hasMember");
285
				//String strTeamMember = nameAbout.getProperty(prop).getString();
286
				nonViralName.setCombinationAuthorTeam(authorTeam);
287
				
288
				//Annotations:
289
				/*
290
				 * <tn:hasAnnotation>
291
            <tn:NomenclaturalNote>
292
                <tn:noteType rdf:resource="http://rs.tdwg.org/ontology/voc/TaxonName#replacementNameFor"/>
293
                <tn:objectTaxonName rdf:resource="urn:lsid:ipni.org:names:151538-1"/>
294
            </tn:NomenclaturalNote>
295
        </tn:hasAnnotation>   
296
				 */
297
				/*
298
				String strInfraspecificEpithet = nameAbout.getProperty(prop).getString();
299
				tcsElementName = "basionymAuthorship";
300
				String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
301
				if (basionymAuthorValue != null){
302
					TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
303
					basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
304
					nonViralName.setBasionymAuthorTeam(basionymAuthor);
305
				}
130 306

  
131
			try {
132
				Rank rank = TcsRdfTransformer.rankString2Rank(strRank);
133
				NomenclaturalCode nomCode = TcsRdfTransformer.nomCodeString2NomCode(strNomenclaturalCode);
134
				TaxonNameBase<?,?> nameBase = nomCode.getNewTaxonNameInstance(rank);
307
				//TODO
308
				tcsElementName = "combinationAuthorship";
309
				String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
310
				if (combinationAuthorValue != null){
311
					TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
312
					combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
313
					nonViralName.setCombinationAuthorTeam(combinationAuthor);
314
				}
135 315

  
136
				Set<String> omitAttributes = null;
137
				makeStandardMapper(elTaxonName, nameBase, omitAttributes, standardMappers);
316
				//set the authorshipCache
317
				tcsElementName = "authorship";
318
				String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
319
				String cache = nonViralName.getAuthorshipCache();
320
				if ( authorValue != null){
321
					//compare existing authorship cache with new one and check if it is necessary to
322
					//make cache protected  //TODO refinement
323
					if (cache == null){
324
						nonViralName.setAuthorshipCache(authorValue);
325
					}else{
326
						cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
327
						cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
328
						cache = cache.replace("\\(|\\)", "");
329
						cache = cache.trim();
330
						if (! cache.equals("")){
331
							nonViralName.setAuthorshipCache(authorValue);
332
						}
333
					}
334
				}*/
335
			}
336
			//ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
337

  
338
			//checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
339
			
340
			return nameBase;
341
				
342
			}catch(Exception e){
343
			e.printStackTrace();
344
			return null;
345
		}
346
			/*
347
			//name
348
			String strNameComplete = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "nameComplete", rdfNamespace);
349
			nameBase.setTitleCache(strNameComplete, true);
350
			
351
			//Reference
352
			//TODO
353
			String tcsElementName = "publishedIn";
354
			Namespace tcsNamespace = config.getCommonNamespaceURIString();
355
			String value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
356
			if (value != null && value != ""){
357
				IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
358
				nomRef.setTitleCache(value, true);
359
				nameBase.setNomenclaturalReference(nomRef);
138 360

  
139
				//Reference
140 361
				//TODO
141
				tcsElementName = "publishedIn";
142
				tcsNamespace = config.getCommonNamespace();
362
				tcsElementName = "year";
363
				tcsNamespace = taxonNameNamespace;
364
				Integer year = null;
143 365
				value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
144 366
				if (value != null){
145
					IGeneric nomRef = ReferenceFactory.newGeneric(); //TODO
146
					nomRef.setTitleCache(value, true);
147
					nameBase.setNomenclaturalReference(nomRef);
148

  
149
					//TODO
150
					tcsElementName = "year";
151
					tcsNamespace = taxonNameNamespace;
152
					Integer year = null;
153
					value = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, tcsNamespace);
154
					if (value != null){
155
						try {
156
							year = Integer.valueOf(value);
157
							TimePeriod timeP = TimePeriod.NewInstance(year);
158
							nomRef.setDatePublished(timeP);
159
						} catch (RuntimeException e) {
160
							logger.warn("year could not be parsed");
161
						}
162
					}
163
					if (state.getConfig().isPublishReferences()){
164
						((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
367
					try {
368
						year = Integer.valueOf(value);
369
						TimePeriod timeP = TimePeriod.NewInstance(year);
370
						nomRef.setDatePublished(timeP);
371
					} catch (RuntimeException e) {
372
						logger.warn("year could not be parsed");
165 373
					}
166 374
				}
375
				if (config.isPublishReferences()){
376
					((Reference<?>)nomRef).addMarker(Marker.NewInstance(MarkerType.PUBLISH(), false));
377
				}
378
			}
167 379

  
168
				//Status
169
				tcsNamespace = taxonNameNamespace;
170
				Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
171
				if (elAnnotation != null){
172
					Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
173
					if (elNomenclaturalNote != null){
174
						String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
175
						String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
176
						String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
177
						if (tdwgType.equalsIgnoreCase(type)){
178
							try {
179
								NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
180
								//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
181
								if (statusType != null){
182
									nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
183
								}
184
							} catch (UnknownCdmTypeException e) {
185
								if (! statusValue.equals("valid")){
186
									logger.warn("Unknown NomenclaturalStatusType: " +  statusValue);
187
								}
380
			//Status
381
			tcsNamespace = taxonNameNamespace;
382
			Element elAnnotation = elTaxonName.getChild("hasAnnotation", tcsNamespace);
383
			if (elAnnotation != null){
384
				Element elNomenclaturalNote = elAnnotation.getChild("NomenclaturalNote", tcsNamespace);
385
				if (elNomenclaturalNote != null){
386
					String statusValue = (String)ImportHelper.getXmlInputValue(elNomenclaturalNote, "note", tcsNamespace);
387
					String type = XmlHelp.getChildAttributeValue(elNomenclaturalNote, "type", tcsNamespace, "resource", rdfNamespace);
388
					String tdwgType = "http://rs.tdwg.org/ontology/voc/TaxonName#PublicationStatus";
389
					if (tdwgType.equalsIgnoreCase(type)){
390
						try {
391
							NomenclaturalStatusType statusType = TcsRdfTransformer.nomStatusString2NomStatus(statusValue);
392
							//NomenclaturalStatusType statusType = NomenclaturalStatusType.getNomenclaturalStatusTypeByAbbreviation(statusValue);
393
							if (statusType != null){
394
								nameBase.addStatus(NomenclaturalStatus.NewInstance(statusType));
395
							}
396
						} catch (UnknownCdmTypeException e) {
397
							if (! statusValue.equals("valid")){
398
								logger.warn("Unknown NomenclaturalStatusType: " +  statusValue);
188 399
							}
189 400
						}
190 401
					}
191 402
				}
403
			}
404

  
405
			if (nameBase instanceof NonViralName){
406
				NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
407
				String strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "genusPart", rdfNamespace);
408
				
409
				//for names of rank genus the uninomial property should be used
410
				if (strGenusPart == null){
411
					strGenusPart =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "uninomial", rdfNamespace);
412
				}
413
				nonViralName.setGenusOrUninomial(strGenusPart);
414
				
415
				String strInfragenericEpithet =  XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infragenericEpithet", rdfNamespace);
416
				nonViralName.setGenusOrUninomial(strInfragenericEpithet);
417
				
418
				
419
				
420
				String strSpecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "specificEpithet", rdfNamespace);
421
				nonViralName.setSpecificEpithet(strSpecificEpithet);
422
				
423
				String strInfraspecificEpithet = XmlHelp.getChildContent(elTaxonName, "TaxonName", taxonNameNamespace, "infraspecificEpithet", rdfNamespace);
424
				nonViralName.setInfraSpecificEpithet(strInfraspecificEpithet);
425
				//AuthorTeams
426
				//TODO
427
				tcsElementName = "basionymAuthorship";
428
				String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
429
				if (basionymAuthorValue != null){
430
					TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
431
					basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
432
					nonViralName.setBasionymAuthorTeam(basionymAuthor);
433
				}
192 434

  
193
				if (nameBase instanceof NonViralName){
194
					NonViralName<?> nonViralName = (NonViralName<?>)nameBase;
195

  
196
					//AuthorTeams
197
					//TODO
198
					tcsElementName = "basionymAuthorship";
199
					String basionymAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
200
					if (basionymAuthorValue != null){
201
						TeamOrPersonBase<?> basionymAuthor = Team.NewInstance();
202
						basionymAuthor.setNomenclaturalTitle(basionymAuthorValue);
203
						nonViralName.setBasionymAuthorTeam(basionymAuthor);
435
				//TODO
436
				tcsElementName = "combinationAuthorship";
437
				String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
438
				if (combinationAuthorValue != null){
439
					TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
440
					combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
441
					nonViralName.setCombinationAuthorTeam(combinationAuthor);
442
				}
443

  
444
				//set the authorshipCache
445
				tcsElementName = "authorship";
446
				String authorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
447
				String cache = nonViralName.getAuthorshipCache();
448
				if ( authorValue != null){
449
					//compare existing authorship cache with new one and check if it is necessary to
450
					//make cache protected  //TODO refinement
451
					if (cache == null){
452
						nonViralName.setAuthorshipCache(authorValue);
453
					}else{
454
						cache = basionymAuthorValue == null ? cache : cache.replace(basionymAuthorValue, "");
455
						cache = combinationAuthorValue == null ? cache : cache.replace(combinationAuthorValue, "");
456
						cache = cache.replace("\\(|\\)", "");
457
						cache = cache.trim();
458
						if (! cache.equals("")){
459
							nonViralName.setAuthorshipCache(authorValue);
460
						}
204 461
					}
462
				}
463
			}
464
			ImportHelper.setOriginalSource(nameBase, config.getSourceReference(), nameAbout, idNamespace);
205 465

  
206
					//TODO
207
					tcsElementName = "combinationAuthorship";
208
					String combinationAuthorValue = (String)ImportHelper.getXmlInputValue(elTaxonName, tcsElementName, taxonNameNamespace);
209
					if (combinationAuthorValue != null){
210
						TeamOrPersonBase<?> combinationAuthor = Team.NewInstance();
211
						combinationAuthor.setNomenclaturalTitle(combinationAuthorValue);
212
						nonViralName.setCombinationAuthorTeam(combinationAuthor);
466
			checkAdditionalContents(elTaxonName, standardMappers, operationalMappers, unclearMappers);
467

  
468
			//nameId
469
			//TODO
470
			//ImportHelper.setOriginalSource(nameBase, tcsConfig.getSourceReference(), nameId);
471
			//taxonNameMap.put(nameAbout, nameBase);
472
			return nameBase;
473
		}catch(UnknownCdmTypeException e){
474
			e.printStackTrace();
475
		}
476
		return null;*/
477
	}
478
	
479
	protected TaxonNameBase handleNameElement(Element elTaxonName, Namespace rdfNamespace, Namespace taxonNameNamespace, TcsRdfImportConfigurator config, MapWrapper<TaxonNameBase> taxonNameMap){
480
		String idNamespace = "TaxonName";
481
		Attribute about = elTaxonName.getAttribute("about", rdfNamespace);
482
		
483
		//create TaxonName element
484
		
485
	
486
		String nameAbout = elTaxonName.getAttributeValue("about", rdfNamespace);
487
		if (nameAbout == null){
488
			nameAbout = XmlHelp.getChildAttributeValue(elTaxonName, "TaxonName", taxonNameNamespace, "about", rdfNamespace);
489
		}
490
		
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)