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.events;
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 com.tinkerpop.pipes.util.Pipeline;
29 import eu.ehri.project.definitions.Ontology;
30 import eu.ehri.project.models.EntityClass;
31 import eu.ehri.project.models.annotations.EntityType;
32 import eu.ehri.project.models.annotations.Fetch;
33 import eu.ehri.project.models.annotations.Mandatory;
34 import eu.ehri.project.models.base.Accessible;
35 import eu.ehri.project.models.utils.JavaHandlerUtils;
36
37
38
39
40
41 @EntityType(EntityClass.VERSION)
42 public interface Version extends Accessible {
43
44
45
46
47
48
49 @Mandatory
50 @Property(Ontology.VERSION_ENTITY_CLASS)
51 String getEntityType();
52
53
54
55
56
57
58 @Mandatory
59 @Property(Ontology.VERSION_ENTITY_ID)
60 String getEntityId();
61
62
63
64
65
66
67 @Property(Ontology.VERSION_ENTITY_DATA)
68 String getEntityData();
69
70
71
72
73
74
75 @Fetch(value = Ontology.VERSION_HAS_EVENT, ifLevel = 0)
76 @Adjacency(label = Ontology.VERSION_HAS_EVENT, direction = Direction.OUT)
77 SystemEvent getTriggeringEvent();
78
79
80
81
82
83
84
85 @JavaHandler
86 Accessible getEntity();
87
88
89
90
91 abstract class Impl implements JavaHandlerContext<Vertex>, Version {
92 public Accessible getEntity() {
93 Pipeline<Vertex,Vertex> out = gremlin().as("n").in(Ontology.ENTITY_HAS_PRIOR_VERSION)
94 .loop("n", JavaHandlerUtils.noopLoopFunc,
95 vertexLoopBundle -> !vertexLoopBundle.getObject().getVertices(Direction.IN,
96 Ontology.ENTITY_HAS_PRIOR_VERSION).iterator().hasNext());
97 return (Accessible)(out.hasNext() ? frame(out.next()) : null);
98 }
99 }
100 }