Revision c4920945
Added by Andreas Müller over 12 years ago
cdmlib-io/src/main/java/eu/etaxonomy/cdm/io/common/CdmImportBase.java | ||
---|---|---|
28 | 28 |
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper; |
29 | 29 |
import eu.etaxonomy.cdm.io.common.mapping.IInputTransformer; |
30 | 30 |
import eu.etaxonomy.cdm.io.common.mapping.UndefinedTransformerMethodException; |
31 |
import eu.etaxonomy.cdm.io.markup.MarkupTransformer; |
|
31 | 32 |
import eu.etaxonomy.cdm.model.common.AnnotationType; |
32 | 33 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
34 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
|
33 | 35 |
import eu.etaxonomy.cdm.model.common.DescriptionElementSource; |
34 | 36 |
import eu.etaxonomy.cdm.model.common.ExtensionType; |
35 | 37 |
import eu.etaxonomy.cdm.model.common.IOriginalSource; |
... | ... | |
37 | 39 |
import eu.etaxonomy.cdm.model.common.IdentifiableEntity; |
38 | 40 |
import eu.etaxonomy.cdm.model.common.IdentifiableSource; |
39 | 41 |
import eu.etaxonomy.cdm.model.common.Language; |
42 |
import eu.etaxonomy.cdm.model.common.Marker; |
|
40 | 43 |
import eu.etaxonomy.cdm.model.common.MarkerType; |
41 | 44 |
import eu.etaxonomy.cdm.model.common.OrderedTermVocabulary; |
42 | 45 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
46 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
43 | 47 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
44 | 48 |
import eu.etaxonomy.cdm.model.description.Feature; |
45 | 49 |
import eu.etaxonomy.cdm.model.description.PresenceTerm; |
46 | 50 |
import eu.etaxonomy.cdm.model.description.TaxonDescription; |
51 |
import eu.etaxonomy.cdm.model.description.TextData; |
|
47 | 52 |
import eu.etaxonomy.cdm.model.location.NamedArea; |
48 | 53 |
import eu.etaxonomy.cdm.model.location.NamedAreaLevel; |
49 | 54 |
import eu.etaxonomy.cdm.model.location.NamedAreaType; |
... | ... | |
76 | 81 |
public static final UUID uuidUserDefinedReferenceSystemVocabulary = UUID.fromString("467591a3-10b4-4bf1-9239-f06ece33e90a"); |
77 | 82 |
public static final UUID uuidUserDefinedFeatureVocabulary = UUID.fromString("fe5fccb3-a2f2-4b97-b199-6e2743cf1627"); |
78 | 83 |
public static final UUID uuidUserDefinedAnnotationTypeVocabulary = UUID.fromString("cd9ecdd2-9cae-4890-9032-ad83293ae883"); |
84 |
public static final UUID uuidUserDefinedMarkerTypeVocabulary = UUID.fromString("5f02a261-fd7d-4fce-bbe4-21472de8cd51"); |
|
79 | 85 |
|
80 | 86 |
|
81 | 87 |
private static final String UuidOnly = "UUIDOnly"; |
... | ... | |
182 | 188 |
extensionType.setUuid(uuid); |
183 | 189 |
if (voc == null){ |
184 | 190 |
boolean isOrdered = false; |
185 |
voc = getVocabulary(uuidUserDefinedExtensionTypeVocabulary, "User defined vocabulary for extension types", "User Defined Extension Types", null, null, isOrdered); |
|
191 |
voc = getVocabulary(uuidUserDefinedExtensionTypeVocabulary, "User defined vocabulary for extension types", "User Defined Extension Types", null, null, isOrdered, extensionType);
|
|
186 | 192 |
} |
187 | 193 |
voc.addTerm(extensionType); |
188 | 194 |
getTermService().saveOrUpdate(extensionType); |
... | ... | |
214 | 220 |
} |
215 | 221 |
|
216 | 222 |
protected MarkerType getMarkerType(STATE state, UUID uuid, String label, String text, String labelAbbrev){ |
223 |
return getMarkerType(state, uuid, label, text, labelAbbrev, null); |
|
224 |
} |
|
225 |
|
|
226 |
|
|
227 |
protected MarkerType getMarkerType(STATE state, UUID uuid, String label, String text, String labelAbbrev, TermVocabulary<MarkerType> voc){ |
|
217 | 228 |
if (uuid == null){ |
218 | 229 |
uuid = UUID.randomUUID(); |
219 | 230 |
} |
... | ... | |
223 | 234 |
if (markerType == null){ |
224 | 235 |
markerType = MarkerType.NewInstance(label, text, labelAbbrev); |
225 | 236 |
markerType.setUuid(uuid); |
226 |
UUID uuidMarkerTypeVoc = UUID.fromString("19dffff7-e142-429c-a420-5d28e4ebe305"); |
|
227 |
TermVocabulary voc = getVocabularyService().find(uuidMarkerTypeVoc); |
|
237 |
if (voc == null){ |
|
238 |
boolean isOrdered = false; |
|
239 |
voc = getVocabulary(uuidUserDefinedMarkerTypeVocabulary, "User defined vocabulary for marker types", "User Defined Marker Types", null, null, isOrdered, markerType); |
|
240 |
} |
|
228 | 241 |
voc.addTerm(markerType); |
229 | 242 |
getTermService().save(markerType); |
230 | 243 |
} |
... | ... | |
245 | 258 |
annotationType.setUuid(uuid); |
246 | 259 |
if (voc == null){ |
247 | 260 |
boolean isOrdered = false; |
248 |
voc = getVocabulary(uuidUserDefinedAnnotationTypeVocabulary, "User defined vocabulary for annotation types", "User Defined Annotation Types", null, null, isOrdered); |
|
261 |
voc = getVocabulary(uuidUserDefinedAnnotationTypeVocabulary, "User defined vocabulary for annotation types", "User Defined Annotation Types", null, null, isOrdered, annotationType);
|
|
249 | 262 |
} |
250 | 263 |
|
251 | 264 |
voc.addTerm(annotationType); |
... | ... | |
268 | 281 |
refSystem = ReferenceSystem.NewInstance(text, label, labelAbbrev); |
269 | 282 |
if (voc == null){ |
270 | 283 |
boolean isOrdered = false; |
271 |
voc = getVocabulary(uuidUserDefinedReferenceSystemVocabulary, "User defined vocabulary for named areas", "User Defined Reference System", null, null, isOrdered); |
|
284 |
voc = getVocabulary(uuidUserDefinedReferenceSystemVocabulary, "User defined vocabulary for named areas", "User Defined Reference System", null, null, isOrdered, refSystem);
|
|
272 | 285 |
} |
273 | 286 |
voc.addTerm(refSystem); |
274 | 287 |
refSystem.setUuid(uuid); |
... | ... | |
321 | 334 |
namedArea = NamedArea.NewInstance(text, label, labelAbbrev); |
322 | 335 |
if (voc == null){ |
323 | 336 |
boolean isOrdered = true; |
324 |
voc = getVocabulary(uuidUserDefinedNamedAreaVocabulary, "User defined vocabulary for named areas", "User Defined Named Areas", null, null, isOrdered); |
|
337 |
voc = getVocabulary(uuidUserDefinedNamedAreaVocabulary, "User defined vocabulary for named areas", "User Defined Named Areas", null, null, isOrdered, namedArea);
|
|
325 | 338 |
} |
326 | 339 |
voc.addTerm(namedArea); |
327 | 340 |
namedArea.setType(areaType); |
... | ... | |
364 | 377 |
namedAreaLevel = NamedAreaLevel.NewInstance(text, label, labelAbbrev); |
365 | 378 |
if (voc == null){ |
366 | 379 |
boolean isOrdered = true; |
367 |
voc = getVocabulary(uuidUserDefinedNamedAreaLevelVocabulary, "User defined vocabulary for named area levels", "User Defined Named Area Levels", null, null, isOrdered); |
|
380 |
voc = getVocabulary(uuidUserDefinedNamedAreaLevelVocabulary, "User defined vocabulary for named area levels", "User Defined Named Area Levels", null, null, isOrdered, namedAreaLevel);
|
|
368 | 381 |
} |
369 | 382 |
voc.addTerm(namedAreaLevel); |
370 | 383 |
namedAreaLevel.setUuid(uuid); |
... | ... | |
412 | 425 |
// UUID uuidFeatureVoc = UUID.fromString("b187d555-f06f-4d65-9e53-da7c93f8eaa8"); |
413 | 426 |
if (voc == null){ |
414 | 427 |
boolean isOrdered = false; |
415 |
voc = getVocabulary(uuidUserDefinedFeatureVocabulary, "User defined vocabulary for features", "User Defined Features", null, null, isOrdered); |
|
428 |
voc = getVocabulary(uuidUserDefinedFeatureVocabulary, "User defined vocabulary for features", "User Defined Features", null, null, isOrdered, feature);
|
|
416 | 429 |
} |
417 | 430 |
voc.addTerm(feature); |
418 | 431 |
getTermService().save(feature); |
... | ... | |
494 | 507 |
* @return |
495 | 508 |
* |
496 | 509 |
*/ |
497 |
protected TermVocabulary getVocabulary(UUID uuid, String text, String label, String abbrev, URI termSourceUri, boolean isOrdered) {
|
|
498 |
List propPath = Arrays.asList(new String[]{"terms"}); |
|
499 |
TermVocabulary voc = getVocabularyService().load(uuid, propPath); |
|
510 |
protected <T extends DefinedTermBase> TermVocabulary<T> getVocabulary(UUID uuid, String text, String label, String abbrev, URI termSourceUri, boolean isOrdered, T type) {
|
|
511 |
List<String> propPath = Arrays.asList(new String[]{"terms"});
|
|
512 |
TermVocabulary<T> voc = getVocabularyService().load(uuid, propPath);
|
|
500 | 513 |
if (voc == null){ |
501 | 514 |
if (isOrdered){ |
502 | 515 |
voc = OrderedTermVocabulary.NewInstance(text, label, abbrev, termSourceUri); |
... | ... | |
637 | 650 |
} |
638 | 651 |
return result; |
639 | 652 |
} |
653 |
|
|
654 |
|
|
655 |
/** |
|
656 |
* Returns the textdata that holds general information about a feature for a taxon description. |
|
657 |
* This is mainly necessary for descriptions that have more than one description element for |
|
658 |
* a given feature such as 'distribution', 'description' or 'common name'. It may also hold |
|
659 |
* for hierarchical features where no description element exists for a higher hierarchie level. |
|
660 |
* Example: the description feature has subfeatures. But some information like authorship, figures, |
|
661 |
* sources need to be added to the description itself. |
|
662 |
* Currently a feature placeholder is marked by a marker of type 'feature placeholder'. Maybe in future |
|
663 |
* there will be a boolean marker in the TextData class itself. |
|
664 |
* @param state |
|
665 |
* @param taxon |
|
666 |
* @param ref |
|
667 |
* @param createIfNotExists |
|
668 |
* @return |
|
669 |
*/ |
|
670 |
protected TextData getFeaturePlaceholder(STATE state, DescriptionBase<?> description, boolean createIfNotExists) { |
|
671 |
UUID featurePlaceholderUuid = MarkupTransformer.uuidFeaturePlaceholder; |
|
672 |
for (DescriptionElementBase element : description.getElements()){ |
|
673 |
if (element.isInstanceOf(TextData.class)){ |
|
674 |
TextData placeholder = CdmBase.deproxy(element, TextData.class); |
|
675 |
for (Marker marker : placeholder.getMarkers()){ |
|
676 |
MarkerType markerType = marker.getMarkerType(); |
|
677 |
if (markerType != null && |
|
678 |
markerType.getUuid().equals(featurePlaceholderUuid) && |
|
679 |
marker.getValue() == true){ |
|
680 |
return placeholder; |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
if (createIfNotExists){ |
|
686 |
TextData newPlaceholder = TextData.NewInstance(); |
|
687 |
MarkerType placeholderMarkerType = getMarkerType(state, featurePlaceholderUuid, "Feature Placeholder", "Feature Placeholder", null); |
|
688 |
Marker marker = Marker.NewInstance(placeholderMarkerType, true); |
|
689 |
newPlaceholder.addMarker(marker); |
|
690 |
return newPlaceholder; |
|
691 |
}else{ |
|
692 |
return null; |
|
693 |
} |
|
694 |
} |
|
695 |
|
|
640 | 696 |
|
641 | 697 |
|
642 | 698 |
/** |
Also available in: Unified diff
getMarkerType with voc and generics for getVocabulary