View Javadoc
1   package fr.tiogars.chat.domains.taxonomy;
2   
3   import java.time.Instant;
4   
5   import jakarta.persistence.Column;
6   import jakarta.persistence.EntityListeners;
7   import jakarta.persistence.GeneratedValue;
8   import jakarta.persistence.GenerationType;
9   import jakarta.persistence.Id;
10  import jakarta.persistence.MappedSuperclass;
11  import org.springframework.data.annotation.CreatedBy;
12  import org.springframework.data.annotation.CreatedDate;
13  import org.springframework.data.annotation.LastModifiedBy;
14  import org.springframework.data.annotation.LastModifiedDate;
15  import org.springframework.data.jpa.domain.support.AuditingEntityListener;
16  
17  @MappedSuperclass
18  @EntityListeners(AuditingEntityListener.class)
19  public abstract class AuditedTaxonomyEntity {
20      @Id
21      @GeneratedValue(strategy = GenerationType.IDENTITY)
22      private Long id;
23      @Column(nullable = false, unique = true, updatable = false)
24      private String code;
25      @Column(nullable = false)
26      private String label;
27      private String description;
28      @CreatedDate
29      @Column(nullable = false, updatable = false)
30      private Instant createdDate;
31      @LastModifiedDate
32      @Column(nullable = false)
33      private Instant lastModifiedDate;
34      @CreatedBy
35      @Column(nullable = false, updatable = false)
36      private String createdBy;
37      @LastModifiedBy
38      @Column(nullable = false)
39      private String lastModifiedBy;
40  
41      protected AuditedTaxonomyEntity() {
42          // Required by JPA.
43      }
44  
45      protected AuditedTaxonomyEntity(String code, String label, String description) {
46          this.code = code;
47          update(label, description);
48      }
49  
50      public void update(String label, String description) {
51          this.label = label;
52          this.description = description;
53      }
54  
55      public Long getId() {
56          return id;
57      }
58  
59      public String getCode() {
60          return code;
61      }
62  
63      public String getLabel() {
64          return label;
65      }
66  
67      public String getDescription() {
68          return description;
69      }
70  
71      public Instant getCreatedDate() {
72          return createdDate;
73      }
74  
75      public Instant getLastModifiedDate() {
76          return lastModifiedDate;
77      }
78  
79      public String getCreatedBy() {
80          return createdBy;
81      }
82  
83      public String getLastModifiedBy() {
84          return lastModifiedBy;
85      }
86  }