Skip to content

Commit

Permalink
implemented the check for full text search if it is enabled in sysConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
KaterynaHonchar committed Feb 27, 2017
1 parent 00d0e6a commit 21ce210
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 10 deletions.
Expand Up @@ -60,9 +60,10 @@ public static enum SearchViewType{
FULL_TEXT_SEARCH
};

private SearchViewType searchType = SearchViewType.FULL_TEXT_SEARCH;
private SearchViewType searchType;

private boolean showAdvanced = false;
private boolean isFullTextSearchEnabled = false;

private String advancedQuery;
private String advancedError;
Expand All @@ -75,9 +76,19 @@ public static enum SearchViewType{
private List<SearchItem> items = new ArrayList<>();

public Search(Class<? extends ObjectType> type, Map<ItemPath, ItemDefinition> allDefinitions) {
this(type, allDefinitions, false);
}

public Search(Class<? extends ObjectType> type, Map<ItemPath, ItemDefinition> allDefinitions, boolean isFullTextSearchEnabled) {
this.type = type;
this.allDefinitions = allDefinitions;

this.isFullTextSearchEnabled = isFullTextSearchEnabled;
if (isFullTextSearchEnabled ){
searchType = SearchViewType.FULL_TEXT_SEARCH;
} else {
searchType = SearchViewType.BASIC_SEARCH;
}
availableDefinitions.addAll(allDefinitions.values());
}

Expand Down Expand Up @@ -343,6 +354,14 @@ public void setSearchType(SearchViewType searchType) {
this.searchType = searchType;
}

public boolean isFullTextSearchEnabled() {
return isFullTextSearchEnabled;
}

public void setFullTextSearchEnabled(boolean fullTextSearchEnabled) {
isFullTextSearchEnabled = fullTextSearchEnabled;
}

private String createErrorMessage(Exception ex) {
StringBuilder sb = new StringBuilder();

Expand Down
Expand Up @@ -22,6 +22,7 @@
import com.evolveum.midpoint.prism.schema.SchemaRegistry;
import com.evolveum.midpoint.schema.ResourceShadowDiscriminator;
import com.evolveum.midpoint.schema.result.OperationResult;
import com.evolveum.midpoint.schema.util.SystemConfigurationTypeUtil;
import com.evolveum.midpoint.util.exception.ConfigurationException;
import com.evolveum.midpoint.util.exception.ObjectNotFoundException;
import com.evolveum.midpoint.util.exception.SchemaException;
Expand All @@ -41,6 +42,7 @@ public class SearchFactory {

private static final String DOT_CLASS = SearchFactory.class.getName() + ".";
private static final String LOAD_OBJECT_DEFINITION = DOT_CLASS + "loadObjectDefinition";
private static final String LOAD_SYSTEM_CONFIGURATION = DOT_CLASS + "loadSystemConfiguration";

private static final Map<Class, List<ItemPath>> SEARCHABLE_OBJECTS = new HashMap<>();

Expand Down Expand Up @@ -132,8 +134,9 @@ public static <T extends ObjectType> Search createSearch(
PrismObjectDefinition objectDef = findObjectDefinition(type, discriminator, ctx, modelInteractionService);

Map<ItemPath, ItemDefinition> availableDefs = getAvailableDefinitions(objectDef, useDefsFromSuperclass);
boolean isFullTextSearchEnabled = isFullTextSearchEnabled(modelInteractionService);

Search search = new Search(type, availableDefs);
Search search = new Search(type, availableDefs, isFullTextSearchEnabled);

SchemaRegistry registry = ctx.getSchemaRegistry();
PrismObjectDefinition objDef = registry.findObjectDefinitionByCompileTimeClass(ObjectType.class);
Expand Down Expand Up @@ -201,6 +204,16 @@ private static <T extends ObjectType> Map<ItemPath, ItemDefinition> getAvailable
return map;
}

private static boolean isFullTextSearchEnabled(ModelInteractionService modelInteractionService) {
OperationResult result = new OperationResult(LOAD_SYSTEM_CONFIGURATION);
try {
return SystemConfigurationTypeUtil.isFullTextSearchEnabled(modelInteractionService.getSystemConfiguration(result)
.getFullTextSearch());
} catch (SchemaException | ObjectNotFoundException ex) {
throw new SystemException(ex);
}
}

private static <T extends ObjectType> Map<ItemPath, ItemDefinition> createExtensionDefinitionList(
PrismObjectDefinition<T> objectDef) {

Expand Down
Expand Up @@ -190,10 +190,7 @@ public boolean isEnabled() {
return true;
}
return false;
// Search search = getModelObject();
// PrismContext ctx = getPageBase().getPrismContext();
// return search.isAdvancedQueryValid(ctx);
}
}

@Override
public boolean isVisible() {
Expand Down Expand Up @@ -303,7 +300,8 @@ public void onClick(AjaxRequestTarget target) {
fullTextButton.add(new VisibleEnableBehaviour(){
@Override
public boolean isVisible() {
return !Search.SearchViewType.FULL_TEXT_SEARCH.equals(getModelObject().getSearchType());
return isFullTextSearchEnabled() &&
!Search.SearchViewType.FULL_TEXT_SEARCH.equals(getModelObject().getSearchType());
}
});
linksContainer.add(fullTextButton);
Expand Down Expand Up @@ -333,7 +331,14 @@ public String load() {
initPopover();

WebMarkupContainer fullTextContainer = new WebMarkupContainer(ID_FULL_TEXT_CONTAINER);
fullTextContainer.add(createVisibleBehaviour(Search.SearchViewType.FULL_TEXT_SEARCH));
fullTextContainer.add(new VisibleEnableBehaviour(){
private static final long serialVersionUID = 1L;
@Override
public boolean isVisible(){
return isFullTextSearchEnabled()
&& getModelObject().getSearchType().equals(Search.SearchViewType.FULL_TEXT_SEARCH);
}
});
fullTextContainer.setOutputMarkupId(true);
form.add(fullTextContainer);

Expand Down Expand Up @@ -663,4 +668,8 @@ private void updateAdvancedArea(Component area, AjaxRequestTarget target) {
get(createComponentPath(ID_FORM, ID_ADVANCED_GROUP)),
get(createComponentPath(ID_FORM, ID_SEARCH_CONTAINER)));
}

private boolean isFullTextSearchEnabled(){
return getModelObject().isFullTextSearchEnabled();
}
}
Expand Up @@ -36,7 +36,7 @@
</div>

<form class="form-inline pull-right search-form" wicket:id="searchForm">
<div class="form-group" style="margin-top: -15px;">
<div class="form-group" wicket:id="choiceContainer">
<label class="sr-only"><wicket:message key="pageDebugList.objectType"/></label>
<select class="form-control input-sm" wicket:id="choice"/>
</div>
Expand Down
Expand Up @@ -40,6 +40,7 @@
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
import org.apache.wicket.ajax.markup.html.form.AjaxCheckBox;
import org.apache.wicket.behavior.AttributeAppender;
import org.apache.wicket.extensions.ajax.markup.html.modal.ModalWindow;
import org.apache.wicket.extensions.markup.html.repeater.data.grid.ICellPopulator;
import org.apache.wicket.extensions.markup.html.repeater.data.table.AbstractColumn;
Expand Down Expand Up @@ -138,6 +139,7 @@ public class PageDebugList extends PageAdminConfiguration {
private static final String ID_MAIN_FORM = "mainForm";
private static final String ID_ZIP_CHECK = "zipCheck";
private static final String ID_TABLE = "table";
private static final String ID_CHOICE_CONTAINER = "choiceContainer";
private static final String ID_CHOICE = "choice";
private static final String ID_EXPORT = "export";
private static final String ID_EXPORT_ALL = "exportAll";
Expand Down Expand Up @@ -968,9 +970,22 @@ protected String resourceKey(ObjectTypes object) {
}
};

WebMarkupContainer choiceContainer = new WebMarkupContainer(ID_CHOICE_CONTAINER);
choiceContainer.setOutputMarkupId(true);
choiceContainer.add(new AttributeAppender("style", new LoadableModel<String>() {
private static final long serialVersionUID = 1L;
@Override
public String load(){
PageDebugList page = (PageDebugList) getPage();
return page.searchModel.getObject().getSearch().isFullTextSearchEnabled() ?
"margin-top: -15px;" : "";
}
}));
searchForm.add(choiceContainer);

DropDownChoice choice = new DropDownChoice(ID_CHOICE,
new PropertyModel(model, DebugSearchDto.F_TYPE), createChoiceModel(renderer), renderer);
searchForm.add(choice);
choiceContainer.add(choice);
choice.add(new OnChangeAjaxBehavior() {

@Override
Expand Down
Expand Up @@ -186,6 +186,8 @@ <F extends ObjectType> ModelContext<F> previewChanges(
*/
AdminGuiConfigurationType getAdminGuiConfiguration(Task task, OperationResult parentResult) throws ObjectNotFoundException, SchemaException;

SystemConfigurationType getSystemConfiguration(OperationResult parentResult) throws ObjectNotFoundException, SchemaException;

DeploymentInformationType getDeploymentInformationConfiguration(OperationResult parentResult) throws ObjectNotFoundException, SchemaException;

AccessCertificationConfigurationType getCertificationConfiguration(OperationResult parentResult)
Expand Down
Expand Up @@ -680,6 +680,15 @@ public AdminGuiConfigurationType getAdminGuiConfiguration(Task task, OperationRe
}
}

@Override
public SystemConfigurationType getSystemConfiguration(OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(parentResult);
if (systemConfiguration == null) {
return null;
}
return systemConfiguration.asObjectable();
}

@Override
public DeploymentInformationType getDeploymentInformationConfiguration(OperationResult parentResult) throws ObjectNotFoundException, SchemaException {
PrismObject<SystemConfigurationType> systemConfiguration = systemObjectCache.getSystemConfiguration(parentResult);
Expand Down

0 comments on commit 21ce210

Please sign in to comment.