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;
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
39
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
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
76
77
78
79
80
81
82 public String getName() {
83 return name;
84 }
85
86
87
88
89
90
91 public Class<? extends Entity> getJavaClass() {
92 return cls;
93 }
94
95
96
97
98
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 }