Merge branch 'release/4.6.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / derivateSearch / DerivateLabelProvider.java
1 /**
2 * Copyright (C) 2013 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 package eu.etaxonomy.taxeditor.view.derivateSearch;
10
11 import java.util.ArrayList;
12 import java.util.Collection;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
16 import java.util.Map;
17 import java.util.Map.Entry;
18 import java.util.Set;
19 import java.util.UUID;
20
21 import org.eclipse.jface.viewers.ColumnLabelProvider;
22 import org.eclipse.jface.viewers.TreeNode;
23 import org.eclipse.swt.graphics.Image;
24 import org.hibernate.LazyInitializationException;
25
26 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
27 import eu.etaxonomy.cdm.api.service.IOccurrenceService;
28 import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
29 import eu.etaxonomy.cdm.common.CdmUtils;
30 import eu.etaxonomy.cdm.format.CdmFormatterFactory;
31 import eu.etaxonomy.cdm.format.ICdmFormatter.FormatKey;
32 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
33 import eu.etaxonomy.cdm.model.common.CdmBase;
34 import eu.etaxonomy.cdm.model.common.DefinedTerm;
35 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
36 import eu.etaxonomy.cdm.model.common.Identifier;
37 import eu.etaxonomy.cdm.model.molecular.DnaSample;
38 import eu.etaxonomy.cdm.model.molecular.Sequence;
39 import eu.etaxonomy.cdm.model.molecular.SingleRead;
40 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
41 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
42 import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
43 import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
44 import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
45 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
46 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
47 import eu.etaxonomy.cdm.strategy.cache.common.IdentifiableEntityDefaultCacheStrategy;
48 import eu.etaxonomy.taxeditor.model.ImageResources;
49 import eu.etaxonomy.taxeditor.store.CdmStore;
50
51 /**
52 * Label provider for the views to show {@link SpecimenOrObservationBase}s.<br>
53 * <br>
54 * <b>Note:</b> If you use this label provider you need to assure that you
55 * created a {@link ConversationHolder} resp. have an open session because
56 * the labels are generated from various fields of the derivate hierarchy which
57 * are lazy loaded and could therefore throw a {@link LazyInitializationException}.<br>
58 * Use <b>{@link #setConversation(ConversationHolder)}</b> to assign the session to this provider.
59 */
60 public class DerivateLabelProvider extends ColumnLabelProvider {
61
62 private static final String NO_SAMPLE_DESIGNATION = "[no sample designation]";
63
64 private static Set<SingleRead> multiLinkSingleReads;
65
66 private static Map<DerivedUnit, Collection<SpecimenTypeDesignation>> typeDesignations;
67
68 private ConversationHolder conversation;
69
70 private static DefinedTerm photoTerm = null;
71 private static DefinedTerm drawingTerm = null;
72 private static DefinedTerm specimenScanTerm = null;
73 private static DefinedTerm detailImageTerm = null;
74 private static DefinedTerm sampleDesignationTerm = null;
75
76 //FIXME: move static term getters to new singleton utility class
77 private static void initializeTerms() {
78 List<DefinedTerm> preferredTerms = CdmStore.getTermManager().getPreferredTerms(DefinedTerm.class);
79 for (DefinedTerm definedTerm : preferredTerms) {
80 if(definedTerm.getUuid().equals(UUID.fromString("c5c59c42-f254-471e-96c6-09f459f7c903"))){
81 photoTerm = definedTerm;
82 }
83 else if(definedTerm.getUuid().equals(UUID.fromString("669b0409-4aa4-4695-aae4-a95ed27bad4c"))){
84 drawingTerm = definedTerm;
85 }
86 else if(definedTerm.getUuid().equals(UUID.fromString("acda15be-c0e2-4ea8-8783-b9b0c4ad7f03"))){
87 specimenScanTerm = definedTerm;
88 }
89 else if(definedTerm.getUuid().equals(UUID.fromString("31eb8d02-bf5d-437c-bcc6-87a626445f34"))){
90 detailImageTerm = definedTerm;
91 }
92 else if(definedTerm.getUuid().equals(UUID.fromString("fadeba12-1be3-4bc7-9ff5-361b088d86fc"))){
93 sampleDesignationTerm = definedTerm;
94 }
95 }
96 }
97
98 public static DefinedTerm getLivingPlantPhotoTerm(){
99 if(photoTerm==null){
100 initializeTerms();
101 }
102 return photoTerm;
103 }
104
105 public static DefinedTerm getArtworkTerm(){
106 if(drawingTerm==null){
107 initializeTerms();
108 }
109 return drawingTerm;
110 }
111
112 public static DefinedTerm getSpecimenScanTerm(){
113 if(specimenScanTerm==null){
114 initializeTerms();
115 }
116 return specimenScanTerm;
117 }
118
119 public static DefinedTerm getDetailImageTerm(){
120 if(detailImageTerm==null){
121 initializeTerms();
122 }
123 return detailImageTerm;
124 }
125
126 public static DefinedTerm getSampleDesignationTerm(){
127 if(sampleDesignationTerm==null){
128 initializeTerms();
129 }
130 return sampleDesignationTerm;
131 }
132
133
134 /** {@inheritDoc} */
135 @Override
136 public String getText(Object element) {
137 if(element instanceof TreeNode){
138 element = ((TreeNode) element).getValue();
139 }
140 String text = null;
141
142 //check if collection code does not exist -> use collection name then
143 FormatKey collectionKey = FormatKey.COLLECTION_CODE;
144 text = CdmFormatterFactory.format(element,new FormatKey[]{FormatKey.COLLECTION_CODE});
145 if(CdmUtils.isBlank(text)){
146 collectionKey = FormatKey.COLLECTION_NAME;
147 }
148
149 //Use titlecache for FieldUnits
150 if(element instanceof FieldUnit){
151 return ((FieldUnit) element).getTitleCache();
152 }
153 else if(element instanceof MediaSpecimen){
154 text = CdmFormatterFactory.format(element,
155 new FormatKey[]{
156 FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE,
157 collectionKey, FormatKey.SPACE,
158 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
159 FormatKey.MEDIA_TITLE, FormatKey.SPACE,
160 FormatKey.MEDIA_ARTIST, FormatKey.SPACE,
161 });
162 }
163 else if (element instanceof DnaSample) {
164 text = CdmFormatterFactory.format(element,
165 new FormatKey[] {
166 collectionKey, FormatKey.SPACE,
167 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
168 FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE
169 });
170 }
171 else if (element instanceof DerivedUnit) {
172 text = CdmFormatterFactory.format(element,
173 new FormatKey[] {
174 collectionKey, FormatKey.SPACE,
175 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE
176 });
177 }
178 else if (element instanceof Sequence) {
179 text = CdmFormatterFactory.format(element,
180 new FormatKey[] {
181 FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE
182 });
183 }
184 else if (element instanceof SingleRead) {
185 text = CdmFormatterFactory.format(element,
186 new FormatKey[] {
187 FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE,
188 FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
189 });
190 }
191 else if(element instanceof IdentifiableEntity){
192 IdentifiableEntity identifiableEntity = (IdentifiableEntity) element;
193 if(identifiableEntity.isProtectedTitleCache()){
194 text = identifiableEntity.getTitleCache();
195 }
196 }
197 if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){
198 if(element instanceof CdmBase){
199 text = ((CdmBase) element).getUuid().toString();
200 }
201 else{
202 text = element.toString();
203 }
204 }
205 return text;
206 }
207
208 /** {@inheritDoc} */
209 @Override
210 public String getToolTipText(Object element) {
211 return getDerivateText(element);
212 }
213
214 /**
215 * @param conversation the conversation to set
216 */
217 public void setConversation(ConversationHolder conversation) {
218 this.conversation = conversation;
219 }
220
221 public String getDerivateText(Object element){
222 return getDerivateText(element, conversation);
223 }
224
225 public static String getDerivateText(Object element, ConversationHolder conversation){
226 //TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values
227 TreeNode parentNode = null;
228 TreeNode node = null;
229 Object derivate = element;
230 if(element instanceof TreeNode){
231 node = (TreeNode) element;
232 parentNode = node.getParent();
233 //unwrap specimen from TreeNode
234 derivate = node.getValue();
235 }
236
237 if(conversation!=null){
238 conversation.bind();
239 }
240
241 final String emptyString = "";
242 final String separator = " ";
243
244 String label = emptyString;
245
246 //Field Unit
247 if(derivate instanceof FieldUnit){
248 FieldUnit fieldUnit = (FieldUnit)derivate;
249 if(fieldUnit.getGatheringEvent()!=null){
250 GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
251 label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
252 label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
253 label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
254 label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
255 }
256 label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString;
257 }
258 //MediaSpecimen
259 else if(derivate instanceof MediaSpecimen){
260 MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate;
261 if(mediaSpecimen.getMediaSpecimen()!=null){
262 label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]";
263 label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString;
264 }
265 eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection();
266 if(collection!=null){
267 label += collection.getName()!=null?collection.getName()+" ":emptyString;
268 label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
269 }
270 label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString;
271 label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString;
272 }
273 //TissueSample + DnaSample
274 else if(derivate instanceof DnaSample){
275 DnaSample dnaSample = (DnaSample)derivate;
276 if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){
277 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
278 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
279 label += currentSampleDesignation.getIdentifier()+separator;
280 }
281 else{
282 label += NO_SAMPLE_DESIGNATION+separator;
283 }
284 }
285 else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){
286 if(dnaSample.getKindOfUnit()!=null){
287 label += dnaSample.getKindOfUnit()+separator;
288 }
289 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
290 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
291 label += currentSampleDesignation.getIdentifier()+separator;
292 }
293 else{
294 label += NO_SAMPLE_DESIGNATION+separator;
295 }
296 }
297
298 }
299 //DerivedUnit + TissueSample
300 else if(derivate instanceof DerivedUnit){
301 DerivedUnit derivedUnit = (DerivedUnit)derivate;
302 if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
303 //check for type designation
304 if(typeDesignations.get(derivedUnit)==null){
305 for (SpecimenTypeDesignation specimenTypeDesignation : derivedUnit.getSpecimenTypeDesignations()) {
306 addTypeDesignation(derivedUnit, specimenTypeDesignation);
307 }
308 }
309 //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
310 //TODO : This is not generic anymore for performance reasons
311 Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
312 if(originals!=null && originals.size() ==1) {
313 SpecimenOrObservationBase specimen = originals.iterator().next();
314 if(specimen instanceof FieldUnit) {
315 FieldUnit fieldUnit = (FieldUnit)specimen;
316 GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
317 if(gatheringEvent!=null){
318 label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
319 }
320 label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
321 }
322 }
323
324 eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
325 if(collection!=null){
326 label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
327 }
328 String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
329 label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
330 }
331 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
332 //TissueSample should only be created by using it's own class
333 //in future using only one class with different SpecimenOrObservationTypes is desired
334 // label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION;
335 }
336 }
337 //Sequence
338 else if(derivate instanceof Sequence){
339 Sequence sequence = (Sequence)derivate;
340 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
341 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
342 label += currentSampleDesignation.getIdentifier()+separator;
343 }
344 else{
345 label += NO_SAMPLE_DESIGNATION+separator;
346 }
347 label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString;
348 }
349 //SingleRead
350 else if(derivate instanceof SingleRead){
351 SingleRead singleRead = (SingleRead)derivate;
352 if(parentNode!=null && parentNode.getValue() instanceof Sequence){
353 Sequence sequence = (Sequence) parentNode.getValue();
354 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
355 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
356 label = currentSampleDesignation.getIdentifier()+separator;
357 }
358 else{
359 label += NO_SAMPLE_DESIGNATION+separator;
360 }
361 label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString;
362 if(sequence!=null && sequence.getDnaMarker()!=null){
363 label += sequence.getDnaMarker()+separator;
364 }
365 if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){
366 label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator;
367 }
368 }
369 }
370 //SOOB
371 else if(derivate instanceof SpecimenOrObservationBase){
372 SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate;
373 SpecimenOrObservationType type = specimen.getRecordBasis();
374 return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString);
375 }
376 if(label.isEmpty()){
377 label = derivate.toString();
378 }
379 //remove last comma
380 else if(label.endsWith(separator)){
381 label = label.substring(0, label.length()-separator.length());
382 }
383 return label;
384 }
385
386 @Override
387 public Image getImage(Object element) {
388 if(element instanceof TreeNode){
389 element = ((TreeNode) element).getValue();
390 }
391 if(element instanceof CdmBase){
392 CdmBase cdmBase = (CdmBase)element;
393 boolean hasCharacterData = false;
394 if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
395 SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
396 if(specimen.hasCharacterData()){
397 hasCharacterData = true;
398 }
399 }
400 if(cdmBase.isInstanceOf(FieldUnit.class)){
401 return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
402 }
403 else if(cdmBase.isInstanceOf(DerivedUnit.class)){
404 DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
405
406 if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
407 return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
408 }
409 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
410 return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
411 }
412 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
413 return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
414 }
415 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
416 if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){
417 return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE);
418 }
419 return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
420 }
421 else if(derivedUnit.getRecordBasis().isMedia()
422 || derivedUnit.getRecordBasis().isKindOf(SpecimenOrObservationType.Media)){
423 if(derivedUnit.getKindOfUnit()!=null){
424 if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
425 return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
426 }
427 else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
428 return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
429 }
430 else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
431 return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
432 }
433 else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
434 return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
435 }
436 }
437 }
438 }
439 else if(cdmBase.isInstanceOf(Sequence.class)){
440 return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
441 }
442
443 else if(cdmBase.isInstanceOf(SingleRead.class)){
444 if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){
445 return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
446 }
447 else{
448 return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
449 }
450 }
451 }
452 return ImageResources.getImage(ImageResources.DEFAULT_DERIVATIVE);
453 }
454
455 public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) {
456 if(entity.isInstanceOf(DnaSample.class)){
457 DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class);
458 for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) {
459 if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
460 //first sample designation is the current
461 return identifier;
462 }
463 }
464 }
465 else if(entity.isInstanceOf(Sequence.class)){
466 Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class);
467 if(sequence.getDnaSample()!=null){
468 return getCurrentSampleDesignation(sequence.getDnaSample());
469 }
470 }
471 return null;
472 }
473
474 private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
475 Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
476 if(list==null){
477 list = new ArrayList<SpecimenTypeDesignation>();
478 }
479 list.add(typeDesignation);
480 typeDesignations.put(derivedUnit, list);
481 }
482
483 public static Set<SingleRead> getMultiLinkSingleReads() {
484 return multiLinkSingleReads;
485 }
486
487 public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
488 multiLinkSingleReads = new HashSet<SingleRead>();
489 typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
490 for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
491 if(entry.getValue().size()>1){
492 multiLinkSingleReads.add(entry.getKey());
493 }
494 }
495 if(rootElements!=null){
496 Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
497 for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) {
498 derivedUnits.addAll(CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid()));
499 if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
500 derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
501 }
502 }
503 for (DerivedUnit derivedUnit : derivedUnits) {
504 if(!derivedUnit.getSpecimenTypeDesignations().isEmpty()){
505 typeDesignations.put(derivedUnit, derivedUnit.getSpecimenTypeDesignations());
506 }
507 }
508 }
509 }
510
511 }