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 static eu.etaxonomy.cdm.io.common.ImportHelper.OBLIGATORY;
|
13
|
import static eu.etaxonomy.cdm.io.common.ImportHelper.OVERWRITE;
|
14
|
|
15
|
import java.util.ArrayList;
|
16
|
import java.util.Arrays;
|
17
|
import java.util.HashSet;
|
18
|
import java.util.List;
|
19
|
import java.util.Set;
|
20
|
|
21
|
import org.apache.log4j.Logger;
|
22
|
import org.jdom.Content;
|
23
|
import org.jdom.Element;
|
24
|
import org.jdom.Text;
|
25
|
|
26
|
import com.hp.hpl.jena.rdf.model.Statement;
|
27
|
|
28
|
import eu.etaxonomy.cdm.io.common.CdmImportBase;
|
29
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
30
|
import eu.etaxonomy.cdm.io.common.mapping.IXmlMapper;
|
31
|
import eu.etaxonomy.cdm.io.tcsxml.CdmSingleAttributeXmlMapperBase;
|
32
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
33
|
|
34
|
/**
|
35
|
* @author a.mueller
|
36
|
* @since 04.08.2008
|
37
|
*/
|
38
|
public abstract class TcsRdfImportBase extends CdmImportBase<TcsRdfImportConfigurator, TcsRdfImportState> {
|
39
|
private static final long serialVersionUID = -8765093240068562907L;
|
40
|
|
41
|
private static final Logger logger = Logger.getLogger(TcsRdfImportBase.class);
|
42
|
|
43
|
protected static String nsTcom = "http://rs.tdwg.org/ontology/voc/Common#";
|
44
|
protected static String nsTn = "http://rs.tdwg.org/ontology/voc/TaxonName#";
|
45
|
protected static String nsTgeo = "http://rs.tdwg.org/ontology/voc/GeographicRegion#";
|
46
|
protected static String nsTc = "http://rs.tdwg.org/ontology/voc/TaxonConcept#";
|
47
|
protected static String nsTpub = "http://rs.tdwg.org/ontology/voc/PublicationCitation#";
|
48
|
protected static String nsTm = "http://rs.tdwg.org/ontology/voc/Team";
|
49
|
protected static String nsTpalm = "http://wp5.e-taxonomy.eu/import/palmae/common";
|
50
|
|
51
|
|
52
|
@Override
|
53
|
protected abstract void doInvoke(TcsRdfImportState state);
|
54
|
|
55
|
// /* (non-Javadoc)
|
56
|
// * @see eu.etaxonomy.cdm.io.common.CdmIoBase#doInvoke(eu.etaxonomy.cdm.io.common.IImportConfigurator, eu.etaxonomy.cdm.api.application.CdmApplicationController, java.util.Map)
|
57
|
// */
|
58
|
// @Override
|
59
|
// protected boolean doInvoke(IImportConfigurator config,
|
60
|
// Map<String, MapWrapper<? extends CdmBase>> stores){
|
61
|
// TcsRdfImportState state = ((TcsRdfImportConfigurator)config).getState();
|
62
|
// state.setConfig((TcsRdfImportConfigurator)config);
|
63
|
// return doInvoke(state);
|
64
|
// }
|
65
|
|
66
|
protected boolean makeStandardMapper(Statement resource, CdmBase ref, Set<String> omitAttributes, CdmSingleAttributeRDFMapperBase[] classMappers){
|
67
|
if (omitAttributes == null){
|
68
|
omitAttributes = new HashSet<String>();
|
69
|
}
|
70
|
boolean result = true;
|
71
|
for (CdmSingleAttributeRDFMapperBase mapper : classMappers){
|
72
|
Object value = getValue(mapper, resource);
|
73
|
//write to destination
|
74
|
if (value != null){
|
75
|
String destinationAttribute = mapper.getDestinationAttribute();
|
76
|
if (! omitAttributes.contains(destinationAttribute)){
|
77
|
result &= ImportHelper.addValue(value, ref, destinationAttribute, mapper.getTypeClass(), OVERWRITE, OBLIGATORY);
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
return result;
|
82
|
}
|
83
|
|
84
|
public Object getValue(CdmSingleAttributeRDFMapperBase mapper, Statement resource){
|
85
|
String sourceAttribute = mapper.getSourceAttribute();
|
86
|
String sourceNamespace = mapper.getSourceNameSpace(resource);
|
87
|
String value = resource.getProperty(resource.getModel().createProperty(sourceNamespace+sourceAttribute)).getString();
|
88
|
|
89
|
return value;
|
90
|
}
|
91
|
|
92
|
protected boolean checkAdditionalContents(Element parentElement, IXmlMapper[] classMappers, CdmSingleAttributeXmlMapperBase[] operationalMappers, CdmSingleAttributeXmlMapperBase[] unclearMappers){
|
93
|
List<Content> additionalContentList = new ArrayList<Content>();
|
94
|
List<Content> contentList = parentElement.getContent();
|
95
|
List<IXmlMapper> mapperList = new ArrayList<IXmlMapper>();
|
96
|
|
97
|
mapperList.addAll(Arrays.asList(classMappers));
|
98
|
mapperList.addAll(Arrays.asList(operationalMappers));
|
99
|
mapperList.addAll(Arrays.asList(unclearMappers));
|
100
|
|
101
|
for(Content content: contentList){
|
102
|
boolean contentExists = false;
|
103
|
if (content instanceof Element){
|
104
|
Element elementContent = (Element)content;
|
105
|
for (IXmlMapper mapper : mapperList){
|
106
|
if (mapper.mapsSource(content, parentElement)){
|
107
|
contentExists = true;
|
108
|
break;
|
109
|
}
|
110
|
}
|
111
|
|
112
|
}else if (content instanceof Text){
|
113
|
//empty Text
|
114
|
if (((Text)content).getTextNormalize().equals("")){
|
115
|
contentExists = true;
|
116
|
}else{
|
117
|
//
|
118
|
}
|
119
|
}
|
120
|
|
121
|
if (contentExists == false){
|
122
|
additionalContentList.add(content);
|
123
|
}
|
124
|
}
|
125
|
for (Content additionalContent : additionalContentList){
|
126
|
logger.warn("Additional content: " + additionalContent);
|
127
|
}
|
128
|
return (additionalContentList.size() == 0);
|
129
|
}
|
130
|
|
131
|
}
|