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.pmfm.Matrix;
31  import net.sumaris.core.model.referential.QualityFlag;
32  import net.sumaris.core.model.referential.pmfm.Unit;
33  import net.sumaris.core.model.referential.taxon.ReferenceTaxon;
34  import net.sumaris.core.model.referential.taxon.TaxonGroup;
35  import org.hibernate.annotations.Cascade;
36  
37  import javax.persistence.*;
38  import java.util.ArrayList;
39  import java.util.Date;
40  import java.util.List;
41  
42  @Data
43  @FieldNameConstants
44  @Entity
45  @Table(name = "sample")
46  public class Sample implements IRootDataEntity<Integer> {
47  
48      @Id
49      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SAMPLE_SEQ")
50      @SequenceGenerator(name = "SAMPLE_SEQ", sequenceName="SAMPLE_SEQ")
51      private Integer id;
52  
53      @Column(length = 40, nullable = false)
54      private String label;
55  
56      @Column(name = "rank_order", nullable = false)
57      private Integer rankOrder;
58  
59      @Column(name = "sample_date")
60      private Date sampleDate;
61  
62      @Column(name = "individual_count")
63      private Integer individualCount;
64  
65      @Column(name = "sample_size")
66      private Double size;
67  
68      @ManyToOne(fetch = FetchType.LAZY)
69      @JoinColumn(name = "size_unit_fk")
70      private Unit sizeUnit;
71  
72      @ManyToOne(fetch = FetchType.LAZY)
73      @JoinColumn(name = "taxon_group_fk")
74      private TaxonGroup taxonGroup;
75  
76      @ManyToOne(fetch = FetchType.LAZY)
77      @JoinColumn(name = "reference_taxon_fk")
78      private ReferenceTaxon referenceTaxon;
79  
80      @ManyToOne(fetch = FetchType.LAZY)
81      @JoinColumn(name = "matrix_fk", nullable = false)
82      private Matrix matrix;
83  
84      @Column(length = LENGTH_COMMENTS)
85      private String comments;
86  
87      /* -- Quality insurance -- */
88  
89      @Column(name = "creation_date", nullable = false)
90      @Temporal(TemporalType.TIMESTAMP)
91      private Date creationDate;
92  
93      @Column(name = "update_date")
94      @Temporal(TemporalType.TIMESTAMP)
95      private Date updateDate;
96  
97      @ManyToOne(fetch = FetchType.LAZY)
98      @JoinColumn(name = "recorder_department_fk", nullable = false)
99      private Department recorderDepartment;
100 
101     @ManyToOne(fetch = FetchType.LAZY)
102     @JoinColumn(name = "recorder_person_fk")
103     private Person recorderPerson;
104 
105     @Column(name="control_date")
106     @Temporal(TemporalType.TIMESTAMP)
107     private Date controlDate;
108 
109     @Column(name="validation_date")
110     @Temporal(TemporalType.TIMESTAMP)
111     private Date validationDate;
112 
113     @Column(name="qualification_date")
114     @Temporal(TemporalType.TIMESTAMP)
115     private Date qualificationDate;
116 
117     @Column(name="qualification_comments", length = LENGTH_COMMENTS)
118     private String qualificationComments;
119 
120     @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
121     @JoinColumn(name = "quality_flag_fk", nullable = false)
122     private QualityFlag qualityFlag;
123 
124     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Program.class)
125     @JoinColumn(name = "program_fk", nullable = false)
126     private Program program;
127 
128     /* -- Tree link -- */
129 
130     @OneToMany(fetch = FetchType.LAZY, targetEntity = Sample.class, mappedBy = Fields.PARENT)
131     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
132     private List<Sample> children = new ArrayList<>();
133 
134     @ManyToOne(fetch = FetchType.LAZY)
135     @JoinColumn(name = "parent_sample_fk")
136     private Sample parent;
137 
138 
139     /* -- measurements -- */
140 
141     @OneToMany(fetch = FetchType.LAZY, targetEntity = SampleMeasurement.class, mappedBy = SampleMeasurement.Fields.SAMPLE)
142     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
143     private List<SampleMeasurement> measurements = new ArrayList<>();
144 
145     /* -- Parent link -- */
146 
147     @ManyToOne(fetch = FetchType.LAZY)
148     @JoinColumn(name = "operation_fk")
149     private Operation operation;
150 
151     @ManyToOne(fetch = FetchType.LAZY)
152     @JoinColumn(name = "batch_fk")
153     private Batch batch;
154 
155     @ManyToOne(fetch = FetchType.LAZY)
156     @JoinColumn(name = "landing_fk")
157     private Landing landing;
158 }