Project

General

Profile

Download (25.1 KB) Statistics
| Branch: | Tag: | Revision:
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
        if(element instanceof IdentifiableEntity
142
                && ((IdentifiableEntity) element).isProtectedTitleCache()){
143
            return ((IdentifiableEntity) element).getTitleCache();
144
        }
145

    
146

    
147
        //check if collection code does not exist -> use collection name then
148
        FormatKey collectionKey = FormatKey.COLLECTION_CODE;
149
        text = CdmFormatterFactory.format(element,new FormatKey[]{FormatKey.COLLECTION_CODE});
150
        if(CdmUtils.isBlank(text)){
151
            collectionKey = FormatKey.COLLECTION_NAME;
152
        }
153

    
154
        //Use titlecache for FieldUnits
155
        if(element instanceof FieldUnit){
156
            text = ((FieldUnit) element).getTitleCache();
157
        }
158
        else if(element instanceof MediaSpecimen){
159
            text = CdmFormatterFactory.format(element,
160
                    new FormatKey[]{
161
//                            FormatKey.MEDIA_TITLE_CACHE, FormatKey.SPACE,
162
                            collectionKey, FormatKey.SPACE,
163
                            FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
164
                            FormatKey.MEDIA_TITLE, FormatKey.SPACE,
165
                            FormatKey.MEDIA_ARTIST, FormatKey.SPACE,
166
                            });
167
        }
168
        else if (element instanceof DnaSample) {
169
            text = CdmFormatterFactory.format(element,
170
                    new FormatKey[] {
171
                            collectionKey, FormatKey.SPACE,
172
                            FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE,
173
                            FormatKey.SAMPLE_DESIGNATION, FormatKey.SPACE
174
                            });
175
        }
176
        else if (element instanceof DerivedUnit) {
177
            text = CdmFormatterFactory.format(element,
178
                    new FormatKey[] {
179
                            collectionKey, FormatKey.SPACE,
180
                            FormatKey.MOST_SIGNIFICANT_IDENTIFIER, FormatKey.SPACE
181
                            });
182
        }
183
        else if (element instanceof Sequence) {
184
            text = CdmFormatterFactory.format(element,
185
                    new FormatKey[] {
186
                            FormatKey.SEQUENCE_DNA_MARKER, FormatKey.SPACE
187
                            });
188
        }
189
        else if (element instanceof SingleRead) {
190
            text = CdmFormatterFactory.format(element,
191
                    new FormatKey[] {
192
                            FormatKey.SINGLE_READ_PHEROGRAM_TITLE_CACHE, FormatKey.SPACE,
193
                            FormatKey.AMPLIFICATION_LABEL, FormatKey.SPACE,
194
            });
195
        }
196
        else if(element instanceof IdentifiableEntity){
197

    
198
        	IdentifiableEntity identifiableEntity = (IdentifiableEntity) element;
199
        	if(identifiableEntity.isProtectedTitleCache()){
200
        		text = identifiableEntity.getTitleCache();
201
        	}
202
        }
203
        if(CdmUtils.isBlank(text) || text.equals(IdentifiableEntityDefaultCacheStrategy.TITLE_CACHE_GENERATION_NOT_IMPLEMENTED)){
204
            if(element instanceof CdmBase){
205
                text = ((CdmBase) element).getUuid().toString();
206
            }
207
            else{
208
                text = element.toString();
209
            }
210
        }
211
        //remove dot at the end
212
        if(text.endsWith(".")){
213
            text = text.substring(0, text.length()-1);
214
        }
215
		return text;
216
    }
217

    
218
    /** {@inheritDoc} */
219
    @Override
220
    public String getToolTipText(Object element) {
221
        return getDerivateText(element);
222
    }
223

    
224
    /**
225
     * @param conversation the conversation to set
226
     */
227
    public void setConversation(ConversationHolder conversation) {
228
        this.conversation = conversation;
229
    }
230

    
231
    public String getDerivateText(Object element){
232
        return getDerivateText(element, conversation);
233
    }
234

    
235
    public static String getDerivateText(Object element, ConversationHolder conversation){
236
        //TODO: use list of strings to assemble labels to avoid adding the separator every time and to allow null values
237
        TreeNode parentNode = null;
238
        TreeNode node = null;
239
        Object derivate = element;
240
        if(element instanceof TreeNode){
241
            node = (TreeNode) element;
242
            parentNode = node.getParent();
243
            //unwrap specimen from TreeNode
244
            derivate = node.getValue();
245
        }
246

    
247
        if(conversation!=null){
248
            conversation.bind();
249
        }
250

    
251
        final String emptyString = "";
252
        final String separator = " ";
253

    
254
        String label = emptyString;
255

    
256
        //Field Unit
257
        if(derivate instanceof FieldUnit){
258
            FieldUnit fieldUnit = (FieldUnit)derivate;
259
            if(fieldUnit.getGatheringEvent()!=null){
260
                GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
261
                label += gatheringEvent.getCountry()!=null?gatheringEvent.getCountry().getLabel()+separator:emptyString;
262
                label += gatheringEvent.getLocality()!=null?gatheringEvent.getLocality().getText()+separator:emptyString;
263
                label += gatheringEvent.getGatheringDate()!=null?gatheringEvent.getGatheringDate()+separator:emptyString;
264
                label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
265
            }
266
            label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber():emptyString;
267
        }
268
        //MediaSpecimen
269
        else if(derivate instanceof MediaSpecimen){
270
            MediaSpecimen mediaSpecimen = (MediaSpecimen)derivate;
271
            if(mediaSpecimen.getMediaSpecimen()!=null){
272
                label += mediaSpecimen.getMediaSpecimen().getTitle()!=null?mediaSpecimen.getMediaSpecimen().getTitle().getText()+separator:"[no motif]";
273
                label += mediaSpecimen.getMediaSpecimen().getArtist()!=null?mediaSpecimen.getMediaSpecimen().getArtist()+separator:emptyString;
274
            }
275
            eu.etaxonomy.cdm.model.occurrence.Collection collection = mediaSpecimen.getCollection();
276
            if(collection!=null){
277
                label += collection.getName()!=null?collection.getName()+" ":emptyString;
278
                label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
279
            }
280
            label += mediaSpecimen.getAccessionNumber()!=null?mediaSpecimen.getAccessionNumber()+separator:emptyString;
281
            label += mediaSpecimen.getBarcode()!=null?mediaSpecimen.getBarcode()+separator:emptyString;
282
        }
283
        //TissueSample + DnaSample
284
        else if(derivate instanceof DnaSample){
285
            DnaSample dnaSample = (DnaSample)derivate;
286
            if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.DnaSample){
287
                Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
288
                if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
289
                    label += currentSampleDesignation.getIdentifier()+separator;
290
                }
291
                else{
292
                    label += NO_SAMPLE_DESIGNATION+separator;
293
                }
294
            }
295
            else if(((DnaSample) derivate).getRecordBasis()==SpecimenOrObservationType.TissueSample){
296
                if(dnaSample.getKindOfUnit()!=null){
297
                    label += dnaSample.getKindOfUnit()+separator;
298
                }
299
                Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(dnaSample);
300
                if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
301
                    label += currentSampleDesignation.getIdentifier()+separator;
302
                }
303
                else{
304
                    label += NO_SAMPLE_DESIGNATION+separator;
305
                }
306
            }
307

    
308
        }
309
        //DerivedUnit + TissueSample
310
        else if(derivate instanceof DerivedUnit){
311
            DerivedUnit derivedUnit = (DerivedUnit)derivate;
312
            if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
313
                //check for type designation
314
                if(typeDesignations.get(derivedUnit)==null){
315
                    for (SpecimenTypeDesignation specimenTypeDesignation : derivedUnit.getSpecimenTypeDesignations()) {
316
                        addTypeDesignation(derivedUnit, specimenTypeDesignation);
317
                    }
318
                }
319
                //java.util.Collection<FieldUnit> fieldUnits = CdmStore.getService(IOccurrenceService.class).getFieldUnits(derivedUnit.getUuid());
320
                //TODO : This is not generic anymore for performance reasons
321
                Set<SpecimenOrObservationBase> originals = derivedUnit.getOriginals();
322
                if(originals!=null && originals.size() ==1) {
323
                    SpecimenOrObservationBase specimen = originals.iterator().next();
324
                    if(specimen instanceof FieldUnit) {
325
                        FieldUnit fieldUnit = (FieldUnit)specimen;
326
                        GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
327
                        if(gatheringEvent!=null){
328
                            label += gatheringEvent.getCollector()!=null?gatheringEvent.getCollector()+separator:emptyString;
329
                        }
330
                        label += fieldUnit.getFieldNumber()!=null?fieldUnit.getFieldNumber()+separator:emptyString;
331
                    }
332
                }
333

    
334
                eu.etaxonomy.cdm.model.occurrence.Collection collection = derivedUnit.getCollection();
335
                if(collection!=null){
336
                    label += collection.getCode()!=null?"("+collection.getCode()+")"+separator:emptyString;
337
                }
338
                String mostSignificantIdentifier = derivedUnit.getMostSignificantIdentifier();
339
                label += mostSignificantIdentifier!=null?mostSignificantIdentifier+separator:emptyString;
340
            }
341
            else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
342
                //TissueSample should only be created by using it's own class
343
                //in future using only one class with different SpecimenOrObservationTypes is desired
344
//                label += derivedUnit.getKindOfUnit() + NO_SAMPLE_DESIGNATION;
345
            }
346
        }
347
        //Sequence
348
        else if(derivate instanceof Sequence){
349
            Sequence sequence = (Sequence)derivate;
350
            Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
351
            if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
352
                label += currentSampleDesignation.getIdentifier()+separator;
353
            }
354
            else{
355
                label += NO_SAMPLE_DESIGNATION+separator;
356
            }
357
            label += sequence.getDnaMarker()!=null?sequence.getDnaMarker():emptyString;
358
        }
359
        //SingleRead
360
        else if(derivate instanceof SingleRead){
361
            SingleRead singleRead = (SingleRead)derivate;
362
            if(parentNode!=null && parentNode.getValue() instanceof Sequence){
363
                Sequence sequence = (Sequence) parentNode.getValue();
364
                Identifier<DnaSample> currentSampleDesignation = getCurrentSampleDesignation(sequence);
365
                if(currentSampleDesignation!=null && currentSampleDesignation.getIdentifier()!=null){
366
                    label = currentSampleDesignation.getIdentifier()+separator;
367
                }
368
                else{
369
                    label += NO_SAMPLE_DESIGNATION+separator;
370
                }
371
                label += singleRead.getPrimer()!=null?singleRead.getPrimer().getLabel()+separator:emptyString;
372
                if(sequence!=null && sequence.getDnaMarker()!=null){
373
                    label += sequence.getDnaMarker()+separator;
374
                }
375
                if(singleRead.getAmplificationResult()!=null && singleRead.getAmplificationResult().getAmplification()!=null){
376
                    label += singleRead.getAmplificationResult().getAmplification().getLabelCache()+separator;
377
                }
378
            }
379
        }
380
        //SOOB
381
        else if(derivate instanceof SpecimenOrObservationBase){
382
            SpecimenOrObservationBase<?> specimen = (SpecimenOrObservationBase<?>) derivate;
383
            SpecimenOrObservationType type = specimen.getRecordBasis();
384
            return specimen.getTitleCache() + (type!=null?" ["+type.toString()+"]":emptyString);
385
        }
386
        if(label.isEmpty()){
387
            label = derivate.toString();
388
        }
389
        //remove last comma
390
        else if(label.endsWith(separator)){
391
            label = label.substring(0, label.length()-separator.length());
392
        }
393
        return label;
394
    }
395

    
396
    @Override
397
    public Image getImage(Object element) {
398
        if(element instanceof TreeNode){
399
            element = ((TreeNode) element).getValue();
400
        }
401
        if(element instanceof CdmBase){
402
            CdmBase cdmBase = (CdmBase)element;
403
            boolean hasCharacterData = false;
404
            if(cdmBase.isInstanceOf(SpecimenOrObservationBase.class)){
405
                SpecimenOrObservationBase<?> specimen = HibernateProxyHelper.deproxy(cdmBase, SpecimenOrObservationBase.class);
406
                if(specimen.hasCharacterData()){
407
                    hasCharacterData = true;
408
                }
409
            }
410
            if(cdmBase.isInstanceOf(FieldUnit.class)){
411
                return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
412
            }
413
            else if(cdmBase.isInstanceOf(DerivedUnit.class)){
414
                DerivedUnit derivedUnit = HibernateProxyHelper.deproxy(element, DerivedUnit.class);
415

    
416
                if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.FieldUnit){
417
                    return hasCharacterData?ImageResources.getImage(ImageResources.FIELD_UNIT_CHARACTER_DATA):ImageResources.getImage(ImageResources.FIELD_UNIT);
418
                }
419
                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.DnaSample){
420
                    return hasCharacterData?ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DNA_SAMPLE_DERIVATE);
421
                }
422
                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.TissueSample){
423
                    return hasCharacterData?ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.TISSUE_SAMPLE_DERIVATE);
424
                }
425
                else if(derivedUnit.getRecordBasis()==SpecimenOrObservationType.PreservedSpecimen){
426
                    if(typeDesignations.get(derivedUnit)!=null && !typeDesignations.get(derivedUnit).isEmpty()){
427
                        return ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_TYPE);
428
                    }
429
                    return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_DERIVATE);
430
                }
431
                else if(derivedUnit.getRecordBasis().isMedia()
432
                        || derivedUnit.getRecordBasis().isKindOf(SpecimenOrObservationType.Media)){
433
                    if(derivedUnit.getKindOfUnit()!=null){
434
                        if(derivedUnit.getKindOfUnit().equals(getArtworkTerm())){
435
                            return hasCharacterData?ImageResources.getImage(ImageResources.ARTWORK_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.ARTWORK_DERIVATE);
436
                        }
437
                        else if(derivedUnit.getKindOfUnit().equals(getLivingPlantPhotoTerm())){
438
                            return hasCharacterData?ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.LIVING_PLANT_PHOTO_DERIVATE);
439
                        }
440
                        else if(derivedUnit.getKindOfUnit().equals(getSpecimenScanTerm())){
441
                            return hasCharacterData?ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.SPECIMEN_SCAN_DERIVATE);
442
                        }
443
                        else if(derivedUnit.getKindOfUnit().equals(getDetailImageTerm())){
444
                            return hasCharacterData?ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE_CHARACTER_DATA):ImageResources.getImage(ImageResources.DETAIL_IMAGE_DERIVATE);
445
                        }
446
                    }
447
                }
448
            }
449
            else if(cdmBase.isInstanceOf(Sequence.class)){
450
                return ImageResources.getImage(ImageResources.SEQUENCE_DERIVATE);
451
            }
452

    
453
            else if(cdmBase.isInstanceOf(SingleRead.class)){
454
                if(multiLinkSingleReads!=null && multiLinkSingleReads.contains(element)){
455
                    return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE_MULTILINK);
456
                }
457
                else{
458
                    return ImageResources.getImage(ImageResources.SINGLE_READ_DERIVATE);
459
                }
460
            }
461
        }
462
        return ImageResources.getImage(ImageResources.DEFAULT_DERIVATIVE);
463
    }
464

    
465
    public static Identifier<DnaSample> getCurrentSampleDesignation(CdmBase entity) {
466
        if(entity.isInstanceOf(DnaSample.class)){
467
            DnaSample dnaSample = HibernateProxyHelper.deproxy(entity, DnaSample.class);
468
            for (Identifier<DnaSample> identifier : dnaSample.getIdentifiers()) {
469
                if(identifier.getType()!=null && identifier.getType().equals(DerivateLabelProvider.getSampleDesignationTerm())){
470
                    //first sample designation is the current
471
                    return identifier;
472
                }
473
            }
474
        }
475
        else if(entity.isInstanceOf(Sequence.class)){
476
            Sequence sequence = HibernateProxyHelper.deproxy(entity, Sequence.class);
477
            if(sequence.getDnaSample()!=null){
478
                return getCurrentSampleDesignation(sequence.getDnaSample());
479
            }
480
        }
481
        return null;
482
    }
483

    
484
    private static void addTypeDesignation(DerivedUnit derivedUnit, SpecimenTypeDesignation typeDesignation){
485
        Collection<SpecimenTypeDesignation> list = typeDesignations.get(derivedUnit);
486
        if(list==null){
487
            list = new ArrayList<SpecimenTypeDesignation>();
488
        }
489
        list.add(typeDesignation);
490
        typeDesignations.put(derivedUnit, list);
491
    }
492

    
493
    public static Set<SingleRead> getMultiLinkSingleReads() {
494
        return multiLinkSingleReads;
495
    }
496

    
497
    public void updateLabelCache(Collection<SpecimenOrObservationBase<?>> rootElements) {
498
        multiLinkSingleReads = new HashSet<SingleRead>();
499
        typeDesignations = new HashMap<DerivedUnit, Collection<SpecimenTypeDesignation>>();
500
        for(Entry<SingleRead, Collection<Sequence>> entry:CdmStore.getService(ISequenceService.class).getSingleReadSequencesMap().entrySet()){
501
            if(entry.getValue().size()>1){
502
                multiLinkSingleReads.add(entry.getKey());
503
            }
504
        }
505
        if(rootElements!=null){
506
            Collection<DerivedUnit> derivedUnits = new ArrayList<DerivedUnit>();
507
            for (SpecimenOrObservationBase specimenOrObservationBase : rootElements) {
508
                List<DerivedUnit> childUnits = CdmStore.getService(IOccurrenceService.class).getAllChildDerivatives(specimenOrObservationBase.getUuid());
509
                if (childUnits != null){
510
                    derivedUnits.addAll(childUnits);
511
                }
512
                if(specimenOrObservationBase.isInstanceOf(DerivedUnit.class)){
513
                    specimenOrObservationBase = CdmStore.getService(IOccurrenceService.class).load(specimenOrObservationBase.getUuid());
514
                    if (specimenOrObservationBase != null){
515
                        derivedUnits.add(HibernateProxyHelper.deproxy(specimenOrObservationBase, DerivedUnit.class));
516
                    }
517
                }
518
            }
519
            for (DerivedUnit derivedUnit : derivedUnits) {
520
                if(!derivedUnit.getSpecimenTypeDesignations().isEmpty()){
521
                    typeDesignations.put(derivedUnit, derivedUnit.getSpecimenTypeDesignations());
522
                }
523
            }
524
        }
525
    }
526

    
527
}
(2-2/2)