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.programStrategy.Program;
28  import net.sumaris.core.model.administration.user.Department;
29  import net.sumaris.core.model.administration.user.Person;
30  import net.sumaris.core.model.referential.gear.Gear;
31  import net.sumaris.core.model.referential.QualityFlag;
32  import org.hibernate.annotations.Cascade;
33  
34  import javax.persistence.*;
35  import java.util.ArrayList;
36  import java.util.Date;
37  import java.util.List;
38  
39  @Data
40  @FieldNameConstants
41  @Entity
42  @Table(name="physical_gear")
43  public class PhysicalGear implements IRootDataEntity<Integer> {
44  
45      @Id
46      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "PHYSICAL_GEAR_SEQ")
47      @SequenceGenerator(name = "PHYSICAL_GEAR_SEQ", sequenceName="PHYSICAL_GEAR_SEQ")
48      private Integer id;
49  
50      @Column(name = "creation_date", nullable = false)
51      @Temporal(TemporalType.TIMESTAMP)
52      private Date creationDate;
53  
54      @Column(name = "update_date")
55      @Temporal(TemporalType.TIMESTAMP)
56      private Date updateDate;
57  
58      @ManyToOne(fetch = FetchType.LAZY)
59      @JoinColumn(name = "recorder_person_fk")
60      private Person recorderPerson;
61  
62      @ManyToOne(fetch = FetchType.LAZY)
63      @JoinColumn(name = "recorder_department_fk", nullable = false)
64      private Department recorderDepartment;
65  
66      @Column(length = LENGTH_COMMENTS)
67      private String comments;
68  
69      @Column(name="control_date")
70      @Temporal(TemporalType.TIMESTAMP)
71      private Date controlDate;
72  
73      @Column(name="validation_date")
74      @Temporal(TemporalType.TIMESTAMP)
75      private Date validationDate;
76  
77      @Column(name="qualification_date")
78      @Temporal(TemporalType.TIMESTAMP)
79      private Date qualificationDate;
80  
81      @Column(name="qualification_comments", length = LENGTH_COMMENTS)
82      private String qualificationComments;
83  
84      @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
85      @JoinColumn(name = "quality_flag_fk", nullable = false)
86      private QualityFlag qualityFlag;
87  
88      @Column(name = "rank_order", nullable = false)
89      private Integer rankOrder;
90  
91      @ManyToOne(fetch = FetchType.LAZY, targetEntity = Gear.class)
92      @JoinColumn(name = "gear_fk", nullable = false)
93      private Gear gear;
94  
95      @ManyToOne(fetch = FetchType.LAZY, targetEntity = Program.class)
96      @JoinColumn(name = "program_fk", nullable = false)
97      private Program program;
98  
99      /* -- measurements -- */
100 
101     @OneToMany(fetch = FetchType.LAZY, targetEntity = PhysicalGearMeasurement.class, mappedBy = PhysicalGearMeasurement.Fields.PHYSICAL_GEAR)
102     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
103     private List<PhysicalGearMeasurement> measurements = new ArrayList<>();
104 
105     /* -- parent -- */
106 
107     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Trip.class)
108     @JoinColumn(name = "trip_fk", nullable = false)
109     private Trip trip;
110 
111     public String toString() {
112         return new StringBuilder().append(super.toString()).append(",gear=").append(this.gear).toString();
113     }
114 }