/
SearchFactory.java
533 lines (470 loc) · 27.3 KB
/
SearchFactory.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
/*
* 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.web.component.search;
import java.lang.reflect.Modifier;
import java.util.*;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.xml.ns._public.common.audit_3.AuditEventRecordType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringTranslationType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;
import org.apache.cxf.common.util.CollectionUtils;
import com.evolveum.midpoint.gui.api.page.PageBase;
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.model.api.authentication.CompiledGuiProfile;
import com.evolveum.midpoint.model.api.authentication.CompiledObjectCollectionView;
import com.evolveum.midpoint.prism.*;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.FullTextSearchConfigurationUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import org.jetbrains.annotations.NotNull;
import javax.xml.namespace.QName;
public class SearchFactory {
private static final String DOT_CLASS = SearchFactory.class.getName() + ".";
private static final String LOAD_OBJECT_DEFINITION = DOT_CLASS + "loadObjectDefinition";
private static final String LOAD_SYSTEM_CONFIGURATION = DOT_CLASS + "loadSystemConfiguration";
private static final String LOAD_ADMIN_GUI_CONFIGURATION = DOT_CLASS + "loadAdminGuiConfiguration";
private static final Map<Class<?>, List<ItemPath>> SEARCHABLE_OBJECTS = new HashMap<>();
static {
SEARCHABLE_OBJECTS.put(ObjectType.class, Arrays.asList(
ItemPath.create(ObjectType.F_NAME),
ItemPath.create(ObjectType.F_LIFECYCLE_STATE),
ItemPath.create(ObjectType.F_SUBTYPE),
ItemPath.create(ObjectType.F_METADATA, MetadataType.F_CREATE_TIMESTAMP),
ItemPath.create(ObjectType.F_METADATA, MetadataType.F_MODIFY_TIMESTAMP)
));
SEARCHABLE_OBJECTS.put(FocusType.class, Arrays.asList(
ItemPath.create(FocusType.F_ACTIVATION, ActivationType.F_ADMINISTRATIVE_STATUS),
ItemPath.create(FocusType.F_ROLE_MEMBERSHIP_REF),
ItemPath.create(FocusType.F_ACTIVATION, ActivationType.F_EFFECTIVE_STATUS),
ItemPath.create(FocusType.F_ACTIVATION, ActivationType.F_LOCKOUT_STATUS)
));
SEARCHABLE_OBJECTS.put(UserType.class, Arrays.asList(
ItemPath.create(UserType.F_TITLE),
ItemPath.create(UserType.F_GIVEN_NAME),
ItemPath.create(UserType.F_FAMILY_NAME),
ItemPath.create(UserType.F_FULL_NAME),
ItemPath.create(UserType.F_ADDITIONAL_NAME),
ItemPath.create(UserType.F_COST_CENTER),
ItemPath.create(UserType.F_EMAIL_ADDRESS),
ItemPath.create(UserType.F_TELEPHONE_NUMBER),
ItemPath.create(UserType.F_EMPLOYEE_NUMBER),
ItemPath.create(UserType.F_EMPLOYEE_TYPE),
ItemPath.create(UserType.F_ORGANIZATIONAL_UNIT),
ItemPath.create(UserType.F_LOCALITY)
));
SEARCHABLE_OBJECTS.put(RoleType.class, Arrays.asList(
ItemPath.create(RoleType.F_NAME),
ItemPath.create(RoleType.F_DISPLAY_NAME),
ItemPath.create(RoleType.F_ROLE_TYPE)
));
SEARCHABLE_OBJECTS.put(ServiceType.class, Arrays.asList(
ItemPath.create(ServiceType.F_NAME),
ItemPath.create(RoleType.F_DISPLAY_NAME),
ItemPath.create(ServiceType.F_SERVICE_TYPE),
ItemPath.create(ServiceType.F_URL)
));
SEARCHABLE_OBJECTS.put(ConnectorHostType.class, Arrays.asList(
ItemPath.create(ConnectorHostType.F_HOSTNAME)
));
SEARCHABLE_OBJECTS.put(ConnectorType.class, Arrays.asList(
ItemPath.create(ConnectorType.F_CONNECTOR_BUNDLE),
ItemPath.create(ConnectorType.F_CONNECTOR_VERSION),
ItemPath.create(ConnectorType.F_CONNECTOR_TYPE)
));
SEARCHABLE_OBJECTS.put(AbstractRoleType.class, Arrays.asList(
ItemPath.create(AbstractRoleType.F_IDENTIFIER),
ItemPath.create(AbstractRoleType.F_REQUESTABLE)
));
SEARCHABLE_OBJECTS.put(OrgType.class, Arrays.asList(
ItemPath.create(OrgType.F_DISPLAY_NAME),
ItemPath.create(OrgType.F_COST_CENTER),
ItemPath.create(OrgType.F_ORG_TYPE),
ItemPath.create(OrgType.F_TENANT),
ItemPath.create(OrgType.F_PARENT_ORG_REF),
ItemPath.create(OrgType.F_LOCALITY)
));
SEARCHABLE_OBJECTS.put(GenericObjectType.class, Arrays.asList(
ItemPath.create(GenericObjectType.F_OBJECT_TYPE)
));
SEARCHABLE_OBJECTS.put(NodeType.class, Arrays.asList(
ItemPath.create(NodeType.F_NODE_IDENTIFIER)
));
// SEARCHABLE_OBJECTS.put(ReportType.class, Arrays.asList(
// ItemPath.create(ReportType.F_NAME)
// ));
SEARCHABLE_OBJECTS.put(ShadowType.class, Arrays.asList(
ItemPath.create(ShadowType.F_OBJECT_CLASS),
ItemPath.create(ShadowType.F_RESOURCE_REF),
ItemPath.create(ShadowType.F_DEAD),
ItemPath.create(ShadowType.F_INTENT),
ItemPath.create(ShadowType.F_EXISTS),
ItemPath.create(ShadowType.F_SYNCHRONIZATION_SITUATION)
));
SEARCHABLE_OBJECTS.put(TaskType.class, Arrays.asList(
ItemPath.create(TaskType.F_TASK_IDENTIFIER),
ItemPath.create(TaskType.F_NODE),
ItemPath.create(TaskType.F_CATEGORY),
ItemPath.create(TaskType.F_RESULT_STATUS),
ItemPath.create(TaskType.F_EXECUTION_STATUS),
ItemPath.create(TaskType.F_HANDLER_URI),
ItemPath.create(TaskType.F_OBJECT_REF)
));
SEARCHABLE_OBJECTS.put(AssignmentType.class, Arrays.asList(
ItemPath.create(AssignmentType.F_TARGET_REF),
ItemPath.create(AssignmentType.F_CONSTRUCTION, ConstructionType.F_RESOURCE_REF),
ItemPath.create(AssignmentType.F_TENANT_REF),
ItemPath.create(AssignmentType.F_ORG_REF)
));
SEARCHABLE_OBJECTS.put(CaseWorkItemType.class, Arrays.asList(
ItemPath.create(CaseWorkItemType.F_ASSIGNEE_REF),
ItemPath.create(CaseWorkItemType.F_ORIGINAL_ASSIGNEE_REF),
ItemPath.create(PrismConstants.T_PARENT, CaseType.F_STATE),
ItemPath.create(PrismConstants.T_PARENT, CaseType.F_OBJECT_REF),
ItemPath.create(CaseWorkItemType.F_PERFORMER_REF)
));
SEARCHABLE_OBJECTS.put(CaseType.class, Arrays.asList(
ItemPath.create(CaseType.F_STATE),
ItemPath.create(CaseType.F_PARENT_REF),
ItemPath.create(CaseType.F_REQUESTOR_REF),
ItemPath.create(CaseType.F_TARGET_REF),
ItemPath.create(CaseType.F_TASK_REF),
ItemPath.create(CaseType.F_OBJECT_REF)
));
SEARCHABLE_OBJECTS.put(ObjectPolicyConfigurationType.class, Arrays.asList(
ItemPath.create(ObjectPolicyConfigurationType.F_SUBTYPE),
ItemPath.create(ObjectPolicyConfigurationType.F_OBJECT_TEMPLATE_REF)
));
SEARCHABLE_OBJECTS.put(AuditEventRecordType.class, Arrays.asList(
ItemPath.create(AuditEventRecordType.F_TIMESTAMP),
ItemPath.create(AuditEventRecordType.F_INITIATOR_REF),
ItemPath.create(AuditEventRecordType.F_EVENT_STAGE),
ItemPath.create(AuditEventRecordType.F_EVENT_TYPE),
ItemPath.create(AuditEventRecordType.F_TARGET_REF),
ItemPath.create(AuditEventRecordType.F_TARGET_OWNER_REF),
ItemPath.create(AuditEventRecordType.F_CHANGED_ITEM),
ItemPath.create(AuditEventRecordType.F_OUTCOME),
ItemPath.create(AuditEventRecordType.F_CHANNEL),
ItemPath.create(AuditEventRecordType.F_HOST_IDENTIFIER),
ItemPath.create(AuditEventRecordType.F_REQUEST_IDENTIFIER),
ItemPath.create(AuditEventRecordType.F_REFERENCE),
ItemPath.create(AuditEventRecordType.F_TASK_IDENTIFIER)
));
}
public static <C extends Containerable> Search createContainerSearch(ContainerTypeSearchItem<C> type, ModelServiceLocator modelServiceLocator) {
return createContainerSearch(type, null, modelServiceLocator, false);
}
public static <C extends Containerable> Search createContainerSearch(ContainerTypeSearchItem<C> type, ItemPath defaultSearchItem,
ModelServiceLocator modelServiceLocator, boolean useObjectCollection) {
return createContainerSearch(type, defaultSearchItem, null, modelServiceLocator, useObjectCollection);
}
public static <C extends Containerable> Search createContainerSearch(ContainerTypeSearchItem<C> type, ItemPath defaultSearchItem, List<SearchItemDefinition> defaultAvailableDefs,
ModelServiceLocator modelServiceLocator, boolean useObjectCollection) {
PrismContainerDefinition<C> containerDef = modelServiceLocator.getPrismContext().getSchemaRegistry()
.findContainerDefinitionByCompileTimeClass(type.getTypeClass());
List<SearchItemDefinition> availableDefs = defaultAvailableDefs;
if (CollectionUtils.isEmpty(defaultAvailableDefs)) {
availableDefs = getAvailableDefinitions(containerDef, null, true, modelServiceLocator);
}
Search search = new Search(type, availableDefs);
List<SearchItemDefinition> configuredSearchItemDefs = null;
if (useObjectCollection) {
configuredSearchItemDefs = getConfiguredSearchItemDefinitions(availableDefs, modelServiceLocator, containerDef.getTypeName(), null, Search.PanelType.DEFAULT);
}
if (!CollectionUtils.isEmpty(configuredSearchItemDefs)) {
processSearchItemDefFromCompiledView(configuredSearchItemDefs, search, containerDef);
} else if (defaultSearchItem != null) {
ItemDefinition defaultItemDef = containerDef.findItemDefinition(defaultSearchItem);
if (defaultItemDef != null) {
search.addItem(defaultItemDef);
}
}
return search;
}
public static <T extends ObjectType> Search createSearch(Class<? extends T> type, ModelServiceLocator modelServiceLocator) {
@NotNull ObjectTypes objectTypes = ObjectTypes.getObjectType(type);
return createSearch(new ContainerTypeSearchItem<T>(new SearchValue(type,"ObjectType." + objectTypes.getTypeQName().getLocalPart())), null, null,
null, modelServiceLocator, null, true, true, Search.PanelType.DEFAULT);
}
public static <T extends ObjectType> Search createSearch(ContainerTypeSearchItem<T> type, ModelServiceLocator modelServiceLocator, boolean isOidSearchEnabled) {
return createSearch(type, null, null, null, modelServiceLocator, null, true,
true, Search.PanelType.DEFAULT, isOidSearchEnabled);
}
public static <T extends ObjectType> Search createSearch(
ContainerTypeSearchItem<T> type, String collectionViewName, List<ItemPath> fixedSearchItems, ResourceShadowDiscriminator discriminator,
ModelServiceLocator modelServiceLocator, List<ItemPath> availableItemPath, boolean useDefsFromSuperclass, boolean useObjectCollection, Search.PanelType panelType) {
return createSearch(type, collectionViewName, fixedSearchItems, discriminator, modelServiceLocator, availableItemPath, useDefsFromSuperclass, useObjectCollection,
panelType, false );
}
public static <T extends ObjectType> Search createSearch(
ContainerTypeSearchItem<T> type, String collectionViewName, List<ItemPath> fixedSearchItems, ResourceShadowDiscriminator discriminator,
ModelServiceLocator modelServiceLocator, List<ItemPath> availableItemPath, boolean useDefsFromSuperclass, boolean useObjectCollection, Search.PanelType panelType,
boolean isOidSearchEnabled) {
PrismObjectDefinition objectDef = findObjectDefinition(type.getTypeClass(), discriminator, modelServiceLocator);
List<SearchItemDefinition> availableDefs = getAvailableDefinitions(objectDef, availableItemPath, useDefsFromSuperclass, modelServiceLocator);
boolean isFullTextSearchEnabled = isFullTextSearchEnabled(modelServiceLocator, type.getTypeClass());
QName qNametype = WebComponentUtil.classToQName(modelServiceLocator.getPrismContext(), type.getTypeClass());
SearchBoxConfigurationType searchBox = getSearchBoxConfiguration(modelServiceLocator, qNametype, collectionViewName, panelType);
SearchBoxModeType searchMode = null;
List<SearchBoxModeType> allowedSearchModes = new ArrayList<>();
if (searchBox != null) {
searchMode = searchBox.getDefaultMode();
allowedSearchModes = searchBox.getAllowedMode();
}
Search search = new Search(type, availableDefs, isFullTextSearchEnabled, searchMode, allowedSearchModes, isOidSearchEnabled);
SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(type.getTypeClass());
List<SearchItemDefinition> configuredSearchItemDefs = null;
if (useObjectCollection) {
configuredSearchItemDefs = getConfiguredSearchItemDefinitions(availableDefs, modelServiceLocator, qNametype, collectionViewName, panelType);
}
if (useObjectCollection && !CollectionUtils.isEmpty(configuredSearchItemDefs)) {
processSearchItemDefFromCompiledView(configuredSearchItemDefs, search, objDef);
} else {
if (CollectionUtils.isEmpty(fixedSearchItems)) {
fixedSearchItems = new ArrayList<>();
fixedSearchItems.add(ObjectType.F_NAME);
}
fixedSearchItems.forEach(searchItemPath -> {
ItemDefinition def = objDef.findItemDefinition(searchItemPath);
SearchItem item = search.addItem(def);
if (item != null) {
item.setFixed(true);
}
});
}
search.setCanConfigure(isAllowToConfigureSearchItems(modelServiceLocator, qNametype, collectionViewName, panelType));
return search;
}
public static void processSearchItemDefFromCompiledView(List<SearchItemDefinition> configuredSearchItemDefs, Search search, PrismContainerDefinition containerDef) {
configuredSearchItemDefs.forEach(searchItemDef -> {
search.addItemToAllDefinitions(searchItemDef);
if (searchItemDef.isVisibleByDefault()) {
SearchItem item = null;
if (searchItemDef.getPath() != null) {
ItemDefinition def = containerDef.findItemDefinition(searchItemDef.getPath());
item = search.addItem(def);
((PropertySearchItem) item).setDisplayName(searchItemDef.getDisplayName());
} else if (searchItemDef.getPredefinedFilter() != null) {
item = search.addItem(searchItemDef.getPredefinedFilter());
}
if (item != null) {
item.setFixed(true);
item.setDefinition(searchItemDef);
}
}
});
}
public static <T extends ObjectType> PrismObjectDefinition findObjectDefinition(
Class<T> type, ResourceShadowDiscriminator discriminator,
ModelServiceLocator modelServiceLocator) {
Task task = modelServiceLocator.createSimpleTask(LOAD_OBJECT_DEFINITION);
OperationResult result = task.getResult();
try {
if (Modifier.isAbstract(type.getModifiers())) {
SchemaRegistry registry = modelServiceLocator.getPrismContext().getSchemaRegistry();
return registry.findObjectDefinitionByCompileTimeClass(type);
}
PrismObject empty = modelServiceLocator.getPrismContext().createObject(type);
if (ShadowType.class.equals(type)) {
return modelServiceLocator.getModelInteractionService().getEditShadowDefinition(discriminator,
AuthorizationPhaseType.REQUEST, task, result);
} else {
return modelServiceLocator.getModelInteractionService().getEditObjectDefinition(
empty, AuthorizationPhaseType.REQUEST, task, result);
}
} catch (SchemaException | ConfigurationException | ObjectNotFoundException | ExpressionEvaluationException | CommunicationException | SecurityViolationException ex) {
result.recordFatalError(ex.getMessage());
throw new SystemException(ex);
}
}
public static <C extends Containerable> List<SearchItemDefinition> getConfiguredSearchItemDefinitions(List<SearchItemDefinition> availableDefinitions,
ModelServiceLocator modelServiceLocator, QName type, String collectionViewName, Search.PanelType panelType) {
SearchBoxConfigurationType searchConfig = getSearchBoxConfiguration(modelServiceLocator, type, collectionViewName, panelType);
if (searchConfig == null) {
return null;
}
SearchItemsType configuredSearchItems = searchConfig.getSearchItems();
if (configuredSearchItems == null || CollectionUtils.isEmpty(configuredSearchItems.getSearchItem())) {
return null;
}
List<SearchItemDefinition> configuredSearchItemList = new ArrayList<>();
configuredSearchItems.getSearchItem().forEach(searchItem -> {
for (SearchItemDefinition def : availableDefinitions) {
ItemPathType searchItemPath = new ItemPathType(def.getPath());
if (searchItem.getPath() != null && searchItem.getPath().equivalent(searchItemPath)) {
def.setDisplayName(searchItem.getDisplayName());
configuredSearchItemList.add(def);
return;
}
}
});
configuredSearchItems.getSearchItem().forEach(searchItem -> {
if (searchItem.getFilter() != null || searchItem.getFilterExpression() != null) {
configuredSearchItemList.add(new SearchItemDefinition(searchItem));
return;
}
});
return configuredSearchItemList;
}
public static <C extends Containerable> List<SearchItemDefinition> getAvailableDefinitions(
PrismContainerDefinition<C> objectDef, List<ItemPath> availableItemPath, boolean useDefsFromSuperclass, ModelServiceLocator modelServiceLocator) {
List<SearchItemDefinition> definitions = new ArrayList<>();
if (objectDef == null) {
return definitions;
}
definitions.addAll(createExtensionDefinitionList(objectDef));
Class<C> typeClass = objectDef.getCompileTimeClass();
while (typeClass != null && !com.evolveum.prism.xml.ns._public.types_3.ObjectType.class.equals(typeClass)) {
List<ItemPath> paths = CollectionUtils.isEmpty(availableItemPath) ? getAvailableSearchableItems(typeClass, modelServiceLocator) : availableItemPath;
if (paths != null) {
for (ItemPath path : paths) {
ItemDefinition def = objectDef.findItemDefinition(path);
if (def != null) {
SearchItemDefinition searchItemDef = new SearchItemDefinition(path, def, null);
definitions.add(searchItemDef);
}
}
}
if (!useDefsFromSuperclass) {
break;
}
typeClass = (Class<C>) typeClass.getSuperclass();
}
return definitions;
}
public static List<ItemPath> getAvailableSearchableItems(Class<?> typeClass, ModelServiceLocator modelServiceLocator) {
List<ItemPath> items = SEARCHABLE_OBJECTS.get(typeClass);
if (AuditEventRecordType.class.equals(typeClass)) {
SystemConfigurationType systemConfigurationType = null;
try {
systemConfigurationType = modelServiceLocator.getModelInteractionService().getSystemConfiguration(new OperationResult("load_system_config"));
} catch (SchemaException | ObjectNotFoundException e) {
throw new SystemException(e);
}
if (systemConfigurationType != null && systemConfigurationType.getAudit() != null
&& systemConfigurationType.getAudit().getEventRecording() != null &&
Boolean.TRUE.equals(systemConfigurationType.getAudit().getEventRecording().isRecordResourceOids())) {
ArrayList<ItemPath> auditItems = new ArrayList<ItemPath>();
auditItems.addAll(items);
auditItems.add(ItemPath.create(AuditEventRecordType.F_RESOURCE_OID));
items = auditItems;
}
}
return items;
}
private static <T extends ObjectType> boolean isFullTextSearchEnabled(ModelServiceLocator modelServiceLocator, Class<T> type) {
OperationResult result = new OperationResult(LOAD_SYSTEM_CONFIGURATION);
try {
return FullTextSearchConfigurationUtil.isEnabledFor(modelServiceLocator.getModelInteractionService().getSystemConfiguration(result)
.getFullTextSearch(), type);
} catch (SchemaException | ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}
private static <T extends ObjectType> boolean isAllowToConfigureSearchItems(ModelServiceLocator modelServiceLocator, QName type,
String collectionViewName, Search.PanelType panelType) {
SearchBoxConfigurationType searchConfig = getSearchBoxConfiguration(modelServiceLocator, type, collectionViewName, panelType);
if (searchConfig == null || searchConfig.isAllowToConfigureSearchItems() == null) {
return true; //todo should be set to false
}
return searchConfig.isAllowToConfigureSearchItems();
}
private static <C extends Containerable> SearchBoxConfigurationType getSearchBoxConfiguration(ModelServiceLocator modelServiceLocator,
QName type, String collectionViewName, Search.PanelType panelType) {
OperationResult result = new OperationResult(LOAD_ADMIN_GUI_CONFIGURATION);
try {
CompiledGuiProfile guiConfig = modelServiceLocator.getModelInteractionService().getCompiledGuiProfile(null, result);
CompiledObjectCollectionView view = guiConfig.findObjectCollectionView(type, collectionViewName);
if (view != null) {
if (Search.PanelType.MEMBER_PANEL.equals(panelType) && view.getAdditionalPanels() != null
&& view.getAdditionalPanels().getMemberPanel() != null) {
return view.getAdditionalPanels().getMemberPanel().getSearchBoxConfiguration();
}
return view.getSearchBoxConfiguration();
}
return null;
} catch (SchemaException | ObjectNotFoundException | CommunicationException | ConfigurationException | SecurityViolationException | ExpressionEvaluationException ex) {
throw new SystemException(ex);
}
}
public static <C extends Containerable> List<SearchItemDefinition> createExtensionDefinitionList(
PrismContainerDefinition<C> objectDef) {
// Map<ItemPath, ItemDefinition> map = new HashMap<>();
List<SearchItemDefinition> searchItemDefinitions = new ArrayList<>();
ItemPath extensionPath = ObjectType.F_EXTENSION;
PrismContainerDefinition ext = objectDef.findContainerDefinition(ObjectType.F_EXTENSION);
if (ext == null) {
return searchItemDefinitions;
}
for (ItemDefinition def : (List<ItemDefinition>) ext.getDefinitions()) {
ItemPath itemPath = ItemPath.create(extensionPath, def.getItemName());
if (!isIndexed(def)) {
continue;
}
if (def instanceof PrismPropertyDefinition) {
addSearchPropertyDef(objectDef, itemPath, searchItemDefinitions);
}
if (def instanceof PrismReferenceDefinition) {
addSearchRefDef(objectDef, itemPath, searchItemDefinitions, null, null);
}
if (!(def instanceof PrismPropertyDefinition)
&& !(def instanceof PrismReferenceDefinition)) {
continue;
}
}
return searchItemDefinitions;
}
public static <C extends Containerable> void addSearchRefDef(PrismContainerDefinition<C> containerDef, ItemPath path, List<SearchItemDefinition> defs, AreaCategoryType category, PageBase pageBase) {
PrismReferenceDefinition refDef = containerDef.findReferenceDefinition(path);
if (refDef == null) {
return;
}
if (pageBase == null) {
defs.add(new SearchItemDefinition(path, refDef, Collections.singletonList(WebComponentUtil.getDefaultRelationOrFail())));
return;
}
defs.add(new SearchItemDefinition(path, refDef, WebComponentUtil.getCategoryRelationChoices(category, pageBase)));
}
public static <C extends Containerable> void addSearchPropertyDef(PrismContainerDefinition<C> containerDef, ItemPath path, List<SearchItemDefinition> defs) {
addSearchPropertyDef(containerDef, path, defs, null);
}
public static <C extends Containerable> void addSearchPropertyDef(PrismContainerDefinition<C> containerDef, ItemPath path, List<SearchItemDefinition> defs, String key) {
PrismPropertyDefinition propDef = containerDef.findPropertyDefinition(path);
if (propDef == null) {
return;
}
SearchItemDefinition searchItem = new SearchItemDefinition(path, propDef, null);
if (key != null) {
PolyStringType displayName = new PolyStringType(propDef.getItemName().getLocalPart());
PolyStringTranslationType translation = new PolyStringTranslationType();
translation.setFallback(propDef.getItemName().getLocalPart());
translation.setKey(key);
displayName.setTranslation(translation);
searchItem.setDisplayName(displayName);
}
defs.add(searchItem);
}
private static boolean isIndexed(ItemDefinition def) {
if (!(def instanceof PrismPropertyDefinition)) {
return true;
}
PrismPropertyDefinition propertyDef = (PrismPropertyDefinition) def;
Boolean indexed = propertyDef.isIndexed();
if (indexed == null) {
return true;
}
return indexed.booleanValue();
}
}