ref #6794 change FeatureTree to TermTree
[cdmlib.git] / cdmlib-io / src / main / java / eu / etaxonomy / cdm / io / sdd / out / SDDDataSet.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
8 */
9
10 package eu.etaxonomy.cdm.io.sdd.out;
11
12 import java.util.ArrayList;
13 import java.util.Collection;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Set;
17
18 import javax.xml.bind.annotation.XmlAccessType;
19 import javax.xml.bind.annotation.XmlAccessorType;
20 import javax.xml.bind.annotation.XmlElement;
21 import javax.xml.bind.annotation.XmlElementWrapper;
22 import javax.xml.bind.annotation.XmlElements;
23 import javax.xml.bind.annotation.XmlRootElement;
24 import javax.xml.bind.annotation.XmlType;
25
26 import eu.etaxonomy.cdm.model.agent.Address;
27 import eu.etaxonomy.cdm.model.agent.AgentBase;
28 import eu.etaxonomy.cdm.model.agent.Contact;
29 import eu.etaxonomy.cdm.model.agent.Institution;
30 import eu.etaxonomy.cdm.model.agent.InstitutionalMembership;
31 import eu.etaxonomy.cdm.model.agent.Person;
32 import eu.etaxonomy.cdm.model.agent.Team;
33 import eu.etaxonomy.cdm.model.common.AnnotationType;
34 import eu.etaxonomy.cdm.model.common.ExtensionType;
35 import eu.etaxonomy.cdm.model.common.Language;
36 import eu.etaxonomy.cdm.model.common.LanguageString;
37 import eu.etaxonomy.cdm.model.common.LanguageStringBase;
38 import eu.etaxonomy.cdm.model.common.MarkerType;
39 import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
40 import eu.etaxonomy.cdm.model.common.RelationshipBase;
41 import eu.etaxonomy.cdm.model.common.SourcedEntityBase;
42 import eu.etaxonomy.cdm.model.common.VersionableEntity;
43 import eu.etaxonomy.cdm.model.description.Feature;
44 import eu.etaxonomy.cdm.model.description.MeasurementUnit;
45 import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
46 import eu.etaxonomy.cdm.model.description.State;
47 import eu.etaxonomy.cdm.model.description.StatisticalMeasure;
48 import eu.etaxonomy.cdm.model.description.TextFormat;
49 import eu.etaxonomy.cdm.model.location.Country;
50 import eu.etaxonomy.cdm.model.location.NamedArea;
51 import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
52 import eu.etaxonomy.cdm.model.location.NamedAreaType;
53 import eu.etaxonomy.cdm.model.location.ReferenceSystem;
54 import eu.etaxonomy.cdm.model.media.RightsType;
55 import eu.etaxonomy.cdm.model.molecular.DnaSample;
56 import eu.etaxonomy.cdm.model.name.HomotypicalGroup;
57 import eu.etaxonomy.cdm.model.name.HybridRelationship;
58 import eu.etaxonomy.cdm.model.name.HybridRelationshipType;
59 import eu.etaxonomy.cdm.model.name.NameRelationship;
60 import eu.etaxonomy.cdm.model.name.NameRelationshipType;
61 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
62 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
63 import eu.etaxonomy.cdm.model.name.NomenclaturalStatus;
64 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
65 import eu.etaxonomy.cdm.model.name.Rank;
66 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
67 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
68 import eu.etaxonomy.cdm.model.name.TaxonName;
69 import eu.etaxonomy.cdm.model.occurrence.DerivationEventType;
70 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
71 import eu.etaxonomy.cdm.model.occurrence.PreservationMethod;
72 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
73 import eu.etaxonomy.cdm.model.reference.Reference;
74 import eu.etaxonomy.cdm.model.taxon.Synonym;
75 import eu.etaxonomy.cdm.model.taxon.SynonymType;
76 import eu.etaxonomy.cdm.model.taxon.Taxon;
77 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
78 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
79 import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
80 import eu.etaxonomy.cdm.model.term.DefinedTerm;
81 import eu.etaxonomy.cdm.model.term.DefinedTermBase;
82 import eu.etaxonomy.cdm.model.term.TermTreeNode;
83 import eu.etaxonomy.cdm.model.term.TermTree;
84 import eu.etaxonomy.cdm.model.term.Representation;
85 import eu.etaxonomy.cdm.model.term.TermVocabulary;
86
87 /**
88 * @author a.babadshanjan
89 */
90 @XmlAccessorType(XmlAccessType.FIELD)
91 @XmlType(name = "", propOrder = {
92 "terms",
93 "termVocabularies",
94 "agents",
95 "agentData",
96 "occurrences",
97 "references",
98 "referencedEntities",
99 "featureData",
100 "languageData",
101 "taxonomicNames",
102 "homotypicalGroups",
103 "taxa",
104 "synonyms",
105 "relationships",
106 "media"
107 })
108 @XmlRootElement(name = "DataSet", namespace = "http://etaxonomy.eu/cdm/model/1.0")
109 public class SDDDataSet {
110
111 // Some fields are of type List and some are of type Set.
112 // This is mainly because
113 // the service classes return lists, i.e.
114 // TaxonServiceImpl.getRootTaxa() returns List<Taxon>
115 // and the Taxon methods return sets, i.e.
116 // Taxon.getTaxonomicChildren() returns Set<Taxon>.
117
118 @XmlElementWrapper(name = "Agents")
119 @XmlElements({
120 @XmlElement(name = "Team", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = Team.class),
121 @XmlElement(name = "Institution", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = Institution.class),
122 @XmlElement(name = "Person", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = Person.class)
123 })
124 protected List<? extends AgentBase> agents;
125
126 @XmlElementWrapper(name = "AgentData")
127 @XmlElements({
128 @XmlElement(name = "Address", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = Address.class),
129 @XmlElement(name = "Contact", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = Contact.class),
130 @XmlElement(name = "InstitutionalMembership", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = InstitutionalMembership.class)
131 })
132 protected List<VersionableEntity> agentData;
133
134 @XmlElementWrapper(name = "FeatureData")
135 @XmlElements({
136 @XmlElement(name = "FeatureNode", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TermTreeNode.class),
137 @XmlElement(name = "FeatureTree", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TermTree.class)
138 })
139 // protected List<VersionableEntity> featureData;
140 protected List<VersionableEntity> featureData;
141
142 @XmlElementWrapper(name = "LanguageData")
143 @XmlElements({
144 @XmlElement(name = "Representation", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = Representation.class),
145 @XmlElement(name = "LanguageString", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = LanguageString.class)
146 })
147 protected List<LanguageStringBase> languageData;
148
149 @XmlElementWrapper(name = "Terms")
150 @XmlElements({
151 @XmlElement(name = "AnnotationType", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = AnnotationType.class),
152 @XmlElement(name = "Continent", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = NamedArea.class),
153 @XmlElement(name = "DerivationEventType", namespace = "http://etaxonomy.eu/cdm/model/occurrence/1.0", type = DerivationEventType.class),
154 @XmlElement(name = "DeterminationModifier", namespace = "http://etaxonomy.eu/cdm/model/occurrence/1.0", type = DefinedTerm.class),
155 @XmlElement(name = "ExtensionType", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = ExtensionType.class),
156 @XmlElement(name = "Feature", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = Feature.class),
157 @XmlElement(name = "HybridRelationshipType", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = HybridRelationshipType.class),
158 @XmlElement(name = "InstitutionType", namespace = "http://etaxonomy.eu/cdm/model/agent/1.0", type = DefinedTerm.class),
159 @XmlElement(name = "Language", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = Language.class),
160 @XmlElement(name = "MarkerType", namespace = "http://etaxonomy.eu/cdm/model/common/1.0", type = MarkerType.class),
161 @XmlElement(name = "MeasurementUnit", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = MeasurementUnit.class),
162 @XmlElement(name = "Modifier", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = DefinedTerm.class),
163 @XmlElement(name = "NamedArea", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = NamedArea.class),
164 @XmlElement(name = "NamedAreaLevel", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = NamedAreaLevel.class),
165 @XmlElement(name = "NamedAreaType", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = NamedAreaType.class),
166 @XmlElement(name = "NameRelationshipType", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NameRelationshipType.class),
167 @XmlElement(name = "NomenclaturalCode", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NomenclaturalCode.class),
168 @XmlElement(name = "NomenclaturalStatusType", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NomenclaturalStatusType.class),
169 @XmlElement(name = "PresenceAbsenceTerm", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = PresenceAbsenceTerm.class),
170 @XmlElement(name = "PreservationMethod", namespace = "http://etaxonomy.eu/cdm/model/occurrence/1.0", type = PreservationMethod.class),
171 @XmlElement(name = "Rank", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = Rank.class),
172 @XmlElement(name = "ReferenceSystem", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = ReferenceSystem.class),
173 @XmlElement(name = "RightsType", namespace = "http://etaxonomy.eu/cdm/model/media/1.0", type = RightsType.class),
174 @XmlElement(name = "Scope", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = DefinedTerm.class),
175 @XmlElement(name = "Sex", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = DefinedTerm.class),
176 @XmlElement(name = "Stage", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = DefinedTerm.class),
177 @XmlElement(name = "State", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = State.class),
178 @XmlElement(name = "StatisticalMeasure", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = StatisticalMeasure.class),
179 @XmlElement(name = "SynonymType", namespace = "http://etaxonomy.eu/cdm/model/taxon/1.0", type = SynonymType.class),
180 @XmlElement(name = "TaxonRelationshipType", namespace = "http://etaxonomy.eu/cdm/model/taxon/1.0", type = TaxonRelationshipType.class),
181 @XmlElement(name = "TextFormat", namespace = "http://etaxonomy.eu/cdm/model/description/1.0", type = TextFormat.class),
182 @XmlElement(name = "TypeDesignationStatus", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = SpecimenTypeDesignationStatus.class),
183 @XmlElement(name = "Country", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = Country.class)
184 })
185 protected List<DefinedTermBase> terms;
186
187 @XmlElementWrapper(name = "TermVocabularies")
188 @XmlElement(name = "TermVocabulary", namespace = "http://etaxonomy.eu/cdm/model/common/1.0")
189 protected List<TermVocabulary<DefinedTermBase>> termVocabularies;
190
191 @XmlElementWrapper(name = "Occurrences")
192 @XmlElements({
193 @XmlElement(name = "DnaSample", namespace = "http://etaxonomy.eu/cdm/model/occurrence/1.0", type = DnaSample.class),
194 @XmlElement(name = "FieldUnit", namespace = "http://etaxonomy.eu/cdm/model/occurrence/1.0", type = FieldUnit.class)
195 })
196 protected List<SpecimenOrObservationBase> occurrences;
197
198 @XmlElementWrapper(name = "References")
199 @XmlElement(name = "Reference", namespace = "http://etaxonomy.eu/cdm/model/reference/1.0", type = Reference.class)
200
201 protected List<Reference> references;
202
203 @XmlElementWrapper(name = "ReferencedEntities")
204 @XmlElements({
205 @XmlElement(name = "NomenclaturalStatus", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NomenclaturalStatus.class),
206 })
207 protected List<ReferencedEntityBase> referencedEntities;
208
209 @XmlElementWrapper(name = "SourcedEntities")
210 @XmlElements({
211 @XmlElement(name = "NameTypeDesignation", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NameTypeDesignation.class),
212 @XmlElement(name = "SpecimenTypeDesignation", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = SpecimenTypeDesignation.class)
213 })
214 protected List<SourcedEntityBase> sourcedEntities;
215
216
217 @XmlElementWrapper(name = "TaxonomicNames")
218 @XmlElements({
219 @XmlElement(name = "TaxonName", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = TaxonName.class),
220 })
221 protected List<TaxonName> taxonomicNames;
222
223 @XmlElementWrapper(name = "Taxa")
224 @XmlElement(name = "Taxon", namespace = "http://etaxonomy.eu/cdm/model/taxon/1.0")
225 protected List<Taxon> taxa;
226
227 @XmlElementWrapper(name = "Synonyms")
228 @XmlElement(name = "Synonym", namespace = "http://etaxonomy.eu/cdm/model/taxon/1.0")
229 protected List<Synonym> synonyms;
230
231 @XmlElementWrapper(name = "Relationships")
232 @XmlElements({
233 @XmlElement(name = "TaxonRelationship", namespace = "http://etaxonomy.eu/cdm/model/taxon/1.0", type = TaxonRelationship.class),
234 @XmlElement(name = "NameRelationship", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = NameRelationship.class),
235 @XmlElement(name = "HybridRelationship", namespace = "http://etaxonomy.eu/cdm/model/name/1.0", type = HybridRelationship.class)
236 })
237 protected Set<RelationshipBase> relationships;
238
239 @XmlElementWrapper(name = "Media_")
240 @XmlElement(name = "Media", namespace = "http://etaxonomy.eu/cdm/model/media/1.0")
241 protected List<VersionableEntity> media;
242
243 @XmlElementWrapper(name = "HomotypicalGroups")
244 @XmlElement(name = "HomotypicalGroup", namespace = "http://etaxonomy.eu/cdm/model/name/1.0")
245 protected List<HomotypicalGroup> homotypicalGroups;
246
247 // @XmlElement(name = "TdwgArea", namespace = "http://etaxonomy.eu/cdm/model/location/1.0", type = TdwgArea.class),
248
249 public SDDDataSet () {
250
251 agents = new ArrayList<>();
252 agentData = new ArrayList<>();
253 featureData = new ArrayList<>();
254 languageData = new ArrayList<>();
255 terms = new ArrayList<>();
256 termVocabularies = new ArrayList<>();
257 occurrences = new ArrayList<>();
258 references = new ArrayList<>();
259 referencedEntities = new ArrayList<>();
260 taxonomicNames = new ArrayList<>();
261 taxa = new ArrayList<>();
262 synonyms = new ArrayList<>();
263 media = new ArrayList<>();
264 homotypicalGroups = new ArrayList<>();
265 }
266
267 public List<? extends AgentBase> getAgents() {
268 return agents;
269 }
270 public void setAgents(List<? extends AgentBase> value) {
271 this.agents = value;
272 }
273
274
275 public List<VersionableEntity> getAgentData() {
276 return agentData;
277 }
278 public void setAgentData(List<VersionableEntity> value) {
279 this.agentData = value;
280 }
281
282 //public List<? extends TermBase> getTerms() {
283 public List<DefinedTermBase> getTerms() {
284 return terms;
285 }
286
287 //public void setTerms(List<? extends TermBase> value) {
288 public void setTerms(List<DefinedTermBase> value) {
289 this.terms = value;
290 }
291
292 public List<TermVocabulary<DefinedTermBase>> getTermVocabularies() {
293 return termVocabularies;
294 }
295
296 public void setTermVocabularies(List<TermVocabulary<DefinedTermBase>> value) {
297 this.termVocabularies = value;
298 }
299
300 public List<TaxonName> getTaxonomicNames() {
301 return taxonomicNames;
302 }
303 public void setTaxonomicNames(List<TaxonName> value) {
304 this.taxonomicNames = value;
305 }
306
307 public List<SpecimenOrObservationBase> getOccurrences() {
308 return occurrences;
309 }
310
311 public void setOccurrences(List<SpecimenOrObservationBase> value) {
312 this.occurrences = value;
313 }
314
315 public List<Reference> getReferences() {
316 return references;
317 }
318 public void setReferences(List<Reference> value) {
319 this.references = value;
320 }
321
322 public <T extends ReferencedEntityBase> void addReferencedEntities(Collection<T> value) {
323 for (T referencedEntity: value) {
324 this.referencedEntities.add(referencedEntity);
325 }
326 }
327 public List<ReferencedEntityBase> getReferencedEntities() {
328 return referencedEntities;
329 }
330 public void setReferencedEntities(List<? extends ReferencedEntityBase> value) {
331 this.referencedEntities = new ArrayList<>();
332 referencedEntities.addAll(value);
333 }
334
335 public <T extends SourcedEntityBase> void addSourcedEntities(Collection<T> value) {
336 if (sourcedEntities == null){
337 this.sourcedEntities = new ArrayList<>();
338 }
339 for (T sourcedEntity: value) {
340 this.sourcedEntities.add(sourcedEntity);
341 }
342 }
343
344 public List<SourcedEntityBase> getSourcedEntities() {
345 return sourcedEntities;
346 }
347 public void setSourcedEntities(List<? extends SourcedEntityBase> value) {
348 this.sourcedEntities = new ArrayList<>();
349 sourcedEntities.addAll(value);
350 }
351
352 public <T extends VersionableEntity> void addFeatureData(Collection<T> value) {
353 for (T featureItem: value) {
354 this.featureData.add(featureItem);
355 }
356 }
357 // public List<VersionableEntity> getFeatureData() {
358 public List<VersionableEntity> getFeatureData() {
359 return featureData;
360 }
361 public <T extends VersionableEntity> void setFeatureData(List<T> value) {
362 featureData = new ArrayList<>();
363 for (T featureItem: value) {
364 this.featureData.add(featureItem);
365 }
366 }
367
368 // public void setFeatureData(List<? extends VersionableEntity> value) {
369 //public void setFeatureData(List<? extends VersionableEntity<?>> value) {
370 // this.featureData = new ArrayList<VersionableEntity>();
371 // this.featureData = new ArrayList<VersionableEntity<?>>();
372 // featureData.addAll(value);
373 //}
374
375 public <T extends LanguageStringBase> void addLanguageData(Collection<T> value) {
376 for (T languageItem: value) {
377 this.languageData.add(languageItem);
378 }
379 }
380 public List<LanguageStringBase> getLanguageData() {
381 return languageData;
382 }
383 public void setLanguageData(List<? extends LanguageStringBase> value) {
384 this.languageData = new ArrayList<>();
385 languageData.addAll(value);
386 }
387
388 public void addTaxa(Collection<Taxon> value) {
389 for (Taxon taxon: value) {
390 this.taxa.add(taxon);
391 }
392 }
393
394 public Collection<? extends TaxonBase> getTaxa() {
395
396 //TODO can be deleted when everything works
397 //Object obj = taxa;
398 //Collection<TaxonBase> taxonBases = (Collection<TaxonBase>)obj;
399 List<Taxon> list = taxa;
400 return list;
401 }
402
403 public Collection<TaxonBase> getTaxonBases() {
404
405 Collection<TaxonBase> result = new HashSet<>();
406 if (taxa != null) {
407 result.addAll(taxa);
408 }
409 if (synonyms != null) {
410 result.addAll(synonyms);
411 }
412 return result;
413 }
414
415 public void setTaxa(List<Taxon> value) {
416 this.taxa = value;
417 }
418 public void addTaxon(Taxon value) {
419 this.taxa.add(value);
420 }
421
422 public List<Synonym> getSynonyms() {
423 return synonyms;
424 }
425 public void setSynonyms(List<Synonym> value) {
426 this.synonyms = value;
427 }
428
429 public void addSynonym(Synonym value) {
430 this.synonyms.add(value);
431 }
432 public void addSynonyms(Collection<Synonym> value) {
433 for (Synonym synonym: value) {
434 this.synonyms.add(synonym);
435 }
436 }
437
438 public <T extends VersionableEntity> void addMedia(Collection<T> value) {
439 for (T medium: value) {
440 this.media.add(medium);
441 }
442 }
443
444 public List<VersionableEntity> getMedia() {
445 return media;
446 }
447
448 public void setMedia(List<? extends VersionableEntity> value) {
449 this.media = new ArrayList<>();
450 media.addAll(value);
451 }
452
453 public List<HomotypicalGroup> getHomotypicalGroups() {
454 return homotypicalGroups;
455 }
456
457 public void setHomotypicalGroups(List<HomotypicalGroup> value) {
458 this.homotypicalGroups = value;
459 }
460
461 }