Skip to content

Commit

Permalink
improving error handling for searchFilterType model.. might help with…
Browse files Browse the repository at this point in the history
… MID-6719
  • Loading branch information
katkav committed Dec 10, 2020
1 parent f29de7d commit e5301a2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
Expand Up @@ -8,6 +8,9 @@

import javax.annotation.PostConstruct;

import com.evolveum.midpoint.gui.api.Validatable;

import org.apache.wicket.feedback.ComponentFeedbackMessageFilter;
import org.apache.wicket.markup.html.panel.Panel;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -41,10 +44,20 @@ protected Panel getPanel(PrismPropertyPanelContext<SearchFilterType> panelCtx) {
return new SearchFilterConfigurationPanel(
panelCtx.getComponentId(), panelCtx.getRealValueModel(), containerWrapper);
}
return new AceEditorPanel(
AceEditorPanel panel = new AceEditorPanel(
panelCtx.getComponentId(),
null,
new SearchFilterTypeModel(panelCtx.getRealValueModel(), panelCtx.getPageBase()),
10);
return panel;
}

@Override
public void configure(PrismPropertyPanelContext<SearchFilterType> panelCtx, org.apache.wicket.Component component) {
if (!(component instanceof AceEditorPanel)) {
super.configure(panelCtx, component);
return;
}
panelCtx.getFeedback().setFilter(new ComponentFeedbackMessageFilter(((AceEditorPanel) component).getEditor()));
}
}
Expand Up @@ -13,9 +13,13 @@
import com.evolveum.midpoint.util.logging.TraceManager;
import com.evolveum.prism.xml.ns._public.query_3.SearchFilterType;
import org.apache.commons.lang3.StringUtils;
import org.apache.wicket.Component;
import org.apache.wicket.Session;
import org.apache.wicket.model.IComponentAssignedModel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.IWrapModel;

public class SearchFilterTypeModel implements IModel<String> {
public class SearchFilterTypeModel implements IComponentAssignedModel<String> {

private static final Trace LOGGER = TraceManager.getTrace(SearchFilterTypeModel.class);

Expand Down Expand Up @@ -45,11 +49,9 @@ public String getObject() {

return pageBase.getPrismContext().xmlSerializer().serializeRealValue(value);
} catch (SchemaException e) {
// TODO handle!!!!
LoggingUtils.logUnexpectedException(LOGGER, "Cannot serialize filter", e);
// getSession().error("Cannot serialize filter");
throw new IllegalStateException("Cannot serialize filter: " + e.getMessage() + ". For more details, please, see midpoint log");
}
return null;
}

@Override
Expand All @@ -62,10 +64,47 @@ public void setObject(String object) {
SearchFilterType filter = pageBase.getPrismContext().parserFor(object).parseRealValue(SearchFilterType.class);
baseModel.setObject(filter);
} catch (SchemaException e) {
// TODO handle!!!!
LoggingUtils.logUnexpectedException(LOGGER, "Cannot parse filter", e);
// getSession().error("Cannot parse filter");
throw new IllegalStateException("Cannot parse filter: " + e.getMessage() + ". For more details, please, see midpoint log");
}

}

@Override
public IWrapModel<String> wrapOnAssignment(Component component) {
return new SearchFilterWrapperModel(component);
}

class SearchFilterWrapperModel implements IWrapModel<String> {

private Component component;

public SearchFilterWrapperModel(Component component) {
this.component = component;
}

@Override
public IModel<?> getWrappedModel() {
return SearchFilterTypeModel.this;
}

@Override
public String getObject() {
try {
return SearchFilterTypeModel.this.getObject();
} catch (Throwable e) {
component.error(e.getMessage());
}
return null;
}

@Override
public void setObject(String object) {
try {
SearchFilterTypeModel.this.setObject(object);
} catch (Throwable e) {
component.error(e.getMessage());
}
}
}
}

0 comments on commit e5301a2

Please sign in to comment.