Project

General

Profile

« Previous | Next » 

Revision a9527b12

Added by Andreas Kohlbecker over 3 years ago

ref #9252 determinig hasTypes from actual data and fixing type probelms in methods

View differences:

cdmlib-model/src/main/java/eu/etaxonomy/cdm/format/occurrences/MediaSpecimenFormatter.java
8 8
*/
9 9
package eu.etaxonomy.cdm.format.occurrences;
10 10

  
11
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
11 12
import eu.etaxonomy.cdm.model.media.Media;
12 13
import eu.etaxonomy.cdm.model.occurrence.MediaSpecimen;
13 14

  
......
24 25
    @Override
25 26
    protected void initFormatKeys(Object object) {
26 27
        super.initFormatKeys(object);
27
        MediaSpecimen mediaSpecimen = (MediaSpecimen)object;
28
        MediaSpecimen mediaSpecimen = HibernateProxyHelper.deproxy(object, MediaSpecimen.class);
28 29
        Media media = mediaSpecimen.getMediaSpecimen();
29 30
        if(media!=null){
30 31
            if(media.getArtist()!=null){
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/IOccurrenceService.java
689 689
    List<FieldUnitDTO> findFieldUnitDTOByAssociatedTaxon(Set<TaxonRelationshipEdge> includedRelationships,
690 690
            UUID associatedTaxonUuid, List<String> propertyPaths);
691 691

  
692
    FieldUnitDTO findFieldUnitDTO(SpecimenOrObservationBaseDTO derivedUnitDTO, Collection<FieldUnitDTO> fieldUnits,
692
    FieldUnitDTO findFieldUnitDTO(DerivedUnitDTO derivedUnitDTO, Collection<FieldUnitDTO> fieldUnits,
693 693
            HashMap<UUID, SpecimenOrObservationBaseDTO> alreadyCollectedSpecimen);
694 694

  
695 695

  
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/OccurrenceServiceImpl.java
399 399
        return derivedUnitDTO;
400 400
    }
401 401

  
402
    private Set<SpecimenOrObservationBaseDTO> getDerivedUnitDTOsFor(SpecimenOrObservationBaseDTO specimenDto, DerivedUnit specimen, HashMap<UUID, SpecimenOrObservationBaseDTO> alreadyCollectedSpecimen) {
403
        Set<SpecimenOrObservationBaseDTO> derivedUnits = new HashSet<>();
404
//        load
402
    private Set<DerivedUnitDTO> getDerivedUnitDTOsFor(SpecimenOrObservationBaseDTO specimenDto, DerivedUnit specimen, HashMap<UUID, SpecimenOrObservationBaseDTO> alreadyCollectedSpecimen) {
403
        Set<DerivedUnitDTO> derivedUnits = new HashSet<>();
404

  
405 405
        for (DerivationEvent derivationEvent : specimen.getDerivationEvents()) {
406 406
            for (DerivedUnit derivative : derivationEvent.getDerivatives()) {
407 407
                if (!alreadyCollectedSpecimen.containsKey(specimenDto.getUuid())){
......
517 517
            for (SpecimenOrObservationBase<?> o : perTaxonOccurrences) {
518 518
                if (o.isInstanceOf(DerivedUnit.class)){
519 519
                    DerivedUnit derivedUnit;
520
                    SpecimenOrObservationBaseDTO derivedUnitDTO;
520
                    DerivedUnitDTO derivedUnitDTO;
521 521
                    if (o.isInstanceOf(DnaSample.class)) {
522 522
                         derivedUnit = HibernateProxyHelper.deproxy(o, DnaSample.class);
523 523
                        derivedUnitDTO = new DNASampleDTO(derivedUnit);
......
548 548
            List<String> propertyPaths)  {
549 549

  
550 550
        DnaSample dnaSample = dao.findByGeneticAccessionNumber(accessionNumberString, propertyPaths);
551
        SpecimenOrObservationBaseDTO derivedUnitDTO;
551
        DerivedUnitDTO derivedUnitDTO;
552 552
        HashMap<UUID, SpecimenOrObservationBaseDTO> alreadyCollectedSpecimen = new HashMap<>();
553 553
        List<FieldUnitDTO> fieldUnitDTOs = new ArrayList<>();
554 554
        if (dnaSample != null){
......
659 659

  
660 660
    @Override
661 661
    @Transactional(readOnly=true)
662
    public FieldUnitDTO findFieldUnitDTO(SpecimenOrObservationBaseDTO derivedUnitDTO, Collection<FieldUnitDTO> fieldUnits,
662
    public FieldUnitDTO findFieldUnitDTO(DerivedUnitDTO derivedUnitDTO, Collection<FieldUnitDTO> fieldUnits,
663 663
            HashMap<UUID, SpecimenOrObservationBaseDTO> alreadyCollectedSpecimen) {
664 664
        //It will search recursively over all {@link DerivationEvent}s and get the "originals" ({@link SpecimenOrObservationBase})
665 665
        //from which this DerivedUnit was derived until all FieldUnits are found.
......
695 695
                fieldUnitDto.addDerivate(derivedUnitDTO);
696 696
                fieldUnits.add(fieldUnitDto);
697 697
            }else{
698
                SpecimenOrObservationBaseDTO originalDTO;
698
                DerivedUnitDTO originalDTO;
699 699
                if (specimen instanceof DnaSample){
700 700
                    originalDTO = new DNASampleDTO((DnaSample)specimen);
701 701
                } else {
......
721 721
    public FieldUnitDTO loadFieldUnitDTO(UUID derivedUnitUuid) {
722 722

  
723 723
        FieldUnitDTO fieldUnitDTO = null;
724
        SpecimenOrObservationBaseDTO derivedUnitDTO = null;
724
        DerivedUnitDTO derivedUnitDTO = null;
725 725

  
726 726
        Map<UUID, SpecimenOrObservationBaseDTO> cycleDetectionMap = new HashMap<>();
727 727
        SpecimenOrObservationBase derivative = dao.load(derivedUnitUuid);
......
776 776
                        }
777 777
                        break;
778 778
                    }else{
779
                        // So this must be a DerivedUnitDTO
779 780
                        if (derivedUnitDTO == null){
780
                            derivedUnitDTO = originalDTO;
781
                            derivedUnitDTO = (DerivedUnitDTO)originalDTO;
781 782
                        } else {
782 783
                            originalDTO.addDerivate(derivedUnitDTO);
783
                            derivedUnitDTO = originalDTO;
784
                            derivedUnitDTO = (DerivedUnitDTO)originalDTO;
784 785
                        }
785 786
                    }
786 787
                }
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/FieldUnitDTO.java
39 39
	private String date;
40 40
	private String collectionsStatistics;
41 41

  
42
	private boolean hasType;
43

  
44 42
	private GatheringEventDTO gatheringEvent;
45 43

  
46 44
	public static FieldUnitDTO fromEntity(FieldUnit entity){
......
71 69
	 */
72 70
    private FieldUnitDTO(FieldUnit fieldUnit, EnumSet<SpecimenOrObservationType> specimenOrObservationTypeFilter ) {
73 71
        super(fieldUnit);
72

  
73
        if(specimenOrObservationTypeFilter == null) {
74
            specimenOrObservationTypeFilter = EnumSet.allOf(SpecimenOrObservationType.class);
75
        }
74 76
        if (fieldUnit.getGatheringEvent() != null){
75 77
            gatheringEvent = GatheringEventDTO.newInstance(fieldUnit.getGatheringEvent());
76 78
        }
......
235 237
    }
236 238

  
237 239
    public boolean isHasType() {
240
        boolean hasType = collectDerivatives()
241
                .stream()
242
                .anyMatch(derivedUnitDTO -> derivedUnitDTO.getSpecimenTypeDesignations() != null && !derivedUnitDTO.getSpecimenTypeDesignations().isEmpty());
238 243
        return hasType;
239 244
    }
240
    public void setHasType(boolean hasType) {
241
        this.hasType = hasType;
242
    }
243 245

  
244 246
    public GatheringEventDTO getGatheringEvent() {
245 247
        return gatheringEvent;
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/SpecimenOrObservationBaseDTO.java
11 11
import java.io.Serializable;
12 12
import java.util.AbstractMap;
13 13
import java.util.ArrayList;
14
import java.util.Collection;
14 15
import java.util.Comparator;
15 16
import java.util.HashSet;
16 17
import java.util.List;
......
58 59
    private String collectorsNumber;
59 60
    private String barcode;
60 61
    private String preservationMethod;
61
    private Set<SpecimenOrObservationBaseDTO> derivates;
62
    private Set<DerivedUnitDTO> derivates;
62 63

  
63 64
    private Set<SpecimenTypeDesignationDTO> specimenTypeDesignations;
64 65

  
......
79 80
                setSpecimenTypeDesignations(derivedUnit.getSpecimenTypeDesignations());
80 81
            }
81 82
        }
82

  
83

  
84 83
    }
85
//    @Override
86
//    public String getTitleCache() {
87
//        return getLabel();
88
//    }
89 84

  
90 85

  
91 86
    public String getListLabel() {
......
312 307

  
313 308

  
314 309

  
315
    public Set<SpecimenOrObservationBaseDTO> getDerivates() {
310
    public Set<DerivedUnitDTO> getDerivates() {
311
        if (this.derivates == null){
312
            this.derivates = new HashSet<>();
313
        }
316 314
        return derivates;
317 315
    }
318 316

  
319
    public void setDerivates(Set<SpecimenOrObservationBaseDTO> derivates) {
317
    public void setDerivates(Set<DerivedUnitDTO> derivates) {
320 318
        this.derivates = derivates;
321 319
    }
322 320

  
323
    public void addDerivate(SpecimenOrObservationBaseDTO derivate){
321
    public void addDerivate(DerivedUnitDTO derivate){
324 322
        if (this.derivates == null){
325 323
            this.derivates = new HashSet<>();
326 324
        }
327 325
        this.derivates.add(derivate);
328 326
    }
329
    public void addAllDerivates(Set<SpecimenOrObservationBaseDTO> derivates){
327
    public void addAllDerivates(Set<DerivedUnitDTO> derivates){
330 328
        if (this.derivates == null){
331 329
            this.derivates = new HashSet<>();
332 330
        }
333 331
        this.derivates.addAll(derivates);
334 332
    }
335 333

  
334
    /**
335
     * collects all derivatives from this an derivatives of this.
336
     */
337
    public Collection<DerivedUnitDTO> collectDerivatives() {
338
        return collectDerivatives(new HashSet<>());
339
    }
340

  
341
    /**
342
     * private partner method to {@link #collectDerivatives()} for recursive calls.
343
     *
344
     * @param dtos
345
     */
346
    private Collection<DerivedUnitDTO> collectDerivatives(Set<DerivedUnitDTO> dtos) {
347
        dtos.addAll(getDerivates());
348
        if(derivates != null) {
349
            for(SpecimenOrObservationBaseDTO subDto : derivates) {
350
                dtos.addAll(subDto.collectDerivatives(dtos));
351
            }
352
        }
353
        return dtos;
354
    }
355

  
336 356
    public DerivationEventDTO getDerivationEvent() {
337 357
        return derivationEvent;
338 358
    }

Also available in: Unified diff