Skip to content

Commit

Permalink
save oid filter and display it on the search panel
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed May 25, 2022
1 parent 0b760f0 commit c4a9a4e
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5344,6 +5344,7 @@ public static <C extends Containerable> GuiObjectListViewType getPrincipalUserOb
return null;
}
objectListView = new GuiObjectListViewType();
objectListView.setType(WebComponentUtil.containerClassToQName(PrismContext.get(), viewType));
views.getObjectCollectionView().add(objectListView);
}
return objectListView;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,11 @@ private void saveCustomQuery() {
if (fulltextSearchItem != null) {
availableFilter.getSearchItem().add(fulltextSearchItem);
}
} else if (SearchBoxModeType.FULLTEXT.equals(getModelObject().getSearchMode())) {
SearchItemType oidtSearchItem = createOidSearchItem(getModelObject().findOidSearchItemWrapper());
if (oidtSearchItem != null) {
availableFilter.getSearchItem().add(oidtSearchItem);
}
}
saveSearchItemToAdminConfig(availableFilter);
}
Expand Down Expand Up @@ -189,7 +194,7 @@ private SearchItemType createAxiomSearchItem() {
axiomSearchItem.setFilter(PrismContext.get().getQueryConverter().createSearchFilterType(axiomFilter));
return axiomSearchItem;
} catch (SchemaException e) {
LOGGER.error("Unable to create parse axiom filter from query: {}, {}", getModelObject().getDslQuery(), e.getLocalizedMessage());
LOGGER.error("Unable to parse axiom filter from query: {}, {}", getModelObject().getDslQuery(), e.getLocalizedMessage());
}
return null;
}
Expand All @@ -203,7 +208,19 @@ private SearchItemType createFulltextSearchItem() {
fulltextSearchItem.setFilter(PrismContext.get().getQueryConverter().createSearchFilterType(filter));
return fulltextSearchItem;
} catch (SchemaException e) {
LOGGER.error("Unable to create parse axiom filter from query: {}, {}", getModelObject().getFullText(), e.getLocalizedMessage());
LOGGER.error("Unable to create fulltext filter from query: {}, {}", getModelObject().getFullText(), e.getLocalizedMessage());
}
return null;
}

private SearchItemType createOidSearchItem(OidSearchItemWrapper oidSearchItemWrapper) {
try {
SearchItemType oidSearchItem = new SearchItemType();
ObjectFilter filter = oidSearchItemWrapper.createFilter(getModelObject().getTypeClass(), getPageBase(), null);
oidSearchItem.setFilter(PrismContext.get().getQueryConverter().createSearchFilterType(filter));
return oidSearchItem;
} catch (SchemaException e) {
LOGGER.error("Unable to create oid filter from query: {}, {}", getModelObject().getFullText(), e.getLocalizedMessage());
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@
import com.evolveum.midpoint.prism.path.ItemPath;
import com.evolveum.midpoint.prism.query.*;
import com.evolveum.midpoint.util.exception.SchemaException;
import com.evolveum.midpoint.web.application.CollectionInstance;
import com.evolveum.midpoint.web.component.dialog.Popupable;
import com.evolveum.midpoint.web.component.search.SearchValue;

import com.evolveum.midpoint.xml.ns._public.common.common_3.*;

import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -257,7 +259,7 @@ public boolean isVisible() {
searchContainer.add(li);

WebMarkupContainer saveSearchContainer = new WebMarkupContainer(ID_SAVE_SEARCH_CONTAINER);
saveSearchContainer.add(new VisibleBehaviour(() -> !isPopupWindow()));
saveSearchContainer.add(new VisibleBehaviour(() -> !isPopupWindow() && isCollectionInstancePage()));
saveSearchContainer.setOutputMarkupId(true);
form.add(saveSearchContainer);
AjaxButton saveSearchButton = new AjaxButton(ID_SAVE_SEARCH_BUTTON) {
Expand Down Expand Up @@ -302,6 +304,10 @@ public boolean isVisible() {

}

private boolean isCollectionInstancePage() {
return getPageBase().getClass().getAnnotation(CollectionInstance.class) != null;
}

private boolean isPopupWindow() {
Component parent = SearchPanel.this.getParent();
while (parent != null) {
Expand Down Expand Up @@ -573,36 +579,42 @@ private void applyFilterToFulltextMode(List<SearchItemType> items) {

private void applyBasicModeSearchItem(SearchItemType searchItem) {
try {
if (searchItem.getPath() == null) {
return;
}
ItemPath path = searchItem.getPath().getItemPath();
PropertySearchItemWrapper item = null;
Iterator<AbstractSearchItemWrapper> it = getModelObject().getItems().iterator();
while (it.hasNext()) {
AbstractSearchItemWrapper itemWrapper = it.next();
if (itemWrapper instanceof PropertySearchItemWrapper && ((PropertySearchItemWrapper<?>) itemWrapper).getPath().equivalent(path)) {
item = (PropertySearchItemWrapper) itemWrapper;
break;
}
}
if (item == null) {
ObjectFilter filter = getPageBase().getQueryConverter().parseFilter(searchItem.getFilter(), getModelObject().getTypeClass());
if (searchItem.getPath() == null && filter instanceof ValueFilter && ((ValueFilter) filter).getPath() == null) {
return;
}
item.setVisible(true);

ObjectFilter filter = getPageBase().getQueryConverter().parseFilter(searchItem.getFilter(), getModelObject().getTypeClass());

AbstractSearchItemWrapper item = null;
if (filter instanceof ValueFilter) {
ItemPath path = searchItem.getPath().getItemPath();
Iterator<AbstractSearchItemWrapper> it = getModelObject().getItems().iterator();
while (it.hasNext()) {
AbstractSearchItemWrapper itemWrapper = it.next();
if (itemWrapper instanceof PropertySearchItemWrapper && ((PropertySearchItemWrapper<?>) itemWrapper).getPath().equivalent(path)) {
item = itemWrapper;
break;
}
}
List<? extends PrismValue> values = ((ValueFilter) filter).getValues();
if (values != null && values.size() > 0) {//todo can it be there multiple values?
if (TextSearchItemPanel.class.equals(item.getSearchItemPanelClass())) {
item.setValue(new SearchValue(values.get(0).getRealValue().toString()));
item.setValue(new SearchValue<String>(values.get(0).getRealValue().toString()));
} else {
item.setValue(new SearchValue(values.get(0).getRealValue()));
}
}
} else if (filter instanceof InOidFilter) {
item = getModelObject().findOidSearchItemWrapper();
if (((InOidFilter)filter).getOids() != null) {
item.setValue(new SearchValue<String>(StringUtils.join(((InOidFilter) filter).getOids(), " ")));
}
}

if (item == null) {
return;
}
item.setVisible(true);

} catch (SchemaException e) {
LOG.error("Unable to parse filter {}, {}", searchItem.getFilter(), e.getLocalizedMessage());
}
Expand Down

0 comments on commit c4a9a4e

Please sign in to comment.