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