View Javadoc

1   /*
2    * Copyright 2015 Data Archiving and Networked Services (an institute of
3    * Koninklijke Nederlandse Akademie van Wetenschappen), King's College London,
4    * Georg-August-Universitaet Goettingen Stiftung Oeffentlichen Rechts
5    *
6    * Licensed under the EUPL, Version 1.1 or – as soon they will be approved by
7    * the European Commission - subsequent versions of the EUPL (the "Licence");
8    * You may not use this work except in compliance with the Licence.
9    * You may obtain a copy of the Licence at:
10   *
11   * https://joinup.ec.europa.eu/software/page/eupl
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the Licence is distributed on an "AS IS" basis,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the Licence for the specific language governing
17   * permissions and limitations under the Licence.
18   */
19  
20  package eu.ehri.project.models.events;
21  
22  import com.tinkerpop.blueprints.Vertex;
23  import com.tinkerpop.frames.Adjacency;
24  import com.tinkerpop.frames.Property;
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.EntityClass;
30  import eu.ehri.project.models.annotations.EntityType;
31  import eu.ehri.project.models.annotations.Mandatory;
32  import eu.ehri.project.models.base.Entity;
33  import eu.ehri.project.models.utils.JavaHandlerUtils;
34  
35  /**
36   * Class representing the system event queue node, of which
37   * there Will Be Only One.
38   */
39  @EntityType(EntityClass.SYSTEM)
40  public interface SystemEventQueue extends Entity {
41  
42      String STREAM_START = Ontology.ACTIONER_HAS_LIFECYCLE_ACTION + "Stream";
43  
44      /**
45       * Fetch the time stamp of the queue initialisation.
46       *
47       * @return a UTF timestamp string
48       */
49      @Mandatory
50      @Property(Ontology.EVENT_TIMESTAMP)
51      String getTimestamp();
52  
53      /**
54       * Fetch the latest global event.
55       *
56       * @return a system event frame
57       */
58      @Adjacency(label = STREAM_START)
59      SystemEvent getLatestEvent();
60  
61      /**
62       * Get a stream of system events, latest first.
63       *
64       * @return an iterable of event frames
65       */
66      @JavaHandler
67      Iterable<SystemEvent> getSystemEvents();
68  
69      abstract class Impl implements JavaHandlerContext<Vertex>, SystemEventQueue {
70          public Iterable<SystemEvent> getSystemEvents() {
71              Pipeline<Vertex,Vertex> otherPipe = gremlin().as("n")
72                      .out(Ontology.ACTIONER_HAS_LIFECYCLE_ACTION)
73                      .loop("n", JavaHandlerUtils.noopLoopFunc, JavaHandlerUtils.noopLoopFunc);
74              return frameVertices(gremlin()
75                      .out(STREAM_START).cast(Vertex.class)
76                      .copySplit(gremlin(), otherPipe)
77                      .exhaustMerge().cast(Vertex.class));
78          }
79      }
80  }