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.cvoc;
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.EntityClass;
29 import eu.ehri.project.models.annotations.EntityType;
30 import eu.ehri.project.models.annotations.Fetch;
31 import eu.ehri.project.models.annotations.InverseOf;
32 import eu.ehri.project.models.annotations.Mandatory;
33 import eu.ehri.project.models.annotations.Meta;
34 import eu.ehri.project.models.base.Described;
35 import eu.ehri.project.models.base.ItemHolder;
36 import eu.ehri.project.models.utils.JavaHandlerUtils;
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 @EntityType(EntityClass.CVOC_CONCEPT)
52 public interface Concept extends Described, AuthoritativeItem, ItemHolder {
53
54
55 @Mandatory
56 @Adjacency(label = Ontology.ITEM_IN_AUTHORITATIVE_SET)
57 Vocabulary getVocabulary();
58
59 @Adjacency(label = Ontology.ITEM_IN_AUTHORITATIVE_SET)
60 void setVocabulary(Vocabulary vocabulary);
61
62 @Meta(CHILD_COUNT)
63 @JavaHandler
64 int getChildCount();
65
66
67
68
69 @Fetch(Ontology.CONCEPT_HAS_BROADER)
70 @Adjacency(label = Ontology.CONCEPT_HAS_NARROWER, direction=Direction.IN)
71 Iterable<Concept> getBroaderConcepts();
72
73
74 @Adjacency(label = Ontology.CONCEPT_HAS_NARROWER, direction = Direction.OUT)
75 @InverseOf(Ontology.CONCEPT_HAS_BROADER)
76 Iterable<Concept> getNarrowerConcepts();
77
78 @JavaHandler
79 void addNarrowerConcept(Concept concept);
80
81 @JavaHandler
82 void addBroaderConcept(Concept concept);
83
84 @JavaHandler
85 void removeNarrowerConcept(Concept concept);
86
87 @JavaHandler
88 void removeBroaderConcept(Concept concept);
89
90
91 @Adjacency(label = Ontology.CONCEPT_HAS_RELATED)
92 Iterable<Concept> getRelatedConcepts();
93
94 @JavaHandler
95 void addRelatedConcept(Concept concept);
96
97 @Adjacency(label = Ontology.CONCEPT_HAS_RELATED)
98 void removeRelatedConcept(Concept concept);
99
100
101 @Adjacency(label = Ontology.CONCEPT_HAS_RELATED, direction=Direction.IN)
102 Iterable<Concept> getRelatedByConcepts();
103
104
105
106
107 abstract class Impl implements JavaHandlerContext<Vertex>, Concept {
108
109 @Override
110 public int getChildCount() {
111 return Math.toIntExact(gremlin().outE(Ontology.CONCEPT_HAS_NARROWER).count());
112 }
113
114 @Override
115 public void addRelatedConcept(Concept related) {
116 JavaHandlerUtils.addUniqueRelationship(it(),
117 related.asVertex(), Ontology.CONCEPT_HAS_RELATED);
118 }
119
120 @Override
121 public void addNarrowerConcept(Concept concept) {
122 if (!concept.asVertex().equals(it())) {
123 JavaHandlerUtils.addUniqueRelationship(it(),
124 concept.asVertex(), Ontology.CONCEPT_HAS_NARROWER);
125 }
126 }
127
128 @Override
129 public void addBroaderConcept(Concept concept) {
130 if (!concept.asVertex().equals(it())) {
131 JavaHandlerUtils.addUniqueRelationship(concept.asVertex(),
132 it(), Ontology.CONCEPT_HAS_NARROWER);
133 }
134 }
135
136 @Override
137 public void removeNarrowerConcept(Concept concept) {
138 JavaHandlerUtils.removeAllRelationships(it(), concept.asVertex(),
139 Ontology.CONCEPT_HAS_NARROWER);
140 }
141
142 @Override
143 public void removeBroaderConcept(Concept concept) {
144 JavaHandlerUtils.removeAllRelationships(concept.asVertex(), it(),
145 Ontology.CONCEPT_HAS_NARROWER);
146 }
147 }
148 }