Project

General

Profile

Download (9.16 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.List;
13
import java.util.Set;
14

    
15
import org.joda.time.Partial;
16

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

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

    
34
    FieldUnit fieldUnit;
35

    
36
    VersionableEntity baseEntity;
37

    
38
    List<SpecimenTypeDesignation> specimenTypeDesignations = new ArrayList<>();
39

    
40
    List<SpecimenTypeDesignationDTO> specimenTypeDesignationsDTOs = new ArrayList<>();
41

    
42
    OWNER owner;
43

    
44
    private Integer citationEntityID;
45

    
46
    private Integer typifiedNameEntityID;
47

    
48
    /**
49
     *
50
     * @param owner
51
     * @param baseEntity
52
     * @param specimenTypeDesignations can be <code>null</code>
53
     */
54
    public SpecimenTypeDesignationWorkingSetDTO(OWNER owner, VersionableEntity baseEntity, List<SpecimenTypeDesignation> specimenTypeDesignations) {
55
        super();
56
        this.owner = owner;
57
        this.baseEntity = baseEntity;
58
        if(baseEntity instanceof FieldUnit){
59
            this.fieldUnit = (FieldUnit) baseEntity;
60
            if(fieldUnit.getGatheringEvent() == null){
61
                fieldUnit.setGatheringEvent(GatheringEvent.NewInstance());
62
            }
63
        }
64
        if(specimenTypeDesignations != null){
65
            this.specimenTypeDesignations = specimenTypeDesignations;
66
            this.specimenTypeDesignations.forEach(std -> specimenTypeDesignationsDTOs.add(new SpecimenTypeDesignationDTO(std)));
67
        }
68
    }
69

    
70
    /**
71
     * @param reg
72
     * @param newfieldUnit
73
     * @param citationEntityID
74
     * @param typifiedNameEntityID
75
     */
76
    public SpecimenTypeDesignationWorkingSetDTO(OWNER reg, FieldUnit newfieldUnit, Integer citationEntityID,
77
            Integer typifiedNameEntityID) {
78
        this(reg, newfieldUnit, null);
79
        this.citationEntityID = citationEntityID;
80
        this.typifiedNameEntityID = typifiedNameEntityID;
81
    }
82

    
83
    /**
84
     * @return the fieldUnit
85
     *      <code>null</code> if the base baseEntity is a not a fieldUnit
86
     */
87
    public FieldUnit getFieldUnit() {
88
        return fieldUnit;
89
    }
90

    
91

    
92
    /**
93
     *
94
     * @return the baseEntity
95
     *   <code>null</code> if the base baseEntity is a fieldUnit
96
     */
97
    public VersionableEntity getBaseEntity() {
98
        return baseEntity;
99
    }
100

    
101
    /**
102
     * @return the derivedUnits
103
     */
104
    protected List<SpecimenTypeDesignation> getSpecimenTypeDesignations() {
105
        return specimenTypeDesignations;
106
    }
107

    
108
    public List<SpecimenTypeDesignationDTO> getSpecimenTypeDesignationDTOs(){
109
        return specimenTypeDesignationsDTOs;
110
    }
111

    
112
    /**
113
     * The {@link VersionableEntity} which contains the DerivedUnit in this working set.
114
     * This can be for example a {@link Registration} entity
115
     *
116
     * @return
117
     */
118
    public OWNER getOwner() {
119
        return owner;
120
    }
121

    
122
    // ====== FieldUnit Wrapper methods ====== //
123

    
124

    
125
    public String getFieldNumber() {
126
        return fieldUnit.getFieldNumber();
127
    }
128

    
129
    public void setFieldNumber(String fieldNumber) {
130
        this.fieldUnit.setFieldNumber(fieldNumber);
131
    }
132

    
133
    public String getFieldNotes() {
134
        return fieldUnit.getFieldNotes();
135
    }
136

    
137
    // ====== GateringEvent Wrapper methods ====== //
138

    
139
    public String getLocality(){
140
        if(fieldUnit.getGatheringEvent().getLocality() != null){
141
            return fieldUnit.getGatheringEvent().getLocality().getText();
142
        }
143
        return null;
144
    }
145

    
146
    public void setLocality(String locality){
147
        fieldUnit.getGatheringEvent().setLocality(
148
                LanguageString.NewInstance(locality, Language.DEFAULT())
149
                );
150
    }
151
    public NamedArea getCountry() {
152
        return fieldUnit.getGatheringEvent().getCountry();
153
    }
154

    
155
    public void setCountry(NamedArea country) {
156
        fieldUnit.getGatheringEvent().setCountry(country);
157
    }
158

    
159
    public Point getExactLocation() {
160
        return fieldUnit.getGatheringEvent().getExactLocation();
161
    }
162

    
163
    public void setExactLocation(Point exactLocation) {
164
        fieldUnit.getGatheringEvent().setExactLocation(exactLocation);
165
    }
166

    
167
    public Integer getAbsoluteElevation() {
168
        return fieldUnit.getGatheringEvent().getAbsoluteElevation();
169
    }
170

    
171
    public void setAbsoluteElevation(Integer absoluteElevation) {
172
        fieldUnit.getGatheringEvent().setAbsoluteElevation(absoluteElevation);
173
    }
174

    
175
    public Integer getAbsoluteElevationMax() {
176
        return fieldUnit.getGatheringEvent().getAbsoluteElevationMax();
177
    }
178

    
179
    public void setAbsoluteElevationMax(Integer absoluteElevationMax) {
180
        fieldUnit.getGatheringEvent().setAbsoluteElevationMax(absoluteElevationMax);
181
    }
182

    
183
    public String getAbsoluteElevationText() {
184
        return fieldUnit.getGatheringEvent().getAbsoluteElevationText();
185
    }
186

    
187
    public void setAbsoluteElevationText(String absoluteElevationText) {
188
        fieldUnit.getGatheringEvent().setAbsoluteElevationText(absoluteElevationText);
189
    }
190

    
191
    public Double getDistanceToWaterSurface() {
192
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurface();
193
    }
194

    
195
    public void setDistanceToWaterSurface(Double distanceToWaterSurface) {
196
        fieldUnit.getGatheringEvent().setDistanceToWaterSurface(distanceToWaterSurface);
197
    }
198

    
199
    public Double getDistanceToWaterSurfaceMax() {
200
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceMax();
201
    }
202

    
203
    public void setDistanceToWaterSurfaceMax(Double distanceToWaterSurfaceMax) {
204
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceMax(distanceToWaterSurfaceMax);
205
    }
206

    
207
    public String getDistanceToWaterSurfaceText() {
208
        return fieldUnit.getGatheringEvent().getDistanceToWaterSurfaceText();
209
    }
210

    
211
    public void setDistanceToWaterSurfaceText(String distanceToWaterSurfaceText) {
212
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToWaterSurfaceText);
213
    }
214

    
215

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

    
220
    public void setDistanceToGround(Double distanceToGround) {
221
        fieldUnit.getGatheringEvent().setDistanceToGround(distanceToGround);
222
    }
223

    
224
    public Double getDistanceToGroundMax() {
225
        return fieldUnit.getGatheringEvent().getDistanceToGroundMax();
226
    }
227

    
228
    public void setDistanceToGroundMax(Double distanceToGroundMax) {
229
        fieldUnit.getGatheringEvent().setDistanceToGroundMax(distanceToGroundMax);
230
    }
231

    
232
    public String getDistanceToGroundText() {
233
        return fieldUnit.getGatheringEvent().getDistanceToGroundText();
234
    }
235

    
236
    public AgentBase getCollector(){
237
        return fieldUnit.getGatheringEvent().getActor();
238
    }
239

    
240
    public void setCollector(AgentBase collector){
241
        fieldUnit.getGatheringEvent().setActor(collector);
242
    }
243

    
244
    public void setDistanceToGroundText(String distanceToGroundText) {
245
        fieldUnit.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToGroundText);
246
    }
247

    
248
    /**
249
     * WARNING: This method returns only one of the possibly multiple areas which can
250
     * be hold by the GatheringEvent.
251
     *
252
     * @return
253
     */
254
    public NamedArea getCollectingArea() {
255
        try {
256
            return fieldUnit.getGatheringEvent().getCollectingAreas().iterator().next();
257
        } catch (Exception e){
258
            return null;
259
        }
260
    }
261

    
262
    public void setCollectingArea(NamedArea collectingArea) throws Exception {
263
        if(fieldUnit.getGatheringEvent().getCollectingAreas().size() > 1){
264
            throw new Exception("The GatheringEvent has multiple collectingAreas, use addCollectingArea() instead");
265
        }
266
        fieldUnit.getGatheringEvent().getCollectingAreas().clear();
267
        fieldUnit.getGatheringEvent().addCollectingArea(collectingArea);
268

    
269
    }
270

    
271
    public Set<NamedArea> getCollectingAreas() {
272
       return fieldUnit.getGatheringEvent().getCollectingAreas();
273
    }
274

    
275
    public Partial getGatheringDate(){
276
        return fieldUnit.getGatheringEvent().getGatheringDate();
277
    }
278

    
279
    public void getGatheringDate(Partial gatheringDate){
280
        fieldUnit.getGatheringEvent().setGatheringDate(gatheringDate);
281
    }
282

    
283
    /**
284
     * @param id
285
     */
286
    public void setCitationEntityID(int id) {
287
        citationEntityID = id;
288

    
289
    }
290

    
291
    /**
292
     * @return
293
     */
294
    public int getCitationEntityID() {
295
        return citationEntityID;
296
    }
297

    
298
    /**
299
     * @param id
300
     */
301
    public void setTypifiedNameEntityID(int id) {
302
        typifiedNameEntityID = id;
303

    
304
    }
305

    
306
    /**
307
     * @return
308
     */
309
    public int getTypifiedNameEntityID() {
310
        return typifiedNameEntityID;
311
    }
312

    
313
}
(5-5/6)