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.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.base.Accessible;
31  import eu.ehri.project.models.base.ItemHolder;
32  import eu.ehri.project.models.base.Named;
33  import eu.ehri.project.models.base.PermissionScope;
34  import eu.ehri.project.models.utils.JavaHandlerUtils;
35  
36  /**
37   * A frame class representing a item that holds other
38   * <i>authoritative</i> items, such as concepts and
39   * historical agents.
40   */
41  @EntityType(EntityClass.AUTHORITATIVE_SET)
42  public interface AuthoritativeSet extends Accessible,
43          PermissionScope, ItemHolder, Named {
44  
45      /**
46       * Fetch all items within this set.
47       *
48       * @return an iterable of authoritative items
49       */
50      @Adjacency(label = Ontology.ITEM_IN_AUTHORITATIVE_SET, direction = Direction.IN)
51      Iterable<AuthoritativeItem> getAuthoritativeItems();
52  
53      /**
54       * Add an authoritative item to this set.
55       *
56       * @param item an authoritative item frame
57       */
58      @JavaHandler
59      void addItem(AuthoritativeItem item);
60  
61      /**
62       * Implementation of complex methods.
63       */
64      abstract class Impl implements JavaHandlerContext<Vertex>, AuthoritativeSet {
65  
66          @Override
67          public int getChildCount() {
68              return Math.toIntExact(gremlin().inE(Ontology.ITEM_IN_AUTHORITATIVE_SET).count());
69          }
70  
71          @Override
72          public void addItem(AuthoritativeItem item) {
73              JavaHandlerUtils.addSingleRelationship(item.asVertex(), it(),
74                      Ontology.ITEM_IN_AUTHORITATIVE_SET);
75          }
76      }
77  }