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.google.common.collect.Lists;
23 import com.tinkerpop.blueprints.Direction;
24 import com.tinkerpop.blueprints.Vertex;
25 import com.tinkerpop.frames.Adjacency;
26 import com.tinkerpop.frames.modules.javahandler.JavaHandler;
27 import com.tinkerpop.frames.modules.javahandler.JavaHandlerContext;
28 import eu.ehri.project.definitions.Ontology;
29 import eu.ehri.project.models.PermissionGrant;
30 import eu.ehri.project.models.utils.JavaHandlerUtils;
31
32 import java.util.Collection;
33 import java.util.List;
34
35
36
37
38 public interface PermissionScope extends Identifiable {
39
40
41
42
43
44
45 @Adjacency(label = Ontology.PERMISSION_GRANT_HAS_SCOPE, direction = Direction.IN)
46 Iterable<PermissionGrant> getPermissionGrants();
47
48
49
50
51
52
53
54 @JavaHandler
55 Iterable<PermissionScope> getPermissionScopes();
56
57
58
59
60
61
62 @Adjacency(label = Ontology.HAS_PERMISSION_SCOPE, direction = Direction.IN)
63 Iterable<Accessible> getContainedItems();
64
65
66
67
68
69
70
71 @JavaHandler
72 Iterable<Accessible> getAllContainedItems();
73
74
75
76
77
78 @JavaHandler
79 Collection<String> idPath();
80
81 abstract class Impl implements JavaHandlerContext<Vertex>, PermissionScope {
82 public Iterable<Accessible> getAllContainedItems() {
83 return frameVertices(gremlin().as("n")
84 .in(Ontology.HAS_PERMISSION_SCOPE)
85 .loop("n", JavaHandlerUtils.noopLoopFunc, JavaHandlerUtils.noopLoopFunc));
86 }
87
88 public Iterable<PermissionScope> getPermissionScopes() {
89 return frameVertices(gremlin().as("n")
90 .out(Ontology.HAS_PERMISSION_SCOPE)
91 .loop("n", JavaHandlerUtils.defaultMaxLoops, JavaHandlerUtils.noopLoopFunc));
92 }
93
94 public Collection<String> idPath() {
95
96 List<String> pIds = Lists.reverse(gremlin().as("n")
97 .out(Ontology.HAS_PERMISSION_SCOPE)
98 .loop("n", JavaHandlerUtils.defaultMaxLoops, JavaHandlerUtils.noopLoopFunc)
99 .transform(vertex -> vertex.<String>getProperty(Ontology.IDENTIFIER_KEY))
100 .toList());
101 pIds.add(it().<String>getProperty(Ontology.IDENTIFIER_KEY));
102 return pIds;
103 }
104 }
105 }