Project

General

Profile

« Previous | Next » 

Revision 06b2c5f6

Added by Andreas Kohlbecker over 3 years ago

ref #9252 ref #9257 exposing SpecimenOrObservationType filter to factory method and better flag handling

View differences:

cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/service/dto/FieldUnitDTO.java
9 9
package eu.etaxonomy.cdm.api.service.dto;
10 10

  
11 11
import java.util.ArrayList;
12
import java.util.EnumSet;
12 13
import java.util.HashMap;
13 14
import java.util.List;
14 15
import java.util.Map;
......
43 44
	private GatheringEventDTO gatheringEvent;
44 45

  
45 46
	public static FieldUnitDTO fromEntity(FieldUnit entity){
47
        return FieldUnitDTO.fromEntity(entity, null);
48
	}
49

  
50
	/**
51
     * Factory method for the construction of a FieldUnitDTO.
52
     *
53
     *
54
     * @param fieldUnit
55
     *     The FieldUnit entity to create a DTO for. Is null save.
56
     * @param specimenOrObservationTypeFilter
57
     *     Set of SpecimenOrObservationType to be included into the collection of {@link #getDerivates() derivative DTOs}
58
     */
59
	public static FieldUnitDTO fromEntity(FieldUnit entity, EnumSet<SpecimenOrObservationType> specimenOrObservationTypeFilter){
46 60
        if(entity == null) {
47 61
            return null;
48 62
        }
49
        return new FieldUnitDTO(entity);
50
	}
63
        return new FieldUnitDTO(entity, specimenOrObservationTypeFilter);
64
    }
51 65

  
52
    private FieldUnitDTO(FieldUnit fieldUnit) {
66
	/**
67
	 * @param fieldUnit
68
	 *     The FieldUnit entity to create a DTO for
69
	 * @param specimenOrObservationTypeFilter
70
	 *     Set of SpecimenOrObservationType to be included into the collection of {@link #getDerivates() derivative DTOs}
71
	 */
72
    private FieldUnitDTO(FieldUnit fieldUnit, EnumSet<SpecimenOrObservationType> specimenOrObservationTypeFilter ) {
53 73
        super(fieldUnit);
54 74
        if (fieldUnit.getGatheringEvent() != null){
55 75
            gatheringEvent = GatheringEventDTO.newInstance(fieldUnit.getGatheringEvent());
......
121 141
                    }
122 142
                    collectionToCountMap.put(collection, herbariumCount + 1);
123 143
                }
124
                if (derivedUnit.getRecordBasis().equals(SpecimenOrObservationType.PreservedSpecimen)) {
125
                    DerivedUnitDTO preservedSpecimenDTO = DerivedUnitDTO.fromEntity(derivedUnit, null);
126
                    addDerivate(preservedSpecimenDTO);
127
                    setHasCharacterData(isHasCharacterData() || preservedSpecimenDTO.isHasCharacterData());
128
                    setHasDetailImage(isHasDetailImage() || preservedSpecimenDTO.isHasDetailImage());
129
                    setHasDna(isHasDna() || preservedSpecimenDTO.isHasDna());
130
                    setHasSpecimenScan(isHasSpecimenScan() || preservedSpecimenDTO.isHasSpecimenScan());
144
                if (specimenOrObservationTypeFilter.contains(derivedUnit.getRecordBasis())) {
145
                    DerivedUnitDTO derivedUnitDTO = DerivedUnitDTO.fromEntity(derivedUnit, null);
146
                    addDerivate(derivedUnitDTO);
147
                    setHasCharacterData(isHasCharacterData() || derivedUnitDTO.isHasCharacterData());
148
                    // NOTE! the flags setHasDetailImage, setHasDna, setHasSpecimenScan are also set in
149
                    // setDerivateDataDTO(), see below
150
                    setHasDetailImage(isHasDetailImage() || derivedUnitDTO.isHasDetailImage());
151
                    setHasDna(isHasDna() || derivedUnitDTO.isHasDna());
152
                    setHasSpecimenScan(isHasSpecimenScan() || derivedUnitDTO.isHasSpecimenScan());
131 153
                }
132 154
            }
133 155
        }
156

  
134 157
        // assemble derivate data DTO
135 158
        DerivateDataDTO derivateDataDTO = DerivateDataDTO.fromEntity(fieldUnit, null);
136 159
        setDerivateDataDTO(derivateDataDTO);

Also available in: Unified diff