View Javadoc
1   package net.sumaris.core.model.referential.gear;
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.Strategy;
28  import net.sumaris.core.model.referential.IItemReferentialEntity;
29  import net.sumaris.core.model.referential.Status;
30  import org.hibernate.annotations.Cascade;
31  
32  import javax.persistence.*;
33  import java.util.Date;
34  import java.util.List;
35  
36  @Data
37  @FieldNameConstants
38  @Entity
39  @Table(name = "gear")
40  @Cacheable
41  public class Gear implements IItemReferentialEntity {
42  
43      @Id
44      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "GEAR_SEQ")
45      @SequenceGenerator(name = "GEAR_SEQ", sequenceName="GEAR_SEQ")
46      private Integer id;
47  
48      @ManyToOne(fetch = FetchType.LAZY)
49      @JoinColumn(name = "status_fk", nullable = false)
50      private Status status;
51  
52      @Column(name = "creation_date", nullable = false)
53      @Temporal(TemporalType.TIMESTAMP)
54      private Date creationDate;
55  
56      @Column(name = "update_date")
57      @Temporal(TemporalType.TIMESTAMP)
58      private Date updateDate;
59  
60      @Column(nullable = false, length = LENGTH_LABEL)
61      private String label;
62  
63      @Column(nullable = false, length = LENGTH_NAME)
64      private String name;
65  
66      private String description;
67  
68      @Column(length = LENGTH_COMMENTS)
69      private String comments;
70  
71      /**
72       * Indique si l'engin est actif ou passif :<ul>
73       *     <li>Actif (=vrai) : l'engin se déplace pour capturer l'espèce recherchée.</li>
74       *     <li>Passif (=faux) : l'engin attend que la cible se prenne dedans.</li>
75       * </ul>
76       */
77      @Column(name = "is_active")
78      private Boolean isActive;
79  
80      /**
81       * Indique si le type d'engin est trainant ou dormant.<br/>
82       * Actuellement, isTowed (à défaut d'autre champ libre) a été rempli pour  permettre son utilisation dans Allegro avec le sens suivant : « autorise ou non la  superposition d'opérations de pêche simultanées » :
83       * <ul>
84       *     <li>is_towed=1 : l'opération utilisant cet engin ne peut pas être superposée avec d'autres opérations ayant aussi un engin is_towed=1</li>
85       *     <li>is_towed=0 : superposition avec d'autres opérations possibles (quelques soit la valeur is_towed de leur engin)</li>
86       * </ul>
87       */
88      @Column(name = "is_towed")
89      private Boolean isTowed;
90  
91      @ManyToOne(fetch = FetchType.LAZY)
92      @JoinColumn(name = "gear_classification_fk", nullable = false)
93      private GearClassification gearClassification;
94  
95      @ManyToOne(fetch = FetchType.LAZY)
96      @JoinColumn(name = "parent_gear_fk")
97      private Gear parent;
98  
99      @OneToMany(fetch = FetchType.LAZY, targetEntity = Gear.class, mappedBy = Gear.Fields.PARENT)
100     @Cascade(org.hibernate.annotations.CascadeType.DELETE)
101     private List<Gear> children;
102 
103     @ManyToMany(fetch = FetchType.LAZY, targetEntity = Strategy.class, mappedBy = Strategy.Fields.GEARS)
104     @Cascade(org.hibernate.annotations.CascadeType.DETACH)
105     private List<Strategy> strategies;
106 //
107 //    public String toString() {
108 //        return new StringBuilder().append(super.toString())
109 //                .append(",id=").append(this.id)
110 //                .append(",label=").append(this.label)
111 //                .toString();
112 //    }
113 }