Skip to content

Commit

Permalink
fix for showing search by resource oid for audit event records(MID-5526)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 3, 2021
1 parent a341c11 commit 68472e0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
Expand Up @@ -14,6 +14,8 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.AttributeModifier;
Expand Down Expand Up @@ -503,7 +505,7 @@ private String getSortProperty(GuiObjectColumnType customColumn, ItemPath column
// because such sort will work according to data in repo and if the expression
// somehow modify the data, it could be confusing
if (pathNotEmpty(columnPath) && expressionType == null) {
List<ItemPath> searchablePaths = getSearchablePaths(getType());
List<ItemPath> searchablePaths = getSearchablePaths(getType(), getPageBase());

for (ItemPath searchablePath : searchablePaths) {
if (searchablePath.size() > 1) {
Expand All @@ -518,8 +520,8 @@ private String getSortProperty(GuiObjectColumnType customColumn, ItemPath column
return null;
}

private List<ItemPath> getSearchablePaths(Class<C> type) {
List<ItemPath> availablePaths = SearchFactory.getAvailableSearchableItems(type);
private List<ItemPath> getSearchablePaths(Class<C> type, ModelServiceLocator modelServiceLocator) {
List<ItemPath> availablePaths = SearchFactory.getAvailableSearchableItems(type, modelServiceLocator);
if (CollectionUtils.isEmpty(availablePaths)) {
availablePaths = new ArrayList<>();
}
Expand All @@ -533,7 +535,7 @@ private List<ItemPath> addSuperSearchablePaths(Class<?> type, List<ItemPath> typ
return typePaths;
}

List<ItemPath> superPaths = SearchFactory.getAvailableSearchableItems(superClass);
List<ItemPath> superPaths = SearchFactory.getAvailableSearchableItems(superClass, getPageBase());
if (CollectionUtils.isNotEmpty(superPaths)) {
typePaths.addAll(superPaths);
}
Expand Down
Expand Up @@ -9,6 +9,7 @@
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;

Expand Down Expand Up @@ -175,7 +176,6 @@ public class SearchFactory {
ItemPath.create(AuditEventRecordType.F_HOST_IDENTIFIER),
ItemPath.create(AuditEventRecordType.F_REQUEST_IDENTIFIER),
ItemPath.create(AuditEventRecordType.F_REFERENCE),
ItemPath.create(AuditEventRecordType.F_RESOURCE_OID),
ItemPath.create(AuditEventRecordType.F_TASK_IDENTIFIER)
));
}
Expand All @@ -195,7 +195,7 @@ public static <C extends Containerable> Search createContainerSearch(ContainerTy
.findContainerDefinitionByCompileTimeClass(type.getTypeClass());
List<SearchItemDefinition> availableDefs = defaultAvailableDefs;
if (CollectionUtils.isEmpty(defaultAvailableDefs)) {
availableDefs = getAvailableDefinitions(containerDef, null, true);
availableDefs = getAvailableDefinitions(containerDef, null, true, modelServiceLocator);
}

Search search = new Search(type, availableDefs);
Expand Down Expand Up @@ -239,7 +239,7 @@ public static <T extends ObjectType> Search createSearch(
boolean isOidSearchEnabled) {

PrismObjectDefinition objectDef = findObjectDefinition(type.getTypeClass(), discriminator, modelServiceLocator);
List<SearchItemDefinition> availableDefs = getAvailableDefinitions(objectDef, availableItemPath, useDefsFromSuperclass);
List<SearchItemDefinition> availableDefs = getAvailableDefinitions(objectDef, availableItemPath, useDefsFromSuperclass, modelServiceLocator);
boolean isFullTextSearchEnabled = isFullTextSearchEnabled(modelServiceLocator, type.getTypeClass());

QName qNametype = WebComponentUtil.classToQName(modelServiceLocator.getPrismContext(), type.getTypeClass());
Expand Down Expand Up @@ -355,7 +355,7 @@ public static <C extends Containerable> List<SearchItemDefinition> getConfigured
}

public static <C extends Containerable> List<SearchItemDefinition> getAvailableDefinitions(
PrismContainerDefinition<C> objectDef, List<ItemPath> availableItemPath, boolean useDefsFromSuperclass) {
PrismContainerDefinition<C> objectDef, List<ItemPath> availableItemPath, boolean useDefsFromSuperclass, ModelServiceLocator modelServiceLocator) {
List<SearchItemDefinition> definitions = new ArrayList<>();

if (objectDef == null) {
Expand All @@ -366,7 +366,7 @@ public static <C extends Containerable> List<SearchItemDefinition> getAvailableD

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) : availableItemPath;
List<ItemPath> paths = CollectionUtils.isEmpty(availableItemPath) ? getAvailableSearchableItems(typeClass, modelServiceLocator) : availableItemPath;
if (paths != null) {
for (ItemPath path : paths) {
ItemDefinition def = objectDef.findItemDefinition(path);
Expand All @@ -387,8 +387,25 @@ public static <C extends Containerable> List<SearchItemDefinition> getAvailableD
return definitions;
}

public static List<ItemPath> getAvailableSearchableItems(Class<?> typeClass) {
return SEARCHABLE_OBJECTS.get(typeClass);
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) {
Expand Down
Expand Up @@ -348,7 +348,7 @@ protected List<Property> load() {
if (ObjectType.class.isAssignableFrom(type)) {
PrismObjectDefinition objectDef = SearchFactory.findObjectDefinition(getType(), null, getPageBase());
List<SearchItemDefinition> availableDefs =
SearchFactory.getAvailableDefinitions(objectDef, null, true);
SearchFactory.getAvailableDefinitions(objectDef, null, true, getPageBase());
List<Property> propertiesList = new ArrayList<>();
availableDefs.forEach(searchItemDef -> {
if (!isPropertyAlreadyAdded(searchItemDef.getPath())) {
Expand Down

0 comments on commit 68472e0

Please sign in to comment.