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;
21  
22  import eu.ehri.project.definitions.Entities;
23  import eu.ehri.project.models.base.Entity;
24  import eu.ehri.project.models.cvoc.AuthoritativeSet;
25  import eu.ehri.project.models.cvoc.Concept;
26  import eu.ehri.project.models.cvoc.ConceptDescription;
27  import eu.ehri.project.models.cvoc.Vocabulary;
28  import eu.ehri.project.models.events.EventLink;
29  import eu.ehri.project.models.events.SystemEvent;
30  import eu.ehri.project.models.events.SystemEventQueue;
31  import eu.ehri.project.models.events.Version;
32  import eu.ehri.project.models.idgen.DescriptionIdGenerator;
33  import eu.ehri.project.models.idgen.GenericIdGenerator;
34  import eu.ehri.project.models.idgen.IdGenerator;
35  import eu.ehri.project.models.idgen.IdentifiableEntityIdGenerator;
36  
37  /**
38   * Mapping of Entity type names to Frames interfaces classes and
39   * their associated id generator classes.
40   */
41  public enum EntityClass {
42  
43      DOCUMENTARY_UNIT(Entities.DOCUMENTARY_UNIT, DocumentaryUnit.class, IdentifiableEntityIdGenerator.INSTANCE),
44      REPOSITORY(Entities.REPOSITORY, Repository.class, IdentifiableEntityIdGenerator.INSTANCE),
45      HISTORICAL_AGENT(Entities.HISTORICAL_AGENT, HistoricalAgent.class, IdentifiableEntityIdGenerator.INSTANCE),
46      GROUP(Entities.GROUP, Group.class, IdentifiableEntityIdGenerator.INSTANCE),
47      USER_PROFILE(Entities.USER_PROFILE, UserProfile.class, IdentifiableEntityIdGenerator.INSTANCE),
48      AUTHORITATIVE_SET(Entities.AUTHORITATIVE_SET, AuthoritativeSet.class, IdentifiableEntityIdGenerator.INSTANCE),
49      COUNTRY(Entities.COUNTRY, Country.class, IdentifiableEntityIdGenerator.INSTANCE),
50      CVOC_VOCABULARY(Entities.CVOC_VOCABULARY, Vocabulary.class, IdentifiableEntityIdGenerator.INSTANCE),
51      CVOC_CONCEPT(Entities.CVOC_CONCEPT, Concept.class, IdentifiableEntityIdGenerator.INSTANCE),
52      VIRTUAL_UNIT(Entities.VIRTUAL_UNIT, VirtualUnit.class, IdentifiableEntityIdGenerator.INSTANCE),
53  
54      DOCUMENTARY_UNIT_DESCRIPTION(Entities.DOCUMENTARY_UNIT_DESCRIPTION, DocumentaryUnitDescription.class, DescriptionIdGenerator.INSTANCE),
55      REPOSITORY_DESCRIPTION(Entities.REPOSITORY_DESCRIPTION, RepositoryDescription.class, DescriptionIdGenerator.INSTANCE),
56      HISTORICAL_AGENT_DESCRIPTION(Entities.HISTORICAL_AGENT_DESCRIPTION, HistoricalAgentDescription.class, DescriptionIdGenerator.INSTANCE),
57      CVOC_CONCEPT_DESCRIPTION(Entities.CVOC_CONCEPT_DESCRIPTION, ConceptDescription.class, DescriptionIdGenerator.INSTANCE),
58  
59      // Generic entities.
60      DATE_PERIOD(Entities.DATE_PERIOD, DatePeriod.class),
61      ANNOTATION(Entities.ANNOTATION, Annotation.class),
62      ADDRESS(Entities.ADDRESS, Address.class),
63      SYSTEM_EVENT(Entities.SYSTEM_EVENT, SystemEvent.class),
64      VERSION(Entities.VERSION, Version.class),
65      SYSTEM(Entities.SYSTEM, SystemEventQueue.class),
66      UNKNOWN_PROPERTY(Entities.UNKNOWN_PROPERTY, UnknownProperty.class),
67      PERMISSION(Entities.PERMISSION, Permission.class),
68      PERMISSION_GRANT(Entities.PERMISSION_GRANT, PermissionGrant.class),
69      CONTENT_TYPE(Entities.CONTENT_TYPE, ContentType.class),
70      MAINTENANCE_EVENT(Entities.MAINTENANCE_EVENT, MaintenanceEvent.class),
71      ACCESS_POINT(Entities.ACCESS_POINT, AccessPoint.class),
72      LINK(Entities.LINK, Link.class),
73      EVENT_LINK(Entities.EVENT_LINK, EventLink.class);
74  
75      // Accessors.
76  
77      /**
78       * Get the string name of this EntityType.
79       *
80       * @return the type's name
81       */
82      public String getName() {
83          return name;
84      }
85  
86      /**
87       * Get the interface to which this EntityType refers.
88       *
89       * @return the Java model class associated with the type
90       */
91      public Class<? extends Entity> getJavaClass() {
92          return cls;
93      }
94  
95      /**
96       * Get the ID generator class for this entityType.
97       *
98       * @return the IdGenerator instance associated with the type
99       */
100     public IdGenerator getIdGen() {
101         return idGen;
102     }
103 
104     public static EntityClass withName(String name) {
105         for (EntityClass et : EntityClass.values()) {
106             if (et.getName().equals(name))
107                 return et;
108         }
109         throw new IllegalArgumentException("Invalid entity type: " + name);
110     }
111 
112     private final String name;
113     private final Class<? extends Entity> cls;
114     private final IdGenerator idGen;
115 
116     EntityClass(String name, Class<? extends Entity> cls, IdGenerator idGen) {
117         this.name = name;
118         this.cls = cls;
119         this.idGen = idGen;
120     }
121 
122     EntityClass(String name, Class<? extends Entity> cls) {
123         this(name, cls, GenericIdGenerator.INSTANCE);
124     }
125 
126     @Override
127     public String toString() {
128         return name;
129     }
130 }