Project

General

Profile

« Previous | Next » 

Revision 9c9b6874

Added by Andreas Kohlbecker over 3 years ago

ref #9252 adding MediaSpecimen.media to DerivedUnitDTO.listOfMedia

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/DerivedUnitDTO.java
30 30
import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
31 31
import eu.etaxonomy.cdm.model.description.QuantitativeData;
32 32
import eu.etaxonomy.cdm.model.description.TaxonDescription;
33
import eu.etaxonomy.cdm.model.media.Media;
33 34
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
34 35
import eu.etaxonomy.cdm.model.name.TaxonName;
35 36
import eu.etaxonomy.cdm.model.name.TypeDesignationStatusBase;
......
37 38
import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
38 39
import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
39 40
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
41
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
42
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
40 43
import eu.etaxonomy.cdm.model.taxon.Taxon;
41 44
import eu.etaxonomy.cdm.ref.TypedEntityReference;
42 45

  
......
224 227

  
225 228
    }
226 229

  
230
    @Override
231
    protected Set<Media> collectMedia(SpecimenOrObservationBase<?> specimenOrObservation){
232
        Set<Media> collectedMedia = super.collectMedia(specimenOrObservation);
233
        if(specimenOrObservation instanceof MediaSpecimen) {
234
            if(((MediaSpecimen)specimenOrObservation).getMediaSpecimen() != null) {
235
            collectedMedia.add(((MediaSpecimen)specimenOrObservation).getMediaSpecimen());
236
            }
237
        }
238
        return collectedMedia;
239
    }
227 240

  
228 241

  
229 242
    public String getAccessionNumber() {
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/SpecimenOrObservationBaseDTO.java
75 75
    protected SpecimenOrObservationBaseDTO(SpecimenOrObservationBase<?> specimenOrObservation) {
76 76
        super((Class<SpecimenOrObservationBase<?>>) specimenOrObservation.getClass(), specimenOrObservation.getUuid(), specimenOrObservation.getTitleCache());
77 77
        this.id = specimenOrObservation.getId();
78
        addMedia(specimenOrObservation);
78
        Set<Media> collectedMedia = collectMedia(specimenOrObservation);
79
        addMediaAsDTO(collectedMedia);
79 80
        setKindOfUnit(specimenOrObservation.getKindOfUnit());
80 81
        setSex(specimenOrObservation.getSex());
81 82
        lifeStage = specimenOrObservation.getLifeStage();
......
381 382
        this.listOfMedia = listOfMedia;
382 383
    }
383 384

  
384
    public void addMedia(SpecimenOrObservationBase specimenOrObservation){
385
        Set<DescriptionBase> descriptions = specimenOrObservation.getSpecimenDescriptionImageGallery();
386
        for (DescriptionBase desc : descriptions){
385

  
386
    protected Set<Media> collectMedia(SpecimenOrObservationBase<?> specimenOrObservation){
387
        Set<Media> collectedMedia = new HashSet<>();
388
        Set<SpecimenDescription> descriptions = specimenOrObservation.getSpecimenDescriptionImageGallery();
389
        for (DescriptionBase<?> desc : descriptions){
387 390
            if (desc instanceof SpecimenDescription){
388 391
                SpecimenDescription specimenDesc = (SpecimenDescription)desc;
389 392
                for (DescriptionElementBase element : specimenDesc.getElements()){
390 393
                    if (element.isInstanceOf(TextData.class)&& element.getFeature().equals(Feature.IMAGE())) {
391 394
                        for (Media media :element.getMedia()){
392
                            media.getAllTitles(); // initialize all titles!!!
393
                            for (MediaRepresentation rep :media.getRepresentations()){
394
                                for(MediaRepresentationPart p : rep.getParts()){
395
                                    if(p.getUri() != null){
396
                                        MediaDTO dto = new MediaDTO(media.getUuid());
397
                                        dto.setUri(p.getUri().toString());
398
                                        this.getListOfMedia().add(dto);
399
                                    }
400
                                }
401
                            }
395
                            collectedMedia.add(media);
402 396
                        }
403 397
                    }
404 398
                }
405 399
            }
406 400
        }
401
        return collectedMedia;
402
    }
403

  
404
    private void addMediaAsDTO(Set<Media> media) {
405
        for(Media m : media) {
406
            m.getAllTitles(); // initialize all titles!!!
407
            for (MediaRepresentation rep :m.getRepresentations()){
408
                for(MediaRepresentationPart p : rep.getParts()){
409
                    if(p.getUri() != null){
410
                        MediaDTO dto = new MediaDTO(m.getUuid());
411
                        dto.setUri(p.getUri().toString());
412
                        getListOfMedia().add(dto);
413
                    }
414
                }
415
            }
416
        }
407 417
    }
418

  
408 419
    public TermBase getKindOfUnit() {
409 420
        return kindOfUnit;
410 421
    }

Also available in: Unified diff