1 package de.dlr.shepard.neo4Core.entities;
2
3 import java.util.ArrayList;
4 import java.util.Date;
5 import java.util.List;
6 import java.util.Objects;
7
8 import org.neo4j.ogm.annotation.GeneratedValue;
9 import org.neo4j.ogm.annotation.Id;
10 import org.neo4j.ogm.annotation.Index;
11 import org.neo4j.ogm.annotation.Relationship;
12 import org.neo4j.ogm.annotation.typeconversion.DateLong;
13
14 import de.dlr.shepard.util.Constants;
15 import de.dlr.shepard.util.HasId;
16 import lombok.Data;
17 import lombok.NoArgsConstructor;
18 import lombok.ToString;
19
20 @Data
21 @NoArgsConstructor
22 public class BasicEntity implements HasId {
23
24 @Id
25 @GeneratedValue
26 private Long id;
27
28 @Index
29 private boolean deleted = false;
30
31 @DateLong
32 private Date createdAt;
33
34 @ToString.Exclude
35 @Relationship(type = Constants.CREATED_BY)
36 private User createdBy;
37
38 @DateLong
39 private Date updatedAt;
40
41 @ToString.Exclude
42 @Relationship(type = Constants.UPDATED_BY)
43 private User updatedBy;
44
45 private String name;
46
47 @ToString.Exclude
48 @Relationship(type = Constants.HAS_ANNOTATION)
49 private List<SemanticAnnotation> annotations = new ArrayList<>();
50
51
52
53
54
55
56 public BasicEntity(long id) {
57 this.id = id;
58 }
59
60 public void addAnnotation(SemanticAnnotation annotation) {
61 annotations.add(annotation);
62 }
63
64 @Override
65 public int hashCode() {
66 final int prime = 31;
67 int result = 1;
68 result = prime * result + Objects.hash(id, deleted, createdAt, updatedAt, name);
69 result = prime * result + HasId.hashcodeHelper(createdBy);
70 result = prime * result + HasId.hashcodeHelper(updatedBy);
71 result = prime * result + HasId.hashcodeHelper(annotations);
72 return result;
73 }
74
75 @Override
76 public boolean equals(Object obj) {
77 if (this == obj)
78 return true;
79 if (!(obj instanceof BasicEntity))
80 return false;
81 BasicEntity other = (BasicEntity) obj;
82 return Objects.equals(id, other.id) && deleted == other.deleted && Objects.equals(createdAt, other.createdAt)
83 && Objects.equals(updatedAt, other.updatedAt) && HasId.equalsHelper(createdBy, other.createdBy)
84 && HasId.equalsHelper(updatedBy, other.updatedBy) && Objects.equals(name, other.name)
85 && HasId.equalsHelper(annotations, other.annotations);
86 }
87
88 @Override
89 public String getUniqueId() {
90 return id.toString();
91 }
92 }