Skip to content

Commit

Permalink
more refactoring of search factory, adapting code
Browse files Browse the repository at this point in the history
  • Loading branch information
katkav committed Dec 13, 2022
1 parent 33f3999 commit 7c91b80
Show file tree
Hide file tree
Showing 15 changed files with 227 additions and 481 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5118,6 +5118,10 @@ public static List<DisplayableValue<?>> getAllowedValues(ExpressionType expressi
return allowedValues;
}

public static String getCollectionNameParameterValueAsString(PageBase pageBase) {
StringValue stringValue = getCollectionNameParameterValue(pageBase);
return stringValue == null ? null : stringValue.toString();
}
public static StringValue getCollectionNameParameterValue(PageBase pageBase) {
PageParameters parameters = pageBase.getPageParameters();
return parameters == null ? null : parameters.get(PageBase.PARAMETER_OBJECT_COLLECTION_NAME);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
import java.util.stream.Collectors;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.gui.impl.component.search.panel.SearchPanel;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.AbstractSearchItemWrapper;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.ObjectCollectionSearchItemWrapper;
import com.evolveum.midpoint.gui.impl.component.search.wrapper.PropertySearchItemWrapper;
import com.evolveum.midpoint.web.component.data.*;

import com.evolveum.midpoint.web.component.search.SearchValue;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -45,7 +37,11 @@
import com.evolveum.midpoint.gui.api.util.ModelServiceLocator;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.api.util.WebModelServiceUtils;
import com.evolveum.midpoint.gui.impl.component.search.*;
import com.evolveum.midpoint.gui.impl.component.search.PredefinedSearchableItems;
import com.evolveum.midpoint.gui.impl.component.search.Search;
import com.evolveum.midpoint.gui.impl.component.search.SearchBoxConfigurationUtil;
import com.evolveum.midpoint.gui.impl.component.search.SearchFactory;
import com.evolveum.midpoint.gui.impl.component.search.panel.SearchPanel;
import com.evolveum.midpoint.gui.impl.component.table.WidgetTableHeader;
import com.evolveum.midpoint.gui.impl.page.admin.report.PageReport;
import com.evolveum.midpoint.gui.impl.util.GuiImplUtil;
Expand All @@ -66,14 +62,14 @@
import com.evolveum.midpoint.schema.expression.VariablesMap;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.MiscSchemaUtil;
import com.evolveum.midpoint.schema.util.ObjectQueryUtil;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
import com.evolveum.midpoint.task.api.Task;
import com.evolveum.midpoint.util.QNameUtil;
import com.evolveum.midpoint.util.exception.*;
import com.evolveum.midpoint.util.logging.Trace;
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.midpoint.web.component.CompositedIconButtonDto;
import com.evolveum.midpoint.web.component.data.*;
import com.evolveum.midpoint.web.component.data.column.CheckBoxHeaderColumn;
import com.evolveum.midpoint.web.component.data.column.InlineMenuButtonColumn;
import com.evolveum.midpoint.web.component.menu.cog.InlineMenuItem;
Expand Down Expand Up @@ -166,101 +162,47 @@ private boolean isUseStorageSearch(Search<C> search) {
}

String searchByName = getSearchByNameParameterValue();
if (searchByName != null && search.searchByNameEquals(searchByName)) {
return false;
}
return true;
return searchByName == null || !search.searchByNameEquals(searchByName);
}

protected LoadableDetachableModel<Search<C>> createSearchModel() {
private LoadableDetachableModel<Search<C>> createSearchModel() {
return new LoadableDetachableModel<>() {

private static final long serialVersionUID = 1L;

@Override
public Search<C> load() {
return loadSearchModel();
}
};
}

Search<C> search = null;
PageStorage storage = getPageStorage();
if (storage != null) {
search = storage.getSearch();
}

if (!isUseStorageSearch(search)) {
search = createSearch(getType());
}



private Search<C> loadSearchModel() {
PageStorage storage = getPageStorage();
Search<C> search = loadSearch(storage);

if (storage != null) {
storage.setSearch(search);
}
getPageBase().getPageParameters().remove(PageBase.PARAMETER_SEARCH_BY_NAME);
return search;
}

// Search<C> newSearch = createSearch(getType());
//
// Search<C> search = null;
// PageStorage storage = getPageStorage();
// String searchByName = getSearchByNameParameterValue();
// if (storage != null && storage.getSearch() != null && (searchByName == null || storage.getSearch().searchByNameEquals(searchByName))) { // do NOT use storage when using name search (e.g. from dashboard)
// search = storage.getSearch();
// }
//
// if (search == null || search.isTypeChanged() ||
// (!SearchBoxModeType.BASIC.equals(search.getSearchMode()) && !search.allPropertyItemsPresent(newSearch.getItems()))) {
// search = newSearch;
//// search.searchWasReload();
// }

// if (searchByName != null && !search.searchByNameEquals(searchByName)) {
// if (SearchBoxModeType.FULLTEXT.equals(search.getSearchMode())) {
// search.setFullText(searchByName);
// } else {
// for (AbstractSearchItemWrapper item : search.getItems()) {
// if (!(item instanceof PropertySearchItemWrapper)) {
// continue;
// }
// if (ItemPath.create(ObjectType.F_NAME).equivalent(((PropertySearchItemWrapper) item).getPath())) {
// item.setValue(new SearchValue<>(searchByName));
// }
// }
// }
// }

// todo this should not be here! Search model doesn't handle paging, only query. Paging is handled by table (which technically doesn't care about specific query)
// if (isCollectionViewPanel()) {
// CompiledObjectCollectionView view = getObjectCollectionView();
// if (view == null) {
// getPageBase().redirectToNotFoundPage();
// }
//
// if (isCollectionViewPanelForWidget()) {
// search.getItems().add(new ObjectCollectionSearchItemWrapper(view));
// }
//
// if (storage != null && view.getPaging() != null) {
// ObjectPaging paging = ObjectQueryUtil.convertToObjectPaging(view.getPaging(), getPrismContext());
// if (storage.getPaging() == null) {
// storage.setPaging(paging);
// }
// if (getTableId() != null && paging.getMaxSize() != null
// && !getPageBase().getSessionStorage().getUserProfile().isExistPagingSize(getTableId())) {
// getPageBase().getSessionStorage().getUserProfile().setPagingSize(getTableId(), paging.getMaxSize());
// }
// }
// }
private Search<C> loadSearch(PageStorage storage) {
Search<C> search = null;
if (storage != null) {
search = storage.getSearch();
}

if (storage != null) {
storage.setSearch(search);
}
getPageBase().getPageParameters().remove(PageBase.PARAMETER_SEARCH_BY_NAME);
return search;
}
};
if (!isUseStorageSearch(search)) {
search = createSearch();
}
return search;
}

protected String getSearchByNameParameterValue() {
return null;
}

protected Search<C> createSearch(Class<C> type) {
private Search<C> createSearch() {
Class<C> defaultType = getType();

SearchFactory<C> searchFactory = new SearchFactory<>()
Expand All @@ -273,12 +215,10 @@ protected Search<C> createSearch(Class<C> type) {
.isViewForDashboard(isCollectionViewPanelForWidget());

return searchFactory.createSearch();

// return SearchFactory.createSearch(getContainerDefinitionForColumns(), getDefaultSearchBoxConfiguration(defaultType), getObjectCollectionView(), getPageBase());
}

protected SearchBoxConfigurationType getDefaultSearchBoxConfiguration(Class<C> type) {
return SearchBoxConfigurationUtil.getDefaultSearchBoxConfiguration(type, Arrays.asList(ObjectType.F_EXTENSION), null, getPageBase());
return SearchBoxConfigurationUtil.getDefaultSearchBoxConfiguration(type, null, getPageBase());
}

private void initLayout() {
Expand All @@ -287,7 +227,7 @@ private void initLayout() {
itemTable.setOutputMarkupPlaceholderTag(true);
add(itemTable);

itemTable.add(new VisibleBehaviour(() -> isListPanelVisible()));
itemTable.add(new VisibleBehaviour(this::isListPanelVisible));
setOutputMarkupId(true);

}
Expand Down Expand Up @@ -394,10 +334,7 @@ protected boolean isPagingVisible() {
private int getDefaultPageSize() {
if (isPreview()) {
Integer previewSize = ((PreviewContainerPanelConfigurationType) config).getPreviewSize();
if (previewSize == null) {
return UserProfileStorage.DEFAULT_DASHBOARD_PAGING_SIZE;
}
return previewSize;
return Objects.requireNonNullElse(previewSize, UserProfileStorage.DEFAULT_DASHBOARD_PAGING_SIZE);
}

Integer collectionViewPagingSize = getViewPagingMaxSize();
Expand Down Expand Up @@ -718,7 +655,7 @@ private boolean pathNotEmpty(ItemPath columnPath) {
}

protected IModel<?> getExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
return new ReadOnlyModel<>(() -> loadExportableColumnDataModel(rowModel, customColumn, columnPath, expression));
return () -> loadExportableColumnDataModel(rowModel, customColumn, columnPath, expression);
}

public Collection<String> loadExportableColumnDataModel(IModel<PO> rowModel, GuiObjectColumnType customColumn, ItemPath columnPath, ExpressionType expression) {
Expand All @@ -729,7 +666,7 @@ public Collection<String> loadExportableColumnDataModel(IModel<PO> rowModel, Gui
Item<?, ?> item = findItem(value, columnPath);

if (expression != null) {
Collection collection = evaluateExpression(value, item, expression, customColumn);
Collection<String> collection = evaluateExpression(value, item, expression, customColumn);
return getValuesString(collection, customColumn.getDisplayValue());
}
if (item != null) {
Expand Down Expand Up @@ -778,6 +715,7 @@ private List<String> getValuesString(Item<?, ?> item, DisplayValueType displayVa
String number;
//This is really ugly HACK FIXME TODO
if (item.getDefinition() != null && UserType.F_LINK_REF.equivalent(item.getDefinition().getItemName())) {
//noinspection unchecked
number = WebComponentUtil.countLinkFroNonDeadShadows((Collection<ObjectReferenceType>) item.getRealValues());
} else {
number = String.valueOf(item.getValues().size());
Expand All @@ -790,14 +728,14 @@ private List<String> getValuesString(Item<?, ?> item, DisplayValueType displayVa
.collect(Collectors.toList());
}

private List<String> getValuesString(Collection collection, DisplayValueType displayValue) {
private List<String> getValuesString(Collection<String> collection, DisplayValueType displayValue) {
if (collection == null) {
return null;
}
if (DisplayValueType.NUMBER.equals(displayValue)) {
return Collections.singletonList(String.valueOf(collection.size()));
}
return (List<String>) collection.stream()
return collection.stream()
.filter(Objects::nonNull)
.map(object -> getStringValue(object, null))
.collect(Collectors.toList());
Expand Down Expand Up @@ -1058,7 +996,7 @@ public CompiledObjectCollectionView getObjectCollectionView() {
if (view != null) {
return view;
}
String collectionName = WebComponentUtil.getCollectionNameParameterValue(getPageBase()).toString();
String collectionName = WebComponentUtil.getCollectionNameParameterValueAsString(getPageBase());
return getPageBase().getCompiledGuiProfile().findObjectCollectionView
(WebComponentUtil.containerClassToQName(getPageBase().getPrismContext(), getType()), collectionName);
}
Expand Down Expand Up @@ -1152,8 +1090,7 @@ private String getWidgetNameOfCollection() {
}

protected boolean isCollectionViewPanelForCompiledView() {
return WebComponentUtil.getCollectionNameParameterValue(getPageBase()) != null
&& WebComponentUtil.getCollectionNameParameterValue(getPageBase()).toString() != null;
return WebComponentUtil.getCollectionNameParameterValueAsString(getPageBase()) != null;
}

protected boolean isCollectionViewPanel() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,9 @@ public void setCollectionRefOid(String collectionRefOid) {
this.collectionRefOid = collectionRefOid;
}

@Deprecated
public Search(SearchConfigurationWrapper searchConfigurationWrapper) {
this.searchConfigurationWrapper = searchConfigurationWrapper;
}

public Search(Class type, SearchBoxConfigurationType searchBoxConfigurationType) {
this.typeClass = type;
this.defaultSearchBoxMode = searchBoxConfigurationType.getDefaultMode();

//TODO collection view
// if (collectionViewN == null) {
// //todo we need to get saved searches here for the specified type
// List<CompiledObjectCollectionView> views = modelServiceLocator.getCompiledGuiProfile()
// .findAllApplicableObjectCollectionViews(WebComponentUtil.containerClassToQName(PrismContext.get(), type))
// .stream()
// .filter(v -> v.getFilter() != null) //todo should we check also collectionRef?
// .collect(Collectors.toList());
// if (CollectionUtils.isNotEmpty(views)) {
// ObjectCollectionListSearchItemWrapper<C> viewListItem = new ObjectCollectionListSearchItemWrapper<>(type,
// views);
// viewListItem.setVisible(true);
// basicSearchWrapper.getItemsList().add(viewListItem);
// }
// }
}

public void setAllowedTypeList(List<QName> allowedTypeList) {
Expand Down Expand Up @@ -196,22 +175,17 @@ public String getAdvancedError() {
return advancedError;
}

@Deprecated
//TODO
public String getAdvancedQuery() {
return null;
return advancedQueryWrapper.getAdvancedQuery();
}

@Deprecated
//TODO
public String getDslQuery() {
return null;
return axiomQueryWrapper.getDslQuery();
}

@Deprecated
//TODO
public void setDslQuery(String dslQuery) {

axiomQueryWrapper = new AxiomQueryWrapper();
axiomQueryWrapper.setDslQuery(dslQuery);
}

private ObjectQuery createAdvancedObjectFilter(PrismContext ctx) throws SchemaException {
Expand Down Expand Up @@ -486,22 +460,19 @@ public VariablesMap getFilterVariables(VariablesMap defaultVariables, PageBase p
return variables;
}

@Deprecated
//TODO
public void setAdvancedQuery(String advancedQuery) {
advancedQueryWrapper = new AdvancedQueryWrapper();
advancedQueryWrapper.setAdvancedQuery(advancedQuery);
// this.advancedQuery = advancedQuery;
}

@Deprecated
//TODO
public String getFullText() {
return null;
return fulltextQueryWrapper.getFullText();
}

@Deprecated
//TODO
public void setFullText(String fullText) {

fulltextQueryWrapper = new FulltextQueryWrapper();
fulltextQueryWrapper.setFullText(fullText);
}

public boolean allPropertyItemsPresent(List<AbstractSearchItemWrapper> items) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ public class SearchBoxConfigurationUtil {
));
}

public static <C extends Containerable> SearchBoxConfigurationType getDefaultSearchBoxConfiguration(Class<C> type, Collection<ItemPath> extensionPaths, ResourceShadowCoordinates coordinates, ModelServiceLocator modelServiceLocator) {
public static <C extends Containerable> SearchBoxConfigurationType getDefaultSearchBoxConfiguration(Class<C> type, ResourceShadowCoordinates coordinates, ModelServiceLocator modelServiceLocator) {
SearchBoxConfigurationType defaultSearchBoxConfig = createDefaultSearchBoxConfig();
SearchItemsType searchItemsType = createSearchItemsForType(type, extensionPaths, coordinates, modelServiceLocator);
SearchItemsType searchItemsType = createSearchItemsForType(type, Arrays.asList(ObjectType.F_EXTENSION), coordinates, modelServiceLocator);
defaultSearchBoxConfig.setSearchItems(searchItemsType);
return defaultSearchBoxConfig;
}
Expand Down

0 comments on commit 7c91b80

Please sign in to comment.