Skip to content

Commit

Permalink
started with SearchItemDefinition clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Dec 14, 2021
1 parent 17cec78 commit 9bd32c9
Show file tree
Hide file tree
Showing 18 changed files with 272 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.web.component.search.AbstractSearchItemDefinition;
import com.evolveum.midpoint.web.component.search.FunctionSearchItemDefinition;
import com.evolveum.midpoint.web.component.search.Search;
import com.evolveum.midpoint.web.component.search.SearchItem;
import com.evolveum.midpoint.web.component.util.VisibleBehaviour;
Expand All @@ -30,6 +32,7 @@
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.EnumChoiceRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.StringResourceModel;
import org.apache.wicket.model.util.ListModel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ protected Search createSearch(Class<O> type) {
ContainerTypeSearchItem<O> typeSearchItem = new ContainerTypeSearchItem<>(new SearchValue<>(type, ""));
String collectionName = isCollectionViewPanelForCompiledView() ? getCollectionNameParameterValue().toString() : null;
return SearchFactory.createSearch(typeSearchItem, collectionName, getFixedSearchItems(), null, getPageBase(),
null, true, true, Search.PanelType.DEFAULT);
null, getSpecialSearchItemDefs(), true, true, Search.PanelType.DEFAULT);
}

protected List<SearchItem> getSpecialSearchItemDefs() {
return new ArrayList<>();
}

protected List<ItemPath> getFixedSearchItems() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public Search<C> load() {
}

if (search == null ||
(!SearchBoxModeType.ADVANCED.equals(search.getSearchType()) && !search.getAllDefinitions().containsAll(newSearch.getAllDefinitions()))
(!SearchBoxModeType.ADVANCED.equals(search.getSearchType()) && !search.getSearchItems().containsAll(newSearch.getSearchItems()))
|| search.isTypeChanged()) {
search = newSearch;
search.searchWasReload();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@

public abstract class AbstractSearchItemDefinition implements Serializable, Comparable<AbstractSearchItemDefinition> {

protected boolean searchItemDisplayed;
protected boolean visibleByDefault = true;
private PolyStringType displayName;
private String description;
private boolean fixed;
private boolean selected = false;

public abstract String getName();

Expand Down Expand Up @@ -49,14 +47,6 @@ public void setDescription(String description) {
this.description = description;
}

public boolean isSearchItemDisplayed() {
return searchItemDisplayed;
}

public void setSearchItemDisplayed(boolean searchItemDisplayed) {
this.searchItemDisplayed = searchItemDisplayed;
}

public boolean isFixed() {
return fixed;
}
Expand All @@ -65,14 +55,6 @@ public void setFixed(boolean fixed) {
this.fixed = fixed;
}

public boolean isSelected() {
return selected;
}

public void setSelected(boolean selected) {
this.selected = selected;
}

@Override
public int compareTo(AbstractSearchItemDefinition def) {
String n1 = getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
import java.time.Duration;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Predicate;
import javax.xml.namespace.QName;

import org.apache.commons.lang3.StringUtils;
Expand Down Expand Up @@ -43,16 +40,13 @@

import com.evolveum.midpoint.gui.api.GuiStyleConstants;
import com.evolveum.midpoint.gui.api.component.BasePanel;
import com.evolveum.midpoint.gui.api.model.LoadableModel;
import com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIcon;
import com.evolveum.midpoint.gui.impl.component.icon.CompositedIconBuilder;
import com.evolveum.midpoint.gui.impl.component.icon.IconCssStyle;
import com.evolveum.midpoint.gui.impl.component.icon.LayeredIconCssStyle;
import com.evolveum.midpoint.prism.Containerable;
import com.evolveum.midpoint.prism.PrismContext;
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.path.ItemPathCollectionsUtil;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.util.exception.SystemException;
import com.evolveum.midpoint.util.logging.Trace;
Expand Down Expand Up @@ -149,22 +143,22 @@ protected void onInitialize() {
// };
// }

private List<AbstractSearchItemDefinition> createPropertiesList() {
List<AbstractSearchItemDefinition> list = new ArrayList<>();

List<ItemPath> specialItemPaths = new ArrayList<>();
getModelObject().getSpecialItems().stream().filter(specItem -> (specItem instanceof PropertySearchItem))
.forEach(specItem -> specialItemPaths.add(((PropertySearchItem<?>) specItem).getPath()));

Search search = getModelObject();
search.getAllDefinitions().stream().filter((Predicate<AbstractSearchItemDefinition>) def ->
(def instanceof PropertySearchItemDefinition) &&
!ItemPathCollectionsUtil.containsEquivalent(specialItemPaths, ((PropertySearchItemDefinition)def).getPath()))
.forEach((Consumer<AbstractSearchItemDefinition>) def -> list.add(def));
Collections.sort(list);

return list;
}
// private List<AbstractSearchItemDefinition> createPropertiesList() {
// List<AbstractSearchItemDefinition> list = new ArrayList<>();
//
// List<ItemPath> specialItemPaths = new ArrayList<>();
// getModelObject().getSpecialItems().stream().filter(specItem -> (specItem instanceof PropertySearchItem))
// .forEach(specItem -> specialItemPaths.add(((PropertySearchItem<?>) specItem).getPath()));
//
// Search search = getModelObject();
// search.getAllDefinitions().stream().filter((Predicate<AbstractSearchItemDefinition>) def ->
// (def instanceof PropertySearchItemDefinition) &&
// !ItemPathCollectionsUtil.containsEquivalent(specialItemPaths, ((PropertySearchItemDefinition)def).getPath()))
// .forEach((Consumer<AbstractSearchItemDefinition>) def -> list.add(def));
// Collections.sort(list);
//
// return list;
// }

private <S extends SearchItem, T extends Serializable> void initLayout() {
setOutputMarkupId(true);
Expand Down Expand Up @@ -340,8 +334,8 @@ private void searchBoxTypeUpdated(AjaxRequestTarget target, SearchBoxModeType se
refreshSearchForm(target);
}

private void addOneItemPerformed(AbstractSearchItemDefinition searchItemDef, AjaxRequestTarget target) {
searchItemDef.setSearchItemDisplayed(true);
private void addOneItemPerformed(SearchItem searchItem, AjaxRequestTarget target) {
searchItem.setSearchItemDisplayed(true);
// Search search = getModelObject();
// SearchItem item = search.addItem(property);
// item.setEditWhenVisible(true);
Expand All @@ -350,10 +344,10 @@ private void addOneItemPerformed(AbstractSearchItemDefinition searchItemDef, Aja
}

private void addItemPerformed(AjaxRequestTarget target) {
getModelObject().getAllDefinitions().forEach(def -> {
if (def.isSelected()) {
def.setSearchItemDisplayed(true);
def.setSelected(false);
getModelObject().getSearchItems().forEach(searchItem -> {
if (searchItem.isSelected()) {
searchItem.setSearchItemDisplayed(true);
searchItem.setSelected(false);
}
});
// Search search = getModelObject();
Expand Down Expand Up @@ -512,7 +506,7 @@ public void onClick(AjaxRequestTarget target) {
@Override
public boolean isVisible() {
Search search = getModelObject();
return !search.getAllDefinitions().isEmpty();
return !search.getSearchItems().isEmpty();
}
});
more.setOutputMarkupId(true);
Expand Down Expand Up @@ -546,12 +540,12 @@ protected void onUpdate(AjaxRequestTarget target) {
});
popover.add(addText);

ListView properties = new ListView<AbstractSearchItemDefinition>(ID_PROPERTIES,
Model.ofList(getModelObject().getAllDefinitions())) {
ListView properties = new ListView<SearchItem>(ID_PROPERTIES,
Model.ofList(getModelObject().getSearchItems())) {
private static final long serialVersionUID = 1L;

@Override
protected void populateItem(final ListItem<AbstractSearchItemDefinition> item) {
protected void populateItem(final ListItem<SearchItem> item) {
CheckBox check = new CheckBox(ID_CHECK,
new PropertyModel<>(item.getModel(), SearchItemDefinition.F_SELECTED));
check.add(new AjaxFormComponentUpdatingBehavior("change") {
Expand Down Expand Up @@ -631,10 +625,10 @@ public String getDataPlacement() {
// });
}

private boolean isPropertyItemVisible(AbstractSearchItemDefinition def, String propertySearchText) {
return !def.isSearchItemDisplayed() &&
private boolean isPropertyItemVisible(SearchItem searchItem, String propertySearchText) {
return !searchItem.isSearchItemDisplayed() &&
(StringUtils.isEmpty(propertySearchText)
|| def.getName().toLowerCase().contains(propertySearchText.toLowerCase()));
|| searchItem.getName().toLowerCase().contains(propertySearchText.toLowerCase()));
}
};
propList.add(properties);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2021 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 com.evolveum.midpoint.gui.api.util.WebComponentUtil;
import com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectReferenceType;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.model.IModel;

import java.util.function.Function;

public class FunctionSearchItemDefinition extends SpecialSearchItemDefinition<Function<Search, SearchItem>> {

public FunctionSearchItemDefinition(IModel<Function<Search, SearchItem>> valueModel) {
super(valueModel);
}

@Override
public String getName() {
return ""; //todo implement
}

@Override
public String getHelp(){
return ""; //todo implement
}

@Override
public SearchItem<FilterSearchItemDefinition> createSearchItem() {
return null; //todo implement
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (C) 2021 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 org.apache.wicket.model.IModel;

public class OidSearchItemDefinition extends SpecialSearchItemDefinition {

public OidSearchItemDefinition(IModel valueModel) {
super(valueModel);
}

@Override
public String getName() {
return ""; //todo implement
}

@Override
public String getHelp(){
return ""; //todo implement
}

@Override
public SearchItem<OidSearchItemDefinition> createSearchItem() {
return null; //todo implement
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ public void setPath(ItemPath path) {

@Override
public PropertySearchItem<PropertySearchItemDefinition> createSearchItem() {
return new PropertySearchItem<>(null, PropertySearchItemDefinition.this);
PropertySearchItem<PropertySearchItemDefinition> item = new PropertySearchItem<>(null, PropertySearchItemDefinition.this);
item.setSearchItemDisplayed(isVisibleByDefault());
return item;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import com.evolveum.midpoint.gui.api.model.LoadableModel;

import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.jetbrains.annotations.NotNull;

import com.evolveum.midpoint.gui.api.page.PageBase;
Expand Down Expand Up @@ -82,7 +80,7 @@ public enum PanelType {
private String oid;

private final ContainerTypeSearchItem typeSearchItem;
private final List<AbstractSearchItemDefinition> allDefinitions;
private final List<SearchItem> searchItems;

// private final List<AbstractSearchItemDefinition> availableDefinitions = new ArrayList<>();
private LoadableModel<List<SearchItem>> itemsModel;
Expand All @@ -93,14 +91,14 @@ public enum PanelType {
private boolean isCollectionItemVisible = false;
private boolean isOidSearchEnabled = false;

public Search(ContainerTypeSearchItem<C> typeSearchItem, List<AbstractSearchItemDefinition> allDefinitions) {
this(typeSearchItem, allDefinitions, false, null, null, false);
public Search(ContainerTypeSearchItem<C> typeSearchItem, List<SearchItem> searchItems) {
this(typeSearchItem, searchItems, false, null, null, false);
}

public Search(ContainerTypeSearchItem<C> typeSearchItem, List<AbstractSearchItemDefinition> allDefinitions, boolean isFullTextSearchEnabled,
public Search(ContainerTypeSearchItem<C> typeSearchItem, List<SearchItem> searchItems, boolean isFullTextSearchEnabled,
SearchBoxModeType searchBoxModeType, List<SearchBoxModeType> allowedSearchType, boolean isOidSearchenabled) {
this.typeSearchItem = typeSearchItem;
this.allDefinitions = allDefinitions;
this.searchItems = searchItems;
this.isOidSearchEnabled = isOidSearchenabled;

this.isFullTextSearchEnabled = isFullTextSearchEnabled;
Expand Down Expand Up @@ -139,11 +137,8 @@ private void initItemsModel() {
itemsModel = new LoadableModel<List<SearchItem>>() {
@Override
protected List<SearchItem> load() {
List<SearchItem> items = new ArrayList<>();
List<AbstractSearchItemDefinition> defs = allDefinitions.stream().filter(def -> def.isSearchItemDisplayed())
return searchItems.stream().filter(searchItem -> searchItem.isSearchItemDisplayed())
.collect(Collectors.toList());
defs.forEach(def -> items.add(def.createSearchItem()));
return items;
}
};
}
Expand Down Expand Up @@ -212,8 +207,8 @@ public List<FilterSearchItem> getFilterItems() {
// return Collections.unmodifiableList(availableDefinitions);
// }

public List<AbstractSearchItemDefinition> getAllDefinitions() {
return Collections.unmodifiableList(allDefinitions);
public List<SearchItem> getSearchItems() {
return Collections.unmodifiableList(searchItems);
}

// public AttributeSearchItem addItem(ItemDefinition def) {
Expand Down Expand Up @@ -331,7 +326,7 @@ public List<AbstractSearchItemDefinition> getAllDefinitions() {
// availableDefinitions.add(itemDef);
// }

public void delete(AbstractSearchItemDefinition item) {
public void delete(SearchItem item) {
item.setSearchItemDisplayed(false);
// if (items.remove(item)) {
// availableDefinitions.add(item.getSearchItemDefinition());
Expand Down Expand Up @@ -867,7 +862,7 @@ public String debugDump(int indent) {
DebugUtil.debugDumpWithLabelLn(sb, "advancedQuery", advancedQuery, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "advancedError", advancedError, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "type", getTypeClass(), indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "allDefinitions", allDefinitions, indent + 1);
DebugUtil.debugDumpWithLabelLn(sb, "allDefinitions", searchItems, indent + 1);
// DebugUtil.debugDumpWithLabelLn(sb, "availableDefinitions", availableDefinitions, indent + 1);
DebugUtil.debugDumpWithLabel(sb, "items", itemsModel.getObject(), indent + 1);
return sb.toString();
Expand Down

0 comments on commit 9bd32c9

Please sign in to comment.