1 |
01be5674
|
Andreas Müller
|
/**
|
2 |
bba7e155
|
h.fradin
|
* 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 |
01be5674
|
Andreas Müller
|
|
10 |
49f54e3f
|
Andreas Müller
|
package eu.etaxonomy.cdm.io.sdd.in;
|
11 |
cb85c609
|
h.fradin
|
|
12 |
14c311fb
|
h.fradin
|
import java.io.File;
|
13 |
|
|
import java.net.MalformedURLException;
|
14 |
218848c8
|
m.venin
|
import java.net.URI;
|
15 |
14c311fb
|
h.fradin
|
import java.net.URL;
|
16 |
cdbae74d
|
h.fradin
|
import java.text.SimpleDateFormat;
|
17 |
3ff51780
|
h.fradin
|
import java.util.ArrayList;
|
18 |
cdbae74d
|
h.fradin
|
import java.util.Date;
|
19 |
cb85c609
|
h.fradin
|
import java.util.HashMap;
|
20 |
cdbae74d
|
h.fradin
|
import java.util.HashSet;
|
21 |
cb85c609
|
h.fradin
|
import java.util.List;
|
22 |
|
|
import java.util.Map;
|
23 |
cdbae74d
|
h.fradin
|
import java.util.Set;
|
24 |
ee0eed2d
|
Andreas Müller
|
import java.util.UUID;
|
25 |
cb85c609
|
h.fradin
|
|
26 |
cfd73bf1
|
Andreas Müller
|
import org.apache.commons.lang.StringUtils;
|
27 |
cb85c609
|
h.fradin
|
import org.apache.log4j.Logger;
|
28 |
|
|
import org.jdom.Element;
|
29 |
|
|
import org.jdom.Namespace;
|
30 |
|
|
import org.joda.time.DateTime;
|
31 |
5acb39d8
|
ben.clark
|
import org.springframework.stereotype.Component;
|
32 |
cdbae74d
|
h.fradin
|
import org.springframework.transaction.TransactionStatus;
|
33 |
cb85c609
|
h.fradin
|
|
34 |
|
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
35 |
370503cf
|
n.hoffmann
|
import eu.etaxonomy.cdm.common.media.ImageInfo;
|
36 |
79c0eaa0
|
Andreas Müller
|
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor;
|
37 |
75cb8a46
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
38 |
1ffe3106
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.common.ICdmImport;
|
39 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
40 |
6b8ba655
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.common.XmlImportBase;
|
41 |
7b6a429a
|
Andreas Müller
|
import eu.etaxonomy.cdm.io.sdd.SDDTransformer;
|
42 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.agent.Person;
|
43 |
106caaa4
|
h.fradin
|
import eu.etaxonomy.cdm.model.agent.Team;
|
44 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
45 |
cb404210
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.AnnotationType;
|
46 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
47 |
fb3ea98b
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
48 |
9068f64f
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
49 |
57606ee3
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
50 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.Language;
|
51 |
bba7e155
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
52 |
5f03512e
|
m.venin
|
import eu.etaxonomy.cdm.model.common.Marker;
|
53 |
|
|
import eu.etaxonomy.cdm.model.common.MarkerType;
|
54 |
9068f64f
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.Representation;
|
55 |
|
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
56 |
cdbae74d
|
h.fradin
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
57 |
|
|
import eu.etaxonomy.cdm.model.common.VersionableEntity;
|
58 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
59 |
|
|
import eu.etaxonomy.cdm.model.description.Feature;
|
60 |
bba7e155
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
61 |
af1882d9
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
62 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
63 |
75cb8a46
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.description.Modifier;
|
64 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
65 |
|
|
import eu.etaxonomy.cdm.model.description.State;
|
66 |
fb3ea98b
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.StateData;
|
67 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
68 |
|
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
|
69 |
|
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
70 |
|
|
import eu.etaxonomy.cdm.model.description.TextData;
|
71 |
435d1ded
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.description.WorkingSet;
|
72 |
75cb8a46
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
73 |
|
|
import eu.etaxonomy.cdm.model.media.IdentifiableMediaEntity;
|
74 |
14c311fb
|
h.fradin
|
import eu.etaxonomy.cdm.model.media.ImageFile;
|
75 |
9653d159
|
h.fradin
|
import eu.etaxonomy.cdm.model.media.Media;
|
76 |
14c311fb
|
h.fradin
|
import eu.etaxonomy.cdm.model.media.MediaRepresentation;
|
77 |
c7ab9b2a
|
h.fradin
|
import eu.etaxonomy.cdm.model.media.MediaRepresentationPart;
|
78 |
cdbae74d
|
h.fradin
|
import eu.etaxonomy.cdm.model.media.Rights;
|
79 |
cb85c609
|
h.fradin
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
80 |
514d0c79
|
h.fradin
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
81 |
e192e06c
|
m.venin
|
import eu.etaxonomy.cdm.model.occurrence.Specimen;
|
82 |
1d36aa54
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
83 |
f53af173
|
Katja Luther
|
import eu.etaxonomy.cdm.model.reference.ReferenceFactory;
|
84 |
1d36aa54
|
Andreas Müller
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
85 |
5f03512e
|
m.venin
|
import eu.etaxonomy.cdm.model.taxon.Synonym;
|
86 |
75cb8a46
|
Andreas Kohlbecker
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
87 |
|
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
88 |
cb85c609
|
h.fradin
|
|
89 |
01be5674
|
Andreas Müller
|
/**
|
90 |
|
|
* @author h.fradin
|
91 |
|
|
* @created 24.10.2008
|
92 |
|
|
* @version 1.0
|
93 |
|
|
*/
|
94 |
7b6a429a
|
Andreas Müller
|
@Component("sddImport")
|
95 |
6b8ba655
|
Andreas Müller
|
public class SDDImport extends XmlImportBase<SDDImportConfigurator, SDDImportState> implements ICdmImport<SDDImportConfigurator, SDDImportState> {
|
96 |
036cf746
|
Andreas Müller
|
private static final Logger logger = Logger.getLogger(SDDImport.class);
|
97 |
cb85c609
|
h.fradin
|
|
98 |
e4a7b23e
|
h.fradin
|
private static int modCount = 1000;
|
99 |
cb85c609
|
h.fradin
|
|
100 |
ee0eed2d
|
Andreas Müller
|
private UUID uuidAnnotationTypeLocation = UUID.fromString("a3737e07-72e3-46d2-986d-fa4cf5de0b63");
|
101 |
|
|
|
102 |
|
|
|
103 |
bba7e155
|
h.fradin
|
private Map<String,Person> authors = new HashMap<String,Person>();
|
104 |
|
|
private Map<String,String> citations = new HashMap<String,String>();
|
105 |
808e5e3b
|
h.fradin
|
private Map<String,String> defaultUnitPrefixes = new HashMap<String,String>();
|
106 |
bba7e155
|
h.fradin
|
private Map<String,Person> editors = new HashMap<String,Person>();
|
107 |
|
|
private Map<String,FeatureNode> featureNodes = new HashMap<String,FeatureNode>();
|
108 |
808e5e3b
|
h.fradin
|
private Map<String,Feature> features = new HashMap<String,Feature>();
|
109 |
bba7e155
|
h.fradin
|
private Map<String,String> locations = new HashMap<String,String>();
|
110 |
|
|
private Map<String,List<CdmBase>> mediaObject_ListCdmBase = new HashMap<String,List<CdmBase>>();
|
111 |
|
|
private Map<String,String> mediaObject_Role = new HashMap<String,String>();
|
112 |
5559e194
|
Andreas Müller
|
private Map<String,Reference<?>> publications = new HashMap<String,Reference<?>>();
|
113 |
0ae635c4
|
m.venin
|
private Map<String,State> states = new HashMap<String,State>();
|
114 |
bba7e155
|
h.fradin
|
private Map<String,TaxonDescription> taxonDescriptions = new HashMap<String,TaxonDescription>();
|
115 |
5559e194
|
Andreas Müller
|
private Map<String,NonViralName<?>> taxonNameBases = new HashMap<String,NonViralName<?>>();
|
116 |
bba7e155
|
h.fradin
|
private Map<String,MeasurementUnit> units = new HashMap<String,MeasurementUnit>();
|
117 |
5f03512e
|
m.venin
|
private Map<String,TaxonNode> taxonNodes = new HashMap<String,TaxonNode>();
|
118 |
e192e06c
|
m.venin
|
private Map<String,NamedArea> namedAreas = new HashMap<String,NamedArea>();
|
119 |
|
|
private Map<String,Specimen> specimens = new HashMap<String,Specimen>();
|
120 |
fc15b32c
|
m.venin
|
private Map<String,Modifier> modifiers = new HashMap<String,Modifier>();
|
121 |
|
|
|
122 |
|
|
private Set<MarkerType> markerTypes = new HashSet<MarkerType>();
|
123 |
5559e194
|
Andreas Müller
|
private Set<TermVocabulary<?>> vocabularies = new HashSet<TermVocabulary<?>>();
|
124 |
5d556bff
|
h.fradin
|
|
125 |
fc15b32c
|
m.venin
|
private Set<Feature> descriptiveConcepts = new HashSet<Feature>();
|
126 |
cb404210
|
h.fradin
|
private Set<AnnotationType> annotationTypes = new HashSet<AnnotationType>();
|
127 |
435d1ded
|
Andreas Müller
|
// private Set<Feature> featureSet = new HashSet<Feature>();
|
128 |
5559e194
|
Andreas Müller
|
private Set<Reference<?>> sources = new HashSet<Reference<?>>();
|
129 |
|
|
private Reference<?> sec = ReferenceFactory.newDatabase();
|
130 |
|
|
private Reference<?> sourceReference = null;
|
131 |
9068f64f
|
h.fradin
|
|
132 |
|
|
private Language datasetLanguage = null;
|
133 |
435d1ded
|
Andreas Müller
|
private WorkingSet workingSet = null;
|
134 |
9068f64f
|
h.fradin
|
|
135 |
|
|
private Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
|
136 |
|
|
|
137 |
808e5e3b
|
h.fradin
|
private String generatorName = "";
|
138 |
|
|
private String generatorVersion = "";
|
139 |
4f213356
|
m.venin
|
|
140 |
808e5e3b
|
h.fradin
|
|
141 |
|
|
private Set<StatisticalMeasure> statisticalMeasures = new HashSet<StatisticalMeasure>();
|
142 |
|
|
private Set<VersionableEntity> featureData = new HashSet<VersionableEntity>();
|
143 |
af1882d9
|
h.fradin
|
private Set<FeatureTree> featureTrees = new HashSet<FeatureTree>();
|
144 |
1d36aa54
|
Andreas Müller
|
private Set<Classification> classifications = new HashSet<Classification>();
|
145 |
808e5e3b
|
h.fradin
|
|
146 |
|
|
private Rights copyright = null;
|
147 |
|
|
|
148 |
2d28b538
|
m.venin
|
private int taxonNamesCount = 0;
|
149 |
e192e06c
|
m.venin
|
|
150 |
036cf746
|
Andreas Müller
|
public SDDImport(){
|
151 |
cb85c609
|
h.fradin
|
super();
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
@Override
|
155 |
6b2cc8fd
|
Andreas Müller
|
public boolean doCheck(SDDImportState state){
|
156 |
cb85c609
|
h.fradin
|
boolean result = true;
|
157 |
|
|
logger.warn("No check implemented for SDD");
|
158 |
|
|
return result;
|
159 |
|
|
}
|
160 |
|
|
|
161 |
5d556bff
|
h.fradin
|
// @Override
|
162 |
|
|
// public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
|
163 |
|
|
@Override
|
164 |
51171c9d
|
Andreas Müller
|
public void doInvoke(SDDImportState state){
|
165 |
036cf746
|
Andreas Müller
|
|
166 |
d37cd796
|
ben.clark
|
TransactionStatus ts = startTransaction();
|
167 |
6b2cc8fd
|
Andreas Müller
|
SDDImportConfigurator sddConfig = state.getConfig();
|
168 |
1d36aa54
|
Andreas Müller
|
IProgressMonitor progressMonitor = sddConfig.getProgressMonitor();
|
169 |
|
|
|
170 |
808e5e3b
|
h.fradin
|
logger.info("start Datasets ...");
|
171 |
1d36aa54
|
Andreas Müller
|
|
172 |
cb85c609
|
h.fradin
|
// <Datasets xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://rs.tdwg.org/UBIF/2006/" xsi:schemaLocation="http://rs.tdwg.org/UBIF/2006/ ../SDD.xsd">
|
173 |
|
|
Element root = sddConfig.getSourceRoot();
|
174 |
|
|
Namespace sddNamespace = sddConfig.getSddNamespace();
|
175 |
14c311fb
|
h.fradin
|
|
176 |
e4a7b23e
|
h.fradin
|
logger.info("start TechnicalMetadata ...");
|
177 |
cb85c609
|
h.fradin
|
// <TechnicalMetadata created="2006-04-20T10:00:00">
|
178 |
808e5e3b
|
h.fradin
|
importTechnicalMetadata(root, sddNamespace, sddConfig);
|
179 |
|
|
List<Element> elDatasets = root.getChildren("Dataset",sddNamespace);
|
180 |
5559e194
|
Andreas Müller
|
// int i = 0;
|
181 |
9068f64f
|
h.fradin
|
|
182 |
808e5e3b
|
h.fradin
|
//for each Dataset
|
183 |
|
|
logger.info("start Dataset ...");
|
184 |
1d36aa54
|
Andreas Müller
|
progressMonitor.beginTask("Importing SDD data", elDatasets.size());
|
185 |
808e5e3b
|
h.fradin
|
for (Element elDataset : elDatasets){
|
186 |
51171c9d
|
Andreas Müller
|
importDataset(elDataset, sddNamespace, state);
|
187 |
1d36aa54
|
Andreas Müller
|
// if ((++i % modCount) == 0){ logger.info("dataset(s) handled: " + i);}
|
188 |
|
|
// logger.info(i + " dataset(s) handled");
|
189 |
|
|
progressMonitor.worked(1);
|
190 |
8940919e
|
h.fradin
|
}
|
191 |
d37cd796
|
ben.clark
|
commitTransaction(ts);
|
192 |
1d36aa54
|
Andreas Müller
|
progressMonitor.done();
|
193 |
218848c8
|
m.venin
|
logger.info("End of transaction");
|
194 |
51171c9d
|
Andreas Müller
|
return;
|
195 |
808e5e3b
|
h.fradin
|
}
|
196 |
cdbae74d
|
h.fradin
|
|
197 |
808e5e3b
|
h.fradin
|
/* (non-Javadoc)
|
198 |
|
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
199 |
|
|
*/
|
200 |
6b2cc8fd
|
Andreas Müller
|
protected boolean isIgnore(SDDImportState state){
|
201 |
808e5e3b
|
h.fradin
|
return false;
|
202 |
|
|
}
|
203 |
cb85c609
|
h.fradin
|
|
204 |
|
|
|
205 |
808e5e3b
|
h.fradin
|
// associates the reference of a media object in SDD with a CdmBase Object
|
206 |
|
|
protected void associateImageWithCdmBase(String refMO, CdmBase cb){
|
207 |
|
|
if ((refMO != null) && (cb!=null)) {
|
208 |
cfd73bf1
|
Andreas Müller
|
if (! refMO.equals("")) {
|
209 |
|
|
if (! mediaObject_ListCdmBase.containsKey(refMO)) {
|
210 |
808e5e3b
|
h.fradin
|
List<CdmBase> lcb = new ArrayList<CdmBase>();
|
211 |
|
|
lcb.add(cb);
|
212 |
|
|
mediaObject_ListCdmBase.put(refMO,lcb);
|
213 |
|
|
} else {
|
214 |
|
|
List<CdmBase> lcb = mediaObject_ListCdmBase.get(refMO);
|
215 |
|
|
lcb.add(cb);
|
216 |
|
|
mediaObject_ListCdmBase.put(refMO,lcb);
|
217 |
|
|
}
|
218 |
|
|
}
|
219 |
|
|
}
|
220 |
|
|
}
|
221 |
cb85c609
|
h.fradin
|
|
222 |
808e5e3b
|
h.fradin
|
// imports information about the Dataset
|
223 |
8d3d15fd
|
h.fradin
|
protected void importDatasetRepresentation(Element parent, Namespace sddNamespace){
|
224 |
808e5e3b
|
h.fradin
|
logger.info("start Representation ...");
|
225 |
|
|
/* <Representation>
|
226 |
|
|
<Label>The Genus Viola</Label>
|
227 |
|
|
<Detail>This is an example for a very simple SDD file, representing a single description with categorical, quantitative, and text character. Compare also the "Fragment*" examples, which contain more complex examples in the form of document fragments. Intended for version="SDD 1.1".</Detail>
|
228 |
|
|
</Representation>
|
229 |
|
|
*/
|
230 |
435d1ded
|
Andreas Müller
|
|
231 |
|
|
|
232 |
|
|
|
233 |
808e5e3b
|
h.fradin
|
Element elRepresentation = parent.getChild("Representation",sddNamespace);
|
234 |
|
|
String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
235 |
|
|
String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace);
|
236 |
435d1ded
|
Andreas Müller
|
|
237 |
|
|
//new
|
238 |
|
|
Representation representation = Representation.NewInstance(detail, label, null, datasetLanguage);
|
239 |
|
|
workingSet.addRepresentation(representation);
|
240 |
|
|
|
241 |
20d09165
|
h.fradin
|
|
242 |
435d1ded
|
Andreas Müller
|
//old
|
243 |
|
|
// sec.setTitleCache(label, true);
|
244 |
|
|
//
|
245 |
|
|
// if (detail != null) {
|
246 |
|
|
// Annotation annotation = Annotation.NewInstance(detail, datasetLanguage);
|
247 |
|
|
// annotation.setAnnotationType(AnnotationType.EDITORIAL());
|
248 |
|
|
// sec.addAnnotation(annotation);
|
249 |
|
|
// }
|
250 |
|
|
|
251 |
cb85c609
|
h.fradin
|
|
252 |
808e5e3b
|
h.fradin
|
List<Element> listMediaObjects = elRepresentation.getChildren("MediaObject",sddNamespace);
|
253 |
9068f64f
|
h.fradin
|
|
254 |
808e5e3b
|
h.fradin
|
for (Element elMediaObject : listMediaObjects) {
|
255 |
|
|
String ref = null;
|
256 |
|
|
String role = null;
|
257 |
|
|
if (elMediaObject != null) {
|
258 |
|
|
ref = elMediaObject.getAttributeValue("ref");
|
259 |
|
|
role = elMediaObject.getAttributeValue("role");
|
260 |
cb85c609
|
h.fradin
|
}
|
261 |
808e5e3b
|
h.fradin
|
if (ref != null) {
|
262 |
|
|
if (!ref.equals("")) {
|
263 |
8d3d15fd
|
h.fradin
|
this.associateImageWithCdmBase(ref,sourceReference);
|
264 |
808e5e3b
|
h.fradin
|
this.associateImageWithCdmBase(ref,sec);
|
265 |
|
|
mediaObject_Role.put(ref,role);
|
266 |
|
|
}
|
267 |
83383bc9
|
h.fradin
|
}
|
268 |
808e5e3b
|
h.fradin
|
}
|
269 |
|
|
}
|
270 |
cb85c609
|
h.fradin
|
|
271 |
808e5e3b
|
h.fradin
|
// imports the representation (label, detail, lang) of a particular SDD element
|
272 |
51171c9d
|
Andreas Müller
|
protected void importRepresentation(Element parent, Namespace sddNamespace, VersionableEntity ve, String id, SDDImportState state){
|
273 |
808e5e3b
|
h.fradin
|
Element elRepresentation = parent.getChild("Representation",sddNamespace);
|
274 |
cfd73bf1
|
Andreas Müller
|
|
275 |
514d0c79
|
h.fradin
|
Map<Language,List<String>> langLabDet = new HashMap<Language,List<String>>();
|
276 |
|
|
|
277 |
cfd73bf1
|
Andreas Müller
|
handleRepresentationLabels(sddNamespace, elRepresentation, langLabDet);
|
278 |
|
|
handleRepresentationDetails(sddNamespace, elRepresentation, langLabDet);
|
279 |
|
|
|
280 |
|
|
if (ve instanceof TermBase) {
|
281 |
|
|
makeRepresentationForTerms((TermBase)ve, langLabDet);
|
282 |
|
|
}else if (ve instanceof Media) {
|
283 |
|
|
makeRepresentationForMedia((Media)ve, langLabDet);
|
284 |
|
|
}else if (ve instanceof IdentifiableEntity<?>) {
|
285 |
|
|
IdentifiableEntity<?> ie = (IdentifiableEntity<?>)ve;
|
286 |
|
|
makeRepresentationForIdentifiableEntity(sddNamespace, ie, elRepresentation, langLabDet);
|
287 |
|
|
if (ve instanceof IdentifiableMediaEntity<?>){
|
288 |
|
|
makeRepresentationForIdentifiableMediaEntity(parent, sddNamespace, (IdentifiableMediaEntity<?>)ve);
|
289 |
808e5e3b
|
h.fradin
|
}
|
290 |
|
|
}
|
291 |
cb85c609
|
h.fradin
|
|
292 |
218848c8
|
m.venin
|
makeRepresentationMediaObjects(sddNamespace, ve, elRepresentation);//FIXME
|
293 |
cfd73bf1
|
Andreas Müller
|
|
294 |
|
|
}
|
295 |
|
|
|
296 |
|
|
|
297 |
|
|
/**
|
298 |
|
|
* Handles the "Detail" children of representations. Adds the result to the langLabDet.
|
299 |
|
|
* @param sddNamespace
|
300 |
|
|
* @param elRepresentation
|
301 |
|
|
* @param langLabDet
|
302 |
|
|
*/
|
303 |
|
|
private void handleRepresentationDetails(Namespace sddNamespace,
|
304 |
|
|
Element elRepresentation, Map<Language, List<String>> langLabDet) {
|
305 |
|
|
List<Element> listDetails = elRepresentation.getChildren("Detail",sddNamespace);
|
306 |
514d0c79
|
h.fradin
|
for (Element elDetail : listDetails){
|
307 |
cfd73bf1
|
Andreas Müller
|
Language language = getLanguage(elDetail);
|
308 |
514d0c79
|
h.fradin
|
String role = elDetail.getAttributeValue("role");
|
309 |
|
|
String detail = elDetail.getText();
|
310 |
|
|
List<String> labDet = langLabDet.get(language);
|
311 |
|
|
labDet.add(detail);
|
312 |
|
|
labDet.add(role);
|
313 |
|
|
langLabDet.put(language, labDet);
|
314 |
808e5e3b
|
h.fradin
|
}
|
315 |
cfd73bf1
|
Andreas Müller
|
}
|
316 |
cb85c609
|
h.fradin
|
|
317 |
cfd73bf1
|
Andreas Müller
|
/**
|
318 |
|
|
* Handles the "Label" children of representations. Adds the result to the langLabDet.
|
319 |
|
|
* @param sddNamespace
|
320 |
|
|
* @param elRepresentation
|
321 |
|
|
* @param langLabDet
|
322 |
|
|
*/
|
323 |
|
|
private void handleRepresentationLabels(Namespace sddNamespace,
|
324 |
|
|
Element elRepresentation, Map<Language, List<String>> langLabDet) {
|
325 |
|
|
// <Label xml:lang="la">Viola hederacea Labill.</Label>
|
326 |
|
|
List<Element> listLabels = elRepresentation.getChildren("Label",sddNamespace);
|
327 |
|
|
for (Element elLabel : listLabels){
|
328 |
|
|
Language language = getLanguage(elLabel);
|
329 |
|
|
String label = elLabel.getText();
|
330 |
|
|
List<String> labDet = new ArrayList<String>(3);
|
331 |
|
|
labDet.add(label);
|
332 |
|
|
langLabDet.put(language, labDet);
|
333 |
|
|
}
|
334 |
|
|
}
|
335 |
|
|
|
336 |
|
|
/**
|
337 |
|
|
*
|
338 |
|
|
* @param ve
|
339 |
|
|
* @param langLabDet
|
340 |
|
|
*/
|
341 |
|
|
private void makeRepresentationForMedia(Media m, Map<Language, List<String>> langLabDet) {
|
342 |
|
|
for (Language lang : langLabDet.keySet()){
|
343 |
|
|
List<String> labDet = langLabDet.get(lang);
|
344 |
|
|
if (labDet.get(0) != null){
|
345 |
e66d9d39
|
Katja Luther
|
m.putTitle(LanguageString.NewInstance(labDet.get(0), lang));
|
346 |
cfd73bf1
|
Andreas Müller
|
}
|
347 |
|
|
if (labDet.size()>1) {
|
348 |
|
|
m.addDescription(labDet.get(1), lang);
|
349 |
|
|
}
|
350 |
|
|
}
|
351 |
|
|
}
|
352 |
5d556bff
|
h.fradin
|
|
353 |
cfd73bf1
|
Andreas Müller
|
/**
|
354 |
|
|
* Handles representations for terms. Adds one representation per language in langLabDet.
|
355 |
|
|
*
|
356 |
|
|
* @param ve
|
357 |
|
|
* @param langLabDet
|
358 |
|
|
*/
|
359 |
|
|
private void makeRepresentationForTerms(TermBase tb, Map<Language, List<String>> langLabDet) {
|
360 |
|
|
for (Language lang : langLabDet.keySet()){
|
361 |
5d556bff
|
h.fradin
|
List<String> labDet = langLabDet.get(lang);
|
362 |
|
|
if (labDet.size()>0){
|
363 |
|
|
if (labDet.size()>1) {
|
364 |
|
|
tb.addRepresentation(Representation.NewInstance(labDet.get(1), labDet.get(0), labDet.get(0), lang));
|
365 |
|
|
} else {
|
366 |
|
|
tb.addRepresentation(Representation.NewInstance(labDet.get(0), labDet.get(0), labDet.get(0), lang));
|
367 |
|
|
}
|
368 |
|
|
}
|
369 |
|
|
}
|
370 |
cfd73bf1
|
Andreas Müller
|
}
|
371 |
5d556bff
|
h.fradin
|
|
372 |
|
|
|
373 |
cfd73bf1
|
Andreas Müller
|
/**
|
374 |
|
|
* Handles the "MediaObject" children of representations.
|
375 |
|
|
* @param sddNamespace
|
376 |
|
|
* @param ve
|
377 |
|
|
* @param elRepresentation
|
378 |
|
|
*/
|
379 |
218848c8
|
m.venin
|
private void makeRepresentationMediaObjects(Namespace sddNamespace, VersionableEntity ve, Element elRepresentation) {
|
380 |
cfd73bf1
|
Andreas Müller
|
List <Element> listMediaObjects = elRepresentation.getChildren("MediaObject", sddNamespace);
|
381 |
|
|
for (Element elMediaObject : listMediaObjects) {
|
382 |
|
|
String ref = null;
|
383 |
|
|
//TODO
|
384 |
|
|
String role = null;
|
385 |
|
|
if (elMediaObject != null) {
|
386 |
|
|
ref = elMediaObject.getAttributeValue("ref");
|
387 |
|
|
role = elMediaObject.getAttributeValue("role");
|
388 |
514d0c79
|
h.fradin
|
}
|
389 |
cfd73bf1
|
Andreas Müller
|
if (StringUtils.isNotBlank(ref)) {
|
390 |
|
|
if (ve instanceof TaxonDescription) {
|
391 |
|
|
TaxonDescription td = (TaxonDescription) ve;
|
392 |
5559e194
|
Andreas Müller
|
if (td.getSources().size() > 0) {
|
393 |
|
|
this.associateImageWithCdmBase(ref, td.getSources().iterator().next().getCitation());
|
394 |
808e5e3b
|
h.fradin
|
} else {
|
395 |
5559e194
|
Andreas Müller
|
Reference<?> descriptionSource = ReferenceFactory.newGeneric();
|
396 |
218848c8
|
m.venin
|
sources.add(descriptionSource);
|
397 |
5559e194
|
Andreas Müller
|
td.addSource(null, null, descriptionSource, null);
|
398 |
cfd73bf1
|
Andreas Müller
|
this.associateImageWithCdmBase(ref,descriptionSource);
|
399 |
cb85c609
|
h.fradin
|
}
|
400 |
cfd73bf1
|
Andreas Müller
|
} else {
|
401 |
|
|
this.associateImageWithCdmBase(ref,ve);
|
402 |
cb85c609
|
h.fradin
|
}
|
403 |
|
|
}
|
404 |
808e5e3b
|
h.fradin
|
}
|
405 |
cfd73bf1
|
Andreas Müller
|
}
|
406 |
cdbae74d
|
h.fradin
|
|
407 |
cfd73bf1
|
Andreas Müller
|
/**
|
408 |
|
|
* Handles the "Links" element
|
409 |
|
|
* @param parent
|
410 |
|
|
* @param sddNamespace
|
411 |
|
|
* @param ve
|
412 |
|
|
*/
|
413 |
|
|
private void makeRepresentationForIdentifiableMediaEntity(Element parent,
|
414 |
|
|
Namespace sddNamespace, IdentifiableMediaEntity ime) {
|
415 |
|
|
Element elLinks = parent.getChild("Links",sddNamespace);
|
416 |
5f03512e
|
m.venin
|
|
417 |
cfd73bf1
|
Andreas Müller
|
if (elLinks != null) {
|
418 |
5f03512e
|
m.venin
|
|
419 |
cfd73bf1
|
Andreas Müller
|
// <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
|
420 |
|
|
List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
|
421 |
|
|
Media link = Media.NewInstance();
|
422 |
|
|
MediaRepresentation mr = MediaRepresentation.NewInstance();
|
423 |
|
|
int k = 0;
|
424 |
|
|
//for each Link
|
425 |
|
|
for (Element elLink : listLinks){
|
426 |
5f03512e
|
m.venin
|
|
427 |
cfd73bf1
|
Andreas Müller
|
try {
|
428 |
|
|
//TODO
|
429 |
|
|
String rel = elLink.getAttributeValue("rel");
|
430 |
|
|
String href = elLink.getAttributeValue("href");
|
431 |
1d36aa54
|
Andreas Müller
|
URI uri = new URI(href);
|
432 |
|
|
mr.addRepresentationPart(MediaRepresentationPart.NewInstance(uri, null));
|
433 |
cfd73bf1
|
Andreas Müller
|
link.addRepresentation(mr);
|
434 |
|
|
ime.addMedia(link);
|
435 |
5f03512e
|
m.venin
|
|
436 |
cfd73bf1
|
Andreas Müller
|
} catch (Exception e) {
|
437 |
|
|
//FIXME
|
438 |
|
|
logger.warn("Import of Link " + k + " failed.");
|
439 |
|
|
}
|
440 |
5f03512e
|
m.venin
|
|
441 |
cfd73bf1
|
Andreas Müller
|
if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
|
442 |
5f03512e
|
m.venin
|
|
443 |
|
|
}
|
444 |
|
|
}
|
445 |
cfd73bf1
|
Andreas Müller
|
}
|
446 |
808e5e3b
|
h.fradin
|
|
447 |
cfd73bf1
|
Andreas Müller
|
/**
|
448 |
|
|
* @param sddNamespace
|
449 |
|
|
* @param ve
|
450 |
|
|
* @param elRepresentation
|
451 |
|
|
* @param langLabDet
|
452 |
|
|
* @return
|
453 |
|
|
*/
|
454 |
|
|
private void makeRepresentationForIdentifiableEntity(Namespace sddNamespace, IdentifiableEntity<?> ie,
|
455 |
|
|
Element elRepresentation, Map<Language, List<String>> langLabDet) {
|
456 |
|
|
List<String> labDet = null;
|
457 |
|
|
|
458 |
|
|
if (ie instanceof TaxonNameBase) {
|
459 |
|
|
if (langLabDet.keySet().contains(getTermService().getLanguageByIso("la"))) {
|
460 |
|
|
labDet = langLabDet.get(getTermService().getLanguageByIso("la"));
|
461 |
|
|
} else if (langLabDet.keySet().contains(datasetLanguage)) {
|
462 |
|
|
labDet = langLabDet.get(datasetLanguage);
|
463 |
|
|
logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
|
464 |
|
|
} else {
|
465 |
|
|
labDet = langLabDet.get(langLabDet.keySet().iterator().next());
|
466 |
|
|
logger.info("TaxonName " + (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace) + " is not specified as a latin name.");
|
467 |
808e5e3b
|
h.fradin
|
}
|
468 |
cfd73bf1
|
Andreas Müller
|
} else {
|
469 |
|
|
labDet = langLabDet.get(langLabDet.keySet().iterator().next());
|
470 |
|
|
}
|
471 |
8940919e
|
h.fradin
|
|
472 |
cfd73bf1
|
Andreas Müller
|
//FIXME labDet is != null only for TaxonNameBase
|
473 |
|
|
ie.setTitleCache(labDet.get(0), true);
|
474 |
|
|
|
475 |
|
|
if (labDet.size()>1) {
|
476 |
|
|
Annotation annotation = null;
|
477 |
|
|
if (labDet.get(1) != null) {
|
478 |
|
|
if (labDet.get(2) != null) {
|
479 |
|
|
annotation = Annotation.NewInstance(labDet.get(2) + " - " + labDet.get(1), datasetLanguage);
|
480 |
|
|
} else {
|
481 |
|
|
annotation = Annotation.NewInstance(labDet.get(1), datasetLanguage);
|
482 |
cdbae74d
|
h.fradin
|
}
|
483 |
cb85c609
|
h.fradin
|
}
|
484 |
cfd73bf1
|
Andreas Müller
|
ie.addAnnotation(annotation);
|
485 |
808e5e3b
|
h.fradin
|
}
|
486 |
cfd73bf1
|
Andreas Müller
|
return;
|
487 |
|
|
}
|
488 |
cb85c609
|
h.fradin
|
|
489 |
cfd73bf1
|
Andreas Müller
|
/**
|
490 |
|
|
* @param elLabel
|
491 |
|
|
* @return
|
492 |
|
|
*/
|
493 |
|
|
private Language getLanguage(Element elLanguage) {
|
494 |
|
|
String lang = elLanguage.getAttributeValue("lang",xmlNamespace);
|
495 |
|
|
Language language = null;
|
496 |
|
|
if (StringUtils.isNotBlank(lang)) {
|
497 |
|
|
language = getTermService().getLanguageByIso(lang.substring(0, 2));
|
498 |
|
|
} else {
|
499 |
|
|
language = datasetLanguage;
|
500 |
|
|
}
|
501 |
|
|
return language;
|
502 |
808e5e3b
|
h.fradin
|
}
|
503 |
e192e06c
|
m.venin
|
|
504 |
8940919e
|
h.fradin
|
|
505 |
808e5e3b
|
h.fradin
|
// imports the representation (label, detail, lang) of a particular SDD element
|
506 |
|
|
protected void importTechnicalMetadata(Element root, Namespace sddNamespace, SDDImportConfigurator sddConfig){
|
507 |
|
|
Element elTechnicalMetadata = root.getChild("TechnicalMetadata", sddNamespace);
|
508 |
|
|
String nameCreated = elTechnicalMetadata.getAttributeValue("created");
|
509 |
|
|
sourceReference = sddConfig.getSourceReference();
|
510 |
3ff51780
|
h.fradin
|
|
511 |
808e5e3b
|
h.fradin
|
if (nameCreated != null) {
|
512 |
|
|
if (!nameCreated.equals("")) {
|
513 |
|
|
int year = Integer.parseInt(nameCreated.substring(0,4));
|
514 |
|
|
int monthOfYear = Integer.parseInt(nameCreated.substring(5,7));
|
515 |
|
|
int dayOfMonth = Integer.parseInt(nameCreated.substring(8,10));
|
516 |
|
|
int hourOfDay = Integer.parseInt(nameCreated.substring(11,13));
|
517 |
|
|
int minuteOfHour = Integer.parseInt(nameCreated.substring(14,16));
|
518 |
|
|
int secondOfMinute = Integer.parseInt(nameCreated.substring(17,19));
|
519 |
|
|
DateTime created = new DateTime(year,monthOfYear,dayOfMonth,hourOfDay,minuteOfHour,secondOfMinute,0);
|
520 |
|
|
sourceReference.setCreated(created);
|
521 |
|
|
sec.setCreated(created);
|
522 |
|
|
}
|
523 |
|
|
}
|
524 |
8940919e
|
h.fradin
|
|
525 |
808e5e3b
|
h.fradin
|
// <Generator name="n/a, handcrafted instance document" version="n/a"/>
|
526 |
|
|
Element elGenerator = elTechnicalMetadata.getChild("Generator", sddNamespace);
|
527 |
|
|
generatorName = elGenerator.getAttributeValue("name");
|
528 |
|
|
generatorVersion = elGenerator.getAttributeValue("version");
|
529 |
bba7e155
|
h.fradin
|
|
530 |
8d3d15fd
|
h.fradin
|
sec.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
|
531 |
|
|
sourceReference.addAnnotation(Annotation.NewDefaultLanguageInstance(generatorName + " - " + generatorVersion));
|
532 |
808e5e3b
|
h.fradin
|
|
533 |
|
|
}
|
534 |
|
|
|
535 |
|
|
// imports the complete dataset information
|
536 |
51171c9d
|
Andreas Müller
|
protected void importDataset(Element elDataset, Namespace sddNamespace, SDDImportState state){ // <Dataset xml:lang="en-us">
|
537 |
|
|
|
538 |
435d1ded
|
Andreas Müller
|
workingSet = WorkingSet.NewInstance();
|
539 |
51171c9d
|
Andreas Müller
|
importDatasetLanguage(elDataset,state);
|
540 |
8d3d15fd
|
h.fradin
|
importDatasetRepresentation(elDataset, sddNamespace);
|
541 |
808e5e3b
|
h.fradin
|
importRevisionData(elDataset, sddNamespace);
|
542 |
51171c9d
|
Andreas Müller
|
importIPRStatements(elDataset, sddNamespace, state);
|
543 |
|
|
importTaxonNames(elDataset, sddNamespace, state);
|
544 |
2669c352
|
Andreas Müller
|
|
545 |
51171c9d
|
Andreas Müller
|
importDescriptiveConcepts(elDataset, sddNamespace, state);
|
546 |
|
|
importCharacters(elDataset, sddNamespace, state);
|
547 |
|
|
importCharacterTrees(elDataset, sddNamespace, state);
|
548 |
75cb8a46
|
Andreas Kohlbecker
|
|
549 |
7b6a429a
|
Andreas Müller
|
MarkerType editorMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerEditor, "editor", "Editor", "edt");
|
550 |
|
|
MarkerType geographicAreaMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerSDDGeographicArea, "SDDGeographicArea", "SDDGeographicArea", "ga");
|
551 |
|
|
MarkerType descriptiveConceptMarkerType = getMarkerType(state, SDDTransformer.uuidMarkerDescriptiveConcept, "DescriptiveConcept", "Descriptive Concept", "DC");
|
552 |
75cb8a46
|
Andreas Kohlbecker
|
markerTypes.add(editorMarkerType);
|
553 |
|
|
markerTypes.add(geographicAreaMarkerType);
|
554 |
|
|
markerTypes.add(descriptiveConceptMarkerType);
|
555 |
2669c352
|
Andreas Müller
|
|
556 |
75cb8a46
|
Andreas Kohlbecker
|
//saving of all imported data into the CDM db
|
557 |
eba3394c
|
Andreas Kohlbecker
|
saveVocabularies();
|
558 |
75cb8a46
|
Andreas Kohlbecker
|
saveFeatures();
|
559 |
|
|
saveModifiers();
|
560 |
|
|
saveStates();
|
561 |
|
|
saveMarkerType();
|
562 |
|
|
saveAreas(geographicAreaMarkerType);
|
563 |
|
|
saveUnits();
|
564 |
|
|
saveStatisticalMeasure();
|
565 |
|
|
saveAnnotationType();
|
566 |
15be68cd
|
Andreas Müller
|
|
567 |
51171c9d
|
Andreas Müller
|
importCodedDescriptions(elDataset, sddNamespace, state);
|
568 |
|
|
importAgents(elDataset, sddNamespace, state);
|
569 |
|
|
importPublications(elDataset, sddNamespace, state);
|
570 |
|
|
importMediaObjects(elDataset, sddNamespace, state);
|
571 |
|
|
importTaxonHierarchies(elDataset, sddNamespace, state);
|
572 |
|
|
importGeographicAreas(elDataset, sddNamespace, state);
|
573 |
|
|
importSpecimens(elDataset,sddNamespace, state);
|
574 |
fc15b32c
|
m.venin
|
|
575 |
|
|
|
576 |
|
|
if ((authors != null)||(editors != null)) {
|
577 |
808e5e3b
|
h.fradin
|
Team team = Team.NewInstance();
|
578 |
fc15b32c
|
m.venin
|
if (authors != null) {
|
579 |
cfd73bf1
|
Andreas Müller
|
for (Person author : authors.values()){
|
580 |
|
|
team.addTeamMember(author);
|
581 |
|
|
}
|
582 |
cb85c609
|
h.fradin
|
}
|
583 |
5f03512e
|
m.venin
|
if (editors != null) {
|
584 |
|
|
Marker marker = Marker.NewInstance();
|
585 |
fc15b32c
|
m.venin
|
marker.setMarkerType(editorMarkerType);
|
586 |
cfd73bf1
|
Andreas Müller
|
for (Person editor : editors.values()){
|
587 |
|
|
Person edit = editor;
|
588 |
5f03512e
|
m.venin
|
edit.addMarker(marker);
|
589 |
|
|
team.addTeamMember(edit);
|
590 |
|
|
}
|
591 |
15be68cd
|
Andreas Müller
|
}
|
592 |
8d3d15fd
|
h.fradin
|
sec.setAuthorTeam(team);
|
593 |
808e5e3b
|
h.fradin
|
sourceReference.setAuthorTeam(team);
|
594 |
|
|
}
|
595 |
cb85c609
|
h.fradin
|
|
596 |
808e5e3b
|
h.fradin
|
if (copyright != null) {
|
597 |
|
|
sourceReference.addRights(copyright);
|
598 |
|
|
sec.addRights(copyright);
|
599 |
|
|
}
|
600 |
e192e06c
|
m.venin
|
|
601 |
|
|
// Returns a CdmApplicationController created by the values of this configuration.
|
602 |
|
|
IDescriptionService descriptionService = getDescriptionService();
|
603 |
218848c8
|
m.venin
|
|
604 |
cfd73bf1
|
Andreas Müller
|
for (TaxonDescription taxonDescription : taxonDescriptions.values()){
|
605 |
e192e06c
|
m.venin
|
// Persists a Description
|
606 |
|
|
descriptionService.save(taxonDescription);
|
607 |
|
|
}
|
608 |
|
|
|
609 |
cfd73bf1
|
Andreas Müller
|
for (String ref : taxonDescriptions.keySet()){
|
610 |
808e5e3b
|
h.fradin
|
TaxonDescription td = taxonDescriptions.get(ref);
|
611 |
|
|
if (citations.containsKey(ref)) {
|
612 |
ee0eed2d
|
Andreas Müller
|
Reference<?> publication = publications.get(citations.get(ref));
|
613 |
808e5e3b
|
h.fradin
|
if (locations.containsKey(ref)) {
|
614 |
cb404210
|
h.fradin
|
Annotation location = Annotation.NewInstance(locations.get(ref), datasetLanguage);
|
615 |
ee0eed2d
|
Andreas Müller
|
//TODO move to a generic place (implemented in hurry therefore dirty)
|
616 |
|
|
AnnotationType annotationType = getAnnotationType(state, uuidAnnotationTypeLocation, "location", "location", "location", null);
|
617 |
|
|
// annotationTypes.add(annotationType); TODO necessary??
|
618 |
cb404210
|
h.fradin
|
location.setAnnotationType(annotationType);
|
619 |
cfd73bf1
|
Andreas Müller
|
(publication).addAnnotation(location);
|
620 |
808e5e3b
|
h.fradin
|
}
|
621 |
5559e194
|
Andreas Müller
|
td.addSource(null, null,publication, null);
|
622 |
808e5e3b
|
h.fradin
|
}
|
623 |
|
|
}
|
624 |
|
|
logger.info("end makeTaxonDescriptions ...");
|
625 |
75cb8a46
|
Andreas Kohlbecker
|
|
626 |
fc15b32c
|
m.venin
|
if (descriptiveConcepts != null) {
|
627 |
cfd73bf1
|
Andreas Müller
|
for (Feature feature : descriptiveConcepts) {
|
628 |
fc15b32c
|
m.venin
|
Marker marker = Marker.NewInstance();
|
629 |
|
|
marker.setMarkerType(descriptiveConceptMarkerType);
|
630 |
|
|
feature.addMarker(marker);
|
631 |
|
|
}
|
632 |
|
|
}
|
633 |
75cb8a46
|
Andreas Kohlbecker
|
saveFeatures();
|
634 |
fc15b32c
|
m.venin
|
|
635 |
5559e194
|
Andreas Müller
|
for (Reference<?> publication : publications.values()){
|
636 |
cfd73bf1
|
Andreas Müller
|
getReferenceService().save(publication);
|
637 |
5d556bff
|
h.fradin
|
}
|
638 |
218848c8
|
m.venin
|
|
639 |
5559e194
|
Andreas Müller
|
for (Reference<?> source : sources){
|
640 |
218848c8
|
m.venin
|
getReferenceService().save(source);
|
641 |
|
|
}
|
642 |
cb85c609
|
h.fradin
|
|
643 |
cfd73bf1
|
Andreas Müller
|
for (FeatureTree featureTree : featureTrees) {
|
644 |
|
|
getFeatureTreeService().save(featureTree);
|
645 |
5d556bff
|
h.fradin
|
}
|
646 |
435d1ded
|
Andreas Müller
|
getWorkingSetService().save(workingSet);
|
647 |
1d36aa54
|
Andreas Müller
|
for (Classification classification : classifications) {
|
648 |
|
|
getClassificationService().save(classification);
|
649 |
5f03512e
|
m.venin
|
}
|
650 |
cfd73bf1
|
Andreas Müller
|
for (Specimen specimen : specimens.values()) {
|
651 |
e192e06c
|
m.venin
|
getOccurrenceService().save(specimen);
|
652 |
|
|
}
|
653 |
fc15b32c
|
m.venin
|
logger.info("end of persistence ...");
|
654 |
|
|
|
655 |
51171c9d
|
Andreas Müller
|
return;
|
656 |
75cb8a46
|
Andreas Kohlbecker
|
}
|
657 |
|
|
|
658 |
eba3394c
|
Andreas Kohlbecker
|
/**
|
659 |
|
|
*
|
660 |
|
|
*/
|
661 |
|
|
private void saveVocabularies() {
|
662 |
5559e194
|
Andreas Müller
|
for (TermVocabulary<?> vocabulary : vocabularies ){
|
663 |
eba3394c
|
Andreas Kohlbecker
|
getVocabularyService().save(vocabulary);
|
664 |
|
|
}
|
665 |
|
|
|
666 |
|
|
}
|
667 |
|
|
|
668 |
75cb8a46
|
Andreas Kohlbecker
|
private void saveAnnotationType() {
|
669 |
e614a39d
|
Andreas Müller
|
for (AnnotationType annotationType: annotationTypes){
|
670 |
ee0eed2d
|
Andreas Müller
|
getTermService().saveOrUpdate(annotationType);
|
671 |
75cb8a46
|
Andreas Kohlbecker
|
}
|
672 |
|
|
}
|
673 |
|
|
|
674 |
|
|
private void saveStatisticalMeasure() {
|
675 |
e614a39d
|
Andreas Müller
|
for (StatisticalMeasure sm : statisticalMeasures){
|
676 |
75cb8a46
|
Andreas Kohlbecker
|
getTermService().save(sm);
|
677 |
|
|
}
|
678 |
|
|
}
|
679 |
|
|
|
680 |
|
|
private void saveUnits() {
|
681 |
|
|
if (units != null) {
|
682 |
e614a39d
|
Andreas Müller
|
for (MeasurementUnit unit : units.values()){
|
683 |
75cb8a46
|
Andreas Kohlbecker
|
if (unit != null) {
|
684 |
|
|
getTermService().save(unit);
|
685 |
|
|
}
|
686 |
|
|
}
|
687 |
|
|
}
|
688 |
|
|
}
|
689 |
|
|
|
690 |
|
|
private void saveAreas(MarkerType geographicAreaMarkerType) {
|
691 |
e614a39d
|
Andreas Müller
|
for (NamedArea area : namedAreas.values() ){
|
692 |
75cb8a46
|
Andreas Kohlbecker
|
Marker marker = Marker.NewInstance();
|
693 |
|
|
marker.setMarkerType(geographicAreaMarkerType);
|
694 |
|
|
area.addMarker(marker);
|
695 |
|
|
getTermService().save(area);
|
696 |
|
|
}
|
697 |
|
|
}
|
698 |
|
|
|
699 |
|
|
private void saveStates() {
|
700 |
e614a39d
|
Andreas Müller
|
for (State state : states.values() ){
|
701 |
75cb8a46
|
Andreas Kohlbecker
|
getTermService().save(state);
|
702 |
|
|
}
|
703 |
|
|
}
|
704 |
|
|
|
705 |
|
|
private void saveMarkerType() {
|
706 |
e614a39d
|
Andreas Müller
|
for (MarkerType markerType : markerTypes){
|
707 |
75cb8a46
|
Andreas Kohlbecker
|
getTermService().save(markerType);
|
708 |
|
|
}
|
709 |
|
|
}
|
710 |
|
|
|
711 |
|
|
private void saveModifiers() {
|
712 |
e614a39d
|
Andreas Müller
|
for (Modifier modifier : modifiers.values() ){
|
713 |
75cb8a46
|
Andreas Kohlbecker
|
getTermService().save(modifier);
|
714 |
|
|
}
|
715 |
|
|
}
|
716 |
|
|
|
717 |
|
|
private void saveFeatures() {
|
718 |
e614a39d
|
Andreas Müller
|
for (Feature feature : features.values() ){
|
719 |
|
|
getTermService().save(feature);
|
720 |
75cb8a46
|
Andreas Kohlbecker
|
}
|
721 |
5d556bff
|
h.fradin
|
}
|
722 |
cb85c609
|
h.fradin
|
|
723 |
5d556bff
|
h.fradin
|
// imports the default language of the dataset
|
724 |
51171c9d
|
Andreas Müller
|
protected void importDatasetLanguage(Element elDataset, SDDImportState state){
|
725 |
5d556bff
|
h.fradin
|
String nameLang = elDataset.getAttributeValue("lang",xmlNamespace);
|
726 |
514d0c79
|
h.fradin
|
|
727 |
435d1ded
|
Andreas Müller
|
if (StringUtils.isNotBlank(nameLang)) {
|
728 |
5d556bff
|
h.fradin
|
String iso = nameLang.substring(0, 2);
|
729 |
|
|
datasetLanguage = getTermService().getLanguageByIso(iso);
|
730 |
|
|
} else {
|
731 |
a2966578
|
Andreas Müller
|
datasetLanguage = Language.DEFAULT();
|
732 |
514d0c79
|
h.fradin
|
}
|
733 |
5d556bff
|
h.fradin
|
if (datasetLanguage == null) {
|
734 |
a2966578
|
Andreas Müller
|
datasetLanguage = Language.DEFAULT();
|
735 |
808e5e3b
|
h.fradin
|
}
|
736 |
5d556bff
|
h.fradin
|
}
|
737 |
e192e06c
|
m.venin
|
|
738 |
fc15b32c
|
m.venin
|
// imports the specimens
|
739 |
51171c9d
|
Andreas Müller
|
protected void importSpecimens(Element elDataset, Namespace sddNamespace, SDDImportState cdmState) {
|
740 |
e192e06c
|
m.venin
|
logger.info("start Specimens ...");
|
741 |
fc15b32c
|
m.venin
|
/* <Specimens>
|
742 |
|
|
<Specimen id="sp1">
|
743 |
|
|
<Representation>
|
744 |
|
|
<Label>TJM45337</Label>
|
745 |
|
|
</Representation>
|
746 |
|
|
</Specimen>
|
747 |
|
|
</Specimens>
|
748 |
|
|
*/
|
749 |
e192e06c
|
m.venin
|
Element elSpecimens = elDataset.getChild("Specimens",sddNamespace);
|
750 |
|
|
if (elSpecimens != null){
|
751 |
|
|
List<Element> listSpecimens = elSpecimens.getChildren("Specimen", sddNamespace);
|
752 |
|
|
for (Element elSpecimen : listSpecimens) {
|
753 |
|
|
String id = elSpecimen.getAttributeValue("id");
|
754 |
fc15b32c
|
m.venin
|
Specimen specimen = null;
|
755 |
e192e06c
|
m.venin
|
if (!id.equals("")) {
|
756 |
fc15b32c
|
m.venin
|
specimen = Specimen.NewInstance();
|
757 |
|
|
specimens.put(id,specimen);
|
758 |
51171c9d
|
Andreas Müller
|
importRepresentation(elSpecimen, sddNamespace, specimen, id, cdmState);
|
759 |
e192e06c
|
m.venin
|
}
|
760 |
|
|
}
|
761 |
fc15b32c
|
m.venin
|
|
762 |
e192e06c
|
m.venin
|
}
|
763 |
|
|
}
|
764 |
cb85c609
|
h.fradin
|
|
765 |
5d556bff
|
h.fradin
|
// imports the revision data associated with the Dataset (authors, modifications)
|
766 |
|
|
protected void importRevisionData(Element elDataset, Namespace sddNamespace){
|
767 |
|
|
// <RevisionData>
|
768 |
|
|
logger.info("start RevisionData ...");
|
769 |
|
|
Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace);
|
770 |
5f03512e
|
m.venin
|
if (elRevisionData != null){
|
771 |
|
|
// <Creators>
|
772 |
|
|
Element elCreators = elRevisionData.getChild("Creators",sddNamespace);
|
773 |
fc15b32c
|
m.venin
|
|
774 |
5f03512e
|
m.venin
|
// <Agent role="aut" ref="a1"/>
|
775 |
|
|
List<Element> listAgents = elCreators.getChildren("Agent", sddNamespace);
|
776 |
fc15b32c
|
m.venin
|
|
777 |
5f03512e
|
m.venin
|
int j = 0;
|
778 |
|
|
//for each Agent
|
779 |
|
|
for (Element elAgent : listAgents){
|
780 |
fc15b32c
|
m.venin
|
|
781 |
5f03512e
|
m.venin
|
String role = elAgent.getAttributeValue("role");
|
782 |
|
|
String ref = elAgent.getAttributeValue("ref");
|
783 |
|
|
if (role.equals("aut")) {
|
784 |
|
|
if(!ref.equals("")) {
|
785 |
|
|
authors.put(ref, null);
|
786 |
|
|
}
|
787 |
5d556bff
|
h.fradin
|
}
|
788 |
5f03512e
|
m.venin
|
if (role.equals("edt")) {
|
789 |
|
|
if(!ref.equals("")) {
|
790 |
|
|
editors.put(ref, null);
|
791 |
|
|
}
|
792 |
5d556bff
|
h.fradin
|
}
|
793 |
5f03512e
|
m.venin
|
if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
|
794 |
fc15b32c
|
m.venin
|
|
795 |
5d556bff
|
h.fradin
|
}
|
796 |
fc15b32c
|
m.venin
|
|
797 |
5f03512e
|
m.venin
|
// <DateModified>2006-04-08T00:00:00</DateModified>
|
798 |
|
|
String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace);
|
799 |
fc15b32c
|
m.venin
|
|
800 |
5f03512e
|
m.venin
|
if (stringDateModified != null) {
|
801 |
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
|
802 |
|
|
Date d = null;
|
803 |
|
|
try {
|
804 |
|
|
d = sdf.parse(stringDateModified);
|
805 |
|
|
} catch(Exception e) {
|
806 |
|
|
System.err.println("Exception :");
|
807 |
|
|
e.printStackTrace();
|
808 |
|
|
}
|
809 |
fc15b32c
|
m.venin
|
|
810 |
5f03512e
|
m.venin
|
DateTime updated = null;
|
811 |
|
|
if (d != null) {
|
812 |
|
|
updated = new DateTime(d);
|
813 |
|
|
sourceReference.setUpdated(updated);
|
814 |
|
|
sec.setUpdated(updated);
|
815 |
|
|
}
|
816 |
514d0c79
|
h.fradin
|
}
|
817 |
5d556bff
|
h.fradin
|
}
|
818 |
|
|
}
|
819 |
|
|
|
820 |
|
|
// imports ipr statements associated with a dataset
|
821 |
51171c9d
|
Andreas Müller
|
protected void importIPRStatements(Element elDataset, Namespace sddNamespace, SDDImportState state){
|
822 |
5d556bff
|
h.fradin
|
// <IPRStatements>
|
823 |
|
|
logger.info("start IPRStatements ...");
|
824 |
|
|
Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace);
|
825 |
|
|
// <IPRStatement role="Copyright">
|
826 |
|
|
if (elIPRStatements != null) {
|
827 |
|
|
List<Element> listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace);
|
828 |
|
|
int j = 0;
|
829 |
|
|
//for each IPRStatement
|
830 |
|
|
|
831 |
|
|
for (Element elIPRStatement : listIPRStatements){
|
832 |
|
|
|
833 |
|
|
String role = elIPRStatement.getAttributeValue("role");
|
834 |
|
|
// <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
|
835 |
|
|
Element elLabel = elIPRStatement.getChild("Label",sddNamespace);
|
836 |
|
|
String lang = "";
|
837 |
|
|
if (elLabel != null) {
|
838 |
|
|
lang = elLabel.getAttributeValue("lang",xmlNamespace);
|
839 |
|
|
}
|
840 |
|
|
String label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace);
|
841 |
|
|
|
842 |
|
|
if (role.equals("Copyright")) {
|
843 |
|
|
Language iprLanguage = null;
|
844 |
|
|
if (lang != null) {
|
845 |
|
|
if (!lang.equals("")) {
|
846 |
|
|
iprLanguage = getTermService().getLanguageByIso(lang.substring(0, 2));
|
847 |
|
|
} else {
|
848 |
|
|
iprLanguage = datasetLanguage;
|
849 |
|
|
}
|
850 |
|
|
}
|
851 |
|
|
if (iprLanguage == null) {
|
852 |
808e5e3b
|
h.fradin
|
iprLanguage = datasetLanguage;
|
853 |
|
|
}
|
854 |
5d556bff
|
h.fradin
|
copyright = Rights.NewInstance(label, iprLanguage);
|
855 |
808e5e3b
|
h.fradin
|
}
|
856 |
8940919e
|
h.fradin
|
|
857 |
5d556bff
|
h.fradin
|
if (copyright != null) {
|
858 |
|
|
sourceReference.addRights(copyright);
|
859 |
|
|
sec.addRights(copyright);
|
860 |
|
|
}
|
861 |
514d0c79
|
h.fradin
|
|
862 |
5d556bff
|
h.fradin
|
if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + j);}
|
863 |
514d0c79
|
h.fradin
|
|
864 |
5d556bff
|
h.fradin
|
}
|
865 |
808e5e3b
|
h.fradin
|
}
|
866 |
|
|
}
|
867 |
cb85c609
|
h.fradin
|
|
868 |
5d556bff
|
h.fradin
|
// imports the taxon names
|
869 |
51171c9d
|
Andreas Müller
|
protected void importTaxonNames(Element elDataset, Namespace sddNamespace, SDDImportState state){
|
870 |
5d556bff
|
h.fradin
|
// <TaxonNames>
|
871 |
|
|
logger.info("start TaxonNames ...");
|
872 |
|
|
Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace);
|
873 |
|
|
// <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
|
874 |
|
|
if (elTaxonNames != null) {
|
875 |
|
|
List<Element> listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace);
|
876 |
|
|
int j = 0;
|
877 |
|
|
//for each TaxonName
|
878 |
|
|
for (Element elTaxonName : listTaxonNames){
|
879 |
|
|
|
880 |
|
|
String id = elTaxonName.getAttributeValue("id");
|
881 |
|
|
String uri = elTaxonName.getAttributeValue("uri");
|
882 |
|
|
|
883 |
5559e194
|
Andreas Müller
|
NonViralName<?> tnb = null;
|
884 |
5d556bff
|
h.fradin
|
if (!id.equals("")) {
|
885 |
|
|
tnb = NonViralName.NewInstance(null);
|
886 |
57606ee3
|
Andreas Müller
|
IdentifiableSource source = null;
|
887 |
5d556bff
|
h.fradin
|
if (uri != null) {
|
888 |
|
|
if (!uri.equals("")) {
|
889 |
c58d06c3
|
Andreas Müller
|
source = IdentifiableSource.NewInstance(id, "TaxonName", ReferenceFactory.newGeneric(), uri);
|
890 |
5d556bff
|
h.fradin
|
}
|
891 |
|
|
} else {
|
892 |
57606ee3
|
Andreas Müller
|
source = IdentifiableSource.NewInstance(id, "TaxonName");
|
893 |
a6a71a15
|
h.fradin
|
}
|
894 |
5d556bff
|
h.fradin
|
tnb.addSource(source);
|
895 |
|
|
taxonNameBases.put(id,tnb);
|
896 |
cb85c609
|
h.fradin
|
}
|
897 |
|
|
|
898 |
5d556bff
|
h.fradin
|
// <Representation>
|
899 |
|
|
// <Label xml:lang="la">Viola hederacea Labill.</Label>
|
900 |
51171c9d
|
Andreas Müller
|
importRepresentation(elTaxonName, sddNamespace, tnb, id, state);
|
901 |
cb85c609
|
h.fradin
|
|
902 |
5d556bff
|
h.fradin
|
if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + j);}
|
903 |
cb85c609
|
h.fradin
|
|
904 |
5d556bff
|
h.fradin
|
}
|
905 |
808e5e3b
|
h.fradin
|
}
|
906 |
|
|
}
|
907 |
cb85c609
|
h.fradin
|
|
908 |
fc15b32c
|
m.venin
|
// imports the characters (categorical, quantitative and text ; sequence characters not supported) which correspond to CDM Features
|
909 |
51171c9d
|
Andreas Müller
|
protected void importCharacters(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
910 |
5d556bff
|
h.fradin
|
// <Characters>
|
911 |
|
|
logger.info("start Characters ...");
|
912 |
|
|
Element elCharacters = elDataset.getChild("Characters", sddNamespace);
|
913 |
808e5e3b
|
h.fradin
|
|
914 |
5d556bff
|
h.fradin
|
// <CategoricalCharacter id="c1">
|
915 |
|
|
if (elCharacters != null) {
|
916 |
51171c9d
|
Andreas Müller
|
handleCategoricalData(sddNamespace, cdmState, elCharacters);
|
917 |
|
|
handleQuantitativeData(sddNamespace, cdmState, elCharacters);
|
918 |
|
|
handleTextCharacters(sddNamespace, cdmState, elCharacters);
|
919 |
7b6a429a
|
Andreas Müller
|
}
|
920 |
5d556bff
|
h.fradin
|
|
921 |
7b6a429a
|
Andreas Müller
|
/*for (Iterator<Feature> f = features.values().iterator() ; f.hasNext() ;){
|
922 |
|
|
featureSet.add(f.next()); //XIM Why this line ?
|
923 |
|
|
}*/
|
924 |
|
|
|
925 |
51171c9d
|
Andreas Müller
|
return;
|
926 |
5d556bff
|
h.fradin
|
|
927 |
7b6a429a
|
Andreas Müller
|
}
|
928 |
5d556bff
|
h.fradin
|
|
929 |
7b6a429a
|
Andreas Müller
|
/**
|
930 |
|
|
* @param sddNamespace
|
931 |
|
|
* @param sddConfig
|
932 |
|
|
* @param elCharacters
|
933 |
|
|
* @return
|
934 |
|
|
*/
|
935 |
51171c9d
|
Andreas Müller
|
private void handleCategoricalData(Namespace sddNamespace, SDDImportState cdmState, Element elCharacters) {
|
936 |
7b6a429a
|
Andreas Müller
|
List<Element> elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace);
|
937 |
|
|
int j = 0;
|
938 |
|
|
for (Element elCategoricalCharacter : elCategoricalCharacters){
|
939 |
|
|
try {
|
940 |
|
|
|
941 |
|
|
String idCC = elCategoricalCharacter.getAttributeValue("id");
|
942 |
|
|
Feature categoricalCharacter = Feature.NewInstance();
|
943 |
|
|
categoricalCharacter.setKindOf(Feature.DESCRIPTION());
|
944 |
51171c9d
|
Andreas Müller
|
importRepresentation(elCategoricalCharacter, sddNamespace, categoricalCharacter, idCC, cdmState);
|
945 |
7b6a429a
|
Andreas Müller
|
categoricalCharacter.setSupportsCategoricalData(true);
|
946 |
|
|
|
947 |
|
|
// <States>
|
948 |
|
|
Element elStates = elCategoricalCharacter.getChild("States",sddNamespace);
|
949 |
|
|
|
950 |
|
|
// <StateDefinition id="s1">
|
951 |
|
|
List<Element> elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace);
|
952 |
2a179529
|
Andreas Müller
|
TermVocabulary<State> termVocabularyState = TermVocabulary.NewInstance(null, null, null, null);
|
953 |
eba3394c
|
Andreas Kohlbecker
|
|
954 |
|
|
vocabularies.add(termVocabularyState);
|
955 |
|
|
|
956 |
7b6a429a
|
Andreas Müller
|
int k = 0;
|
957 |
|
|
//for each StateDefinition
|
958 |
|
|
for (Element elStateDefinition : elStateDefinitions){
|
959 |
514d0c79
|
h.fradin
|
|
960 |
7b6a429a
|
Andreas Müller
|
if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));}
|
961 |
|
|
|
962 |
|
|
String idS = elStateDefinition.getAttributeValue("id");
|
963 |
e614a39d
|
Andreas Müller
|
State state = states.get(idS);
|
964 |
|
|
if (state == null){
|
965 |
|
|
state = State.NewInstance();
|
966 |
|
|
}else{
|
967 |
|
|
logger.debug("State duplicate found");
|
968 |
|
|
}
|
969 |
51171c9d
|
Andreas Müller
|
importRepresentation(elStateDefinition, sddNamespace, state, idS, cdmState);
|
970 |
cb85c609
|
h.fradin
|
|
971 |
7b6a429a
|
Andreas Müller
|
termVocabularyState.addTerm(state);
|
972 |
|
|
states.put(idS,state);
|
973 |
|
|
}
|
974 |
|
|
categoricalCharacter.addSupportedCategoricalEnumeration(termVocabularyState);
|
975 |
|
|
features.put(idCC, categoricalCharacter);
|
976 |
cb85c609
|
h.fradin
|
|
977 |
7b6a429a
|
Andreas Müller
|
} catch (Exception e) {
|
978 |
|
|
logger.warn("Import of CategoricalCharacter " + j + " failed.");
|
979 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
980 |
808e5e3b
|
h.fradin
|
}
|
981 |
cb85c609
|
h.fradin
|
|
982 |
7b6a429a
|
Andreas Müller
|
if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + j);}
|
983 |
cb85c609
|
h.fradin
|
|
984 |
7b6a429a
|
Andreas Müller
|
}
|
985 |
51171c9d
|
Andreas Müller
|
return;
|
986 |
7b6a429a
|
Andreas Müller
|
}
|
987 |
cb85c609
|
h.fradin
|
|
988 |
7b6a429a
|
Andreas Müller
|
/**
|
989 |
|
|
* @param sddNamespace
|
990 |
|
|
* @param sddConfig
|
991 |
|
|
* @param elCharacters
|
992 |
|
|
*/
|
993 |
51171c9d
|
Andreas Müller
|
private void handleQuantitativeData(Namespace sddNamespace, SDDImportState cdmState, Element elCharacters) {
|
994 |
7b6a429a
|
Andreas Müller
|
int j;
|
995 |
|
|
// <QuantitativeCharacter id="c2">
|
996 |
|
|
List<Element> elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace);
|
997 |
|
|
j = 0;
|
998 |
|
|
//for each QuantitativeCharacter
|
999 |
|
|
for (Element elQuantitativeCharacter : elQuantitativeCharacters){
|
1000 |
cdbae74d
|
h.fradin
|
|
1001 |
7b6a429a
|
Andreas Müller
|
try {
|
1002 |
e4a7b23e
|
h.fradin
|
|
1003 |
7b6a429a
|
Andreas Müller
|
String idQC = elQuantitativeCharacter.getAttributeValue("id");
|
1004 |
8940919e
|
h.fradin
|
|
1005 |
7b6a429a
|
Andreas Müller
|
// <Representation>
|
1006 |
|
|
// <Label>Leaf length</Label>
|
1007 |
|
|
// </Representation>
|
1008 |
|
|
Feature quantitativeCharacter = Feature.NewInstance();
|
1009 |
|
|
quantitativeCharacter.setKindOf(Feature.DESCRIPTION());
|
1010 |
51171c9d
|
Andreas Müller
|
importRepresentation(elQuantitativeCharacter, sddNamespace, quantitativeCharacter, idQC, cdmState);
|
1011 |
7b6a429a
|
Andreas Müller
|
|
1012 |
|
|
quantitativeCharacter.setSupportsQuantitativeData(true);
|
1013 |
|
|
|
1014 |
|
|
// <MeasurementUnit>
|
1015 |
|
|
// <Label role="Abbrev">m</Label>
|
1016 |
|
|
// </MeasurementUnit>
|
1017 |
|
|
Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace);
|
1018 |
|
|
String label = "";
|
1019 |
|
|
String role = "";
|
1020 |
|
|
if (elMeasurementUnit != null) {
|
1021 |
|
|
Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace);
|
1022 |
|
|
role = elLabel.getAttributeValue("role");
|
1023 |
|
|
label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace);
|
1024 |
|
|
}
|
1025 |
|
|
|
1026 |
|
|
MeasurementUnit unit = null;
|
1027 |
|
|
if (!label.equals("")){
|
1028 |
|
|
if (role != null) {
|
1029 |
|
|
if (role.equals("Abbrev")){
|
1030 |
|
|
unit = MeasurementUnit.NewInstance(label,label,label);
|
1031 |
5d556bff
|
h.fradin
|
}
|
1032 |
7b6a429a
|
Andreas Müller
|
} else {
|
1033 |
|
|
unit = MeasurementUnit.NewInstance(label,label,label);
|
1034 |
514d0c79
|
h.fradin
|
}
|
1035 |
7b6a429a
|
Andreas Müller
|
}
|
1036 |
5d556bff
|
h.fradin
|
|
1037 |
7b6a429a
|
Andreas Müller
|
if (unit != null) {
|
1038 |
|
|
units.put(idQC, unit);
|
1039 |
|
|
}
|
1040 |
5d556bff
|
h.fradin
|
|
1041 |
7b6a429a
|
Andreas Müller
|
//<Default>
|
1042 |
|
|
// <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
|
1043 |
|
|
//</Default>
|
1044 |
|
|
Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace);
|
1045 |
|
|
if (elDefault != null) {
|
1046 |
|
|
String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace);
|
1047 |
cfd73bf1
|
Andreas Müller
|
if (! measurementUnitPrefix.equals("")){
|
1048 |
7b6a429a
|
Andreas Müller
|
defaultUnitPrefixes.put(idQC, measurementUnitPrefix);
|
1049 |
|
|
}
|
1050 |
808e5e3b
|
h.fradin
|
}
|
1051 |
8940919e
|
h.fradin
|
|
1052 |
7b6a429a
|
Andreas Müller
|
features.put(idQC, quantitativeCharacter);
|
1053 |
8940919e
|
h.fradin
|
|
1054 |
7b6a429a
|
Andreas Müller
|
} catch (Exception e) {
|
1055 |
|
|
//FIXME
|
1056 |
|
|
logger.warn("Import of QuantitativeCharacter " + j + " failed.");
|
1057 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1058 |
808e5e3b
|
h.fradin
|
}
|
1059 |
e4a7b23e
|
h.fradin
|
|
1060 |
7b6a429a
|
Andreas Müller
|
if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + j);}
|
1061 |
20d09165
|
h.fradin
|
|
1062 |
7b6a429a
|
Andreas Müller
|
}
|
1063 |
51171c9d
|
Andreas Müller
|
return;
|
1064 |
7b6a429a
|
Andreas Müller
|
}
|
1065 |
20d09165
|
h.fradin
|
|
1066 |
51171c9d
|
Andreas Müller
|
private void handleTextCharacters(Namespace sddNamespace, SDDImportState cdmState, Element elCharacters) {
|
1067 |
7b6a429a
|
Andreas Müller
|
int j;
|
1068 |
|
|
// <TextCharacter id="c3">
|
1069 |
|
|
List<Element> elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace);
|
1070 |
|
|
j = 0;
|
1071 |
|
|
//for each TextCharacter
|
1072 |
|
|
for (Element elTextCharacter : elTextCharacters){
|
1073 |
7440c566
|
h.fradin
|
|
1074 |
7b6a429a
|
Andreas Müller
|
try {
|
1075 |
3ff51780
|
h.fradin
|
|
1076 |
7b6a429a
|
Andreas Müller
|
String idTC = elTextCharacter.getAttributeValue("id");
|
1077 |
cb85c609
|
h.fradin
|
|
1078 |
7b6a429a
|
Andreas Müller
|
// <Representation>
|
1079 |
|
|
// <Label xml:lang="en">Leaf features not covered by other characters</Label>
|
1080 |
|
|
// </Representation>
|
1081 |
|
|
Feature textCharacter = Feature.NewInstance();
|
1082 |
|
|
textCharacter.setKindOf(Feature.DESCRIPTION());
|
1083 |
51171c9d
|
Andreas Müller
|
importRepresentation(elTextCharacter, sddNamespace, textCharacter, idTC, cdmState);
|
1084 |
cb85c609
|
h.fradin
|
|
1085 |
7b6a429a
|
Andreas Müller
|
textCharacter.setSupportsTextData(true);
|
1086 |
cb85c609
|
h.fradin
|
|
1087 |
7b6a429a
|
Andreas Müller
|
features.put(idTC, textCharacter);
|
1088 |
808e5e3b
|
h.fradin
|
|
1089 |
7b6a429a
|
Andreas Müller
|
} catch (Exception e) {
|
1090 |
|
|
//FIXME
|
1091 |
|
|
logger.warn("Import of TextCharacter " + j + " failed.");
|
1092 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1093 |
cb85c609
|
h.fradin
|
}
|
1094 |
20d09165
|
h.fradin
|
|
1095 |
7b6a429a
|
Andreas Müller
|
if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + j);}
|
1096 |
514d0c79
|
h.fradin
|
|
1097 |
7b6a429a
|
Andreas Müller
|
}
|
1098 |
51171c9d
|
Andreas Müller
|
return;
|
1099 |
808e5e3b
|
h.fradin
|
}
|
1100 |
|
|
|
1101 |
fc15b32c
|
m.venin
|
// imports the descriptions of taxa
|
1102 |
51171c9d
|
Andreas Müller
|
protected void importCodedDescriptions(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1103 |
|
|
|
1104 |
5d556bff
|
h.fradin
|
// <CodedDescriptions>
|
1105 |
|
|
logger.info("start CodedDescriptions ...");
|
1106 |
|
|
Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace);
|
1107 |
4f213356
|
m.venin
|
|
1108 |
cfd73bf1
|
Andreas Müller
|
// <CodedDescription id="D101">
|
1109 |
5d556bff
|
h.fradin
|
if (elCodedDescriptions != null) {
|
1110 |
|
|
List<Element> listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace);
|
1111 |
|
|
int j = 0;
|
1112 |
|
|
//for each CodedDescription
|
1113 |
|
|
for (Element elCodedDescription : listCodedDescriptions){
|
1114 |
51171c9d
|
Andreas Müller
|
handleCodedDescription(sddNamespace, cdmState, elCodedDescription, j);
|
1115 |
cfd73bf1
|
Andreas Müller
|
if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + j);}
|
1116 |
|
|
}
|
1117 |
|
|
}
|
1118 |
51171c9d
|
Andreas Müller
|
return;
|
1119 |
cfd73bf1
|
Andreas Müller
|
}
|
1120 |
cb85c609
|
h.fradin
|
|
1121 |
cfd73bf1
|
Andreas Müller
|
/**
|
1122 |
|
|
* @param sddNamespace
|
1123 |
|
|
* @param sddConfig
|
1124 |
|
|
* @param j
|
1125 |
|
|
* @param elCodedDescription
|
1126 |
|
|
* @return
|
1127 |
|
|
*/
|
1128 |
51171c9d
|
Andreas Müller
|
private void handleCodedDescription(Namespace sddNamespace, SDDImportState cdmState, Element elCodedDescription, int j) {
|
1129 |
cfd73bf1
|
Andreas Müller
|
try {
|
1130 |
|
|
|
1131 |
|
|
String idCD = elCodedDescription.getAttributeValue("id");
|
1132 |
|
|
|
1133 |
|
|
// <Representation>
|
1134 |
|
|
// <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
|
1135 |
|
|
// </Representation>
|
1136 |
|
|
TaxonDescription taxonDescription = TaxonDescription.NewInstance();
|
1137 |
4f213356
|
m.venin
|
if (!generatorName.isEmpty()){
|
1138 |
|
|
Annotation annotation = Annotation.NewInstance(generatorName, AnnotationType.TECHNICAL(),Language.DEFAULT());
|
1139 |
|
|
taxonDescription.addAnnotation(annotation);
|
1140 |
|
|
}
|
1141 |
51171c9d
|
Andreas Müller
|
importRepresentation(elCodedDescription, sddNamespace, taxonDescription, idCD, cdmState);
|
1142 |
cfd73bf1
|
Andreas Müller
|
|
1143 |
|
|
// <Scope>
|
1144 |
|
|
// <TaxonName ref="t1"/>
|
1145 |
|
|
// <Citation ref="p1" location="p. 30"/>
|
1146 |
|
|
// </Scope>
|
1147 |
|
|
Element elScope = elCodedDescription.getChild("Scope", sddNamespace);
|
1148 |
|
|
Taxon taxon;
|
1149 |
|
|
if (elScope != null) {
|
1150 |
51171c9d
|
Andreas Müller
|
taxon = handleCDScope(sddNamespace, cdmState, idCD, elScope);
|
1151 |
cfd73bf1
|
Andreas Müller
|
} else {//in case no taxon is linked to the description, a new one is created
|
1152 |
51171c9d
|
Andreas Müller
|
taxon = handleCDNoScope(sddNamespace, cdmState, elCodedDescription);
|
1153 |
cfd73bf1
|
Andreas Müller
|
}
|
1154 |
514d0c79
|
h.fradin
|
|
1155 |
cfd73bf1
|
Andreas Müller
|
// <SummaryData>
|
1156 |
|
|
Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace);
|
1157 |
|
|
if (elSummaryData != null) {
|
1158 |
|
|
handleSummaryCategoricalData(sddNamespace, taxonDescription, elSummaryData);
|
1159 |
|
|
handleSummaryQuantitativeData(sddNamespace, taxonDescription, elSummaryData);
|
1160 |
|
|
handleSummaryTextData(sddNamespace, taxonDescription, elSummaryData);
|
1161 |
|
|
}
|
1162 |
7440c566
|
h.fradin
|
|
1163 |
cfd73bf1
|
Andreas Müller
|
if (taxon != null) {
|
1164 |
|
|
taxon.addDescription(taxonDescription);
|
1165 |
|
|
}
|
1166 |
218848c8
|
m.venin
|
//
|
1167 |
435d1ded
|
Andreas Müller
|
workingSet.addDescription(taxonDescription);
|
1168 |
|
|
|
1169 |
|
|
//OLD taxonDescription.setDescriptiveSystem(featureSet);
|
1170 |
5d556bff
|
h.fradin
|
|
1171 |
cfd73bf1
|
Andreas Müller
|
taxonDescriptions.put(idCD, taxonDescription);//FIXME
|
1172 |
5d556bff
|
h.fradin
|
|
1173 |
cfd73bf1
|
Andreas Müller
|
} catch (Exception e) {
|
1174 |
|
|
//FIXME
|
1175 |
|
|
logger.warn("Import of CodedDescription " + j + " failed.", e);
|
1176 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1177 |
cfd73bf1
|
Andreas Müller
|
}
|
1178 |
51171c9d
|
Andreas Müller
|
return;
|
1179 |
cfd73bf1
|
Andreas Müller
|
}
|
1180 |
808e5e3b
|
h.fradin
|
|
1181 |
cfd73bf1
|
Andreas Müller
|
/**
|
1182 |
|
|
* @param sddNamespace
|
1183 |
|
|
* @param sddConfig
|
1184 |
|
|
* @param elCodedDescription
|
1185 |
|
|
* @param taxon
|
1186 |
|
|
* @return
|
1187 |
|
|
*/
|
1188 |
51171c9d
|
Andreas Müller
|
private Taxon handleCDNoScope(Namespace sddNamespace, SDDImportState cdmState, Element elCodedDescription ) {
|
1189 |
cfd73bf1
|
Andreas Müller
|
Taxon taxon = null;
|
1190 |
5559e194
|
Andreas Müller
|
NonViralName<?> nonViralName = NonViralName.NewInstance(null);
|
1191 |
cfd73bf1
|
Andreas Müller
|
String id = new String("" + taxonNamesCount);
|
1192 |
|
|
IdentifiableSource source = IdentifiableSource.NewInstance(id, "TaxonName");
|
1193 |
51171c9d
|
Andreas Müller
|
importRepresentation(elCodedDescription, sddNamespace, nonViralName, id, cdmState);
|
1194 |
cfd73bf1
|
Andreas Müller
|
|
1195 |
51171c9d
|
Andreas Müller
|
if(cdmState.getConfig().isDoMatchTaxa()){
|
1196 |
cfd73bf1
|
Andreas Müller
|
taxon = getTaxonService().findBestMatchingTaxon(nonViralName.getTitleCache());
|
1197 |
|
|
}
|
1198 |
|
|
|
1199 |
|
|
if(taxon != null){
|
1200 |
|
|
nonViralName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
|
1201 |
|
|
// taxonNameBases.put(id ,tnb);
|
1202 |
|
|
// taxonNamesCount++;
|
1203 |
218848c8
|
m.venin
|
logger.info("using existing Taxon " + taxon.getTitleCache());
|
1204 |
cfd73bf1
|
Andreas Müller
|
} else {
|
1205 |
|
|
nonViralName.addSource(source);
|
1206 |
|
|
taxonNameBases.put(id ,nonViralName);
|
1207 |
|
|
taxonNamesCount++;
|
1208 |
218848c8
|
m.venin
|
logger.info("creating new Taxon from TaxonName " + nonViralName.getTitleCache());
|
1209 |
cfd73bf1
|
Andreas Müller
|
taxon = Taxon.NewInstance(nonViralName, sec);
|
1210 |
|
|
}
|
1211 |
|
|
return taxon;
|
1212 |
|
|
}
|
1213 |
808e5e3b
|
h.fradin
|
|
1214 |
cfd73bf1
|
Andreas Müller
|
/**
|
1215 |
|
|
* @param sddNamespace
|
1216 |
|
|
* @param sddConfig
|
1217 |
|
|
* @param idCD
|
1218 |
|
|
* @param elScope
|
1219 |
|
|
* @param taxon
|
1220 |
|
|
* @return
|
1221 |
|
|
*/
|
1222 |
51171c9d
|
Andreas Müller
|
private Taxon handleCDScope(Namespace sddNamespace, SDDImportState cdmState,
|
1223 |
cfd73bf1
|
Andreas Müller
|
String idCD, Element elScope) {
|
1224 |
|
|
Taxon taxon = null;
|
1225 |
|
|
Element elTaxonName = elScope.getChild("TaxonName", sddNamespace);
|
1226 |
|
|
String ref = elTaxonName.getAttributeValue("ref");
|
1227 |
5559e194
|
Andreas Müller
|
NonViralName<?> nonViralName = taxonNameBases.get(ref);
|
1228 |
cfd73bf1
|
Andreas Müller
|
|
1229 |
51171c9d
|
Andreas Müller
|
if(cdmState.getConfig().isDoMatchTaxa()){
|
1230 |
cfd73bf1
|
Andreas Müller
|
taxon = getTaxonService().findBestMatchingTaxon(nonViralName.getTitleCache());
|
1231 |
|
|
}
|
1232 |
|
|
|
1233 |
|
|
if(taxon != null){
|
1234 |
|
|
logger.info("using existing Taxon" + taxon.getTitleCache());
|
1235 |
|
|
if(!nonViralName.getUuid().equals(taxon.getName().getUuid())){
|
1236 |
|
|
logger.warn("TaxonNameBase entity of existing taxon does not match Name in list -> replacing Name in list");
|
1237 |
|
|
nonViralName = HibernateProxyHelper.deproxy(taxon.getName(), NonViralName.class);
|
1238 |
|
|
}
|
1239 |
|
|
} else {
|
1240 |
435d1ded
|
Andreas Müller
|
logger.info("creating new Taxon from TaxonName '" + nonViralName.getTitleCache()+"'");
|
1241 |
cfd73bf1
|
Andreas Müller
|
taxon = Taxon.NewInstance(nonViralName, sec);
|
1242 |
|
|
}
|
1243 |
|
|
|
1244 |
|
|
//citation
|
1245 |
|
|
Element elCitation = elScope.getChild("Citation",sddNamespace);
|
1246 |
|
|
if (elCitation != null) {
|
1247 |
|
|
String refCitation = elCitation.getAttributeValue("ref");
|
1248 |
|
|
if (! refCitation.equals("")){
|
1249 |
|
|
citations.put(idCD, refCitation);
|
1250 |
|
|
}
|
1251 |
|
|
String location = elCitation.getAttributeValue("location");
|
1252 |
|
|
if (! location.equals("")){
|
1253 |
|
|
locations.put(idCD, location);
|
1254 |
|
|
}
|
1255 |
|
|
}
|
1256 |
|
|
return taxon;
|
1257 |
|
|
}
|
1258 |
20d09165
|
h.fradin
|
|
1259 |
cfd73bf1
|
Andreas Müller
|
/**
|
1260 |
|
|
* @param sddNamespace
|
1261 |
|
|
* @param taxonDescription
|
1262 |
|
|
* @param elSummaryData
|
1263 |
|
|
*/
|
1264 |
|
|
private void handleSummaryTextData(Namespace sddNamespace,
|
1265 |
|
|
TaxonDescription taxonDescription, Element elSummaryData) {
|
1266 |
|
|
String ref;
|
1267 |
|
|
int k;
|
1268 |
|
|
// <TextChar ref="c3">
|
1269 |
|
|
List<Element> elTextChars = elSummaryData.getChildren("TextChar", sddNamespace);
|
1270 |
|
|
k = 0;
|
1271 |
|
|
//for each TextChar
|
1272 |
|
|
for (Element elTextChar : elTextChars){
|
1273 |
|
|
if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));}
|
1274 |
|
|
ref = elTextChar.getAttributeValue("ref");
|
1275 |
|
|
Feature feature = features.get(ref);
|
1276 |
|
|
TextData textData = TextData.NewInstance();
|
1277 |
|
|
textData.setFeature(feature);
|
1278 |
|
|
|
1279 |
|
|
// <Content>Free form text</Content>
|
1280 |
|
|
String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace);
|
1281 |
e66d9d39
|
Katja Luther
|
textData.putText(datasetLanguage, content);
|
1282 |
cfd73bf1
|
Andreas Müller
|
taxonDescription.addElement(textData);
|
1283 |
|
|
}
|
1284 |
|
|
}
|
1285 |
5d556bff
|
h.fradin
|
|
1286 |
cfd73bf1
|
Andreas Müller
|
/**
|
1287 |
|
|
* @param sddNamespace
|
1288 |
|
|
* @param taxonDescription
|
1289 |
|
|
* @param elSummaryData
|
1290 |
|
|
*/
|
1291 |
|
|
private void handleSummaryQuantitativeData(Namespace sddNamespace,
|
1292 |
|
|
TaxonDescription taxonDescription, Element elSummaryData) {
|
1293 |
|
|
String ref;
|
1294 |
|
|
int k;
|
1295 |
|
|
// <Quantitative ref="c2">
|
1296 |
|
|
List<Element> elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace);
|
1297 |
|
|
k = 0;
|
1298 |
|
|
//for each Quantitative
|
1299 |
|
|
for (Element elQuantitative : elQuantitatives){
|
1300 |
|
|
if ((++k % modCount) == 0){ logger.warn("Quantitative handled: " + (k-1));}
|
1301 |
|
|
ref = elQuantitative.getAttributeValue("ref");
|
1302 |
|
|
Feature feature = features.get(ref);
|
1303 |
|
|
QuantitativeData quantitativeData = QuantitativeData.NewInstance();
|
1304 |
|
|
quantitativeData.setFeature(feature);
|
1305 |
|
|
|
1306 |
|
|
MeasurementUnit unit = units.get(ref);
|
1307 |
|
|
String prefix = defaultUnitPrefixes.get(ref);
|
1308 |
|
|
if (unit != null) {
|
1309 |
|
|
String u = unit.getLabel();
|
1310 |
|
|
if (prefix != null) {
|
1311 |
|
|
u = prefix + u;
|
1312 |
|
|
}
|
1313 |
|
|
unit.setLabel(u);
|
1314 |
|
|
quantitativeData.setUnit(unit);
|
1315 |
|
|
}
|
1316 |
808e5e3b
|
h.fradin
|
|
1317 |
cfd73bf1
|
Andreas Müller
|
// <Measure type="Min" value="2.3"/>
|
1318 |
|
|
List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
|
1319 |
|
|
int l = 0;
|
1320 |
|
|
|
1321 |
|
|
//for each State
|
1322 |
|
|
for (Element elMeasure : elMeasures){
|
1323 |
|
|
if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
|
1324 |
|
|
String type = elMeasure.getAttributeValue("type");
|
1325 |
|
|
String value = elMeasure.getAttributeValue("value");
|
1326 |
|
|
if (value.contains(",")) {
|
1327 |
|
|
value = value.replace(',', '.');
|
1328 |
|
|
}
|
1329 |
|
|
Float v = Float.parseFloat(value);
|
1330 |
|
|
//Float v = new Float(0);
|
1331 |
|
|
StatisticalMeasure t = null;
|
1332 |
|
|
if (type.equals("Min")) {
|
1333 |
|
|
t = StatisticalMeasure.MIN();
|
1334 |
|
|
} else if (type.equals("Mean")) {
|
1335 |
|
|
t = StatisticalMeasure.AVERAGE();
|
1336 |
|
|
} else if (type.equals("Max")) {
|
1337 |
|
|
t = StatisticalMeasure.MAX();
|
1338 |
|
|
} else if (type.equals("SD")) {
|
1339 |
|
|
t = StatisticalMeasure.STANDARD_DEVIATION();
|
1340 |
|
|
} else if (type.equals("N")) {
|
1341 |
|
|
t = StatisticalMeasure.SAMPLE_SIZE();
|
1342 |
|
|
} else if (type.equals("UMethLower")) {
|
1343 |
|
|
t = StatisticalMeasure.TYPICAL_LOWER_BOUNDARY();
|
1344 |
|
|
} else if (type.equals("UMethUpper")) {
|
1345 |
|
|
t = StatisticalMeasure.TYPICAL_UPPER_BOUNDARY();
|
1346 |
|
|
} else if (type.equals("Var")) {
|
1347 |
|
|
t = StatisticalMeasure.VARIANCE();
|
1348 |
|
|
} else {
|
1349 |
|
|
t = StatisticalMeasure.NewInstance(type,type,type);
|
1350 |
|
|
statisticalMeasures.add(t);
|
1351 |
cb85c609
|
h.fradin
|
}
|
1352 |
|
|
|
1353 |
cfd73bf1
|
Andreas Müller
|
StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
|
1354 |
|
|
statisticalValue.setValue(v);
|
1355 |
|
|
statisticalValue.setType(t);
|
1356 |
|
|
quantitativeData.addStatisticalValue(statisticalValue);
|
1357 |
|
|
featureData.add(statisticalValue);
|
1358 |
5d556bff
|
h.fradin
|
}
|
1359 |
cfd73bf1
|
Andreas Müller
|
taxonDescription.addElement(quantitativeData);
|
1360 |
|
|
}
|
1361 |
|
|
}
|
1362 |
514d0c79
|
h.fradin
|
|
1363 |
cfd73bf1
|
Andreas Müller
|
/**
|
1364 |
|
|
* @param sddNamespace
|
1365 |
|
|
* @param taxonDescription
|
1366 |
|
|
* @param elSummaryData
|
1367 |
|
|
*/
|
1368 |
|
|
private void handleSummaryCategoricalData(Namespace sddNamespace,
|
1369 |
|
|
TaxonDescription taxonDescription, Element elSummaryData) {
|
1370 |
|
|
String ref;
|
1371 |
|
|
// <Categorical ref="c4">
|
1372 |
|
|
List<Element> elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace);
|
1373 |
|
|
int k = 0;
|
1374 |
|
|
//for each Categorical
|
1375 |
|
|
for (Element elCategorical : elCategoricals){
|
1376 |
|
|
if ((++k % modCount) == 0){ logger.warn("Categorical handled: " + (k-1));}
|
1377 |
|
|
ref = elCategorical.getAttributeValue("ref");
|
1378 |
|
|
Feature feature = features.get(ref);
|
1379 |
|
|
CategoricalData categoricalData = CategoricalData.NewInstance();
|
1380 |
|
|
categoricalData.setFeature(feature);
|
1381 |
|
|
|
1382 |
|
|
// <State ref="s3"/>
|
1383 |
|
|
List<Element> elStates = elCategorical.getChildren("State", sddNamespace);
|
1384 |
|
|
int l = 0;
|
1385 |
|
|
|
1386 |
|
|
//for each State
|
1387 |
|
|
for (Element elState : elStates){
|
1388 |
|
|
if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
|
1389 |
|
|
ref = elState.getAttributeValue("ref");
|
1390 |
|
|
State state = states.get(ref);
|
1391 |
|
|
if (state != null) {
|
1392 |
|
|
StateData stateData = StateData.NewInstance();
|
1393 |
|
|
stateData.setState(state);
|
1394 |
|
|
List<Element> elModifiers = elState.getChildren("Modifier", sddNamespace);
|
1395 |
|
|
for (Element elModifier : elModifiers){
|
1396 |
|
|
ref = elModifier.getAttributeValue("ref");
|
1397 |
|
|
Modifier modifier = modifiers.get(ref);
|
1398 |
|
|
if (modifier != null) {
|
1399 |
|
|
stateData.addModifier(modifier);
|
1400 |
|
|
}
|
1401 |
|
|
}
|
1402 |
|
|
categoricalData.addState(stateData);
|
1403 |
|
|
}
|
1404 |
|
|
taxonDescription.addElement(categoricalData);
|
1405 |
|
|
}
|
1406 |
808e5e3b
|
h.fradin
|
}
|
1407 |
|
|
}
|
1408 |
cdbae74d
|
h.fradin
|
|
1409 |
5d556bff
|
h.fradin
|
// imports the persons associated with the dataset creation, modification, related publications
|
1410 |
51171c9d
|
Andreas Müller
|
protected void importAgents(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1411 |
5d556bff
|
h.fradin
|
// <Agents>
|
1412 |
|
|
logger.info("start Agents ...");
|
1413 |
|
|
Element elAgents = elDataset.getChild("Agents",sddNamespace);
|
1414 |
5f03512e
|
m.venin
|
if (elAgents != null) {
|
1415 |
|
|
// <Agent id="a1">
|
1416 |
|
|
List <Element> listAgents = elAgents.getChildren("Agent", sddNamespace);
|
1417 |
|
|
int j = 0;
|
1418 |
|
|
//for each Agent
|
1419 |
|
|
for (Element elAgent : listAgents){
|
1420 |
5d556bff
|
h.fradin
|
|
1421 |
5f03512e
|
m.venin
|
try {
|
1422 |
5d556bff
|
h.fradin
|
|
1423 |
5f03512e
|
m.venin
|
String idA = elAgent.getAttributeValue("id");
|
1424 |
8940919e
|
h.fradin
|
|
1425 |
5f03512e
|
m.venin
|
// <Representation>
|
1426 |
|
|
// <Label>Kevin Thiele</Label>
|
1427 |
|
|
// <Detail role="Description">Ali Baba is also known as r.a.m.</Detail>
|
1428 |
|
|
// </Representation>
|
1429 |
|
|
Person person = Person.NewInstance();
|
1430 |
51171c9d
|
Andreas Müller
|
importRepresentation(elAgent, sddNamespace, person, idA, cdmState);
|
1431 |
5f03512e
|
m.venin
|
person.addSource(IdentifiableSource.NewInstance(idA, "Agent"));
|
1432 |
cdbae74d
|
h.fradin
|
|
1433 |
5f03512e
|
m.venin
|
/*XIM <Links>
|
1434 |
|
|
Element elLinks = elAgent.getChild("Links",sddNamespace);
|
1435 |
9653d159
|
h.fradin
|
|
1436 |
5f03512e
|
m.venin
|
if (elLinks != null) {
|
1437 |
9653d159
|
h.fradin
|
|
1438 |
5f03512e
|
m.venin
|
// <Link rel="Alternate" href="http://www.diversitycampus.net/people/hagedorn"/>
|
1439 |
|
|
List<Element> listLinks = elLinks.getChildren("Link", sddNamespace);
|
1440 |
|
|
int k = 0;
|
1441 |
|
|
//for each Link
|
1442 |
|
|
for (Element elLink : listLinks){
|
1443 |
9653d159
|
h.fradin
|
|
1444 |
5f03512e
|
m.venin
|
try {
|
1445 |
e4a7b23e
|
h.fradin
|
|
1446 |
5f03512e
|
m.venin
|
String rel = elLink.getAttributeValue("rel");
|
1447 |
|
|
String href = elLink.getAttributeValue("href");
|
1448 |
9068f64f
|
h.fradin
|
|
1449 |
5f03512e
|
m.venin
|
Media link = Media.NewInstance();
|
1450 |
|
|
MediaRepresentation mr = MediaRepresentation.NewInstance();
|
1451 |
|
|
mr.addRepresentationPart(MediaRepresentationPart.NewInstance(href, null));
|
1452 |
|
|
link.addRepresentation(mr);
|
1453 |
|
|
person.addMedia(link);
|
1454 |
7440c566
|
h.fradin
|
|
1455 |
5f03512e
|
m.venin
|
} catch (Exception e) {
|
1456 |
|
|
//FIXME
|
1457 |
|
|
logger.warn("Import of Link " + k + " failed.");
|
1458 |
|
|
success = false;
|
1459 |
|
|
}
|
1460 |
cdbae74d
|
h.fradin
|
|
1461 |
5f03512e
|
m.venin
|
if ((++k % modCount) == 0){ logger.info("Links handled: " + k);}
|
1462 |
20d09165
|
h.fradin
|
|
1463 |
5f03512e
|
m.venin
|
}
|
1464 |
|
|
}
|
1465 |
|
|
*/
|
1466 |
|
|
if (authors.containsKey(idA)) {
|
1467 |
|
|
authors.put(idA,person);
|
1468 |
|
|
}
|
1469 |
cb85c609
|
h.fradin
|
|
1470 |
5f03512e
|
m.venin
|
if (editors.containsKey(idA)) {
|
1471 |
|
|
editors.put(idA, person);
|
1472 |
808e5e3b
|
h.fradin
|
}
|
1473 |
cb85c609
|
h.fradin
|
|
1474 |
5f03512e
|
m.venin
|
} catch (Exception e) {
|
1475 |
|
|
//FIXME
|
1476 |
|
|
logger.warn("Import of Agent " + j + " failed.");
|
1477 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1478 |
514d0c79
|
h.fradin
|
}
|
1479 |
8940919e
|
h.fradin
|
|
1480 |
5f03512e
|
m.venin
|
if ((++j % modCount) == 0){ logger.info("Agents handled: " + j);}
|
1481 |
9068f64f
|
h.fradin
|
|
1482 |
5f03512e
|
m.venin
|
}
|
1483 |
5d556bff
|
h.fradin
|
}
|
1484 |
514d0c79
|
h.fradin
|
}
|
1485 |
3ff51780
|
h.fradin
|
|
1486 |
5d556bff
|
h.fradin
|
// imports publications related with the data set
|
1487 |
51171c9d
|
Andreas Müller
|
protected void importPublications(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1488 |
fc15b32c
|
m.venin
|
/* <Publications>
|
1489 |
|
|
<Publication id="p112">
|
1490 |
|
|
<Representation>
|
1491 |
|
|
<Label>Gee, X. & Haa, Y. (2003). How to be happy in five minutes. Instant Gratifications, Palm Beach.</Label>
|
1492 |
|
|
</Representation>
|
1493 |
|
|
<Links>
|
1494 |
|
|
<Link rel="BasedOn" href="doi:10.1992/32311"/>
|
1495 |
|
|
<Link rel="Alternate" href="http://some.service.net/providing/bibliographic.data"/>
|
1496 |
|
|
</Links>
|
1497 |
|
|
</Publications>
|
1498 |
|
|
*/
|
1499 |
5d556bff
|
h.fradin
|
logger.info("start Publications ...");
|
1500 |
|
|
Element elPublications = elDataset.getChild("Publications",sddNamespace);
|
1501 |
9068f64f
|
h.fradin
|
|
1502 |
5d556bff
|
h.fradin
|
if (elPublications != null) {
|
1503 |
|
|
List<Element> listPublications = elPublications.getChildren("Publication", sddNamespace);
|
1504 |
|
|
int j = 0;
|
1505 |
|
|
for (Element elPublication : listPublications){
|
1506 |
9068f64f
|
h.fradin
|
|
1507 |
5d556bff
|
h.fradin
|
try {
|
1508 |
9068f64f
|
h.fradin
|
|
1509 |
5d556bff
|
h.fradin
|
String idP = elPublication.getAttributeValue("id");
|
1510 |
5559e194
|
Andreas Müller
|
Reference<?> publication = ReferenceFactory.newArticle();
|
1511 |
51171c9d
|
Andreas Müller
|
importRepresentation(elPublication, sddNamespace, publication, idP, cdmState);
|
1512 |
9068f64f
|
h.fradin
|
|
1513 |
5d556bff
|
h.fradin
|
publications.put(idP,publication);
|
1514 |
808e5e3b
|
h.fradin
|
|
1515 |
5d556bff
|
h.fradin
|
} catch (Exception e) {
|
1516 |
|
|
logger.warn("Import of Publication " + j + " failed.");
|
1517 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1518 |
5d556bff
|
h.fradin
|
}
|
1519 |
514d0c79
|
h.fradin
|
|
1520 |
5d556bff
|
h.fradin
|
if ((++j % modCount) == 0){ logger.info("Publications handled: " + j);}
|
1521 |
514d0c79
|
h.fradin
|
|
1522 |
5d556bff
|
h.fradin
|
}
|
1523 |
9068f64f
|
h.fradin
|
}
|
1524 |
808e5e3b
|
h.fradin
|
}
|
1525 |
514d0c79
|
h.fradin
|
|
1526 |
0ae635c4
|
m.venin
|
// imports media objects such as images //FIXME check mediaobj
|
1527 |
51171c9d
|
Andreas Müller
|
protected void importMediaObjects(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1528 |
5d556bff
|
h.fradin
|
// <MediaObjects>
|
1529 |
|
|
logger.info("start MediaObjects ...");
|
1530 |
|
|
Element elMediaObjects = elDataset.getChild("MediaObjects",sddNamespace);
|
1531 |
|
|
|
1532 |
|
|
if (elMediaObjects != null) {
|
1533 |
|
|
// <MediaObject id="m1">
|
1534 |
|
|
List<Element> listMediaObjects = elMediaObjects.getChildren("MediaObject", sddNamespace);
|
1535 |
|
|
int j = 0;
|
1536 |
|
|
for (Element elMO : listMediaObjects){
|
1537 |
|
|
|
1538 |
|
|
String id = "";
|
1539 |
|
|
|
1540 |
|
|
try {
|
1541 |
|
|
String idMO = elMO.getAttributeValue("id");
|
1542 |
|
|
id = idMO;
|
1543 |
|
|
|
1544 |
|
|
// <Representation>
|
1545 |
|
|
// <Label>Image description, e.g. to be used for alt-attribute in html.</Label>
|
1546 |
|
|
// </Representation>
|
1547 |
|
|
Media media = Media.NewInstance();
|
1548 |
51171c9d
|
Andreas Müller
|
importRepresentation(elMO, sddNamespace, media, idMO, cdmState);
|
1549 |
5d556bff
|
h.fradin
|
|
1550 |
|
|
// <Type>Image</Type>
|
1551 |
|
|
// <Source href="http://test.edu/test.jpg"/>
|
1552 |
|
|
String type = (String)ImportHelper.getXmlInputValue(elMO,"Type",sddNamespace);
|
1553 |
|
|
|
1554 |
|
|
if ((type != null) && (type.equals("Image"))) {
|
1555 |
|
|
Element elSource = elMO.getChild("Source",sddNamespace);
|
1556 |
|
|
String href = elSource.getAttributeValue("href");
|
1557 |
|
|
|
1558 |
370503cf
|
n.hoffmann
|
ImageInfo imageMetaData = null;
|
1559 |
5d556bff
|
h.fradin
|
ImageFile image = null;
|
1560 |
|
|
if (href.substring(0,7).equals("http://")) {
|
1561 |
|
|
try{
|
1562 |
|
|
URL url = new URL(href);
|
1563 |
df748bc6
|
Katja Luther
|
|
1564 |
370503cf
|
n.hoffmann
|
imageMetaData = ImageInfo.NewInstance(url.toURI(), 0);
|
1565 |
1d36aa54
|
Andreas Müller
|
image = ImageFile.NewInstance(url.toURI(), null, imageMetaData);
|
1566 |
5d556bff
|
h.fradin
|
} catch (MalformedURLException e) {
|
1567 |
|
|
logger.error("Malformed URL", e);
|
1568 |
|
|
}
|
1569 |
|
|
} else {
|
1570 |
51171c9d
|
Andreas Müller
|
String sns = cdmState.getConfig().getSourceNameString();
|
1571 |
5d556bff
|
h.fradin
|
File f = new File(sns);
|
1572 |
|
|
File parent = f.getParentFile();
|
1573 |
218848c8
|
m.venin
|
String fi = parent.toString() + File.separator + href;
|
1574 |
5d556bff
|
h.fradin
|
File file = new File(fi);
|
1575 |
370503cf
|
n.hoffmann
|
imageMetaData = ImageInfo.NewInstance(new URI(fi), 0); //file
|
1576 |
1d36aa54
|
Andreas Müller
|
image = ImageFile.NewInstance(file.toURI(), null, imageMetaData);
|
1577 |
808e5e3b
|
h.fradin
|
}
|
1578 |
5d556bff
|
h.fradin
|
MediaRepresentation representation = MediaRepresentation.NewInstance(imageMetaData.getMimeType(), null);
|
1579 |
|
|
representation.addRepresentationPart(image);
|
1580 |
|
|
|
1581 |
|
|
media.addRepresentation(representation);
|
1582 |
|
|
|
1583 |
|
|
ArrayList<CdmBase> lcb = (ArrayList<CdmBase>) mediaObject_ListCdmBase.get(idMO);
|
1584 |
|
|
if (lcb != null) {
|
1585 |
|
|
for (int k = 0; k < lcb.size(); k++) {
|
1586 |
|
|
if (lcb.get(k) instanceof DefinedTermBase) {
|
1587 |
5559e194
|
Andreas Müller
|
DefinedTermBase<?> dtb = (DefinedTermBase<?>) lcb.get(k);
|
1588 |
5d556bff
|
h.fradin
|
// if (lcb.get(0) instanceof DefinedTermBase) {
|
1589 |
|
|
// DefinedTermBase dtb = (DefinedTermBase) lcb.get(0);
|
1590 |
|
|
// if (dtb!=null) {
|
1591 |
|
|
// if (k == 0) {
|
1592 |
|
|
dtb.addMedia(media);
|
1593 |
5f03512e
|
m.venin
|
//System.out.println(dtb.getLabel());
|
1594 |
5d556bff
|
h.fradin
|
// } else {
|
1595 |
|
|
// Media me = (Media) media.clone();
|
1596 |
|
|
// dtb.addMedia(me);
|
1597 |
|
|
// }
|
1598 |
|
|
// }
|
1599 |
1d36aa54
|
Andreas Müller
|
} else if (lcb.get(k) instanceof Reference) {
|
1600 |
5559e194
|
Andreas Müller
|
Reference<?> rb = (Reference<?>) lcb.get(k);
|
1601 |
1d36aa54
|
Andreas Müller
|
//} else if (lcb.get(0) instanceof Reference) {
|
1602 |
|
|
//Reference rb = (Reference) lcb.get(0);
|
1603 |
5d556bff
|
h.fradin
|
// rb.setTitleCache(label);
|
1604 |
|
|
// if (rb!=null) {
|
1605 |
|
|
// if (k == 0) {
|
1606 |
|
|
rb.addMedia(media);
|
1607 |
5f03512e
|
m.venin
|
//System.out.println(rb.getTitle());
|
1608 |
5d556bff
|
h.fradin
|
// } else {
|
1609 |
|
|
// Media me = (Media) media.clone();
|
1610 |
|
|
// rb.addMedia(me);
|
1611 |
|
|
// }
|
1612 |
|
|
// }
|
1613 |
435d1ded
|
Andreas Müller
|
// else if (lcb.get(k) instanceof TaxonNameBase){
|
1614 |
|
|
// TaxonNameBase tb = (TaxonNameBase) lcb.get(k);
|
1615 |
|
|
// tb.addMedia(media);
|
1616 |
|
|
} else {
|
1617 |
|
|
logger.warn("Can't handle associated media for " + lcb.get(k).getId() + "(" + lcb.get(k).getClass().getSimpleName()+")" );
|
1618 |
|
|
}
|
1619 |
808e5e3b
|
h.fradin
|
}
|
1620 |
9068f64f
|
h.fradin
|
}
|
1621 |
|
|
}
|
1622 |
808e5e3b
|
h.fradin
|
|
1623 |
5d556bff
|
h.fradin
|
} catch (Exception e) {
|
1624 |
|
|
//FIXME
|
1625 |
e123eb32
|
Andreas Müller
|
logger.warn("Could not attach MediaObject " + j + "(SDD: " + id + ") to several objects: " + e.getMessage());
|
1626 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1627 |
5d556bff
|
h.fradin
|
}
|
1628 |
514d0c79
|
h.fradin
|
|
1629 |
5d556bff
|
h.fradin
|
if ((++j % modCount) == 0){ logger.info("MediaObjects handled: " + j);
|
1630 |
bba7e155
|
h.fradin
|
|
1631 |
5d556bff
|
h.fradin
|
}
|
1632 |
bba7e155
|
h.fradin
|
}
|
1633 |
|
|
}
|
1634 |
|
|
}
|
1635 |
|
|
|
1636 |
fc15b32c
|
m.venin
|
// imports the <DescriptiveConcepts> block ; DescriptiveConcepts are used as nodes in CharacterTrees and Characters as leaves
|
1637 |
|
|
// but since Modifiers can be linked to DescriptiveConcepts they are stored as features with a particular Marker
|
1638 |
51171c9d
|
Andreas Müller
|
protected void importDescriptiveConcepts(Element elDataset, Namespace sddNamespace, SDDImportState state){
|
1639 |
fc15b32c
|
m.venin
|
/* <DescriptiveConcepts>
|
1640 |
|
|
<DescriptiveConcept id="dc0">
|
1641 |
|
|
<Representation>
|
1642 |
|
|
<Label>Fixed set of modifiers supported in Lucid3</Label>
|
1643 |
|
|
</Representation>
|
1644 |
|
|
<Modifiers>
|
1645 |
|
|
<Modifier id="mod1">
|
1646 |
|
|
<Representation>
|
1647 |
|
|
<Label>rarely</Label>
|
1648 |
|
|
</Representation>
|
1649 |
|
|
<ModifierClass>Frequency</ModifierClass>
|
1650 |
|
|
<ProportionRange lowerestimate="0.0" upperestimate="0.25"/>
|
1651 |
|
|
</Modifier>
|
1652 |
|
|
</Modifiers>
|
1653 |
|
|
</DescriptiveConcept>
|
1654 |
|
|
</DescriptiveConcepts>
|
1655 |
|
|
*/
|
1656 |
5d556bff
|
h.fradin
|
logger.info("start DescriptiveConcepts ...");
|
1657 |
|
|
Element elDescriptiveConcepts = elDataset.getChild("DescriptiveConcepts",sddNamespace);
|
1658 |
|
|
if (elDescriptiveConcepts != null) {
|
1659 |
|
|
List<Element> listDescriptiveConcepts = elDescriptiveConcepts.getChildren("DescriptiveConcept", sddNamespace);
|
1660 |
|
|
int j = 0;
|
1661 |
5f03512e
|
m.venin
|
|
1662 |
5d556bff
|
h.fradin
|
for (Element elDescriptiveConcept : listDescriptiveConcepts){
|
1663 |
fc15b32c
|
m.venin
|
try {
|
1664 |
892efc69
|
Andreas Kohlbecker
|
String id = elDescriptiveConcept.getAttributeValue("id");
|
1665 |
5d556bff
|
h.fradin
|
Feature feature = Feature.NewInstance();
|
1666 |
|
|
feature.setKindOf(Feature.DESCRIPTION());
|
1667 |
fc15b32c
|
m.venin
|
if (!id.equals("")) {
|
1668 |
892efc69
|
Andreas Kohlbecker
|
// <Representation>
|
1669 |
|
|
// <Label>Body</Label>
|
1670 |
51171c9d
|
Andreas Müller
|
importRepresentation(elDescriptiveConcept, sddNamespace, feature, id, state);
|
1671 |
fc15b32c
|
m.venin
|
features.put(id, feature);
|
1672 |
|
|
getTermService().save(feature);//XIM
|
1673 |
|
|
descriptiveConcepts.add(feature);
|
1674 |
|
|
// imports the modifiers
|
1675 |
|
|
Element elModifiers = elDescriptiveConcept.getChild("Modifiers", sddNamespace);
|
1676 |
892efc69
|
Andreas Kohlbecker
|
if (elModifiers !=null){
|
1677 |
|
|
List<Element> listModifiers = elModifiers.getChildren("Modifier", sddNamespace);
|
1678 |
2a179529
|
Andreas Müller
|
TermVocabulary<Modifier> termVocabularyState = TermVocabulary.NewInstance(null, null, null, null);
|
1679 |
892efc69
|
Andreas Kohlbecker
|
for (Element elModifier : listModifiers) {
|
1680 |
5f03512e
|
m.venin
|
Modifier modif = Modifier.NewInstance();
|
1681 |
|
|
String idmod = elModifier.getAttributeValue("id");
|
1682 |
51171c9d
|
Andreas Müller
|
importRepresentation(elModifier, sddNamespace, modif, idmod, state);
|
1683 |
5f03512e
|
m.venin
|
termVocabularyState.addTerm(modif);
|
1684 |
0ae635c4
|
m.venin
|
//termVocabularyStates.add(termVocabularyState);
|
1685 |
fc15b32c
|
m.venin
|
getVocabularyService().save(termVocabularyState);//XIM
|
1686 |
|
|
modifiers.put(idmod, modif);
|
1687 |
5f03512e
|
m.venin
|
}
|
1688 |
892efc69
|
Andreas Kohlbecker
|
feature.addRecommendedModifierEnumeration(termVocabularyState);
|
1689 |
|
|
}
|
1690 |
bba7e155
|
h.fradin
|
|
1691 |
fc15b32c
|
m.venin
|
}
|
1692 |
|
|
}
|
1693 |
|
|
catch (Exception e) {
|
1694 |
c0317737
|
Andreas Müller
|
logger.warn("Import of DescriptiveConcept " + j + " failed: " + e.getMessage());
|
1695 |
fc15b32c
|
m.venin
|
}
|
1696 |
5d556bff
|
h.fradin
|
if ((++j % modCount) == 0){ logger.info("DescriptiveConcepts handled: " + j);}
|
1697 |
bba7e155
|
h.fradin
|
|
1698 |
5d556bff
|
h.fradin
|
}
|
1699 |
bba7e155
|
h.fradin
|
}
|
1700 |
|
|
}
|
1701 |
fc15b32c
|
m.venin
|
|
1702 |
|
|
// imports the <CharacterTrees> block
|
1703 |
51171c9d
|
Andreas Müller
|
protected void importCharacterTrees(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1704 |
5d556bff
|
h.fradin
|
// <CharacterTrees>
|
1705 |
|
|
logger.info("start CharacterTrees ...");
|
1706 |
|
|
Element elCharacterTrees = elDataset.getChild("CharacterTrees",sddNamespace);
|
1707 |
514d0c79
|
h.fradin
|
|
1708 |
5d556bff
|
h.fradin
|
if (elCharacterTrees != null) {
|
1709 |
|
|
List<Element> listCharacterTrees = elCharacterTrees.getChildren("CharacterTree", sddNamespace);
|
1710 |
|
|
int j = 0;
|
1711 |
5f03512e
|
m.venin
|
for (Element elCharacterTree : listCharacterTrees){
|
1712 |
|
|
try {
|
1713 |
|
|
Element elRepresentation = elCharacterTree.getChild("Representation",sddNamespace);
|
1714 |
|
|
String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
|
1715 |
0ae635c4
|
m.venin
|
//Element elDesignedFor = elCharacterTree.getChild("DesignedFor",sddNamespace);//TODO ?
|
1716 |
514d0c79
|
h.fradin
|
|
1717 |
435d1ded
|
Andreas Müller
|
FeatureTree featureTree = FeatureTree.NewInstance();
|
1718 |
51171c9d
|
Andreas Müller
|
importRepresentation(elCharacterTree, sddNamespace, featureTree, "", cdmState);
|
1719 |
435d1ded
|
Andreas Müller
|
FeatureNode root = featureTree.getRoot();
|
1720 |
|
|
List<Element> listeOfNodes = elCharacterTree.getChildren("Nodes", sddNamespace);
|
1721 |
fc15b32c
|
m.venin
|
|
1722 |
|
|
//Nodes of CharacterTrees in SDD always refer to DescriptiveConcepts
|
1723 |
435d1ded
|
Andreas Müller
|
for (Element elNodes : listeOfNodes) {
|
1724 |
2669c352
|
Andreas Müller
|
handleCharacterNodes(sddNamespace, root, elNodes);
|
1725 |
5f03512e
|
m.venin
|
}
|
1726 |
435d1ded
|
Andreas Müller
|
featureTrees.add(featureTree);
|
1727 |
|
|
if (workingSet.getDescriptiveSystem() != null){
|
1728 |
|
|
//TODO how to handle multiple
|
1729 |
|
|
logger.warn("Multiple feature trees not yet supported");
|
1730 |
|
|
}else{
|
1731 |
|
|
workingSet.setDescriptiveSystem(featureTree);
|
1732 |
|
|
}
|
1733 |
2669c352
|
Andreas Müller
|
}
|
1734 |
5f03512e
|
m.venin
|
|
1735 |
|
|
catch (Exception e) {
|
1736 |
|
|
logger.warn("Import of Character tree " + j + " failed.");
|
1737 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1738 |
5f03512e
|
m.venin
|
}
|
1739 |
|
|
if ((++j % modCount) == 0){ logger.info("CharacterTrees handled: " + j);}
|
1740 |
|
|
|
1741 |
|
|
}
|
1742 |
|
|
|
1743 |
|
|
}
|
1744 |
|
|
}
|
1745 |
|
|
|
1746 |
2669c352
|
Andreas Müller
|
/**
|
1747 |
|
|
* @param sddNamespace
|
1748 |
|
|
* @param root
|
1749 |
|
|
* @param elNodes
|
1750 |
|
|
*/
|
1751 |
|
|
private void handleCharacterNodes(Namespace sddNamespace, FeatureNode root, Element elNodes) {
|
1752 |
|
|
List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
|
1753 |
|
|
if (listNodes != null) {
|
1754 |
|
|
for (Element elNode : listNodes){
|
1755 |
|
|
String idN = elNode.getAttributeValue("id");
|
1756 |
|
|
FeatureNode fn = null;
|
1757 |
|
|
Feature dc = null;
|
1758 |
|
|
if (idN!=null) {
|
1759 |
|
|
// DescriptiveConcepts are used as nodes in CharacterTrees
|
1760 |
|
|
Element elDescriptiveConcept = elNode.getChild("DescriptiveConcept", sddNamespace);
|
1761 |
|
|
if (elDescriptiveConcept != null){
|
1762 |
|
|
String refDC = elDescriptiveConcept.getAttributeValue("ref");
|
1763 |
|
|
dc = features.get(refDC);
|
1764 |
|
|
fn = FeatureNode.NewInstance(dc);
|
1765 |
|
|
}
|
1766 |
|
|
if (fn==null){
|
1767 |
|
|
fn = FeatureNode.NewInstance();
|
1768 |
|
|
}
|
1769 |
|
|
Element elParent = elNode.getChild("Parent", sddNamespace);
|
1770 |
|
|
// in SDD links between Nodes are referenced by the <Parent> tag
|
1771 |
|
|
if (elParent!=null){
|
1772 |
|
|
String refP = elParent.getAttributeValue("ref");
|
1773 |
|
|
if (refP!=null) {
|
1774 |
|
|
FeatureNode parent = featureNodes.get(refP);
|
1775 |
|
|
if (parent==null){
|
1776 |
|
|
root.addChild(fn); // if no parent found or the reference is broken, add the node to the root of the tree
|
1777 |
|
|
}
|
1778 |
|
|
else {
|
1779 |
|
|
parent.addChild(fn);
|
1780 |
|
|
}
|
1781 |
|
|
}
|
1782 |
|
|
}
|
1783 |
|
|
else {
|
1784 |
|
|
root.addChild(fn); // if no parent found or the reference is broken, add the node to the root of the tree
|
1785 |
|
|
}
|
1786 |
|
|
}
|
1787 |
|
|
featureNodes.put(idN, fn);
|
1788 |
|
|
}
|
1789 |
|
|
}
|
1790 |
|
|
|
1791 |
|
|
// Leaves of CharacterTrees in SDD are always CharNodes (referring to Characters)
|
1792 |
|
|
List<Element> listCharNodes = elNodes.getChildren("CharNode", sddNamespace);
|
1793 |
|
|
if (listCharNodes != null) {
|
1794 |
|
|
for (Element elCharNode : listCharNodes){
|
1795 |
|
|
Element elParent = elCharNode.getChild("Parent", sddNamespace);
|
1796 |
4f213356
|
m.venin
|
Element elCharacter = elCharNode.getChild("Character", sddNamespace);
|
1797 |
|
|
Element elDependencyRules = elCharNode.getChild("DependencyRules", sddNamespace);
|
1798 |
2669c352
|
Andreas Müller
|
FeatureNode fn = FeatureNode.NewInstance();
|
1799 |
4f213356
|
m.venin
|
|
1800 |
|
|
if (elDependencyRules!=null){
|
1801 |
|
|
Element elInapplicableIf = elCharNode.getChild("InapplicableIf", sddNamespace);
|
1802 |
|
|
if (elInapplicableIf!=null){
|
1803 |
|
|
List<Element> listStates = elInapplicableIf.getChildren("State", sddNamespace);
|
1804 |
|
|
for (Element stateElement : listStates) {
|
1805 |
|
|
String refState = stateElement.getAttributeValue("ref");
|
1806 |
|
|
if ((refState!=null)&&(!refState.equals(""))) {
|
1807 |
|
|
State state = states.get(refState);
|
1808 |
|
|
fn.addInapplicableState(state);
|
1809 |
|
|
}
|
1810 |
|
|
}
|
1811 |
|
|
}
|
1812 |
|
|
Element elOnlyapplicableIf = elCharNode.getChild("OnlyApplicableIf", sddNamespace);
|
1813 |
|
|
if (elOnlyapplicableIf!=null){
|
1814 |
|
|
List<Element> listStates = elInapplicableIf.getChildren("State", sddNamespace);
|
1815 |
|
|
for (Element stateElement : listStates) {
|
1816 |
|
|
String refState = stateElement.getAttributeValue("ref");
|
1817 |
|
|
if ((refState!=null)&&(!refState.equals(""))) {
|
1818 |
|
|
State state = states.get(refState);
|
1819 |
|
|
fn.addApplicableState(state);
|
1820 |
|
|
}
|
1821 |
|
|
}
|
1822 |
|
|
}
|
1823 |
|
|
}
|
1824 |
|
|
|
1825 |
2669c352
|
Andreas Müller
|
if (elParent!=null){
|
1826 |
|
|
String refP = elParent.getAttributeValue("ref");
|
1827 |
|
|
if ((refP!=null)&&(!refP.equals(""))) {
|
1828 |
|
|
FeatureNode parent = featureNodes.get(refP);
|
1829 |
|
|
if (parent==null){
|
1830 |
|
|
parent = root; // if no parent found or the reference is broken, add the node to the root of the tree
|
1831 |
|
|
}
|
1832 |
|
|
parent.addChild(fn);
|
1833 |
|
|
}
|
1834 |
|
|
}
|
1835 |
|
|
String refC = elCharacter.getAttributeValue("ref");
|
1836 |
|
|
if ((refC!=null)&&(!refC.equals(""))){
|
1837 |
|
|
Feature character = features.get(refC);
|
1838 |
|
|
fn.setFeature(character);
|
1839 |
|
|
featureNodes.put(refC, fn);
|
1840 |
|
|
}
|
1841 |
|
|
}
|
1842 |
|
|
}
|
1843 |
|
|
}
|
1844 |
|
|
|
1845 |
fc15b32c
|
m.venin
|
// imports the <TaxonHierarchies> block
|
1846 |
51171c9d
|
Andreas Müller
|
protected void importTaxonHierarchies(Element elDataset, Namespace sddNamespace, SDDImportState cdmState){
|
1847 |
5f03512e
|
m.venin
|
|
1848 |
|
|
logger.info("start TaxonHierarchies ...");
|
1849 |
|
|
Element elTaxonHierarchies = elDataset.getChild("TaxonHierarchies",sddNamespace);
|
1850 |
|
|
|
1851 |
|
|
if (elTaxonHierarchies != null) {
|
1852 |
|
|
List<Element> listTaxonHierarchies = elTaxonHierarchies.getChildren("TaxonHierarchy", sddNamespace);
|
1853 |
|
|
int j = 0;
|
1854 |
|
|
for (Element elTaxonHierarchy : listTaxonHierarchies){
|
1855 |
|
|
try {
|
1856 |
|
|
Element elRepresentation = elTaxonHierarchy.getChild("Representation",sddNamespace);
|
1857 |
|
|
String label = (String)ImportHelper.getXmlInputValue(elRepresentation,"Label",sddNamespace);
|
1858 |
1d36aa54
|
Andreas Müller
|
Classification classification = Classification.NewInstance(label);
|
1859 |
51171c9d
|
Andreas Müller
|
importRepresentation(elTaxonHierarchy, sddNamespace, classification, "", cdmState);
|
1860 |
fc15b32c
|
m.venin
|
|
1861 |
|
|
Element elNodes = elTaxonHierarchy.getChild("Nodes", sddNamespace); // There can be only one <Nodes> block for TaxonHierarchies
|
1862 |
5f03512e
|
m.venin
|
List<Element> listNodes = elNodes.getChildren("Node", sddNamespace);
|
1863 |
fc15b32c
|
m.venin
|
|
1864 |
5f03512e
|
m.venin
|
for (Element elNode : listNodes){
|
1865 |
|
|
String idN = elNode.getAttributeValue("id");
|
1866 |
5559e194
|
Andreas Müller
|
TaxonNameBase<?,?> tnb = null;
|
1867 |
5f03512e
|
m.venin
|
if (!idN.equals("")) {
|
1868 |
|
|
Element elTaxonName = elNode.getChild("TaxonName", sddNamespace);
|
1869 |
|
|
String refTN = elTaxonName.getAttributeValue("ref");
|
1870 |
|
|
tnb = taxonNameBases.get(refTN);
|
1871 |
fc15b32c
|
m.venin
|
Taxon taxon = (Taxon) tnb.getTaxa().iterator().next() ;
|
1872 |
5f03512e
|
m.venin
|
Element elParent = elNode.getChild("Parent", sddNamespace);
|
1873 |
|
|
if (elParent!=null){
|
1874 |
|
|
String refP = elParent.getAttributeValue("ref");
|
1875 |
|
|
if (!refP.equals("")) {
|
1876 |
|
|
TaxonNode parent = taxonNodes.get(refP);
|
1877 |
fc15b32c
|
m.venin
|
TaxonNode child = parent.addChildTaxon(taxon, sec, "", Synonym.NewInstance(tnb, sec));
|
1878 |
5f03512e
|
m.venin
|
taxonNodes.put(idN,child);
|
1879 |
|
|
}
|
1880 |
|
|
}
|
1881 |
|
|
else {
|
1882 |
1d36aa54
|
Andreas Müller
|
TaxonNode tn = classification.addChildTaxon(taxon, sec, "", Synonym.NewInstance(tnb, sec)); // if no parent found or the reference is broken, add the node to the root of the tree
|
1883 |
5f03512e
|
m.venin
|
taxonNodes.put(idN,tn);
|
1884 |
|
|
}
|
1885 |
|
|
}
|
1886 |
|
|
}
|
1887 |
|
|
|
1888 |
1d36aa54
|
Andreas Müller
|
classifications.add(classification);
|
1889 |
5f03512e
|
m.venin
|
}
|
1890 |
|
|
|
1891 |
|
|
catch (Exception e) {
|
1892 |
|
|
//FIXME
|
1893 |
|
|
logger.warn("Import of Taxon Hierarchy " + j + " failed.");
|
1894 |
51171c9d
|
Andreas Müller
|
cdmState.setUnsuccessfull();
|
1895 |
5f03512e
|
m.venin
|
}
|
1896 |
|
|
|
1897 |
|
|
if ((++j % modCount) == 0){ logger.info("TaxonHierarchies handled: " + j);}
|
1898 |
|
|
|
1899 |
|
|
}
|
1900 |
|
|
|
1901 |
|
|
}
|
1902 |
|
|
}
|
1903 |
|
|
|
1904 |
|
|
|
1905 |
fc15b32c
|
m.venin
|
// imports the <GeographicAreas> block
|
1906 |
51171c9d
|
Andreas Müller
|
protected void importGeographicAreas(Element elDataset, Namespace sddNamespace, SDDImportState cdmState) {
|
1907 |
fc15b32c
|
m.venin
|
Element elGeographicAreas = elDataset.getChild("GeographicAreas",sddNamespace);
|
1908 |
|
|
if (elGeographicAreas != null) {
|
1909 |
|
|
List<Element> listGeographicAreas = elGeographicAreas.getChildren("GeographicArea", sddNamespace);
|
1910 |
5f03512e
|
m.venin
|
int j = 0;
|
1911 |
892efc69
|
Andreas Kohlbecker
|
|
1912 |
fc15b32c
|
m.venin
|
for (Element elGeographicArea : listGeographicAreas){
|
1913 |
514d0c79
|
h.fradin
|
|
1914 |
fc15b32c
|
m.venin
|
String id = elGeographicArea.getAttributeValue("id");
|
1915 |
|
|
NamedArea na = new NamedArea();
|
1916 |
51171c9d
|
Andreas Müller
|
importRepresentation(elGeographicArea, sddNamespace, na, id, cdmState);
|
1917 |
fc15b32c
|
m.venin
|
namedAreas.put(id,na);
|
1918 |
892efc69
|
Andreas Kohlbecker
|
}
|
1919 |
fc15b32c
|
m.venin
|
if ((++j % modCount) == 0){ logger.info("GeographicAreas handled: " + j);}
|
1920 |
892efc69
|
Andreas Kohlbecker
|
}
|
1921 |
|
|
}
|
1922 |
cb85c609
|
h.fradin
|
}
|