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.GeneratedValue;
8 import org.neo4j.ogm.annotation.Id;
9 import org.neo4j.ogm.annotation.NodeEntity;
10 import org.neo4j.ogm.annotation.Relationship;
11
12 import de.dlr.shepard.util.Constants;
13 import de.dlr.shepard.util.HasId;
14 import de.dlr.shepard.util.PermissionType;
15 import lombok.Data;
16 import lombok.NoArgsConstructor;
17 import lombok.ToString;
18
19 @NodeEntity
20 @Data
21 @NoArgsConstructor
22 public class Permissions implements HasId {
23
24 @Id
25 @GeneratedValue
26 private Long id;
27
28 @Relationship(type = Constants.HAS_PERMISSIONS, direction = Relationship.INCOMING)
29 private BasicEntity entity;
30
31 @Relationship(type = Constants.OWNED_BY, direction = Relationship.OUTGOING)
32 private User owner;
33
34 private PermissionType permissionType;
35
36 @ToString.Exclude
37 @Relationship(type = Constants.READABLE_BY, direction = Relationship.OUTGOING)
38 private List<User> reader = new ArrayList<>();
39
40 @ToString.Exclude
41 @Relationship(type = Constants.WRITEABLE_BY, direction = Relationship.OUTGOING)
42 private List<User> writer = new ArrayList<>();
43
44 @ToString.Exclude
45 @Relationship(type = Constants.READABLE_BY_GROUP, direction = Relationship.OUTGOING)
46 private List<UserGroup> readerGroups = new ArrayList<>();
47
48 @ToString.Exclude
49 @Relationship(type = Constants.WRITEABLE_BY_GROUP, direction = Relationship.OUTGOING)
50 private List<UserGroup> writerGroups = new ArrayList<>();
51
52 @ToString.Exclude
53 @Relationship(type = Constants.MANAGEABLE_BY, direction = Relationship.OUTGOING)
54 private List<User> manager = new ArrayList<>();
55
56
57
58
59
60
61 public Permissions(long id) {
62 this.id = id;
63 }
64
65 public Permissions(BasicEntity entity, User owner, PermissionType permissionType) {
66 this.entity = entity;
67 this.owner = owner;
68 this.permissionType = permissionType;
69 }
70
71 public Permissions(User owner, List<User> reader, List<User> writer, List<UserGroup> readerGroups,
72 List<UserGroup> writerGroups, List<User> manager, PermissionType permissionType) {
73 this.owner = owner;
74 this.reader = reader;
75 this.writer = writer;
76 this.writerGroups = writerGroups;
77 this.readerGroups = readerGroups;
78 this.manager = manager;
79 this.permissionType = permissionType;
80 }
81
82 @Override
83 public int hashCode() {
84 final int prime = 31;
85 int result = 1;
86 result = prime * result + Objects.hash(id, permissionType, readerGroups, writerGroups);
87 result = prime * result + HasId.hashcodeHelper(entity);
88 result = prime * result + HasId.hashcodeHelper(owner);
89 result = prime * result + HasId.hashcodeHelper(reader);
90 result = prime * result + HasId.hashcodeHelper(writer);
91 result = prime * result + HasId.hashcodeHelper(manager);
92 return result;
93 }
94
95 @Override
96 public boolean equals(Object obj) {
97 if (this == obj)
98 return true;
99 if (!(obj instanceof Permissions))
100 return false;
101 Permissions other = (Permissions) obj;
102 return Objects.equals(id, other.id) && Objects.equals(permissionType, other.permissionType)
103 && Objects.equals(readerGroups, other.readerGroups) && Objects.equals(writerGroups, other.writerGroups)
104 && HasId.equalsHelper(entity, other.entity) && HasId.equalsHelper(owner, other.owner)
105 && HasId.equalsHelper(reader, other.reader) && HasId.equalsHelper(writer, other.writer)
106 && HasId.equalsHelper(manager, other.manager);
107 }
108
109 @Override
110 public String getUniqueId() {
111 return id.toString();
112 }
113
114 }