1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package eu.ehri.project.models.base;
21
22 import com.tinkerpop.blueprints.Direction;
23 import com.tinkerpop.blueprints.Vertex;
24 import com.tinkerpop.frames.Adjacency;
25 import com.tinkerpop.frames.modules.javahandler.JavaHandler;
26 import com.tinkerpop.frames.modules.javahandler.JavaHandlerContext;
27 import eu.ehri.project.definitions.Ontology;
28 import eu.ehri.project.models.Group;
29 import eu.ehri.project.models.PermissionGrant;
30 import eu.ehri.project.models.utils.JavaHandlerUtils;
31
32
33
34
35
36
37 public interface Accessor extends Identifiable {
38
39 @JavaHandler
40 boolean isAdmin();
41
42 @JavaHandler
43 boolean isAnonymous();
44
45 @Adjacency(label = Ontology.ACCESSOR_BELONGS_TO_GROUP)
46 Iterable<Accessor> getParents();
47
48 @JavaHandler
49 Iterable<Accessor> getAllParents();
50
51 @Adjacency(label = Ontology.PERMISSION_GRANT_HAS_SUBJECT, direction=Direction.IN)
52 Iterable<PermissionGrant> getPermissionGrants();
53
54 @Adjacency(label = Ontology.PERMISSION_GRANT_HAS_SUBJECT, direction=Direction.IN)
55 void addPermissionGrant(PermissionGrant grant);
56
57 abstract class Impl implements JavaHandlerContext<Vertex>, Accessor {
58
59 public boolean isAdmin() {
60 return it().getProperty(Ontology.IDENTIFIER_KEY).equals(Group.ADMIN_GROUP_IDENTIFIER);
61 }
62
63 public boolean isAnonymous() {
64 return false;
65 }
66
67 public Iterable<Accessor> getAllParents() {
68 return frameVertices(gremlin().as("n")
69 .out(Ontology.ACCESSOR_BELONGS_TO_GROUP)
70 .loop("n", JavaHandlerUtils.defaultMaxLoops, JavaHandlerUtils.noopLoopFunc));
71 }
72 }
73 }