Skip to content

Commit

Permalink
search fix for accounts panel on resource details page
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed May 6, 2022
1 parent 41d9402 commit fdd78f8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 43 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.evolveum.midpoint.gui.impl.component.search;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.schema.constants.RelationTypes;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

Expand All @@ -11,6 +10,7 @@
import javax.xml.namespace.QName;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class SearchConfigurationWrapper<C extends Containerable> implements Serializable {
Expand Down Expand Up @@ -228,4 +228,22 @@ public boolean isAllowAllTypeSearch() {
public void setAllowAllTypeSearch(boolean allowAllTypeSearch) {
this.allowAllTypeSearch = allowAllTypeSearch;
}

public SearchConfigurationWrapper<C> removePropertySearchItem(ItemPath path) {
if (path == null) {
return this;
}
Iterator<AbstractSearchItemWrapper> it = getItemsList().iterator();
while (it.hasNext()) {
AbstractSearchItemWrapper item = it.next();
if (!(item instanceof PropertySearchItemWrapper)) {
continue;
}
if (path.equivalent(((PropertySearchItemWrapper) item).getPath())) {
it.remove();
return this;
}
}
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,11 @@ public static <C extends Containerable> Search<C> createSearch(
return createSearch(searchConfig, null, modelServiceLocator, Search.PanelType.DEFAULT, true);
}

public static <C extends Containerable> Search<C> createSearch(
SearchConfigurationWrapper<C> searchConfig, boolean mergeWithDefaultSearchWrapper, ModelServiceLocator modelServiceLocator) {
return createSearch(searchConfig, null, modelServiceLocator, Search.PanelType.DEFAULT, mergeWithDefaultSearchWrapper);
}

public static <C extends Containerable> Search<C> createSearch(
SearchConfigurationWrapper<C> searchConfig, ModelServiceLocator modelServiceLocator, boolean combineWithDefaultConfig) {
return createSearch(searchConfig, null, modelServiceLocator, Search.PanelType.DEFAULT, true);
Expand Down Expand Up @@ -365,9 +370,9 @@ public static <C extends Containerable> Search<ShadowType> createProjectionsTabS

private static <C extends Containerable> Search<C> createSearch(
SearchConfigurationWrapper<C> searchConfigurationWrapper, ResourceShadowDiscriminator discriminator,
ModelServiceLocator modelServiceLocator, Search.PanelType panelType, boolean createDefault) {
ModelServiceLocator modelServiceLocator, Search.PanelType panelType, boolean mergeWithDefaultSearchWrapper) {
SearchConfigurationWrapper<C> searchConfWrapper;
if (createDefault) {
if (mergeWithDefaultSearchWrapper) {
SearchConfigurationWrapper<C> defaultWrapper = createDefaultSearchBoxConfigurationWrapper(searchConfigurationWrapper.getTypeClass(),
discriminator, modelServiceLocator);
searchConfWrapper = combineSearchBoxConfiguration(defaultWrapper, searchConfigurationWrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.component.search.SearchConfigurationWrapper;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.schema.GetOperationOptionsBuilder;
import com.evolveum.midpoint.xml.ns._public.common.common_3.*;
Expand Down Expand Up @@ -166,7 +167,16 @@ protected boolean isUseObjectCounting() {

@Override
protected Search createSearch() {
return SearchFactory.createSearch(ShadowType.class, getPageBase());
return SearchFactory.createSearch(createSearchConfigWrapper(), false, getPageBase());
}

private SearchConfigurationWrapper<ShadowType> createSearchConfigWrapper() {
SearchConfigurationWrapper<ShadowType> config = SearchFactory.createDefaultSearchBoxConfigurationWrapper(ShadowType.class, getPageBase());
config
.removePropertySearchItem(ShadowType.F_RESOURCE_REF)
.removePropertySearchItem(ShadowType.F_OBJECT_CLASS)
.removePropertySearchItem(ShadowType.F_INTENT);
return config;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,48 +59,16 @@ protected boolean isUseObjectCounting() {

@Override
protected Search createSearch() {
// List<SearchItemDefinition> availableDefs = new ArrayList<>();
// availableDefs.addAll(createAttributeDefinitionList());
// return new Search(new ContainerTypeSearchItem(ShadowType.class), availableDefs);
return SearchFactory.createSearch(createSearchConfigWrapper(), getPageBase());
return SearchFactory.createSearch(createSearchConfigWrapper(), false, getPageBase());
}

private SearchConfigurationWrapper<ShadowType> createSearchConfigWrapper() {
SearchConfigurationWrapper<ShadowType> config = SearchFactory.createDefaultSearchBoxConfigurationWrapper(ShadowType.class, getPageBase());
config.getItemsList().clear();
config.getItemsList().addAll(createAttributeSearchItemWrappers());
return config;
}

// private <T extends ObjectType> List<SearchItemDefinition> createAttributeDefinitionList() {
//
// List<SearchItemDefinition> map = new ArrayList<>();
//
// RefinedObjectClassDefinition ocDef = null;
// try {
//
// if (getKind() != null) {
//
// ocDef = getDefinitionByKind();
//
// } else if (getObjectClass() != null) {
// ocDef = getDefinitionByObjectClass();
//
// }
// } catch (SchemaException e) {
// warn("Could not get determine object class definition");
// return map;
// }
//
// if (ocDef == null) {
// return map;
// }
//
// for (ResourceAttributeDefinition def : ocDef.getAttributeDefinitions()) {
// map.add(new SearchItemDefinition(ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def)), def, null));
// }
//
// return map;
// }

private <T extends ObjectType> List<AbstractSearchItemWrapper> createAttributeSearchItemWrappers() {

Expand All @@ -127,10 +95,8 @@ private <T extends ObjectType> List<AbstractSearchItemWrapper> createAttributeSe
}

for (ResourceAttributeDefinition def : ocDef.getAttributeDefinitions()) {
SearchItemType searchItem = new SearchItemType()
.path(new ItemPathType(ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def))))
.displayName(WebComponentUtil.getItemDefinitionDisplayNameOrName(def, ResourceContentResourcePanel.this));
itemsList.add(SearchFactory.createPropertySearchItemWrapper(ShadowType.class, def, ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def))));
itemsList.add(SearchFactory.createPropertySearchItemWrapper(ShadowType.class, def,
ItemPath.create(ShadowType.F_ATTRIBUTES, getAttributeName(def))));
}

return itemsList;
Expand Down

0 comments on commit fdd78f8

Please sign in to comment.