Skip to content

Commit

Permalink
fix for MID-9148 searchBoxConfiguration → objectTypeConfiguration doe…
Browse files Browse the repository at this point in the history
…s not work
  • Loading branch information
KaterynaHonchar committed Oct 2, 2023
1 parent b79b078 commit b6fb56a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import com.evolveum.midpoint.prism.query.ObjectFilter;
import com.evolveum.midpoint.prism.query.ObjectPaging;
import com.evolveum.midpoint.prism.query.ObjectQuery;
import com.evolveum.midpoint.schema.GetOperationOptions;
import com.evolveum.midpoint.schema.SelectorOptions;
import com.evolveum.midpoint.schema.constants.ObjectTypes;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.ObjectTypeUtil;
Expand Down Expand Up @@ -209,7 +207,8 @@ private Search createSearch() {
.isPreview(isPreview())
.isViewForDashboard(isCollectionViewPanelForWidget())
.additionalSearchContext(createAdditionalSearchContext())
.setFullTextSearchEnabled(isFulltextEnabled());
.setFullTextSearchEnabled(isFulltextEnabled())
.setTypeChanged(isTypeChanged());

return searchBuilder.build();
}
Expand All @@ -218,6 +217,15 @@ protected boolean isFulltextEnabled() {
return true;
}

private <T extends Serializable> boolean isTypeChanged() {
PageStorage storage = getPageStorage();
if (storage != null && storage.getSearch() != null) {
Search<T> search = storage.getSearch();
return search.isTypeChanged();
}
return false;
}

protected SearchContext createAdditionalSearchContext() {
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,10 @@ public boolean searchByNameEquals(String nameValueToCompare) {
}

public boolean isForceReload() {
return isTypeChanged();
}

public boolean isTypeChanged() {
return type.isTypeChanged();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class SearchBuilder<C extends Serializable> {

private boolean isFullTextSearchEnabled = true;

private boolean typeChanged = false;

private PathKeyedMap<ItemDefinition<?>> allSearchableItems;

private SearchContext additionalSearchContext;
Expand Down Expand Up @@ -105,6 +107,11 @@ public SearchBuilder<C> setFullTextSearchEnabled(boolean fullTextSearchEnabled)
return this;
}

public SearchBuilder<C> setTypeChanged(boolean typeChanged) {
this.typeChanged = typeChanged;
return this;
}

public Search<C> build() {
SearchableItemsDefinitions searchableItemsDefinitions =
new SearchableItemsDefinitions(type, modelServiceLocator)
Expand Down Expand Up @@ -214,6 +221,7 @@ private void initAssociationWrapperIfNeeded(Search<C> search) {

private SearchBoxConfigurationType getMergedConfiguration() {
SearchBoxConfigurationType configuredSearchBox = getConfiguredSearchBox();
resolveRealSearchType(configuredSearchBox);
SearchBoxConfigurationType defaultSearchBoxConfig = new SearchBoxConfigurationBuilder()
.type(type)
.availableDefinitions(allSearchableItems)
Expand All @@ -225,6 +233,21 @@ private SearchBoxConfigurationType getMergedConfiguration() {
return SearchConfigurationMerger.mergeConfigurations(defaultSearchBoxConfig, configuredSearchBox, modelServiceLocator);
}

private void resolveRealSearchType(SearchBoxConfigurationType configuredSearchBox) {
if (configuredSearchBox == null) {
return;
}
//if the search is loaded because of the changed type, the new selected type value
//should be used for search instead of configured default type value
if (typeChanged) {
QName searchType = WebComponentUtil.anyClassToQName(modelServiceLocator.getPrismContext(), type);
configuredSearchBox.setDefaultObjectType(searchType);
if (configuredSearchBox.getObjectTypeConfiguration() != null) {
configuredSearchBox.getObjectTypeConfiguration().setDefaultValue(searchType);
}
}
}

public ItemDefinition<?> getDefinitionOverride() {
return additionalSearchContext == null ? null : additionalSearchContext.getDefinitionOverride();
}
Expand Down

0 comments on commit b6fb56a

Please sign in to comment.