1
|
package eu.etaxonomy.cdm.io.sdd;
|
2
|
|
3
|
import java.util.HashMap;
|
4
|
import java.util.Iterator;
|
5
|
import java.util.List;
|
6
|
import java.util.Map;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.jdom.Element;
|
10
|
import org.jdom.Namespace;
|
11
|
import org.joda.time.DateTime;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
14
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
15
|
import eu.etaxonomy.cdm.io.common.ICdmIO;
|
16
|
import eu.etaxonomy.cdm.io.common.IImportConfigurator;
|
17
|
import eu.etaxonomy.cdm.io.common.ImportHelper;
|
18
|
import eu.etaxonomy.cdm.io.common.MapWrapper;
|
19
|
import eu.etaxonomy.cdm.model.agent.Person;
|
20
|
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
|
21
|
import eu.etaxonomy.cdm.model.common.Annotation;
|
22
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
23
|
import eu.etaxonomy.cdm.model.common.Language;
|
24
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
25
|
import eu.etaxonomy.cdm.model.description.Feature;
|
26
|
import eu.etaxonomy.cdm.model.description.MeasurementUnit;
|
27
|
import eu.etaxonomy.cdm.model.description.QuantitativeData;
|
28
|
import eu.etaxonomy.cdm.model.description.State;
|
29
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
|
30
|
import eu.etaxonomy.cdm.model.description.StatisticalMeasurementValue;
|
31
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
32
|
import eu.etaxonomy.cdm.model.description.TextData;
|
33
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
34
|
import eu.etaxonomy.cdm.model.name.Rank;
|
35
|
import eu.etaxonomy.cdm.model.reference.ReferenceBase;
|
36
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
37
|
|
38
|
|
39
|
public class SDDDescriptionIO extends SDDIoBase implements ICdmIO {
|
40
|
private static final Logger logger = Logger.getLogger(SDDDescriptionIO.class);
|
41
|
|
42
|
private static int modCount = 10;
|
43
|
|
44
|
public SDDDescriptionIO(){
|
45
|
super();
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public boolean doCheck(IImportConfigurator config){
|
50
|
boolean result = true;
|
51
|
logger.warn("No check implemented for SDD");
|
52
|
return result;
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
public boolean doInvoke(IImportConfigurator config, Map<String, MapWrapper<? extends CdmBase>> stores){
|
57
|
|
58
|
String value;
|
59
|
|
60
|
logger.info("start Datasets ...");
|
61
|
SDDImportConfigurator sddConfig = (SDDImportConfigurator)config;
|
62
|
|
63
|
// <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">
|
64
|
Element root = sddConfig.getSourceRoot();
|
65
|
boolean success =true;
|
66
|
|
67
|
Namespace sddNamespace = sddConfig.getSddNamespace();
|
68
|
Namespace xmlNamespace = Namespace.getNamespace("xml","http://www.w3.org/XML/1998/namespace");
|
69
|
|
70
|
// <TechnicalMetadata created="2006-04-20T10:00:00">
|
71
|
Element elTechnicalMetadata = root.getChild("TechnicalMetadata", sddNamespace);
|
72
|
String nameCreated = elTechnicalMetadata.getAttributeValue("created");
|
73
|
int year = Integer.parseInt(nameCreated.substring(0,4));
|
74
|
int monthOfYear = Integer.parseInt(nameCreated.substring(5,7));
|
75
|
int dayOfMonth = Integer.parseInt(nameCreated.substring(8,10));
|
76
|
int hourOfDay = Integer.parseInt(nameCreated.substring(11,13));
|
77
|
int minuteOfHour = Integer.parseInt(nameCreated.substring(14,16));
|
78
|
int secondOfMinute = Integer.parseInt(nameCreated.substring(17,19));
|
79
|
DateTime created = new DateTime(year,monthOfYear,dayOfMonth,hourOfDay,minuteOfHour,secondOfMinute,0);
|
80
|
|
81
|
// <Generator name="n/a, handcrafted instance document" version="n/a"/>
|
82
|
Element elGenerator = elTechnicalMetadata.getChild("Generator", sddNamespace);
|
83
|
String generatorName = elGenerator.getAttributeValue("name");
|
84
|
String generatorVersion = elGenerator.getAttributeValue("version");
|
85
|
|
86
|
List<Element> elDatasets = root.getChildren("Dataset",sddNamespace);
|
87
|
|
88
|
Map<String,TaxonDescription> taxonDescriptions = new HashMap<String,TaxonDescription>();
|
89
|
Map<String,State> states = new HashMap<String,State>();
|
90
|
Map<String,MeasurementUnit> units = new HashMap<String,MeasurementUnit>();
|
91
|
Map<String,Feature> features = new HashMap<String,Feature>();
|
92
|
|
93
|
Rank rank = null; //Rank.getRankByAbbreviation(abbrev);
|
94
|
NonViralName taxonNameBase = NonViralName.NewInstance(rank);
|
95
|
Taxon taxon = Taxon.NewInstance(taxonNameBase, null);
|
96
|
|
97
|
Feature categoricalCharacter = Feature.NewInstance();
|
98
|
|
99
|
int i = 0;
|
100
|
//for each Dataset
|
101
|
for (Element elDataset : elDatasets){
|
102
|
|
103
|
if ((++i % modCount) == 0){ logger.info("Datasets handled: " + (i-1));}
|
104
|
|
105
|
// <Dataset xml:lang="en-us">
|
106
|
String nameLang = elDataset.getAttributeValue("lang",xmlNamespace);
|
107
|
Language datasetLanguage = Language.NewInstance();
|
108
|
if (!nameLang.equals("")) {
|
109
|
if(nameLang.equals("en-us")) {
|
110
|
datasetLanguage = Language.ENGLISH();
|
111
|
}
|
112
|
}
|
113
|
|
114
|
/* <Representation>
|
115
|
<Label>The Genus Viola</Label>
|
116
|
<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>
|
117
|
</Representation>
|
118
|
*/
|
119
|
Element elRepresentation = elDataset.getChild("Representation",sddNamespace);
|
120
|
String label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
121
|
String detail = (String)ImportHelper.getXmlInputValue(elRepresentation, "Detail",sddNamespace);
|
122
|
|
123
|
taxonNameBase.setFullTitleCache(label);
|
124
|
taxon.setCreated(created);
|
125
|
Annotation annotation = Annotation.NewInstance(detail, datasetLanguage);
|
126
|
taxon.addAnnotation(annotation);
|
127
|
|
128
|
// <RevisionData>
|
129
|
Element elRevisionData = elDataset.getChild("RevisionData",sddNamespace);
|
130
|
|
131
|
// <Creators>
|
132
|
Element elCreators = elRevisionData.getChild("Creators",sddNamespace);
|
133
|
|
134
|
// <Agent role="aut" ref="a1"/>
|
135
|
List<Element> listAgents = elCreators.getChildren("Agent", sddNamespace);
|
136
|
|
137
|
int j = 0;
|
138
|
//for each Agent
|
139
|
Map<String,Person> authors = new HashMap<String,Person>();
|
140
|
Map<String,Person> editors = new HashMap<String,Person>();
|
141
|
for (Element elAgent : listAgents){
|
142
|
if ((++j % modCount) == 0){ logger.info("Agents handled: " + (j-1));}
|
143
|
String role = elAgent.getAttributeValue("role");
|
144
|
String ref = elAgent.getAttributeValue("ref");
|
145
|
if (role.equals("aut")) {
|
146
|
if(!ref.equals("")) {
|
147
|
authors.put(ref, null);
|
148
|
}
|
149
|
}
|
150
|
if (role.equals("edt")) {
|
151
|
if(!ref.equals("")) {
|
152
|
editors.put(ref, null);
|
153
|
}
|
154
|
}
|
155
|
}
|
156
|
|
157
|
// <DateModified>2006-04-08T00:00:00</DateModified>
|
158
|
String stringDateModified = (String)ImportHelper.getXmlInputValue(elRevisionData, "DateModified",sddNamespace);
|
159
|
|
160
|
// <IPRStatements>
|
161
|
Element elIPRStatements = elDataset.getChild("IPRStatements",sddNamespace);
|
162
|
// <IPRStatement role="Copyright">
|
163
|
List<Element> listIPRStatements = elIPRStatements.getChildren("IPRStatement", sddNamespace);
|
164
|
j = 0;
|
165
|
//for each IPRStatement
|
166
|
for (Element elIPRStatement : listIPRStatements){
|
167
|
if ((++j % modCount) == 0){ logger.info("IPRStatements handled: " + (j-1));}
|
168
|
String role = elIPRStatement.getAttributeValue("role");
|
169
|
// <Label xml:lang="en-au">(c) 2003-2006 Centre for Occasional Botany.</Label>
|
170
|
Element elLabel = elIPRStatement.getChild("Label",sddNamespace);
|
171
|
String lang = elLabel.getAttributeValue("lang",xmlNamespace);
|
172
|
label = (String)ImportHelper.getXmlInputValue(elIPRStatement, "Label",sddNamespace);
|
173
|
}
|
174
|
|
175
|
// <TaxonNames>
|
176
|
Element elTaxonNames = elDataset.getChild("TaxonNames",sddNamespace);
|
177
|
// <TaxonName id="t1" uri="urn:lsid:authority:namespace:my-own-id">
|
178
|
List<Element> listTaxonNames = elTaxonNames.getChildren("TaxonName", sddNamespace);
|
179
|
j = 0;
|
180
|
Map<String,NonViralName> taxonNameBases = new HashMap<String,NonViralName>();
|
181
|
//for each TaxonName
|
182
|
for (Element elTaxonName : listTaxonNames){
|
183
|
if ((++j % modCount) == 0){ logger.info("TaxonNames handled: " + (j-1));}
|
184
|
String id = elTaxonName.getAttributeValue("id");
|
185
|
String uri = elTaxonName.getAttributeValue("uri");
|
186
|
// <Representation>
|
187
|
elRepresentation = elTaxonName.getChild("Representation",sddNamespace);
|
188
|
// <Label xml:lang="la">Viola hederacea Labill.</Label>
|
189
|
Element elLabel = elRepresentation.getChild("Label",sddNamespace);
|
190
|
String lang = elLabel.getAttributeValue("lang",xmlNamespace);
|
191
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
192
|
NonViralName tnb = NonViralName.NewInstance(rank);
|
193
|
if ((lang.equals("la")) || (lang.equals(""))) {
|
194
|
tnb.setFullTitleCache(label);
|
195
|
}
|
196
|
if (!id.equals("")) {
|
197
|
taxonNameBases.put(id,tnb);
|
198
|
}
|
199
|
|
200
|
}
|
201
|
|
202
|
// <Characters>
|
203
|
Element elCharacters = elDataset.getChild("Characters", sddNamespace);
|
204
|
|
205
|
// <CategoricalCharacter id="c1">
|
206
|
List<Element> elCategoricalCharacters = elCharacters.getChildren("CategoricalCharacter", sddNamespace);
|
207
|
j = 0;
|
208
|
//for each CategoricalCharacter
|
209
|
for (Element elCategoricalCharacter : elCategoricalCharacters){
|
210
|
|
211
|
if ((++j % modCount) == 0){ logger.info("CategoricalCharacters handled: " + (j-1));}
|
212
|
|
213
|
try {
|
214
|
|
215
|
String idCC = elCategoricalCharacter.getAttributeValue("id");
|
216
|
|
217
|
// <Representation>
|
218
|
// <Label> Leaf complexity</Label>
|
219
|
// </Representation>
|
220
|
elRepresentation = elCategoricalCharacter.getChild("Representation",sddNamespace);
|
221
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
222
|
|
223
|
if (label != null){
|
224
|
categoricalCharacter = Feature.NewInstance(label, label, label);
|
225
|
}
|
226
|
categoricalCharacter.setSupportsQuantitativeData(false);
|
227
|
categoricalCharacter.setSupportsTextData(false);
|
228
|
|
229
|
// <States>
|
230
|
Element elStates = elCategoricalCharacter.getChild("States",sddNamespace);
|
231
|
|
232
|
// <StateDefinition id="s1">
|
233
|
List<Element> elStateDefinitions = elStates.getChildren("StateDefinition",sddNamespace);
|
234
|
|
235
|
int k = 0;
|
236
|
//for each StateDefinition
|
237
|
for (Element elStateDefinition : elStateDefinitions){
|
238
|
|
239
|
if ((++k % modCount) == 0){ logger.info("StateDefinitions handled: " + (k-1));}
|
240
|
|
241
|
String idSD = elStateDefinition.getAttributeValue("id");
|
242
|
// <Representation>
|
243
|
// <Label>Simple</Label>
|
244
|
// </Representation>
|
245
|
elRepresentation = elStateDefinition.getChild("Representation",sddNamespace);
|
246
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
247
|
State state = new State(label,label,label);
|
248
|
states.put(idSD, state);
|
249
|
}
|
250
|
|
251
|
features.put(idCC, categoricalCharacter);
|
252
|
|
253
|
} catch (Exception e) {
|
254
|
//FIXME
|
255
|
logger.warn("Import of CategoricalCharacter " + j + " failed.");
|
256
|
success = false;
|
257
|
}
|
258
|
|
259
|
}
|
260
|
|
261
|
// <QuantitativeCharacter id="c2">
|
262
|
List<Element> elQuantitativeCharacters = elCharacters.getChildren("QuantitativeCharacter", sddNamespace);
|
263
|
j = 0;
|
264
|
//for each QuantitativeCharacter
|
265
|
for (Element elQuantitativeCharacter : elQuantitativeCharacters){
|
266
|
|
267
|
if ((++j % modCount) == 0){ logger.info("QuantitativeCharacters handled: " + (j-1));}
|
268
|
|
269
|
try {
|
270
|
|
271
|
String idQC = elQuantitativeCharacter.getAttributeValue("id");
|
272
|
|
273
|
// <Representation>
|
274
|
// <Label>Leaf length</Label>
|
275
|
// </Representation>
|
276
|
elRepresentation = elQuantitativeCharacter.getChild("Representation",sddNamespace);
|
277
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
278
|
|
279
|
Feature quantitativeCharacter = Feature.NewInstance();
|
280
|
|
281
|
if (!label.equals("")){
|
282
|
quantitativeCharacter = Feature.NewInstance(label, label, label);
|
283
|
}
|
284
|
quantitativeCharacter.setSupportsQuantitativeData(true);
|
285
|
quantitativeCharacter.setSupportsTextData(false);
|
286
|
|
287
|
// <MeasurementUnit>
|
288
|
// <Label role="Abbrev">m</Label>
|
289
|
// </MeasurementUnit>
|
290
|
Element elMeasurementUnit = elQuantitativeCharacter.getChild("MeasurementUnit",sddNamespace);
|
291
|
Element elLabel = elMeasurementUnit.getChild("Label",sddNamespace);
|
292
|
String role = elLabel.getAttributeValue("role");
|
293
|
label = (String)ImportHelper.getXmlInputValue(elMeasurementUnit, "Label",sddNamespace);
|
294
|
|
295
|
MeasurementUnit unit = null;
|
296
|
if (!label.equals("")){
|
297
|
if (role.equals("Abbrev")){
|
298
|
unit = MeasurementUnit.NewInstance("","",label);
|
299
|
} else {
|
300
|
unit = MeasurementUnit.NewInstance(label,label,label);
|
301
|
}
|
302
|
|
303
|
}
|
304
|
|
305
|
units.put(idQC, unit);
|
306
|
|
307
|
//<Default>
|
308
|
// <MeasurementUnitPrefix>milli</MeasurementUnitPrefix>
|
309
|
//</Default>
|
310
|
Element elDefault = elQuantitativeCharacter.getChild("Default",sddNamespace);
|
311
|
String measurementUnitPrefix = (String)ImportHelper.getXmlInputValue(elDefault, "MeasurementUnitPrefix",sddNamespace);
|
312
|
Map<String,String> defaultUnitPrefixes = new HashMap<String,String>();
|
313
|
if (!measurementUnitPrefix.equals("")){
|
314
|
defaultUnitPrefixes.put(idQC, measurementUnitPrefix);
|
315
|
}
|
316
|
|
317
|
features.put(idQC, quantitativeCharacter);
|
318
|
|
319
|
} catch (Exception e) {
|
320
|
//FIXME
|
321
|
logger.warn("Import of QuantitativeCharacter " + j + " failed.");
|
322
|
success = false;
|
323
|
}
|
324
|
|
325
|
}
|
326
|
|
327
|
// <TextCharacter id="c3">
|
328
|
List<Element> elTextCharacters = elCharacters.getChildren("TextCharacter", sddNamespace);
|
329
|
j = 0;
|
330
|
//for each TextCharacter
|
331
|
for (Element elTextCharacter : elTextCharacters){
|
332
|
|
333
|
if ((++j % modCount) == 0){ logger.info("TextCharacters handled: " + (j-1));}
|
334
|
|
335
|
try {
|
336
|
|
337
|
String idTC = elTextCharacter.getAttributeValue("id");
|
338
|
|
339
|
// <Representation>
|
340
|
// <Label xml:lang="en">Leaf features not covered by other characters</Label>
|
341
|
// </Representation>
|
342
|
elRepresentation = elTextCharacter.getChild("Representation",sddNamespace);
|
343
|
Element elLabel = elRepresentation.getChild("Label",sddNamespace);
|
344
|
nameLang = elLabel.getAttributeValue("lang",xmlNamespace);
|
345
|
Language language = Language.NewInstance();
|
346
|
if (!nameLang.equals("")) {
|
347
|
if(nameLang.equals("en")) {
|
348
|
language = Language.ENGLISH();
|
349
|
}
|
350
|
}
|
351
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
352
|
|
353
|
Feature textCharacter = Feature.NewInstance();
|
354
|
|
355
|
if (!idTC.equals("")){
|
356
|
textCharacter = Feature.NewInstance(label, label, label);
|
357
|
}
|
358
|
textCharacter.setSupportsQuantitativeData(false);
|
359
|
textCharacter.setSupportsTextData(true);
|
360
|
textCharacter.setLabel(label, language);
|
361
|
|
362
|
Map<String,String> textCharacters = new HashMap<String,String>();
|
363
|
Map<String,Language> textCharactersLang = new HashMap<String,Language>();
|
364
|
if ((!idTC.equals("")) && (!label.equals(""))){
|
365
|
textCharacters.put(idTC, label);
|
366
|
}
|
367
|
if (!idTC.equals("")){
|
368
|
textCharactersLang.put(idTC, language);
|
369
|
}
|
370
|
|
371
|
features.put(idTC, textCharacter);
|
372
|
|
373
|
} catch (Exception e) {
|
374
|
//FIXME
|
375
|
logger.warn("Import of TextCharacter " + j + " failed.");
|
376
|
success = false;
|
377
|
}
|
378
|
|
379
|
}
|
380
|
|
381
|
// <CodedDescriptions>
|
382
|
Element elCodedDescriptions = elDataset.getChild("CodedDescriptions",sddNamespace);
|
383
|
|
384
|
// <CodedDescription id="D101">
|
385
|
List<Element> listCodedDescriptions = elCodedDescriptions.getChildren("CodedDescription", sddNamespace);
|
386
|
j = 0;
|
387
|
//for each CodedDescription
|
388
|
Map<String,String> citations = new HashMap<String,String>();
|
389
|
Map<String,String> locations = new HashMap<String,String>();
|
390
|
for (Element elCodedDescription : listCodedDescriptions){
|
391
|
|
392
|
if ((++j % modCount) == 0){ logger.info("CodedDescriptions handled: " + (j-1));}
|
393
|
|
394
|
try {
|
395
|
|
396
|
String idCD = elCodedDescription.getAttributeValue("id");
|
397
|
|
398
|
// <Representation>
|
399
|
// <Label><i>Viola hederacea</i> Labill. as revised by R. Morris April 8, 2006</Label>
|
400
|
// </Representation>
|
401
|
elRepresentation = elCodedDescription.getChild("Representation",sddNamespace);
|
402
|
Element elLabel = elRepresentation.getChild("Label",sddNamespace);
|
403
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
404
|
|
405
|
TaxonDescription taxonDescription = TaxonDescription.NewInstance();
|
406
|
annotation = Annotation.NewInstance(label, Language.DEFAULT());
|
407
|
taxonDescription.addAnnotation(annotation);
|
408
|
|
409
|
// <Scope>
|
410
|
// <TaxonName ref="t1"/>
|
411
|
// <Citation ref="p1" location="p. 30"/>
|
412
|
// </Scope>
|
413
|
Element elScope = elCodedDescription.getChild("Scope",sddNamespace);
|
414
|
Element elTaxonName = elScope.getChild("TaxonName",sddNamespace);
|
415
|
String ref = elTaxonName.getAttributeValue("ref");
|
416
|
|
417
|
taxonNameBase = taxonNameBases.get(ref);
|
418
|
|
419
|
Element elCitation = elScope.getChild("Citation",sddNamespace);
|
420
|
ref = elCitation.getAttributeValue("ref");
|
421
|
String location = elCitation.getAttributeValue("location");
|
422
|
|
423
|
// <SummaryData>
|
424
|
Element elSummaryData = elCodedDescription.getChild("SummaryData",sddNamespace);
|
425
|
|
426
|
// <Categorical ref="c4">
|
427
|
List<Element> elCategoricals = elSummaryData.getChildren("Categorical", sddNamespace);
|
428
|
int k = 0;
|
429
|
//for each Categorical
|
430
|
for (Element elCategorical : elCategoricals){
|
431
|
if ((++k % modCount) == 0){ logger.info("Categorical handled: " + (k-1));}
|
432
|
ref = elCategorical.getAttributeValue("ref");
|
433
|
Feature feature = features.get(ref);
|
434
|
CategoricalData categoricalData = CategoricalData.NewInstance();
|
435
|
categoricalData.setFeature(feature);
|
436
|
|
437
|
// <State ref="s3"/>
|
438
|
List<Element> elStates = elCategorical.getChildren("State", sddNamespace);
|
439
|
int l = 0;
|
440
|
//for each State
|
441
|
for (Element elState : elStates){
|
442
|
if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
|
443
|
ref = elState.getAttributeValue("ref");
|
444
|
State state = states.get(ref);
|
445
|
categoricalData.addState(state);
|
446
|
}
|
447
|
taxonDescription.addElement(categoricalData);
|
448
|
}
|
449
|
|
450
|
// <Quantitative ref="c2">
|
451
|
List<Element> elQuantitatives = elSummaryData.getChildren("Quantitative", sddNamespace);
|
452
|
k = 0;
|
453
|
//for each Quantitative
|
454
|
for (Element elQuantitative : elQuantitatives){
|
455
|
if ((++k % modCount) == 0){ logger.info("Quantitative handled: " + (k-1));}
|
456
|
ref = elQuantitative.getAttributeValue("ref");
|
457
|
Feature feature = features.get(ref);
|
458
|
QuantitativeData quantitativeData = QuantitativeData.NewInstance();
|
459
|
quantitativeData.setFeature(feature);
|
460
|
|
461
|
MeasurementUnit unit = units.get(ref);
|
462
|
quantitativeData.setUnit(unit);
|
463
|
|
464
|
// <Measure type="Min" value="2.3"/>
|
465
|
List<Element> elMeasures = elQuantitative.getChildren("Measure", sddNamespace);
|
466
|
int l = 0;
|
467
|
//for each State
|
468
|
for (Element elMeasure : elMeasures){
|
469
|
if ((++l % modCount) == 0){ logger.info("States handled: " + (l-1));}
|
470
|
String type = elMeasure.getAttributeValue("type");
|
471
|
value = elMeasure.getAttributeValue("value");
|
472
|
float v = Float.parseFloat(value);
|
473
|
StatisticalMeasure t = StatisticalMeasure.NewInstance(type,type,type);
|
474
|
StatisticalMeasurementValue statisticalValue = StatisticalMeasurementValue.NewInstance();
|
475
|
statisticalValue.setValue(v);
|
476
|
statisticalValue.setType(t);
|
477
|
quantitativeData.addStatisticalValue(statisticalValue);
|
478
|
}
|
479
|
taxonDescription.addElement(quantitativeData);
|
480
|
}
|
481
|
|
482
|
// <TextChar ref="c3">
|
483
|
List<Element> elTextChars = elSummaryData.getChildren("TextChar", sddNamespace);
|
484
|
k = 0;
|
485
|
//for each TextChar
|
486
|
for (Element elTextChar : elTextChars){
|
487
|
if ((++k % modCount) == 0){ logger.info("TextChar handled: " + (k-1));}
|
488
|
ref = elTextChar.getAttributeValue("ref");
|
489
|
Feature feature = features.get(ref);
|
490
|
TextData textData = TextData.NewInstance();
|
491
|
textData.setFeature(feature);
|
492
|
|
493
|
// <Content>Free form text</Content>
|
494
|
String content = (String)ImportHelper.getXmlInputValue(elTextChar, "Content",sddNamespace);
|
495
|
textData.putText(content, datasetLanguage);
|
496
|
taxonDescription.addElement(textData);
|
497
|
}
|
498
|
|
499
|
taxon.addDescription(taxonDescription);
|
500
|
|
501
|
if (!ref.equals("")){
|
502
|
citations.put(idCD, ref);
|
503
|
}
|
504
|
|
505
|
if (!location.equals("")){
|
506
|
locations.put(idCD, location);
|
507
|
}
|
508
|
|
509
|
taxonDescriptions.put(idCD, taxonDescription);
|
510
|
|
511
|
} catch (Exception e) {
|
512
|
//FIXME
|
513
|
logger.warn("Import of CodedDescription " + j + " failed.");
|
514
|
success = false;
|
515
|
}
|
516
|
|
517
|
}
|
518
|
|
519
|
// <Agents>
|
520
|
Element elAgents = elDataset.getChild("Agents",sddNamespace);
|
521
|
|
522
|
// <Agent id="a1">
|
523
|
listAgents = elAgents.getChildren("Agent", sddNamespace);
|
524
|
j = 0;
|
525
|
//for each Agent
|
526
|
for (Element elAgent : listAgents){
|
527
|
|
528
|
if ((++j % modCount) == 0){ logger.info("elAgent handled: " + (j-1));}
|
529
|
|
530
|
try {
|
531
|
|
532
|
String idA = elAgent.getAttributeValue("id");
|
533
|
|
534
|
// <Representation>
|
535
|
// <Label>Kevin Thiele</Label>
|
536
|
// </Representation>
|
537
|
elRepresentation = elAgent.getChild("Representation",sddNamespace);
|
538
|
label = (String)ImportHelper.getXmlInputValue(elRepresentation, "Label",sddNamespace);
|
539
|
|
540
|
if (authors.containsKey(idA)) {
|
541
|
authors.put(idA, Person.NewTitledInstance(label));
|
542
|
}
|
543
|
|
544
|
if (editors.containsKey(idA)) {
|
545
|
editors.put(idA, Person.NewTitledInstance(label));
|
546
|
}
|
547
|
|
548
|
} catch (Exception e) {
|
549
|
//FIXME
|
550
|
logger.warn("Import of Agent " + j + " failed.");
|
551
|
success = false;
|
552
|
}
|
553
|
|
554
|
|
555
|
}
|
556
|
|
557
|
for (Iterator<TaxonDescription> taxonDescription = taxonDescriptions.values().iterator() ; taxonDescription.hasNext() ;){
|
558
|
TaxonDescription td = taxonDescription.next();
|
559
|
/*
|
560
|
if (authors.size()>1) {
|
561
|
for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
|
562
|
td.setCreatedBy(author.next());
|
563
|
}
|
564
|
} else {
|
565
|
Team team = Team.NewInstance();
|
566
|
for (Iterator<Person> author = authors.values().iterator() ; author.hasNext() ;){
|
567
|
team.addTeamMember(author.next());
|
568
|
}
|
569
|
td.setCreatedBy(team);
|
570
|
}
|
571
|
*/
|
572
|
|
573
|
Iterator<Person> author = authors.values().iterator();
|
574
|
if (author.hasNext()){
|
575
|
td.setCreatedBy(author.next());
|
576
|
}
|
577
|
|
578
|
Iterator<Person> editor = editors.values().iterator();
|
579
|
if (editor.hasNext()){
|
580
|
td.setUpdatedBy(editor.next());
|
581
|
}
|
582
|
}
|
583
|
|
584
|
// REPERE
|
585
|
|
586
|
|
587
|
}
|
588
|
logger.info(i + " Datasets handled");
|
589
|
|
590
|
ITermService termService = config.getCdmAppController().getTermService();
|
591
|
for (Iterator<Feature> k = features.values().iterator() ; k.hasNext() ;){
|
592
|
termService.saveTerm(k.next());
|
593
|
}
|
594
|
for (Iterator<MeasurementUnit> k = units.values().iterator() ; k.hasNext() ;){
|
595
|
termService.saveTerm(k.next());
|
596
|
}
|
597
|
|
598
|
// Returns a CdmApplicationController created by the values of this configuration.
|
599
|
IDescriptionService descriptionService = config.getCdmAppController().getDescriptionService();
|
600
|
|
601
|
for (Iterator<TaxonDescription> k = taxonDescriptions.values().iterator() ; k.hasNext() ;){
|
602
|
// Persists a Description
|
603
|
descriptionService.saveDescription(k.next());
|
604
|
}
|
605
|
|
606
|
// makeNameSpecificData(nameMap);
|
607
|
logger.info("end makeTaxonNames ...");
|
608
|
return success;
|
609
|
|
610
|
}
|
611
|
/* (non-Javadoc)
|
612
|
* @see eu.etaxonomy.cdm.io.common.CdmIoBase#isIgnore(eu.etaxonomy.cdm.io.common.IImportConfigurator)
|
613
|
*/
|
614
|
protected boolean isIgnore(IImportConfigurator config){
|
615
|
return false;
|
616
|
}
|
617
|
|
618
|
}
|