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.Property;
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.annotations.EntityType;
30 import eu.ehri.project.models.annotations.Mandatory;
31 import eu.ehri.project.models.annotations.Meta;
32 import eu.ehri.project.models.base.Annotatable;
33 import eu.ehri.project.models.base.ItemHolder;
34 import eu.ehri.project.models.base.PermissionScope;
35 import eu.ehri.project.models.base.Versioned;
36 import eu.ehri.project.models.utils.JavaHandlerUtils;
37
38
39
40
41
42 @EntityType(EntityClass.COUNTRY)
43 public interface Country extends PermissionScope, ItemHolder, Versioned, Annotatable {
44
45
46
47
48
49
50 @Mandatory
51 @Property(Ontology.IDENTIFIER_KEY)
52 String getCode();
53
54
55
56
57
58
59 @Meta(CHILD_COUNT)
60 @JavaHandler
61 int getChildCount();
62
63
64
65
66
67
68 @Adjacency(label = Ontology.REPOSITORY_HAS_COUNTRY, direction = Direction.IN)
69 Iterable<Repository> getRepositories();
70
71 @JavaHandler
72 Iterable<DocumentaryUnit> getTopLevelDocumentaryUnits();
73
74
75
76
77
78
79 @JavaHandler
80 void addRepository(Repository repository);
81
82
83
84
85 abstract class Impl implements JavaHandlerContext<Vertex>, Country {
86
87 @Override
88 public int getChildCount() {
89 return Math.toIntExact(gremlin().inE(Ontology.REPOSITORY_HAS_COUNTRY).count());
90 }
91
92 @Override
93 public void addRepository(Repository repository) {
94 JavaHandlerUtils.addSingleRelationship(repository.asVertex(), it(),
95 Ontology.REPOSITORY_HAS_COUNTRY);
96 }
97
98 @Override
99 public Iterable<DocumentaryUnit> getTopLevelDocumentaryUnits() {
100 return frameVertices(gremlin().in(Ontology.REPOSITORY_HAS_COUNTRY)
101 .in(Ontology.DOC_HELD_BY_REPOSITORY), DocumentaryUnit.class);
102 }
103 }
104 }