View Javadoc
1   package net.sumaris.core.model.data;
2   
3   /*-
4    * #%L
5    * SUMARiS:: Core
6    * %%
7    * Copyright (C) 2018 SUMARiS Consortium
8    * %%
9    * This program is free software: you can redistribute it and/or modify
10   * it under the terms of the GNU General Public License as
11   * published by the Free Software Foundation, either version 3 of the
12   * License, or (at your option) any later version.
13   * 
14   * This program is distributed in the hope that it will be useful,
15   * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17   * GNU General Public License for more details.
18   * 
19   * You should have received a copy of the GNU General Public
20   * License along with this program.  If not, see
21   * <http://www.gnu.org/licenses/gpl-3.0.html>.
22   * #L%
23   */
24  
25  import com.google.common.collect.Sets;
26  import lombok.Data;
27  import lombok.experimental.FieldNameConstants;
28  import net.sumaris.core.model.administration.programStrategy.Program;
29  import net.sumaris.core.model.administration.user.Department;
30  import net.sumaris.core.model.administration.user.Person;
31  import net.sumaris.core.model.referential.QualityFlag;
32  import net.sumaris.core.model.referential.location.Location;
33  import org.hibernate.annotations.Cascade;
34  
35  import javax.persistence.*;
36  import java.util.ArrayList;
37  import java.util.Date;
38  import java.util.List;
39  import java.util.Set;
40  
41  @Data
42  @FieldNameConstants
43  @Entity
44  public class Landing implements IRootDataEntity<Integer>,
45          IWithObserversEntity<Integer, Person>,
46          IWithVesselEntity<Integer, Vessel> {
47  
48      @Id
49      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "LANDING_SEQ")
50      @SequenceGenerator(name = "LANDING_SEQ", sequenceName="LANDING_SEQ")
51      private Integer id;
52  
53      @Column(name = "creation_date", nullable = false)
54      @Temporal(TemporalType.TIMESTAMP)
55      private Date creationDate;
56  
57      @Column(name = "update_date")
58      @Temporal(TemporalType.TIMESTAMP)
59      private Date updateDate;
60  
61      @ManyToOne(fetch = FetchType.LAZY)
62      @JoinColumn(name = "recorder_person_fk")
63      private Person recorderPerson;
64  
65      @ManyToOne(fetch = FetchType.LAZY)
66      @JoinColumn(name = "recorder_department_fk", nullable = false)
67      private Department recorderDepartment;
68  
69      @Column(length = 2000)
70      private String comments;
71  
72      @Column(name="control_date")
73      @Temporal(TemporalType.TIMESTAMP)
74      private Date controlDate;
75  
76      @Column(name="validation_date")
77      @Temporal(TemporalType.TIMESTAMP)
78      private Date validationDate;
79  
80      @Column(name="qualification_date")
81      @Temporal(TemporalType.TIMESTAMP)
82      private Date qualificationDate;
83  
84      @Column(name="qualification_comments", length = LENGTH_COMMENTS)
85      private String qualificationComments;
86  
87      @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
88      @JoinColumn(name = "quality_flag_fk", nullable = false)
89      private QualityFlag qualityFlag;
90  
91      @ManyToOne(fetch = FetchType.LAZY, targetEntity = Vessel.class)
92      @JoinColumn(name = "vessel_fk", nullable = false)
93      private Vessel vessel;
94  
95      @Column(name = "landing_date_time", nullable = false)
96      private Date dateTime;
97  
98      @ManyToOne(fetch = FetchType.EAGER, targetEntity = Location.class)
99      @JoinColumn(name = "landing_location_fk", nullable = false)
100     private Location location;
101 
102     @Column(name = "rank_order")
103     private Integer rankOrder;
104 
105     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Program.class)
106     @JoinColumn(name = "program_fk", nullable = false)
107     private Program program;
108 
109     @ManyToMany(fetch = FetchType.EAGER, targetEntity = Person.class)
110     @Cascade(org.hibernate.annotations.CascadeType.DETACH)
111     @JoinTable(name = "landing2observer_person", joinColumns = {
112             @JoinColumn(name = "landing_fk", nullable = false, updatable = false) },
113             inverseJoinColumns = {
114                     @JoinColumn(name = "person_fk", nullable = false, updatable = false) })
115     private Set<Person> observers = Sets.newHashSet();
116 
117     @OneToMany(fetch = FetchType.LAZY, targetEntity = Sample.class, mappedBy = Sample.Fields.LANDING)
118     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
119     private List<Sample> samples = new ArrayList<>();
120 
121     /* -- measurements -- */
122 
123     @OneToMany(fetch = FetchType.LAZY, targetEntity = LandingMeasurement.class, mappedBy = LandingMeasurement.Fields.LANDING)
124     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
125     private List<LandingMeasurement> measurements = new ArrayList<>();
126 
127     /* -- parent -- */
128 
129     @ManyToOne(fetch = FetchType.LAZY, targetEntity = ObservedLocation.class)
130     @JoinColumn(name = "observed_location_fk")
131     private ObservedLocation observedLocation;
132 
133     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Trip.class)
134     @JoinColumn(name = "trip_fk")
135     private Trip trip;
136 }