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 java.util.UUID;
8 import lombok.Data;
9 import lombok.NoArgsConstructor;
10 import lombok.ToString;
11 import org.neo4j.ogm.annotation.GeneratedValue;
12 import org.neo4j.ogm.annotation.Id;
13 import org.neo4j.ogm.annotation.NodeEntity;
14 import org.neo4j.ogm.annotation.Relationship;
15 import org.neo4j.ogm.annotation.typeconversion.Convert;
16 import org.neo4j.ogm.annotation.typeconversion.DateLong;
17 import org.neo4j.ogm.id.UuidStrategy;
18 import org.neo4j.ogm.typeconversion.UuidStringConverter;
19
20 @NodeEntity
21 @Data
22 @NoArgsConstructor
23 public class Version implements HasId {
24
25 @Id
26 @GeneratedValue(strategy = UuidStrategy.class)
27 @Convert(UuidStringConverter.class)
28 private UUID uid;
29
30 private String name;
31
32 private String description;
33
34 @DateLong
35 private Date createdAt;
36
37 @ToString.Exclude
38 @Relationship(type = Constants.CREATED_BY)
39 private User createdBy;
40
41 @Relationship(type = Constants.HAS_PREDECESSOR)
42 private Version predecessor;
43
44 public Version(String name, String description, Date createdAt, User createdBy, Version predecessor) {
45 this.name = name;
46 this.description = description;
47 this.createdAt = createdAt;
48 this.createdBy = createdBy;
49 this.predecessor = predecessor;
50 }
51
52 public Version(String name, String description, Date createdAt, User createdBy) {
53 this.name = name;
54 this.description = description;
55 this.createdAt = createdAt;
56 this.createdBy = createdBy;
57 }
58
59
60
61
62
63
64 public Version(UUID uid) {
65 this.uid = uid;
66 }
67
68 @Override
69 public String getUniqueId() {
70 return uid.toString();
71 }
72
73 @Override
74 public int hashCode() {
75 final int prime = 31;
76 int result = 1;
77 result = prime * result + Objects.hash(createdAt, uid, name, description);
78 result = prime * result + HasId.hashcodeHelper(createdBy);
79 result = prime * result + HasId.hashcodeHelper(predecessor);
80 return result;
81 }
82
83 @Override
84 public boolean equals(Object obj) {
85 if (this == obj) return true;
86 if (!(obj instanceof Version)) return false;
87 Version other = (Version) obj;
88 return (
89 Objects.equals(createdAt, other.createdAt) &&
90 HasId.equalsHelper(createdBy, other.createdBy) &&
91 Objects.equals(description, other.description) &&
92 Objects.equals(uid, other.uid) &&
93 HasId.equalsHelper(predecessor, other.predecessor) &&
94 Objects.equals(name, other.name)
95 );
96 }
97 }