Merge branch 'release/4.7.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
154 else if(element instanceof MediaSpecimen){
155 text = CdmFormatterFactory.format(element,
156 new FormatKey[]{
157 FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE,
158 collectionKey, FormatKey.SPACE,
159 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
160 FormatKey.MEDIA_TITLE, FormatKey.SPACE,
161 FormatKey.MEDIA_ARTIST, FormatKey.SPACE,
162 });
163 }
164 else if (element instanceof DnaSample) {
165 text = CdmFormatterFactory.format(element,
166 new FormatKey[] {
167 collectionKey, FormatKey.SPACE,
168 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
169 FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE
170 });
171 }
172 else if (element instanceof DerivedUnit) {
173 text = CdmFormatterFactory.format(element,
174 new FormatKey[] {
175 collectionKey, FormatKey.SPACE,
176 FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE
177 });
178 }
179 else if (element instanceof Sequence) {
180 text = CdmFormatterFactory.format(element,
181 new FormatKey[] {
182 FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE
183 });
184 }
185 else if (element instanceof SingleRead) {
186 text = CdmFormatterFactory.format(element,
187 new FormatKey[] {
188 FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE,
189 FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
190 });
191 }
192 else if(element instanceof IdentifiableEntity){
193
194 IdentifiableEntity identifiableEntity = (IdentifiableEntity) element;
195 if(identifiableEntity.isProtectedTitleCache()){
196 text = identifiableEntity.getTitleCache();
197 }
198 }
199 if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){
200 if(element instanceof CdmBase){
201 text = ((CdmBase) element).getUuid().toString();
202 }
203 else{
204 text = element.toString();
205 }
206 }
207 return text;
208 }
209
210 /** {@inheritDoc} */
211 @Override
212 public String getToolTipText(Object element) {
213 return getDerivateText(element);
214 }
215
216 /**
217 * @param conversation the conversation to set
218 */
219 public void setConversation(ConversationHolder conversation) {
220 this.conversation = conversation;
221 }
222
223 public String getDerivateText(Object element){
224 return getDerivateText(element, conversation);
225 }
226
227 public static String getDerivateText(Object element, ConversationHolder conversation){
228 //TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values
229 TreeNode parentNode = null;
230 TreeNode node = null;
231 Object derivate = element;
232 if(element instanceof TreeNode){
233 node = (TreeNode) element;
234 parentNode = node.getParent();
235 //unwrap specimen from TreeNode
236 derivate = node.getValue();
237 }
238
239 if(conversation!=null){
240 conversation.bind();
241 }
242
243 final String emptyString = "";
244 final String separator = " ";
245
246 String label = emptyString;
247
248 //Field Unit
249 if(derivate instanceof FieldUnit){
250 FieldUnit fieldUnit = (FieldUnit)derivate;
251 if(fieldUnit.getGatheringEvent()!=null){
252 GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
253 label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
254 label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
255 label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
256 label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
257 }
258 label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString;
259 }
260 //MediaSpecimen
261 else if(derivate instanceof MediaSpecimen){
262 MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate;
263 if(mediaSpecimen.getMediaSpecimen()!=null){
264 label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]";
265 label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString;
266 }
267 eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection();
268 if(collection!=null){
269 label += collection.getName()!=null?collection.getName()+" ":emptyString;
270 label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
271 }
272 label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString;
273 label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString;
274 }
275 //TissueSample + DnaSample
276 else if(derivate instanceof DnaSample){
277 DnaSample dnaSample = (DnaSample)derivate;
278 if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){
279 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
280 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
281 label += currentSampleDesignation.getIdentifier()+separator;
282 }
283 else{
284 label += NO_SAMPLE_DESIGNATION+separator;
285 }
286 }
287 else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){
288 if(dnaSample.getKindOfUnit()!=null){
289 label += dnaSample.getKindOfUnit()+separator;
290 }
291 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
292 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
293 label += currentSampleDesignation.getIdentifier()+separator;
294 }
295 else{
296 label += NO_SAMPLE_DESIGNATION+separator;
297 }
298 }
299
300 }
301 //DerivedUnit + TissueSample
302 else if(derivate instanceof DerivedUnit){
303 DerivedUnit derivedUnit = (DerivedUnit)derivate;
304 if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
305 //check for type designation
306 if(typeDesignations.get(derivedUnit)==null){
307 for (SpecimenTypeDesignation specimenTypeDesignation : derivedUnit.getSpecimenTypeDesignations()) {
308 addTypeDesignation(derivedUnit, specimenTypeDesignation);
309 }
310 }
311 //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
312 //TODO : This is not generic anymore for performance reasons
313 Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
314 if(originals!=null && originals.size() ==1) {
315 SpecimenOrObservationBase specimen = originals.iterator().next();
316 if(specimen instanceof FieldUnit) {
317 FieldUnit fieldUnit = (FieldUnit)specimen;
318 GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
319 if(gatheringEvent!=null){
320 label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
321 }
322 label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
323 }
324 }
325
326 eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
327 if(collection!=null){
328 label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
329 }
330 String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
331 label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
332 }
333 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
334 //TissueSample should only be created by using it's own class
335 //in future using only one class with different SpecimenOrObservationTypes is desired
336 // label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION;
337 }
338 }
339 //Sequence
340 else if(derivate instanceof Sequence){
341 Sequence sequence = (Sequence)derivate;
342 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
343 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
344 label += currentSampleDesignation.getIdentifier()+separator;
345 }
346 else{
347 label += NO_SAMPLE_DESIGNATION+separator;
348 }
349 label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString;
350 }
351 //SingleRead
352 else if(derivate instanceof SingleRead){
353 SingleRead singleRead = (SingleRead)derivate;
354 if(parentNode!=null && parentNode.getValue() instanceof Sequence){
355 Sequence sequence = (Sequence) parentNode.getValue();
356 Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
357 if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
358 label = currentSampleDesignation.getIdentifier()+separator;
359 }
360 else{
361 label += NO_SAMPLE_DESIGNATION+separator;
362 }
363 label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString;
364 if(sequence!=null && sequence.getDnaMarker()!=null){
365 label += sequence.getDnaMarker()+separator;
366 }
367 if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){
368 label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator;
369 }
370 }
371 }
372 //SOOB
373 else if(derivate instanceof SpecimenOrObservationBase){
374 SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate;
375 SpecimenOrObservationType type = specimen.getRecordBasis();
376 return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString);
377 }
378 if(label.isEmpty()){
379 label = derivate.toString();
380 }
381 //remove last comma
382 else if(label.endsWith(separator)){
383 label = label.substring(0, label.length()-separator.length());
384 }
385 return label;
386 }
387
388 @Override
389 public Image getImage(Object element) {
390 if(element instanceof TreeNode){
391 element = ((TreeNode) element).getValue();
392 }
393 if(element instanceof CdmBase){
394 CdmBase cdmBase = (CdmBase)element;
395 boolean hasCharacterData = false;
396 if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
397 SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
398 if(specimen.hasCharacterData()){
399 hasCharacterData = true;
400 }
401 }
402 if(cdmBase.isInstanceOf(FieldUnit.class)){
403 return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
404 }
405 else if(cdmBase.isInstanceOf(DerivedUnit.class)){
406 DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
407
408 if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
409 return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
410 }
411 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
412 return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
413 }
414 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
415 return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
416 }
417 else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
418 if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){
419 return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE);
420 }
421 return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
422 }
423 else if(derivedUnit.getRecordBasis().isMedia()
424 || derivedUnit.getRecordBasis().isKindOf(SpecimenOrObservationType.Media)){
425 if(derivedUnit.getKindOfUnit()!=null){
426 if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
427 return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
428 }
429 else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
430 return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
431 }
432 else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
433 return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
434 }
435 else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
436 return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
437 }
438 }
439 }
440 }
441 else if(cdmBase.isInstanceOf(Sequence.class)){
442 return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
443 }
444
445 else if(cdmBase.isInstanceOf(SingleRead.class)){
446 if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){
447 return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
448 }
449 else{
450 return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
451 }
452 }
453 }
454 return ImageResources.getImage(ImageResources.DEFAULT_DERIVATIVE);
455 }
456
457 public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) {
458 if(entity.isInstanceOf(DnaSample.class)){
459 DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class);
460 for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) {
461 if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
462 //first sample designation is the current
463 return identifier;
464 }
465 }
466 }
467 else if(entity.isInstanceOf(Sequence.class)){
468 Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class);
469 if(sequence.getDnaSample()!=null){
470 return getCurrentSampleDesignation(sequence.getDnaSample());
471 }
472 }
473 return null;
474 }
475
476 private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
477 Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
478 if(list==null){
479 list = new ArrayList<SpecimenTypeDesignation>();
480 }
481 list.add(typeDesignation);
482 typeDesignations.put(derivedUnit, list);
483 }
484
485 public static Set<SingleRead> getMultiLinkSingleReads() {
486 return multiLinkSingleReads;
487 }
488
489 public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
490 multiLinkSingleReads = new HashSet<SingleRead>();
491 typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
492 for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
493 if(entry.getValue().size()>1){
494 multiLinkSingleReads.add(entry.getKey());
495 }
496 }
497 if(rootElements!=null){
498 Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
499 for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) {
500 List<DerivedUnit> childUnits = CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid());
501 if (childUnits != null){
502 derivedUnits.addAll(childUnits);
503 }
504 if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
505 specimenOrObservationBase = CdmStore.getService(IOccurrenceService.class).load(specimenOrObservationBase.getUuid());
506 if (specimenOrObservationBase != null){
507 derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
508 }
509 }
510 }
511 for (DerivedUnit derivedUnit : derivedUnits) {
512 if(!derivedUnit.getSpecimenTypeDesignations().isEmpty()){
513 typeDesignations.put(derivedUnit, derivedUnit.getSpecimenTypeDesignations());
514 }
515 }
516 }
517 }
518
519 }