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