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;
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 com.tinkerpop.pipes.util.Pipeline;
28 import eu.ehri.project.definitions.Ontology;
29 import eu.ehri.project.models.annotations.EntityType;
30 import eu.ehri.project.models.annotations.Fetch;
31 import eu.ehri.project.models.annotations.Mandatory;
32 import eu.ehri.project.models.annotations.Meta;
33 import eu.ehri.project.models.base.Annotatable;
34 import eu.ehri.project.models.base.Described;
35 import eu.ehri.project.models.base.ItemHolder;
36 import eu.ehri.project.models.base.Versioned;
37 import eu.ehri.project.models.base.Watchable;
38 import eu.ehri.project.models.utils.JavaHandlerUtils;
39
40
41
42
43
44
45 @EntityType(EntityClass.REPOSITORY)
46 public interface Repository extends Described, ItemHolder, Watchable, Versioned, Annotatable {
47
48
49
50
51
52
53
54 @Meta(CHILD_COUNT)
55 @JavaHandler
56 int getChildCount();
57
58
59
60
61
62
63
64 @Adjacency(label = Ontology.DOC_HELD_BY_REPOSITORY, direction = Direction.IN)
65 Iterable<DocumentaryUnit> getTopLevelDocumentaryUnits();
66
67
68
69
70
71
72
73 @JavaHandler
74 Iterable<DocumentaryUnit> getAllDocumentaryUnits();
75
76
77
78
79
80
81
82 @JavaHandler
83 void addTopLevelDocumentaryUnit(DocumentaryUnit unit);
84
85
86
87
88
89
90 @Mandatory
91 @Fetch(Ontology.REPOSITORY_HAS_COUNTRY)
92 @Adjacency(label = Ontology.REPOSITORY_HAS_COUNTRY, direction = Direction.OUT)
93 Country getCountry();
94
95
96
97
98
99
100 @JavaHandler
101 void setCountry(Country country);
102
103
104
105
106 abstract class Impl implements JavaHandlerContext<Vertex>, Repository {
107
108 public int getChildCount() {
109 return Math.toIntExact(gremlin().inE(Ontology.DOC_HELD_BY_REPOSITORY).count());
110 }
111
112 public void addTopLevelDocumentaryUnit(DocumentaryUnit unit) {
113 JavaHandlerUtils.addSingleRelationship(unit.asVertex(), it(),
114 Ontology.DOC_HELD_BY_REPOSITORY);
115 }
116
117 public void setCountry(Country country) {
118 country.addRepository(frame(it(), Repository.class));
119 }
120
121 public Iterable<DocumentaryUnit> getAllDocumentaryUnits() {
122 Pipeline<Vertex, Vertex> otherPipe = gremlin().as("n").in(Ontology.DOC_IS_CHILD_OF)
123 .loop("n", JavaHandlerUtils.noopLoopFunc, JavaHandlerUtils.noopLoopFunc);
124
125 return frameVertices(gremlin().in(Ontology.DOC_HELD_BY_REPOSITORY)
126 .cast(Vertex.class).copySplit(gremlin(), otherPipe)
127 .fairMerge().cast(Vertex.class));
128 }
129 }
130 }