Project

General

Profile

Download (10.3 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
    List<SpecimenTypeDesignation> specimenTypeDesignations = new ArrayList<>();
42

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

    
50
    List<SpecimenTypeDesignationDTO> specimenTypeDesignationsDTOs = new ArrayList<>();
51

    
52
    OWNER owner;
53

    
54
    private Reference citation;
55

    
56
    private TaxonName typifiedName;
57

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

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

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

    
106

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

    
116
    /**
117
     * @return the derivedUnits
118
     */
119
    protected List<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
120
        return specimenTypeDesignations;
121
    }
122

    
123
    public List<SpecimenTypeDesignationDTO> getSpecimenTypeDesignationDTOs(){
124
        return specimenTypeDesignationsDTOs;
125
    }
126

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

    
137
    // ====== FieldUnit Wrapper methods ====== //
138

    
139

    
140
    public String getFieldNumber() {
141
        return fieldUnit.getFieldNumber();
142
    }
143

    
144
    public void setFieldNumber(String fieldNumber) {
145
        this.fieldUnit.setFieldNumber(fieldNumber);
146
    }
147

    
148
    public String getFieldNotes() {
149
        return fieldUnit.getFieldNotes();
150
    }
151

    
152
    // ====== GateringEvent Wrapper methods ====== //
153

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

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

    
170
    public void setCountry(NamedArea country) {
171
        fieldUnit.getGatheringEvent().setCountry(country);
172
    }
173

    
174
    public Point getExactLocation() {
175
        return fieldUnit.getGatheringEvent().getExactLocation();
176
    }
177

    
178
    public void setExactLocation(Point exactLocation) {
179
        fieldUnit.getGatheringEvent().setExactLocation(exactLocation);
180
    }
181

    
182
    public Integer getAbsoluteElevation() {
183
        return fieldUnit.getGatheringEvent().getAbsoluteElevation();
184
    }
185

    
186
    public void setAbsoluteElevation(Integer absoluteElevation) {
187
        fieldUnit.getGatheringEvent().setAbsoluteElevation(absoluteElevation);
188
    }
189

    
190
    public Integer getAbsoluteElevationMax() {
191
        return fieldUnit.getGatheringEvent().getAbsoluteElevationMax();
192
    }
193

    
194
    public void setAbsoluteElevationMax(Integer absoluteElevationMax) {
195
        fieldUnit.getGatheringEvent().setAbsoluteElevationMax(absoluteElevationMax);
196
    }
197

    
198
    public String getAbsoluteElevationText() {
199
        return fieldUnit.getGatheringEvent().getAbsoluteElevationText();
200
    }
201

    
202
    public void setAbsoluteElevationText(String absoluteElevationText) {
203
        fieldUnit.getGatheringEvent().setAbsoluteElevationText(absoluteElevationText);
204
    }
205

    
206
    public Double getDistanceToWaterSurface() {
207
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurface();
208
    }
209

    
210
    public void setDistanceToWaterSurface(Double distanceToWaterSurface) {
211
        fieldUnit.getGatheringEvent().setDistanceToWaterSurface(distanceToWaterSurface);
212
    }
213

    
214
    public Double getDistanceToWaterSurfaceMax() {
215
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceMax();
216
    }
217

    
218
    public void setDistanceToWaterSurfaceMax(Double distanceToWaterSurfaceMax) {
219
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceMax(distanceToWaterSurfaceMax);
220
    }
221

    
222
    public String getDistanceToWaterSurfaceText() {
223
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceText();
224
    }
225

    
226
    public void setDistanceToWaterSurfaceText(String distanceToWaterSurfaceText) {
227
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToWaterSurfaceText);
228
    }
229

    
230

    
231
    public Double getDistanceToGround() {
232
        return fieldUnit.getGatheringEvent().getDistanceToGround();
233
    }
234

    
235
    public void setDistanceToGround(Double distanceToGround) {
236
        fieldUnit.getGatheringEvent().setDistanceToGround(distanceToGround);
237
    }
238

    
239
    public Double getDistanceToGroundMax() {
240
        return fieldUnit.getGatheringEvent().getDistanceToGroundMax();
241
    }
242

    
243
    public void setDistanceToGroundMax(Double distanceToGroundMax) {
244
        fieldUnit.getGatheringEvent().setDistanceToGroundMax(distanceToGroundMax);
245
    }
246

    
247
    public String getDistanceToGroundText() {
248
        return fieldUnit.getGatheringEvent().getDistanceToGroundText();
249
    }
250

    
251
    public AgentBase getCollector(){
252
        return fieldUnit.getGatheringEvent().getActor();
253
    }
254

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

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

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

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

    
284
    }
285

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

    
290
    public Partial getGatheringDate(){
291
        return fieldUnit.getGatheringEvent().getGatheringDate();
292
    }
293

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

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

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

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

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

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

    
336
}
(5-5/6)