Project

General

Profile

Download (10.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.cdm.vaadin.model.registration;
10

    
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15

    
16
import org.joda.time.Partial;
17

    
18
import eu.etaxonomy.cdm.model.agent.AgentBase;
19
import eu.etaxonomy.cdm.model.common.Language;
20
import eu.etaxonomy.cdm.model.common.LanguageString;
21
import eu.etaxonomy.cdm.model.common.VersionableEntity;
22
import eu.etaxonomy.cdm.model.location.NamedArea;
23
import eu.etaxonomy.cdm.model.location.Point;
24
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
25
import eu.etaxonomy.cdm.model.name.TaxonName;
26
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
27
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
28
import eu.etaxonomy.cdm.model.reference.Reference;
29

    
30
/**
31
 * @author a.kohlbecker
32
 * @since Jun 16, 2017
33
 *
34
 */
35
public class SpecimenTypeDesignationWorkingSetDTO<OWNER extends VersionableEntity> {
36

    
37
    FieldUnit fieldUnit;
38

    
39
    VersionableEntity baseEntity;
40

    
41
    /**
42
     * List of all SpecimenTypeDesignation that have been loaded into the
43
     * DTO. By comparing this list with <code>specimenTypeDesignations</code>
44
     * it is possible to find those that have been deleted.
45
     */
46
    List<SpecimenTypeDesignation> specimenTypeDesignationsLoaded = new ArrayList<>();
47

    
48
    List<SpecimenTypeDesignationDTO> specimenTypeDesignationsDTOs = new ArrayList<>();
49

    
50
    OWNER owner;
51

    
52
    private Reference citation;
53

    
54
    private TaxonName typifiedName;
55

    
56
    /**
57
     *
58
     * @param owner
59
     * @param baseEntity
60
     * @param specimenTypeDesignations can be <code>null</code>
61
     */
62
    public SpecimenTypeDesignationWorkingSetDTO(OWNER owner, VersionableEntity baseEntity, List<SpecimenTypeDesignation> specimenTypeDesignations, Reference citation, TaxonName typifiedName) {
63
        super();
64
        this.owner = owner;
65
        this.baseEntity = baseEntity;
66
        if(citation == null){
67
            throw new NullPointerException("citation must not be null");
68
        }
69
        if(typifiedName == null){
70
            throw new NullPointerException("typifiedName must not be null");
71
        }
72
        this.citation = citation;
73
        this.typifiedName = typifiedName;
74
        if(baseEntity instanceof FieldUnit){
75
            this.fieldUnit = (FieldUnit) baseEntity;
76
            if(fieldUnit.getGatheringEvent() == null){
77
                fieldUnit.setGatheringEvent(GatheringEvent.NewInstance());
78
            }
79
        }
80
        if(specimenTypeDesignations != null){
81
            specimenTypeDesignationsLoaded = specimenTypeDesignations;
82
            specimenTypeDesignations.forEach(std -> specimenTypeDesignationsDTOs.add(new SpecimenTypeDesignationDTO(std)));
83
        }
84
    }
85

    
86
    /**
87
     * @param reg
88
     * @param newfieldUnit
89
     * @param citationEntityID
90
     * @param typifiedNameEntityID
91
     */
92
    public SpecimenTypeDesignationWorkingSetDTO(OWNER reg, FieldUnit newfieldUnit, Reference citation, TaxonName typifiedName) {
93
        this(reg, newfieldUnit, null, citation, typifiedName);
94
    }
95

    
96
    /**
97
     * @return the fieldUnit
98
     *      <code>null</code> if the base baseEntity is a not a fieldUnit
99
     */
100
    public FieldUnit getFieldUnit() {
101
        return fieldUnit;
102
    }
103

    
104

    
105
    /**
106
     *
107
     * @return the baseEntity
108
     *   <code>null</code> if the base baseEntity is a fieldUnit
109
     */
110
    public VersionableEntity getBaseEntity() {
111
        return baseEntity;
112
    }
113

    
114
    /**
115
     * @return the typeDesignation entities managed in this workingset
116
     */
117
    protected List<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
118
        List<SpecimenTypeDesignation> specimenTypeDesignations = new ArrayList(specimenTypeDesignationsDTOs.size());
119
        for(SpecimenTypeDesignationDTO dto : specimenTypeDesignationsDTOs){
120
            specimenTypeDesignations.add(dto.asSpecimenTypeDesignation());
121
        }
122
        return specimenTypeDesignations;
123
    }
124

    
125
    public List<SpecimenTypeDesignationDTO> getSpecimenTypeDesignationDTOs(){
126
        return specimenTypeDesignationsDTOs;
127
    }
128

    
129
    /**
130
     * The {@link VersionableEntity} which contains the DerivedUnit in this working set.
131
     * This can be for example a {@link Registration} entity
132
     *
133
     * @return
134
     */
135
    public OWNER getOwner() {
136
        return owner;
137
    }
138

    
139
    // ====== FieldUnit Wrapper methods ====== //
140

    
141

    
142
    public String getFieldNumber() {
143
        return fieldUnit.getFieldNumber();
144
    }
145

    
146
    public void setFieldNumber(String fieldNumber) {
147
        this.fieldUnit.setFieldNumber(fieldNumber);
148
    }
149

    
150
    public String getFieldNotes() {
151
        return fieldUnit.getFieldNotes();
152
    }
153

    
154
    // ====== GateringEvent Wrapper methods ====== //
155

    
156
    public String getLocality(){
157
        if(fieldUnit.getGatheringEvent().getLocality() != null){
158
            return fieldUnit.getGatheringEvent().getLocality().getText();
159
        }
160
        return null;
161
    }
162

    
163
    public void setLocality(String locality){
164
        fieldUnit.getGatheringEvent().setLocality(
165
                LanguageString.NewInstance(locality, Language.DEFAULT())
166
                );
167
    }
168
    public NamedArea getCountry() {
169
        return fieldUnit.getGatheringEvent().getCountry();
170
    }
171

    
172
    public void setCountry(NamedArea country) {
173
        fieldUnit.getGatheringEvent().setCountry(country);
174
    }
175

    
176
    public Point getExactLocation() {
177
        return fieldUnit.getGatheringEvent().getExactLocation();
178
    }
179

    
180
    public void setExactLocation(Point exactLocation) {
181
        fieldUnit.getGatheringEvent().setExactLocation(exactLocation);
182
    }
183

    
184
    public Integer getAbsoluteElevation() {
185
        return fieldUnit.getGatheringEvent().getAbsoluteElevation();
186
    }
187

    
188
    public void setAbsoluteElevation(Integer absoluteElevation) {
189
        fieldUnit.getGatheringEvent().setAbsoluteElevation(absoluteElevation);
190
    }
191

    
192
    public Integer getAbsoluteElevationMax() {
193
        return fieldUnit.getGatheringEvent().getAbsoluteElevationMax();
194
    }
195

    
196
    public void setAbsoluteElevationMax(Integer absoluteElevationMax) {
197
        fieldUnit.getGatheringEvent().setAbsoluteElevationMax(absoluteElevationMax);
198
    }
199

    
200
    public String getAbsoluteElevationText() {
201
        return fieldUnit.getGatheringEvent().getAbsoluteElevationText();
202
    }
203

    
204
    public void setAbsoluteElevationText(String absoluteElevationText) {
205
        fieldUnit.getGatheringEvent().setAbsoluteElevationText(absoluteElevationText);
206
    }
207

    
208
    public Double getDistanceToWaterSurface() {
209
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurface();
210
    }
211

    
212
    public void setDistanceToWaterSurface(Double distanceToWaterSurface) {
213
        fieldUnit.getGatheringEvent().setDistanceToWaterSurface(distanceToWaterSurface);
214
    }
215

    
216
    public Double getDistanceToWaterSurfaceMax() {
217
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceMax();
218
    }
219

    
220
    public void setDistanceToWaterSurfaceMax(Double distanceToWaterSurfaceMax) {
221
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceMax(distanceToWaterSurfaceMax);
222
    }
223

    
224
    public String getDistanceToWaterSurfaceText() {
225
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceText();
226
    }
227

    
228
    public void setDistanceToWaterSurfaceText(String distanceToWaterSurfaceText) {
229
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToWaterSurfaceText);
230
    }
231

    
232

    
233
    public Double getDistanceToGround() {
234
        return fieldUnit.getGatheringEvent().getDistanceToGround();
235
    }
236

    
237
    public void setDistanceToGround(Double distanceToGround) {
238
        fieldUnit.getGatheringEvent().setDistanceToGround(distanceToGround);
239
    }
240

    
241
    public Double getDistanceToGroundMax() {
242
        return fieldUnit.getGatheringEvent().getDistanceToGroundMax();
243
    }
244

    
245
    public void setDistanceToGroundMax(Double distanceToGroundMax) {
246
        fieldUnit.getGatheringEvent().setDistanceToGroundMax(distanceToGroundMax);
247
    }
248

    
249
    public String getDistanceToGroundText() {
250
        return fieldUnit.getGatheringEvent().getDistanceToGroundText();
251
    }
252

    
253
    public AgentBase getCollector(){
254
        return fieldUnit.getGatheringEvent().getActor();
255
    }
256

    
257
    public void setCollector(AgentBase collector){
258
        fieldUnit.getGatheringEvent().setActor(collector);
259
    }
260

    
261
    public void setDistanceToGroundText(String distanceToGroundText) {
262
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToGroundText);
263
    }
264

    
265
    /**
266
     * WARNING: This method returns only one of the possibly multiple areas which can
267
     * be hold by the GatheringEvent.
268
     *
269
     * @return
270
     */
271
    public NamedArea getCollectingArea() {
272
        try {
273
            return fieldUnit.getGatheringEvent().getCollectingAreas().iterator().next();
274
        } catch (Exception e){
275
            return null;
276
        }
277
    }
278

    
279
    public void setCollectingArea(NamedArea collectingArea) throws Exception {
280
        if(fieldUnit.getGatheringEvent().getCollectingAreas().size() > 1){
281
            throw new Exception("The GatheringEvent has multiple collectingAreas, use addCollectingArea() instead");
282
        }
283
        fieldUnit.getGatheringEvent().getCollectingAreas().clear();
284
        fieldUnit.getGatheringEvent().addCollectingArea(collectingArea);
285

    
286
    }
287

    
288
    public Set<NamedArea> getCollectingAreas() {
289
       return fieldUnit.getGatheringEvent().getCollectingAreas();
290
    }
291

    
292
    public Partial getGatheringDate(){
293
        return fieldUnit.getGatheringEvent().getGatheringDate();
294
    }
295

    
296
    public void getGatheringDate(Partial gatheringDate){
297
        fieldUnit.getGatheringEvent().setGatheringDate(gatheringDate);
298
    }
299

    
300
    /**
301
     * @return the citation
302
     */
303
    public Reference getCitation() {
304
        return citation;
305
    }
306

    
307
    /**
308
     * @param citation the citation to set
309
     */
310
    public void setCitation(Reference citation) {
311
        this.citation = citation;
312
    }
313

    
314
    /**
315
     * @return the typifiedName
316
     */
317
    public TaxonName getTypifiedName() {
318
        return typifiedName;
319
    }
320

    
321
    /**
322
     * @param typifiedName the typifiedName to set
323
     */
324
    public void setTypifiedName(TaxonName typifiedName) {
325
        this.typifiedName = typifiedName;
326
    }
327

    
328
    /**
329
     *
330
     * @return the set of SpecimenTypeDesignation that haven been deleted from the <code>SpecimenTypeDesignationWorkingSetDTO</code>.
331
     */
332
    public Set<SpecimenTypeDesignation> deletedSpecimenTypeDesignations() {
333
        Set<SpecimenTypeDesignation> deletedEntities = new HashSet<>(specimenTypeDesignationsLoaded);
334
        deletedEntities.removeAll(getSpecimenTypeDesignations());
335
        return deletedEntities;
336
    }
337

    
338
}
(5-5/6)