Project

General

Profile

Download (9.34 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.name.TaxonName;
25
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
26
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
27
import eu.etaxonomy.cdm.model.reference.Reference;
28

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

    
36
    FieldUnit fieldUnit;
37

    
38
    VersionableEntity baseEntity;
39

    
40
    List<SpecimenTypeDesignation> specimenTypeDesignations = new ArrayList<>();
41

    
42
    List<SpecimenTypeDesignationDTO> specimenTypeDesignationsDTOs = new ArrayList<>();
43

    
44
    OWNER owner;
45

    
46
    private Reference citation;
47

    
48
    private TaxonName typifiedName;
49

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

    
74
    /**
75
     * @param reg
76
     * @param newfieldUnit
77
     * @param citationEntityID
78
     * @param typifiedNameEntityID
79
     */
80
    public SpecimenTypeDesignationWorkingSetDTO(OWNER reg, FieldUnit newfieldUnit, Reference citation, TaxonName typifiedName) {
81
        this(reg, newfieldUnit, null, citation, typifiedName);
82
    }
83

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

    
92

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

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

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

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

    
123
    // ====== FieldUnit Wrapper methods ====== //
124

    
125

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

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

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

    
138
    // ====== GateringEvent Wrapper methods ====== //
139

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
216

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

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

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

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

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

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

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

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

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

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

    
270
    }
271

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

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

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

    
284
    /**
285
     * @return the citation
286
     */
287
    public Reference getCitation() {
288
        return citation;
289
    }
290

    
291
    /**
292
     * @param citation the citation to set
293
     */
294
    public void setCitation(Reference citation) {
295
        this.citation = citation;
296
    }
297

    
298
    /**
299
     * @return the typifiedName
300
     */
301
    public TaxonName getTypifiedName() {
302
        return typifiedName;
303
    }
304

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

    
312

    
313
}
(5-5/6)