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.taxon.ReferenceTaxon;
30  import net.sumaris.core.model.referential.taxon.TaxonGroup;
31  import org.hibernate.annotations.Cascade;
32  
33  import javax.persistence.*;
34  import java.util.ArrayList;
35  import java.util.Date;
36  import java.util.List;
37  
38  @Data
39  @FieldNameConstants
40  @Entity
41  @Table(name = "batch")
42  public class Batch implements IDataEntity<Integer> {
43  
44      @Id
45      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "BATCH_SEQ")
46      @SequenceGenerator(name = "BATCH_SEQ", sequenceName="BATCH_SEQ")
47      private Integer id;
48  
49      @Column(length = 40)
50      private String label;
51  
52      @Column(name = "rank_order", nullable = false)
53      private Integer rankOrder;
54  
55      @Column(name="exhaustive_inventory")
56      private Boolean exhaustiveInventory;
57  
58      @Column(name = "sampling_ratio")
59      private Double samplingRatio;
60  
61      @Column(name = "sampling_ratio_text", length = 50)
62      private String samplingRatioText;
63  
64      @Column(name = "individual_count")
65      private Integer individualCount;
66  
67      @Column(length = IDataEntity.LENGTH_COMMENTS)
68      private String comments;
69  
70      @ManyToOne(fetch = FetchType.LAZY)
71      @JoinColumn(name = "taxon_group_fk")
72      private TaxonGroup taxonGroup;
73  
74      @ManyToOne(fetch = FetchType.LAZY)
75      @JoinColumn(name = "reference_taxon_fk")
76      private ReferenceTaxon referenceTaxon;
77  
78      /* -- quality insurance -- */
79  
80      @Column(name = "update_date")
81      @Temporal(TemporalType.TIMESTAMP)
82      private Date updateDate;
83  
84      @ManyToOne(fetch = FetchType.LAZY)
85      @JoinColumn(name = "recorder_department_fk", nullable = false)
86      private Department recorderDepartment;
87  
88      @Column(name="control_date")
89      @Temporal(TemporalType.TIMESTAMP)
90      private Date controlDate;
91  
92      @Column(name="qualification_date")
93      @Temporal(TemporalType.TIMESTAMP)
94      private Date qualificationDate;
95  
96      @Column(name="qualification_comments", length = LENGTH_COMMENTS)
97      private String qualificationComments;
98  
99      @ManyToOne(fetch = FetchType.LAZY, targetEntity = QualityFlag.class)
100     @JoinColumn(name = "quality_flag_fk", nullable = false)
101     private QualityFlag qualityFlag;
102 
103     /* -- Tree link -- */
104 
105     @OneToMany(fetch = FetchType.LAZY, targetEntity = Batch.class, mappedBy = Fields.PARENT)
106     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
107     private List<Batch> children = new ArrayList<>();
108 
109     @ManyToOne(fetch = FetchType.LAZY)
110     @JoinColumn(name = "parent_batch_fk")
111     private Batch parent;
112 
113     @Column(name = "hash")
114     private Integer hash;
115 
116     /* -- measurements -- */
117 
118     @OneToMany(fetch = FetchType.LAZY, targetEntity = BatchSortingMeasurement.class, mappedBy = BatchSortingMeasurement.Fields.BATCH)
119     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
120     private List<BatchSortingMeasurement> sortingMeasurements = new ArrayList<>();
121 
122     @OneToMany(fetch = FetchType.LAZY, targetEntity = BatchQuantificationMeasurement.class, mappedBy = BatchQuantificationMeasurement.Fields.BATCH)
123     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
124     private List<BatchQuantificationMeasurement> quantificationMeasurements = new ArrayList<>();
125 
126     /* -- parent entity -- */
127 
128     @ManyToOne(fetch = FetchType.LAZY, targetEntity = Operation.class)
129     @JoinColumn(name = "operation_fk", nullable = false)
130     private Operation operation;
131 
132     public String toString() {
133         return String.format("Batch{id=%s,label=%s}", id, label);
134     }
135 }