View Javadoc
1   package de.dlr.shepard.context.version.entities;
2   
3   import de.dlr.shepard.auth.users.entities.User;
4   import de.dlr.shepard.common.util.Constants;
5   import de.dlr.shepard.common.util.HasId;
6   import java.util.Date;
7   import java.util.Objects;
8   import java.util.UUID;
9   import lombok.Data;
10  import lombok.NoArgsConstructor;
11  import lombok.ToString;
12  import org.neo4j.ogm.annotation.GeneratedValue;
13  import org.neo4j.ogm.annotation.Id;
14  import org.neo4j.ogm.annotation.NodeEntity;
15  import org.neo4j.ogm.annotation.Relationship;
16  import org.neo4j.ogm.annotation.typeconversion.Convert;
17  import org.neo4j.ogm.annotation.typeconversion.DateLong;
18  import org.neo4j.ogm.id.UuidStrategy;
19  import org.neo4j.ogm.typeconversion.UuidStringConverter;
20  
21  @NodeEntity
22  @Data
23  @NoArgsConstructor
24  public class Version implements HasId {
25  
26    @Id
27    @GeneratedValue(strategy = UuidStrategy.class)
28    @Convert(UuidStringConverter.class)
29    private UUID uid;
30  
31    private String name;
32  
33    private String description;
34  
35    private boolean isHEADVersion;
36  
37    @DateLong
38    private Date createdAt;
39  
40    @ToString.Exclude
41    @Relationship(type = Constants.CREATED_BY)
42    private User createdBy;
43  
44    @Relationship(type = Constants.HAS_PREDECESSOR)
45    private Version predecessor;
46  
47    /**
48     * For testing purposes only
49     *
50     * @param username identifies the user
51     */
52    public Version(String name) {
53      this.name = name;
54    }
55  
56    public Version(String name, String description, Date createdAt, User createdBy, Version predecessor) {
57      this.name = name;
58      this.description = description;
59      this.createdAt = createdAt;
60      this.createdBy = createdBy;
61      this.predecessor = predecessor;
62    }
63  
64    public Version(String name, String description, Date createdAt, User createdBy) {
65      this.name = name;
66      this.description = description;
67      this.createdAt = createdAt;
68      this.createdBy = createdBy;
69      this.isHEADVersion = true;
70    }
71  
72    /**
73     * For testing purposes only
74     *
75     * @param uid identifies the entity
76     */
77    public Version(UUID uid) {
78      this.uid = uid;
79    }
80  
81    @Override
82    public String getUniqueId() {
83      return uid.toString();
84    }
85  
86    @Override
87    public int hashCode() {
88      final int prime = 31;
89      int result = 1;
90      result = prime * result + Objects.hash(createdAt, uid, name, description, isHEADVersion);
91      result = prime * result + HasId.hashcodeHelper(createdBy);
92      result = prime * result + HasId.hashcodeHelper(predecessor);
93      return result;
94    }
95  
96    @Override
97    public boolean equals(Object obj) {
98      if (this == obj) return true;
99      if (!(obj instanceof Version)) return false;
100     Version other = (Version) obj;
101     return (
102       Objects.equals(createdAt, other.createdAt) &&
103       Objects.equals(isHEADVersion, other.isHEADVersion) &&
104       HasId.equalsHelper(createdBy, other.createdBy) &&
105       Objects.equals(description, other.description) &&
106       Objects.equals(uid, other.uid) &&
107       HasId.equalsHelper(predecessor, other.predecessor) &&
108       Objects.equals(name, other.name)
109     );
110   }
111 }