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.ArrayList;
6 import java.util.List;
7 import java.util.Objects;
8 import lombok.Data;
9 import lombok.NoArgsConstructor;
10 import lombok.ToString;
11 import org.neo4j.ogm.annotation.Id;
12 import org.neo4j.ogm.annotation.NodeEntity;
13 import org.neo4j.ogm.annotation.Relationship;
14 import org.neo4j.ogm.annotation.Relationship.Direction;
15
16 @NodeEntity
17 @Data
18 @NoArgsConstructor
19 public class User implements HasId {
20
21 @Id
22 private String username;
23
24 private String firstName;
25
26 private String lastName;
27
28 private String email;
29
30 @ToString.Exclude
31 @Relationship(type = Constants.SUBSCRIBED_BY, direction = Direction.INCOMING)
32 private List<Subscription> subscriptions = new ArrayList<>();
33
34 @ToString.Exclude
35 @Relationship(type = Constants.BELONGS_TO, direction = Direction.INCOMING)
36 private List<ApiKey> apiKeys = new ArrayList<>();
37
38
39
40
41
42
43 public User(String username) {
44 this.username = username;
45 }
46
47
48
49
50
51
52
53
54
55 public User(String username, String firstName, String lastName, String email) {
56 this.username = username;
57 this.firstName = firstName;
58 this.lastName = lastName;
59 this.email = email;
60 }
61
62 @Override
63 public int hashCode() {
64 final int prime = 31;
65 int result = 1;
66 result = prime * result + Objects.hash(email, firstName, lastName, username);
67 result = prime * result + HasId.hashcodeHelper(apiKeys);
68 result = prime * result + HasId.hashcodeHelper(subscriptions);
69 return result;
70 }
71
72 @Override
73 public boolean equals(Object obj) {
74 if (this == obj) return true;
75 if (!(obj instanceof User)) return false;
76 User other = (User) obj;
77 return (
78 HasId.equalsHelper(apiKeys, other.apiKeys) &&
79 HasId.equalsHelper(subscriptions, other.subscriptions) &&
80 Objects.equals(email, other.email) &&
81 Objects.equals(firstName, other.firstName) &&
82 Objects.equals(lastName, other.lastName) &&
83 Objects.equals(username, other.username)
84 );
85 }
86
87 @Override
88 public String getUniqueId() {
89 return username;
90 }
91 }