1 package de.dlr.shepard.neo4Core.entities;
2
3 import de.dlr.shepard.util.Constants;
4 import de.dlr.shepard.util.HasId;
5 import java.util.Date;
6 import java.util.Objects;
7 import lombok.Getter;
8 import lombok.NoArgsConstructor;
9 import lombok.Setter;
10 import lombok.ToString;
11 import org.neo4j.ogm.annotation.GeneratedValue;
12 import org.neo4j.ogm.annotation.Id;
13 import org.neo4j.ogm.annotation.Index;
14 import org.neo4j.ogm.annotation.Relationship;
15 import org.neo4j.ogm.annotation.typeconversion.DateLong;
16
17
18
19
20
21
22
23 @Getter
24 @Setter
25 @ToString
26 @NoArgsConstructor
27 public abstract class AbstractEntity implements HasId {
28
29 @Id
30 @GeneratedValue
31 protected Long id;
32
33 @Index
34 protected boolean deleted = false;
35
36 @DateLong
37 protected Date createdAt;
38
39 @ToString.Exclude
40 @Relationship(type = Constants.CREATED_BY)
41 protected User createdBy;
42
43 @DateLong
44 protected Date updatedAt;
45
46 @ToString.Exclude
47 @Relationship(type = Constants.UPDATED_BY)
48 protected User updatedBy;
49
50
51
52
53
54
55 public AbstractEntity(long id) {
56 this.id = id;
57 }
58
59 @Override
60 public int hashCode() {
61 return Objects.hash(this.getClass().getName(), id);
62 }
63
64 @Override
65 public boolean equals(Object o) {
66 if (this == o) return true;
67 if (o == null) return false;
68 if (this.getClass() != o.getClass()) return false;
69 AbstractEntity entity = (AbstractEntity) o;
70 return (
71 id.equals(entity.id) &&
72 deleted == entity.deleted &&
73 Objects.equals(createdAt, entity.createdAt) &&
74 Objects.equals(createdBy, entity.createdBy) &&
75 Objects.equals(updatedAt, entity.updatedAt) &&
76 Objects.equals(updatedBy, entity.updatedBy)
77 );
78 }
79
80 @Override
81 public String getUniqueId() {
82 return id.toString();
83 }
84 }