2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.model
.registration
;
11 import java
.util
.ArrayList
;
12 import java
.util
.HashSet
;
13 import java
.util
.List
;
16 import org
.joda
.time
.Partial
;
18 import eu
.etaxonomy
.cdm
.model
.agent
.AgentBase
;
19 import eu
.etaxonomy
.cdm
.model
.common
.Annotation
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
22 import eu
.etaxonomy
.cdm
.model
.common
.VersionableEntity
;
23 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
24 import eu
.etaxonomy
.cdm
.model
.location
.Point
;
25 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
27 import eu
.etaxonomy
.cdm
.model
.occurrence
.FieldUnit
;
28 import eu
.etaxonomy
.cdm
.model
.occurrence
.GatheringEvent
;
29 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
32 * @author a.kohlbecker
36 public class SpecimenTypeDesignationWorkingSetDTO
<OWNER
extends VersionableEntity
> {
40 VersionableEntity baseEntity
;
43 * List of all SpecimenTypeDesignation that have been loaded into the
44 * DTO. By comparing this list with <code>specimenTypeDesignations</code>
45 * it is possible to find those that have been deleted.
47 List
<SpecimenTypeDesignation
> specimenTypeDesignationsLoaded
= new ArrayList
<>();
49 List
<SpecimenTypeDesignationDTO
> specimenTypeDesignationsDTOs
= new ArrayList
<>();
53 private Reference citation
;
55 private TaxonName typifiedName
;
61 * @param specimenTypeDesignations can be <code>null</code>
63 public SpecimenTypeDesignationWorkingSetDTO(OWNER owner
, VersionableEntity baseEntity
, List
<SpecimenTypeDesignation
> specimenTypeDesignations
, Reference citation
, TaxonName typifiedName
) {
66 this.baseEntity
= baseEntity
;
68 throw new NullPointerException("citation must not be null");
70 if(typifiedName
== null){
71 throw new NullPointerException("typifiedName must not be null");
73 this.citation
= citation
;
74 this.typifiedName
= typifiedName
;
75 if(baseEntity
instanceof FieldUnit
){
76 this.fieldUnit
= (FieldUnit
) baseEntity
;
77 if(fieldUnit
.getGatheringEvent() == null){
78 fieldUnit
.setGatheringEvent(GatheringEvent
.NewInstance());
81 if(specimenTypeDesignations
!= null){
82 specimenTypeDesignationsLoaded
= specimenTypeDesignations
;
83 specimenTypeDesignations
.forEach(std
-> specimenTypeDesignationsDTOs
.add(new SpecimenTypeDesignationDTO(std
)));
90 * @param citationEntityID
91 * @param typifiedNameEntityID
93 public SpecimenTypeDesignationWorkingSetDTO(OWNER reg
, FieldUnit newfieldUnit
, Reference citation
, TaxonName typifiedName
) {
94 this(reg
, newfieldUnit
, null, citation
, typifiedName
);
98 * @return the fieldUnit
99 * <code>null</code> if the base baseEntity is a not a fieldUnit
101 public FieldUnit
getFieldUnit() {
108 * @return the baseEntity
109 * <code>null</code> if the base baseEntity is a fieldUnit
111 public VersionableEntity
getBaseEntity() {
116 * @return the typeDesignation entities managed in this workingset
118 protected List
<SpecimenTypeDesignation
> getSpecimenTypeDesignations() {
119 List
<SpecimenTypeDesignation
> specimenTypeDesignations
= new ArrayList(specimenTypeDesignationsDTOs
.size());
120 for(SpecimenTypeDesignationDTO dto
: specimenTypeDesignationsDTOs
){
121 specimenTypeDesignations
.add(dto
.asSpecimenTypeDesignation());
123 return specimenTypeDesignations
;
126 public List
<SpecimenTypeDesignationDTO
> getSpecimenTypeDesignationDTOs(){
127 return specimenTypeDesignationsDTOs
;
131 * The {@link VersionableEntity} which contains the DerivedUnit in this working set.
132 * This can be for example a {@link Registration} entity
136 public OWNER
getOwner() {
140 // ====== FieldUnit Wrapper methods ====== //
143 public String
getFieldNumber() {
144 return fieldUnit
.getFieldNumber();
147 public void setFieldNumber(String fieldNumber
) {
148 this.fieldUnit
.setFieldNumber(fieldNumber
);
151 public String
getFieldNotes() {
152 return fieldUnit
.getFieldNotes();
155 // ====== GateringEvent Wrapper methods ====== //
157 public String
getLocality(){
158 if(fieldUnit
.getGatheringEvent().getLocality() != null){
159 return fieldUnit
.getGatheringEvent().getLocality().getText();
164 public void setLocality(String locality
){
165 fieldUnit
.getGatheringEvent().setLocality(
166 LanguageString
.NewInstance(locality
, Language
.DEFAULT())
169 public NamedArea
getCountry() {
170 return fieldUnit
.getGatheringEvent().getCountry();
173 public void setCountry(NamedArea country
) {
174 fieldUnit
.getGatheringEvent().setCountry(country
);
177 public Point
getExactLocation() {
178 return fieldUnit
.getGatheringEvent().getExactLocation();
181 public void setExactLocation(Point exactLocation
) {
182 fieldUnit
.getGatheringEvent().setExactLocation(exactLocation
);
185 public Integer
getAbsoluteElevation() {
186 return fieldUnit
.getGatheringEvent().getAbsoluteElevation();
189 public void setAbsoluteElevation(Integer absoluteElevation
) {
190 fieldUnit
.getGatheringEvent().setAbsoluteElevation(absoluteElevation
);
193 public Integer
getAbsoluteElevationMax() {
194 return fieldUnit
.getGatheringEvent().getAbsoluteElevationMax();
197 public void setAbsoluteElevationMax(Integer absoluteElevationMax
) {
198 fieldUnit
.getGatheringEvent().setAbsoluteElevationMax(absoluteElevationMax
);
201 public String
getAbsoluteElevationText() {
202 return fieldUnit
.getGatheringEvent().getAbsoluteElevationText();
205 public void setAbsoluteElevationText(String absoluteElevationText
) {
206 fieldUnit
.getGatheringEvent().setAbsoluteElevationText(absoluteElevationText
);
209 public Double
getDistanceToWaterSurface() {
210 return fieldUnit
.getGatheringEvent().getDistanceToWaterSurface();
213 public void setDistanceToWaterSurface(Double distanceToWaterSurface
) {
214 fieldUnit
.getGatheringEvent().setDistanceToWaterSurface(distanceToWaterSurface
);
217 public Double
getDistanceToWaterSurfaceMax() {
218 return fieldUnit
.getGatheringEvent().getDistanceToWaterSurfaceMax();
221 public void setDistanceToWaterSurfaceMax(Double distanceToWaterSurfaceMax
) {
222 fieldUnit
.getGatheringEvent().setDistanceToWaterSurfaceMax(distanceToWaterSurfaceMax
);
225 public String
getDistanceToWaterSurfaceText() {
226 return fieldUnit
.getGatheringEvent().getDistanceToWaterSurfaceText();
229 public void setDistanceToWaterSurfaceText(String distanceToWaterSurfaceText
) {
230 fieldUnit
.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToWaterSurfaceText
);
234 public Double
getDistanceToGround() {
235 return fieldUnit
.getGatheringEvent().getDistanceToGround();
238 public void setDistanceToGround(Double distanceToGround
) {
239 fieldUnit
.getGatheringEvent().setDistanceToGround(distanceToGround
);
242 public Double
getDistanceToGroundMax() {
243 return fieldUnit
.getGatheringEvent().getDistanceToGroundMax();
246 public void setDistanceToGroundMax(Double distanceToGroundMax
) {
247 fieldUnit
.getGatheringEvent().setDistanceToGroundMax(distanceToGroundMax
);
250 public String
getDistanceToGroundText() {
251 return fieldUnit
.getGatheringEvent().getDistanceToGroundText();
254 public AgentBase
getCollector(){
255 return fieldUnit
.getGatheringEvent().getActor();
258 public void setCollector(AgentBase collector
){
259 fieldUnit
.getGatheringEvent().setActor(collector
);
262 public void setDistanceToGroundText(String distanceToGroundText
) {
263 fieldUnit
.getGatheringEvent().setDistanceToWaterSurfaceText(distanceToGroundText
);
267 * WARNING: This method returns only one of the possibly multiple areas which can
268 * be hold by the GatheringEvent.
272 public NamedArea
getCollectingArea() {
274 return fieldUnit
.getGatheringEvent().getCollectingAreas().iterator().next();
275 } catch (Exception e
){
280 public void setCollectingArea(NamedArea collectingArea
) throws Exception
{
281 if(fieldUnit
.getGatheringEvent().getCollectingAreas().size() > 1){
282 throw new Exception("The GatheringEvent has multiple collectingAreas, use addCollectingArea() instead");
284 fieldUnit
.getGatheringEvent().getCollectingAreas().clear();
285 fieldUnit
.getGatheringEvent().addCollectingArea(collectingArea
);
289 public Set
<NamedArea
> getCollectingAreas() {
290 return fieldUnit
.getGatheringEvent().getCollectingAreas();
293 public Partial
getGatheringDate(){
294 return fieldUnit
.getGatheringEvent().getGatheringDate();
297 public void setGatheringDate(Partial gatheringDate
){
298 fieldUnit
.getGatheringEvent().setGatheringDate(gatheringDate
);
302 * @return the citation
304 public Reference
getCitation() {
309 * @param citation the citation to set
311 public void setCitation(Reference citation
) {
312 this.citation
= citation
;
316 * @return the typifiedName
318 public TaxonName
getTypifiedName() {
323 * @param typifiedName the typifiedName to set
325 public void setTypifiedName(TaxonName typifiedName
) {
326 this.typifiedName
= typifiedName
;
331 * @return the set of SpecimenTypeDesignation that haven been deleted from the <code>SpecimenTypeDesignationWorkingSetDTO</code>.
333 public Set
<SpecimenTypeDesignation
> deletedSpecimenTypeDesignations() {
334 Set
<SpecimenTypeDesignation
> deletedEntities
= new HashSet
<>(specimenTypeDesignationsLoaded
);
335 deletedEntities
.removeAll(getSpecimenTypeDesignations());
336 return deletedEntities
;
339 public Set
<Annotation
> getAnnotations() {
340 if(fieldUnit
!= null){
341 return fieldUnit
.getAnnotations();
347 public void setAnnotations(Set
<Annotation
> annotations
) {
349 if(fieldUnit
!= null){
350 List
<Annotation
> currentAnnotations
= new ArrayList
<>(fieldUnit
.getAnnotations());
351 List
<Annotation
> annotationsSeen
= new ArrayList
<>();
352 for(Annotation a
: annotations
){
356 if(!currentAnnotations
.contains(a
)){
357 fieldUnit
.addAnnotation(a
);
359 annotationsSeen
.add(a
);
361 for(Annotation a
: currentAnnotations
){
362 if(!annotationsSeen
.contains(a
)){
363 fieldUnit
.removeAnnotation(a
);