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.location.Location;
32  import net.sumaris.core.model.referential.QualityFlag;
33  import net.sumaris.core.model.referential.SaleType;
34  import org.hibernate.annotations.Cascade;
35  
36  import javax.persistence.*;
37  import java.util.ArrayList;
38  import java.util.Date;
39  import java.util.List;
40  import java.util.Set;
41  
42  @Data
43  @FieldNameConstants
44  @Entity
45  @Table(name = "sale")
46  public class Sale implements IRootDataEntity<Integer>,
47          IWithVesselEntity<Integer, Vessel> {
48  
49      @Id
50      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SALE_SEQ")
51      @SequenceGenerator(name = "SALE_SEQ", sequenceName = "SALE_SEQ")
52      private Integer id;
53  
54      @Column(name = "creation_date", nullable = false)
55      @Temporal(TemporalType.TIMESTAMP)
56      private Date creationDate;
57  
58      @Column(name = "update_date")
59      @Temporal(TemporalType.TIMESTAMP)
60      private Date updateDate;
61  
62      @ManyToOne(fetch = FetchType.LAZY)
63      @JoinColumn(name = "recorder_person_fk")
64      private Person recorderPerson;
65  
66      @ManyToOne(fetch = FetchType.LAZY)
67      @JoinColumn(name = "recorder_department_fk", nullable = false)
68      private Department recorderDepartment;
69  
70      @Column(length = 2000)
71      private String comments;
72  
73      @Column(name = "control_date")
74      @Temporal(TemporalType.TIMESTAMP)
75      private Date controlDate;
76  
77      @Column(name = "validation_date")
78      @Temporal(TemporalType.TIMESTAMP)
79      private Date validationDate;
80  
81      @Column(name = "qualification_date")
82      @Temporal(TemporalType.TIMESTAMP)
83      private Date qualificationDate;
84  
85      @Column(name = "qualification_comments", length = LENGTH_COMMENTS)
86      private String qualificationComments;
87  
88      @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
89      @JoinColumn(name = "quality_flag_fk", nullable = false)
90      private QualityFlag qualityFlag;
91  
92      @ManyToOne(fetch = FetchType.LAZY, targetEntity = Vessel.class)
93      @JoinColumn(name = "vessel_fk", nullable = false)
94      private Vessel vessel;
95  
96      @Column(name = "start_date_time", nullable = false)
97      private Date startDateTime;
98  
99      @Column(name = "end_date_time")
100     private Date endDateTime;
101 
102     @ManyToOne(fetch = FetchType.EAGER, targetEntity = Location.class)
103     @JoinColumn(name = "sale_location_fk", nullable = false)
104     private Location saleLocation;
105 
106     @ManyToOne(fetch = FetchType.EAGER, targetEntity = SaleType.class)
107     @JoinColumn(name = "sale_type_fk", nullable = false)
108     private SaleType saleType;
109 
110     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Program.class)
111     @JoinColumn(name = "program_fk", nullable = false)
112     private Program program;
113 
114     @ManyToMany(fetch = FetchType.EAGER, targetEntity = Person.class)
115     @Cascade(org.hibernate.annotations.CascadeType.DETACH)
116     @JoinTable(name = "sale2observer_person", joinColumns = {
117             @JoinColumn(name = "sale_fk", nullable = false, updatable = false)},
118             inverseJoinColumns = {
119                     @JoinColumn(name = "person_fk", nullable = false, updatable = false)})
120     private Set<Person> observers = Sets.newHashSet();
121 
122     /* -- measurements -- */
123 
124     @OneToMany(fetch = FetchType.LAZY, targetEntity = SaleMeasurement.class, mappedBy = SaleMeasurement.Fields.SALE)
125     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
126     private List<SaleMeasurement> measurements = new ArrayList<>();
127 
128     /* -- parent -- */
129 
130     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Trip.class)
131     @JoinColumn(name = "trip_fk")
132     private Trip trip;
133 
134     @ManyToOne(fetch = FetchType.LAZY, targetEntity = ObservedLocation.class)
135     @JoinColumn(name = "observed_location_fk")
136     private ObservedLocation observedLocation;
137 }