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 lombok.Data;
26  import lombok.experimental.FieldNameConstants;
27  import net.sumaris.core.model.administration.user.Department;
28  import net.sumaris.core.model.referential.QualityFlag;
29  import net.sumaris.core.model.referential.metier.Metier;
30  import org.hibernate.annotations.Cascade;
31  
32  import javax.persistence.*;
33  import java.util.ArrayList;
34  import java.util.Date;
35  import java.util.List;
36  
37  @Data
38  @FieldNameConstants
39  @Entity
40  @Table(name = "operation")
41  @Cacheable
42  public class Operation implements IDataEntity<Integer> {
43  
44      @Id
45      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "OPERATION_SEQ")
46      @SequenceGenerator(name = "OPERATION_SEQ", sequenceName="OPERATION_SEQ")
47      private Integer id;
48  
49      @Column(name = "update_date")
50      @Temporal(TemporalType.TIMESTAMP)
51      private Date updateDate;
52  
53      @ManyToOne(fetch = FetchType.LAZY)
54      @JoinColumn(name = "recorder_department_fk", nullable = false)
55      private Department recorderDepartment;
56  
57      @Column(length = LENGTH_COMMENTS)
58      private String comments;
59  
60      @Column(name="control_date")
61      @Temporal(TemporalType.TIMESTAMP)
62      private Date controlDate;
63  
64      @Column(name="qualification_date")
65      @Temporal(TemporalType.TIMESTAMP)
66      private Date qualificationDate;
67  
68      @Column(name="qualification_comments", length = LENGTH_COMMENTS)
69      private String qualificationComments;
70  
71      @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
72      @JoinColumn(name = "quality_flag_fk", nullable = false)
73      private QualityFlag qualityFlag;
74  
75      @ManyToOne(fetch = FetchType.LAZY)
76      @JoinColumn(name = "trip_fk", nullable = false)
77      private Trip trip;
78  
79      @Column(name = "start_date_time", nullable = false)
80      private Date startDateTime;
81  
82      @Column(name = "end_date_time", nullable = false)
83      private Date endDateTime;
84  
85      @Column(name = "fishing_start_date_time")
86      private Date fishingStartDateTime;
87  
88      @Column(name = "fishing_end_date_time")
89      private Date fishingEndDateTime;
90  
91      @Column(name = "rank_order_on_period")
92      private Integer rankOrderOnPeriod;
93  
94      @Column(name = "has_catch")
95      private Boolean hasCatch;
96  
97      @ManyToOne(fetch = FetchType.LAZY)
98      @JoinColumn(name = "metier_fk")
99      private Metier metier; // <-- /!\ metier is nullable !
100 
101     @ManyToOne(fetch = FetchType.LAZY)
102     @JoinColumn(name = "physical_gear_fk", nullable = false)
103     @Cascade(org.hibernate.annotations.CascadeType.DETACH)
104     private PhysicalGear physicalGear;
105 
106     @OneToMany(fetch = FetchType.LAZY, targetEntity = VesselPosition.class, mappedBy = VesselPosition.Fields.OPERATION)
107     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
108     private List<VesselPosition> positions = new ArrayList<>();
109 
110 
111     @OneToMany(fetch = FetchType.LAZY, targetEntity = VesselUseMeasurement.class, mappedBy = VesselUseMeasurement.Fields.OPERATION)
112     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
113     private List<VesselUseMeasurement> vesselUseMeasurements = new ArrayList<>();
114 
115     @OneToMany(fetch = FetchType.LAZY, targetEntity = GearUseMeasurement.class, mappedBy = GearUseMeasurement.Fields.OPERATION)
116     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
117     private List<GearUseMeasurement> gearUseMeasurements = new ArrayList<>();
118 
119     @OneToMany(fetch = FetchType.LAZY, targetEntity = Sample.class, mappedBy = Sample.Fields.OPERATION)
120     @Cascade({org.hibernate.annotations.CascadeType.DELETE})
121     private List<Sample> samples = new ArrayList<>();
122 
123     @OneToMany(fetch = FetchType.LAZY, targetEntity = Batch.class, mappedBy = Batch.Fields.OPERATION)
124     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
125     private List<Batch> batches;
126 }