-
Notifications
You must be signed in to change notification settings - Fork 188
/
ObjectTypes.java
393 lines (310 loc) · 14.5 KB
/
ObjectTypes.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
/*
* Copyright (c) 2010-2020 Evolveum and contributors
*
* This work is dual-licensed under the Apache License 2.0
* and European Union Public License. See LICENSE file for details.
*/
package com.evolveum.midpoint.schema.constants;
import java.util.ArrayList;
import java.util.List;
import javax.xml.namespace.QName;
import org.apache.commons.lang.Validate;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import com.evolveum.midpoint.schema.SchemaConstantsGenerated;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
/**
* @author lazyman
*/
public enum ObjectTypes {
CONNECTOR(SchemaConstants.C_CONNECTOR_TYPE, SchemaConstants.C_CONNECTOR,
ConnectorType.class, ObjectManager.PROVISIONING, "connectors"),
CONNECTOR_HOST(SchemaConstants.C_CONNECTOR_HOST_TYPE,
SchemaConstants.C_CONNECTOR_HOST, ConnectorHostType.class, ObjectManager.PROVISIONING, "connectorHosts"),
GENERIC_OBJECT(SchemaConstants.C_GENERIC_OBJECT_TYPE,
SchemaConstants.C_GENERIC_OBJECT, GenericObjectType.class, ObjectManager.MODEL, "genericObjects"),
RESOURCE(SchemaConstants.C_RESOURCE_TYPE, SchemaConstants.C_RESOURCE,
ResourceType.class, ObjectManager.PROVISIONING, "resources"),
USER(SchemaConstants.C_USER_TYPE, SchemaConstants.C_USER, UserType.class,
ObjectManager.MODEL, "users"),
OBJECT_TEMPLATE(SchemaConstants.C_OBJECT_TEMPLATE_TYPE,
SchemaConstants.C_OBJECT_TEMPLATE, ObjectTemplateType.class, ObjectManager.MODEL, "objectTemplates"),
SYSTEM_CONFIGURATION(SchemaConstants.C_SYSTEM_CONFIGURATION_TYPE, SchemaConstants.C_SYSTEM_CONFIGURATION,
SystemConfigurationType.class, ObjectManager.MODEL, "systemConfigurations"),
TASK(SchemaConstants.C_TASK_TYPE, SchemaConstants.C_TASK, TaskType.class, ObjectManager.TASK_MANAGER, "tasks"),
SHADOW(SchemaConstants.C_SHADOW_TYPE, SchemaConstants.C_SHADOW, ShadowType.class, ObjectManager.PROVISIONING, "shadows"),
ROLE(RoleType.COMPLEX_TYPE, SchemaConstantsGenerated.C_ROLE, RoleType.class, ObjectManager.MODEL, "roles"),
PASSWORD_POLICY(ValuePolicyType.COMPLEX_TYPE, SchemaConstantsGenerated.C_VALUE_POLICY, ValuePolicyType.class,
ObjectManager.MODEL, "valuePolicies"),
NODE(NodeType.COMPLEX_TYPE, SchemaConstantsGenerated.C_NODE, NodeType.class, ObjectManager.TASK_MANAGER, "nodes"),
FORM(FormType.COMPLEX_TYPE, SchemaConstantsGenerated.C_FORM, FormType.class, ObjectManager.MODEL, "forms"),
ORG(OrgType.COMPLEX_TYPE, SchemaConstantsGenerated.C_ORG, OrgType.class, ObjectManager.MODEL, "orgs"),
ABSTRACT_ROLE(AbstractRoleType.COMPLEX_TYPE, SchemaConstants.C_ABSTRACT_ROLE, AbstractRoleType.class,
ObjectManager.MODEL, "abstractRoles"),
FOCUS_TYPE(FocusType.COMPLEX_TYPE, SchemaConstants.C_FOCUS, FocusType.class, ObjectManager.MODEL, "focus"),
ASSIGNMENT_HOLDER_TYPE(AssignmentHolderType.COMPLEX_TYPE, SchemaConstantsGenerated.C_ASSIGNMENT_HOLDER,
AssignmentHolderType.class, ObjectManager.MODEL, "assignmentHolders"),
REPORT(ReportType.COMPLEX_TYPE, SchemaConstants.C_REPORT, ReportType.class, ObjectManager.MODEL, "reports"),
REPORT_OUTPUT(ReportOutputType.COMPLEX_TYPE, SchemaConstants.C_REPORT_OUTPUT, ReportOutputType.class,
ObjectManager.MODEL, "reportOutputs"),
SECURITY_POLICY(SecurityPolicyType.COMPLEX_TYPE, SchemaConstants.C_SECURITY_POLICY, SecurityPolicyType.class,
ObjectManager.MODEL, "securityPolicies"),
LOOKUP_TABLE(LookupTableType.COMPLEX_TYPE, SchemaConstantsGenerated.C_LOOKUP_TABLE, LookupTableType.class,
ObjectManager.MODEL, "lookupTables"),
ACCESS_CERTIFICATION_DEFINITION(AccessCertificationDefinitionType.COMPLEX_TYPE,
SchemaConstantsGenerated.C_ACCESS_CERTIFICATION_DEFINITION, AccessCertificationDefinitionType.class,
ObjectManager.MODEL, "accessCertificationDefinitions"),
ACCESS_CERTIFICATION_CAMPAIGN(AccessCertificationCampaignType.COMPLEX_TYPE,
SchemaConstantsGenerated.C_ACCESS_CERTIFICATION_CAMPAIGN, AccessCertificationCampaignType.class,
ObjectManager.MODEL, "accessCertificationCampaigns"),
SEQUENCE(SequenceType.COMPLEX_TYPE, SchemaConstantsGenerated.C_SEQUENCE, SequenceType.class, ObjectManager.MODEL,
"sequences"),
SERVICE(ServiceType.COMPLEX_TYPE, SchemaConstantsGenerated.C_SERVICE, ServiceType.class, ObjectManager.MODEL,
"services"),
CASE(CaseType.COMPLEX_TYPE, SchemaConstantsGenerated.C_CASE, CaseType.class, ObjectManager.MODEL,
"cases"),
FUNCTION_LIBRARY(FunctionLibraryType.COMPLEX_TYPE, SchemaConstantsGenerated.C_FUNCTION_LIBRARY, FunctionLibraryType.class, ObjectManager.MODEL,
"functionLibraries"),
OBJECT_COLLECTION(ObjectCollectionType.COMPLEX_TYPE, SchemaConstantsGenerated.C_OBJECT_COLLECTION, ObjectCollectionType.class, ObjectManager.MODEL,
"objectCollections"),
ARCHETYPE(ArchetypeType.COMPLEX_TYPE, SchemaConstantsGenerated.C_ARCHETYPE, ArchetypeType.class, ObjectManager.MODEL,
"archetypes"),
DASHBOARD(DashboardType.COMPLEX_TYPE, SchemaConstantsGenerated.C_DASHBOARD, DashboardType.class, ObjectManager.MODEL,
"dashboards"),
// this should be at end, because otherwise it presents itself as entry for all subtypes of ObjectType
OBJECT(SchemaConstants.C_OBJECT_TYPE, SchemaConstants.C_OBJECT, ObjectType.class, ObjectManager.MODEL, "objects");
public List<ObjectTypes> thisAndSupertypes() {
List<ObjectTypes> rv = new ArrayList<>();
rv.add(this);
ObjectTypes superType = superType();
if (superType != null) {
rv.addAll(superType.thisAndSupertypes());
}
return rv;
}
public ObjectTypes superType() {
return getObjectTypeIfKnown(classDefinition.getSuperclass());
}
public enum ObjectManager {
PROVISIONING, TASK_MANAGER, MODEL, REPOSITORY
}
@NotNull private final QName type;
/**
* As of 2020-06, this is used only for ObjectTypeUtil#toShortString+getShortTypeName.
*/
@NotNull private final QName elementName;
@NotNull private final Class<? extends ObjectType> classDefinition;
@NotNull private final ObjectManager objectManager;
@NotNull private final String restType;
ObjectTypes(@NotNull QName type, @NotNull QName elementName, @NotNull Class<? extends ObjectType> classDefinition,
@NotNull ObjectManager objectManager, @NotNull String restType) {
this.type = type;
this.elementName = elementName;
this.classDefinition = classDefinition;
this.objectManager = objectManager;
this.restType = restType;
}
public boolean isManagedByProvisioning() {
return objectManager == ObjectManager.PROVISIONING;
}
public boolean isManagedByTaskManager() {
return objectManager == ObjectManager.TASK_MANAGER;
}
public String getValue() {
return type.getLocalPart();
}
@NotNull
public QName getElementName() {
return elementName;
}
@NotNull
public QName getTypeQName() {
return type;
}
@NotNull
public Class<? extends ObjectType> getClassDefinition() {
return classDefinition;
}
@NotNull
public String getRestType() {
return restType;
}
@NotNull
public String getObjectTypeUri() {
return QNameUtil.qNameToUri(getTypeQName());
}
@NotNull
public ObjectManager getObjectManager() {
return objectManager;
}
@NotNull
public static ObjectTypes getObjectType(String objectType) {
for (ObjectTypes type : values()) {
if (type.getValue().equals(objectType)) {
return type;
}
}
throw new IllegalArgumentException("Unsupported object type " + objectType);
}
public static ObjectTypes getObjectTypeFromTypeQName(QName typeQName) {
if (typeQName == null) {
return null;
}
// HACK WARNING! FIXME
// UGLY HORRIBLE TERRIBLE AWFUL HACK FOLLOWS
// The JAXB fails to correctly process QNames in default namespace (no prefix)
// e.g it will not understand this: type="RoleType", even if default namespace
// is set, it will parse it as null namespace.
// Therefore substitute null namespace with common namespace
if (typeQName.getNamespaceURI() == null || typeQName.getNamespaceURI().isEmpty()) {
typeQName = new QName(SchemaConstants.NS_C, typeQName.getLocalPart());
}
// END OF UGLY HACK
for (ObjectTypes type : values()) {
if (QNameUtil.match(type.getTypeQName(), typeQName)) {
return type;
}
}
throw new IllegalArgumentException("Unsupported object type qname " + typeQName);
}
@NotNull
public static ObjectTypes getObjectTypeFromUri(String objectTypeUri) {
for (ObjectTypes type : values()) {
if (type.getObjectTypeUri().equals(objectTypeUri)) {
return type;
}
}
throw new IllegalArgumentException("Unsupported object type uri " + objectTypeUri);
}
@NotNull
public static String getObjectTypeUri(String objectType) {
return getObjectType(objectType).getObjectTypeUri();
}
public static Class<? extends ObjectType> getObjectTypeClass(String typeNameLocal) {
for (ObjectTypes type : values()) {
if (type.getValue().equals(typeNameLocal)) {
return type.getClassDefinition();
}
}
throw new IllegalArgumentException("Unsupported object type " + typeNameLocal);
}
@NotNull
public static <O extends ObjectType> Class<O> getObjectTypeClass(QName typeName) {
for (ObjectTypes type : values()) {
if (QNameUtil.match(type.getTypeQName(), typeName)) {
//noinspection unchecked
return (Class<O>) type.getClassDefinition();
}
}
throw new IllegalArgumentException("Unsupported object type " + typeName);
}
@NotNull
public static ObjectTypes getObjectType(@NotNull Class<? extends ObjectType> objectType) {
ObjectTypes rv = getObjectTypeIfKnown(objectType);
if (rv == null) {
throw new IllegalArgumentException("Unsupported object type " + objectType);
}
return rv;
}
public static ObjectTypes getObjectTypeIfKnown(@NotNull Class<?> objectType) {
for (ObjectTypes type : values()) {
if (type.getClassDefinition().equals(objectType)) {
return type;
}
}
// No match. Try with superclass.
Class<?> superclass = objectType.getSuperclass();
if (superclass != null) {
return getObjectTypeIfKnown(superclass);
}
return null;
}
public static boolean isManagedByProvisioning(ObjectType object) {
Validate.notNull(object, "Object must not be null.");
return isClassManagedByProvisioning(object.getClass());
}
public static boolean isClassManagedByProvisioning(Class<? extends ObjectType> clazz) {
Validate.notNull(clazz, "Class must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getClassDefinition().isAssignableFrom(clazz)) {
return type.isManagedByProvisioning();
}
}
return false;
}
public static boolean isObjectTypeManagedByProvisioning(Class<? extends ObjectType> objectType) {
Validate.notNull(objectType, "Object type must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getClassDefinition().equals(objectType)) {
return type.isManagedByProvisioning();
}
}
return false;
}
public static boolean isObjectTypeManagedByProvisioning(String objectType) {
Validate.notEmpty(objectType, "Object type must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getTypeQName().getLocalPart().equals(objectType)) {
return type.isManagedByProvisioning();
}
}
return false;
}
public static ObjectManager getObjectManagerForClass(Class<? extends ObjectType> clazz) {
Validate.notNull(clazz, "Class must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getClassDefinition().isAssignableFrom(clazz)) {
return type.getObjectManager();
}
}
return null;
}
public static Class<? extends ObjectType> getClassFromRestType(String restType) {
Validate.notNull(restType, "Rest type must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getRestType().equals(restType)) {
return type.getClassDefinition();
}
}
throw new IllegalArgumentException("Not suitable class found for rest type: " + restType);
}
public static String getRestTypeFromClass(Class<?> clazz) {
Validate.notNull(clazz, "Class must not be null.");
for (ObjectTypes type : ObjectTypes.values()) {
if (type.getClassDefinition().equals(clazz)) {
return type.getRestType();
}
}
throw new IllegalArgumentException("Not suitable rest type found for class: " + clazz);
}
public static List<Class<? extends ObjectType>> getAllObjectTypes() {
List<Class<? extends ObjectType>> list = new ArrayList<>();
for (ObjectTypes t : ObjectTypes.values()) {
list.add(t.getClassDefinition());
}
return list;
}
/**
* Makes sure the QNames are full representation of object types, e.g. that they include proper namespace.
*/
public static List<QName> canonizeObjectTypes(List<QName> inputQNames) {
if (inputQNames == null) {
return null;
}
List<QName> outputQNames = new ArrayList<>(inputQNames.size());
for (QName inputQname : inputQNames) {
outputQNames.add(canonizeObjectType(inputQname));
}
return outputQNames;
}
/**
* Makes sure the QName is full representation of object types, e.g. that it includes proper namespace.
*/
public static QName canonizeObjectType(QName inputQName) {
if (!StringUtils.isBlank(inputQName.getNamespaceURI())) {
return inputQName;
}
return new QName(SchemaConstants.NS_C, inputQName.getLocalPart());
}
}