Skip to content

Commit

Permalink
save advanced query fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kateryna Honchar committed Jun 9, 2022
1 parent 0a62899 commit 5d4d8db
Showing 1 changed file with 36 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.evolveum.prism.xml.ns._public.types_3.ItemPathType;
import com.evolveum.prism.xml.ns._public.types_3.PolyStringType;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
Expand Down Expand Up @@ -141,24 +142,27 @@ private void saveCustomQuery(AjaxRequestTarget ajaxRequestTarget) {
AvailableFilterType availableFilter = new AvailableFilterType();
availableFilter.setDisplay(new DisplayType().label(queryNameModel.getObject()));
availableFilter.setSearchMode(getModelObject().getSearchMode());
SearchItemType searchItem = null;
if (SearchBoxModeType.BASIC.equals(getModelObject().getSearchMode())) {
availableFilter.getSearchItem().addAll(getAvailableFilterSearchItems(type, search.getItems(), search.getSearchMode()));
} else if (SearchBoxModeType.AXIOM_QUERY.equals(getModelObject().getSearchMode())) {
SearchItemType axiomSearchItem = createAxiomSearchItem();
if (axiomSearchItem != null) {
availableFilter.getSearchItem().add(axiomSearchItem);
} else {
if (SearchBoxModeType.AXIOM_QUERY.equals(getModelObject().getSearchMode())) {
searchItem = createAxiomSearchItem();
} else if (SearchBoxModeType.ADVANCED.equals(getModelObject().getSearchMode())) {
searchItem = createAdvancedSearchItem();
} else if (SearchBoxModeType.FULLTEXT.equals(getModelObject().getSearchMode())) {
searchItem = createFulltextSearchItem();
} else if (SearchBoxModeType.OID.equals(getModelObject().getSearchMode())) {
searchItem = createOidSearchItem(getModelObject().findOidSearchItemWrapper());
}
} else if (SearchBoxModeType.FULLTEXT.equals(getModelObject().getSearchMode())) {
SearchItemType fulltextSearchItem = createFulltextSearchItem();
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);
if (searchItem != null) {
availableFilter.getSearchItem().add(searchItem);
}
}
if (CollectionUtils.isEmpty(availableFilter.getSearchItem())) {
ajaxRequestTarget.add(getPageBase().getFeedbackPanel());
return;
}
saveSearchItemToAdminConfig(availableFilter, ajaxRequestTarget);
}

Expand Down Expand Up @@ -198,6 +202,22 @@ private SearchItemType createAxiomSearchItem() {
return axiomSearchItem;
} catch (SchemaException e) {
LOGGER.error("Unable to parse axiom filter from query: {}, {}", getModelObject().getDslQuery(), e.getLocalizedMessage());
getPageBase().error("Unable to parse axiom filter from query: " + getModelObject().getDslQuery());
}
return null;
}

private SearchItemType createAdvancedSearchItem() {
try {
SearchItemType advancedSearchItem = new SearchItemType();

SearchFilterType search = PrismContext.get().parserFor(getModelObject().getAdvancedQuery()).type(SearchFilterType.COMPLEX_TYPE).parseRealValue();
ObjectFilter advancedFilter = PrismContext.get().getQueryConverter().parseFilter(search, getModelObject().getTypeClass());
advancedSearchItem.setFilter(PrismContext.get().getQueryConverter().createSearchFilterType(advancedFilter));
return advancedSearchItem;
} catch (Exception e) {
LOGGER.error("Unable to parse advanced filter from query: ", getModelObject().getAdvancedQuery(), e.getLocalizedMessage());
getPageBase().error("Unable to parse advanced filter from query: " + getModelObject().getAdvancedQuery());
}
return null;
}
Expand All @@ -212,6 +232,7 @@ private SearchItemType createFulltextSearchItem() {
return fulltextSearchItem;
} catch (SchemaException e) {
LOGGER.error("Unable to create fulltext filter from query: {}, {}", getModelObject().getFullText(), e.getLocalizedMessage());
getPageBase().error("Unable to parse fulltext filter from query: " + getModelObject().getFullText());
}
return null;
}
Expand All @@ -223,7 +244,8 @@ private SearchItemType createOidSearchItem(OidSearchItemWrapper oidSearchItemWra
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());
LOGGER.error("Unable to parse oid filter from query: {}, {}", oidSearchItemWrapper.getValue().getValue(), e.getLocalizedMessage());
getPageBase().error("Unable to parse oid filter from query: " + oidSearchItemWrapper.getValue().getValue());
}
return null;
}
Expand Down

0 comments on commit 5d4d8db

Please sign in to comment.