Skip to content

Commit

Permalink
modify GUI part of run report with parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Apr 21, 2021
1 parent 9ecaa09 commit c69ec0d
Show file tree
Hide file tree
Showing 26 changed files with 303 additions and 449 deletions.
Expand Up @@ -5085,4 +5085,69 @@ public static String countLinkFroNonDeadShadows(Collection<ObjectReferenceType>
}
return Integer.toString(count);
}

public static List<DisplayableValue<?>> getAllowedValues(SearchFilterParameterType parameter, PageBase pageBase) {
List<DisplayableValue<?>> allowedValues = new ArrayList<>();

if (parameter == null || parameter.getAllowedValuesExpression() == null) {
return allowedValues;
}
Task task = pageBase.createSimpleTask("evaluate expression for allowed values");
ExpressionType expression = parameter.getAllowedValuesExpression();
Object value = null;
try {

value = ExpressionUtil.evaluateExpression(new VariablesMap(), null,
expression, MiscSchemaUtil.getExpressionProfile(),
pageBase.getExpressionFactory(), "evaluate expression for allowed values", task, task.getResult());
} catch (Exception e) {
LOGGER.error("Couldn't execute expression " + expression, e);
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.evaluateAllowedValuesExpression", expression).getString());
return allowedValues;
}
if (value instanceof PrismPropertyValue) {
value = ((PrismPropertyValue) value).getRealValue();
}

if (!(value instanceof List)) {
LOGGER.error("Exception return unexpected type, expected List<DisplayableValue>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
return allowedValues;
}

if (!((List<?>) value).isEmpty()) {
if (!(((List<?>) value).get(0) instanceof DisplayableValue)) {
LOGGER.error("Exception return unexpected type, expected List<DisplayableValue>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
return allowedValues;
}
return (List<DisplayableValue<?>>) value;
}
return allowedValues;
}

public static <T extends Object> DropDownChoicePanel createDropDownChoices(String id, IModel<T> model, IModel<List<DisplayableValue<T>>> choices,
boolean allowNull, PageBase pageBase) {
return new DropDownChoicePanel(id, model, choices, new IChoiceRenderer<DisplayableValue>() {
private static final long serialVersionUID = 1L;

@Override
public Object getDisplayValue(DisplayableValue val) {
if (val.getValue() instanceof Enum) {
return pageBase.createStringResource((Enum<?>) val.getValue()).getString();
}
return pageBase.createStringResource(val.getLabel()).getString();
}

@Override
public String getIdValue(DisplayableValue val, int index) {
return Integer.toString(index);
}

@Override
public DisplayableValue getObject(String id, IModel<? extends List<? extends DisplayableValue>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
}, allowNull);
}
}
Expand Up @@ -8,9 +8,11 @@

import com.evolveum.midpoint.gui.api.model.ReadOnlyModel;
import com.evolveum.midpoint.gui.api.prism.wrapper.PrismPropertyWrapper;
import com.evolveum.midpoint.util.DisplayableValue;
import com.evolveum.midpoint.xml.ns._public.common.common_3.LookupTableType;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.StringResourceModel;

import java.util.Collection;

/**
* @author katka
Expand All @@ -27,6 +29,10 @@ public LookupTableType getPredefinedValues() {
return unwrapWrapperModel().getPredefinedValues();
}

public Collection<? extends DisplayableValue<T>> getAllowedValues() {
return unwrapWrapperModel().getAllowedValues();
}

public boolean hasValueEnumerationRef() {
return unwrapWrapperModel().getValueEnumerationRef() != null;
}
Expand Down
Expand Up @@ -7,11 +7,24 @@
package com.evolveum.midpoint.gui.impl.factory.panel;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.PostConstruct;
import javax.xml.namespace.QName;

import com.evolveum.midpoint.util.DisplayableValue;

import com.evolveum.midpoint.web.component.search.FilterSearchItem;
import com.evolveum.midpoint.web.page.admin.configuration.component.EmptyOnChangeAjaxFormUpdatingBehavior;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.springframework.stereotype.Component;

import com.evolveum.midpoint.common.LocalizationService;
Expand Down Expand Up @@ -43,21 +56,44 @@ public void register() {
@Override
protected InputPanel getPanel(PrismPropertyPanelContext<T> panelCtx) {
LookupTableType lookupTable = panelCtx.getPredefinedValues();
if (lookupTable == null) {
return new TextPanel<>(panelCtx.getComponentId(),
panelCtx.getRealValueModel(), panelCtx.getTypeClass(), false);
if (lookupTable != null) {
return new AutoCompleteTextPanel<T>(panelCtx.getComponentId(),
panelCtx.getRealValueModel(), panelCtx.getTypeClass(), panelCtx.hasValueEnumerationRef(), lookupTable) {

private static final long serialVersionUID = 1L;

@Override
public Iterator<T> getIterator(String input) {
return (Iterator<T>) prepareAutoCompleteList(input, lookupTable, panelCtx.getPageBase().getLocalizationService()).iterator();
}
};
}

return new AutoCompleteTextPanel<T>(panelCtx.getComponentId(),
panelCtx.getRealValueModel(), panelCtx.getTypeClass(), panelCtx.hasValueEnumerationRef(), lookupTable) {
Collection<? extends DisplayableValue<T>> allowedValues = panelCtx.getAllowedValues();
if (CollectionUtils.isNotEmpty(allowedValues)) {
IModel<List<DisplayableValue<T>>> choices = Model.ofList(allowedValues.stream().collect(Collectors.toCollection(ArrayList::new)));
IModel convertModel = new IModel<DisplayableValue<T>>(){
@Override
public DisplayableValue<T> getObject() {
Object value = panelCtx.getRealValueModel().getObject();
for (DisplayableValue<T> dispValue : choices.getObject()) {
if (dispValue.getValue().equals(value)) {
return dispValue;
}
}
return null;
}

private static final long serialVersionUID = 1L;
@Override
public void setObject(DisplayableValue<T> object) {
panelCtx.getRealValueModel().setObject(object.getValue());
}
};
return WebComponentUtil.createDropDownChoices(panelCtx.getComponentId(), convertModel, choices, true, panelCtx.getPageBase());
}

@Override
public Iterator<T> getIterator(String input) {
return (Iterator<T>) prepareAutoCompleteList(input, lookupTable, panelCtx.getPageBase().getLocalizationService()).iterator();
}
};
return new TextPanel<>(panelCtx.getComponentId(),
panelCtx.getRealValueModel(), panelCtx.getTypeClass(), false);
}

protected List<String> prepareAutoCompleteList(String input, LookupTableType lookupTable, LocalizationService localizationService) {
Expand Down
Expand Up @@ -78,7 +78,7 @@ protected Component createValuePanel(ListItem<PrismContainerValueWrapper<C>> ite
PrismContainerValuePanel<C, PrismContainerValueWrapper<C>> panel = new PrismContainerValuePanel<C, PrismContainerValueWrapper<C>>("value", item.getModel(), settings) {

@Override
protected void removeValue(PrismContainerValueWrapper<C> valueToRemove, AjaxRequestTarget target) throws SchemaException {
protected void remove(PrismContainerValueWrapper<C> valueToRemove, AjaxRequestTarget target) throws SchemaException {
PrismContainerPanel.this.removeValue(valueToRemove, target);
}
};
Expand Down
Expand Up @@ -283,7 +283,7 @@ public boolean isOn() {
}

@Override
protected void removeValue(CVW valueToRemove, AjaxRequestTarget target) throws SchemaException {
protected void remove(CVW valueToRemove, AjaxRequestTarget target) throws SchemaException {
throw new UnsupportedOperationException("Must be implemented in calling panel");
}

Expand Down
Expand Up @@ -53,8 +53,8 @@ protected Component createValuePanel(ListItem<PrismPropertyValueWrapper<T>> item
PrismPropertyValuePanel<T> panel = new PrismPropertyValuePanel<T>("value", item.getModel(), getSettings()) {

@Override
protected void removeValue(PrismPropertyValueWrapper<T> valueToRemove, AjaxRequestTarget target) throws SchemaException {
PrismPropertyPanel.this.removeValue(valueToRemove, target);
protected void remove(PrismPropertyValueWrapper<T> valueToRemove, AjaxRequestTarget target) throws SchemaException {
removeValue(valueToRemove, target);
}
};
item.add(panel);
Expand Down
Expand Up @@ -51,7 +51,7 @@ protected <PV extends PrismValue> PV createNewValue(PrismPropertyWrapper<T> item
}

@Override
protected void removeValue(PrismPropertyValueWrapper<T> valueToRemove, AjaxRequestTarget target) throws SchemaException {
protected void remove(PrismPropertyValueWrapper<T> valueToRemove, AjaxRequestTarget target) throws SchemaException {
throw new UnsupportedOperationException("Must be implemented in calling panel");
}
}
Expand Up @@ -47,7 +47,7 @@ protected void refreshPanel(AjaxRequestTarget target) {
protected Component createValuePanel(ListItem<PrismReferenceValueWrapperImpl<R>> item) {
PrismReferenceValuePanel<R> valuePanel = new PrismReferenceValuePanel<R>(ID_VALUE, item.getModel(), getSettings()) {
@Override
protected void removeValue(
protected void remove(
PrismReferenceValueWrapperImpl<R> valueToRemove, AjaxRequestTarget target)
throws SchemaException {
PrismReferencePanel.this.removeValue(valueToRemove, target);
Expand Down
Expand Up @@ -118,7 +118,7 @@ private PrismReferenceWrapper<R> getParentWrapper() {
}

@Override
protected void removeValue(PrismReferenceValueWrapperImpl<R> valueToRemove, AjaxRequestTarget target) throws SchemaException {
protected void remove(PrismReferenceValueWrapperImpl<R> valueToRemove, AjaxRequestTarget target) throws SchemaException {
throw new UnsupportedOperationException("Must be implemented in calling panel");
}
}
Expand Up @@ -87,7 +87,7 @@ private WebMarkupContainer createHeaderPanel() {
@Override
public void onClick(AjaxRequestTarget target) {
try {
removeValue(PrismValuePanel.this.getModelObject(), target);
PrismValuePanel.this.remove(PrismValuePanel.this.getModelObject(), target);
} catch (SchemaException e) {
LOGGER.error("Cannot remove value: {}", getModelObject());
getSession().error("Cannot remove value " + getModelObject());
Expand Down Expand Up @@ -272,7 +272,7 @@ private <O extends ObjectType> O getObject() {
protected abstract <PV extends PrismValue> PV createNewValue(IW itemWrapper);

//TODO move to the ItemPanel, exception handling
protected abstract void removeValue(VW valueToRemove, AjaxRequestTarget target) throws SchemaException;
protected abstract void remove(VW valueToRemove, AjaxRequestTarget target) throws SchemaException;

private void showMetadataPerformed(VW value, AjaxRequestTarget target) {
boolean showMetadata = !value.isShowMetadata();
Expand Down
Expand Up @@ -84,7 +84,7 @@ protected <PV extends PrismValue> PV createNewValue(PrismContainerWrapper<C> ite
}

@Override
protected void removeValue(CVW valueToRemove, AjaxRequestTarget target) {
protected void remove(CVW valueToRemove, AjaxRequestTarget target) {

}

Expand Down
Expand Up @@ -157,30 +157,6 @@ protected IModel<List<DisplayableValue<Boolean>>> createBooleanChoices() {
return Model.ofList(list);
}

protected DropDownChoicePanel createDropDownChoices(String id, IModel<Object> model, IModel<List<DisplayableValue<?>>> choices, boolean allowNull) {
return new DropDownChoicePanel(id, model, choices, new IChoiceRenderer<DisplayableValue>() {
private static final long serialVersionUID = 1L;

@Override
public Object getDisplayValue(DisplayableValue val) {
if (val.getValue() instanceof Enum) {
return getPageBase().createStringResource((Enum<?>) val.getValue()).getString();
}
return getPageBase().createStringResource(val.getLabel()).getString();
}

@Override
public String getIdValue(DisplayableValue val, int index) {
return Integer.toString(index);
}

@Override
public DisplayableValue getObject(String id, IModel<? extends List<? extends DisplayableValue>> choices) {
return StringUtils.isNotBlank(id) ? choices.getObject().get(Integer.parseInt(id)) : null;
}
}, allowNull);
}

protected AutoCompleteTextPanel createAutoCompetePanel(String id, IModel<String> model, LookupTableType lookupTable) {
AutoCompleteTextPanel<String> autoCompletePanel = new AutoCompleteTextPanel<String>(id, model, String.class,
true, lookupTable) {
Expand Down
Expand Up @@ -7,6 +7,7 @@
package com.evolveum.midpoint.web.component.search;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

import org.apache.commons.collections4.CollectionUtils;
Expand Down Expand Up @@ -131,43 +132,11 @@ public List<DisplayableValue<?>> getAllowedValues(PageBase pageBase) {
if (allowedValues != null) {
return allowedValues;
}

if (predefinedFilter == null || predefinedFilter.getParameter() == null
|| predefinedFilter.getParameter().getAllowedValuesExpression() == null) {
return null;
}
Task task = pageBase.createSimpleTask("evaluate expression for allowed values");
ExpressionType expression = predefinedFilter.getParameter().getAllowedValuesExpression();
Object value = null;
try {

value = ExpressionUtil.evaluateExpression(new VariablesMap(), null,
expression, MiscSchemaUtil.getExpressionProfile(),
pageBase.getExpressionFactory(), "evaluate expression for allowed values", task, task.getResult());
} catch (Exception e) {
LOGGER.error("Couldn't execute expression " + expression, e);
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.evaluateAllowedValuesExpression", expression).getString());
return null;
}
if (value instanceof PrismPropertyValue) {
value = ((PrismPropertyValue) value).getRealValue();
}

if (!(value instanceof List)) {
LOGGER.error("Exception return unexpected type, expected List<DisplayableValue>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
return null;
}

if (!((List<?>) value).isEmpty()) {
if (!(((List<?>) value).get(0) instanceof DisplayableValue)) {
LOGGER.error("Exception return unexpected type, expected List<DisplayableValue>, but was " + (value == null ? null : value.getClass()));
pageBase.error(pageBase.createStringResource("FilterSearchItem.message.error.wrongType", expression).getString());
return null;
}
if (predefinedFilter == null) {
return Collections.EMPTY_LIST;
}
this.allowedValues = (List<DisplayableValue<?>>) value;
return (List<DisplayableValue<?>>) value;
List<DisplayableValue<?>> values = WebComponentUtil.getAllowedValues(predefinedFilter.getParameter(), pageBase);
return values;
}

public LookupTableType getLookupTable(PageBase pageBase) {
Expand Down
Expand Up @@ -94,7 +94,8 @@ protected void referenceValueUpdated(ObjectReferenceType ort, AjaxRequestTarget
createEnumChoices((Class<? extends Enum>) inputClass) : Model.ofList(getModelObject().getAllowedValues(getPageBase()));
}
if (choices != null) {
inputPanel = createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), FilterSearchItem.F_INPUT), choices, false);
inputPanel = WebComponentUtil.createDropDownChoices(
ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), FilterSearchItem.F_INPUT), (IModel)choices, false, getPageBase());
((InputPanel) inputPanel).getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Expand Down
Expand Up @@ -92,7 +92,8 @@ protected boolean isAllowedNotFoundObjectRef() {
if (choices == null) {
choices = new ListModel(item.getAllowedValues(getPageBase()));
}
searchItemField = createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), "value"), choices, true);
searchItemField = WebComponentUtil.createDropDownChoices(
ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), "value"), (IModel)choices, true, getPageBase());
((InputPanel) searchItemField).getBaseFormComponent().add(new EmptyOnChangeAjaxFormUpdatingBehavior() {
@Override
protected void onUpdate(AjaxRequestTarget target) {
Expand Down
Expand Up @@ -8,6 +8,8 @@

import java.util.List;

import com.evolveum.midpoint.gui.api.util.WebComponentUtil;

import org.apache.wicket.Component;
import org.apache.wicket.ajax.AjaxRequestTarget;
import org.apache.wicket.ajax.form.OnChangeAjaxBehavior;
Expand Down Expand Up @@ -42,7 +44,8 @@ protected void initSearchItemField(WebMarkupContainer searchItemContainer) {
List<DisplayableValue<Class<? extends C>>> allowedValues = item.getAllowedValues(getPageBase());
if (allowedValues != null && !allowedValues.isEmpty()) {
IModel<List<DisplayableValue<?>>> choices = new ListModel(item.getAllowedValues(getPageBase()));
searchItemField = createDropDownChoices(ID_SEARCH_ITEM_FIELD, new PropertyModel<>(getModel(), ContainerTypeSearchItem.F_TYPE), choices, false);
searchItemField = WebComponentUtil.createDropDownChoices(
ID_SEARCH_ITEM_FIELD, new PropertyModel(getModel(), ContainerTypeSearchItem.F_TYPE), (IModel)choices, false, getPageBase());
}
}

Expand Down
Expand Up @@ -290,7 +290,7 @@ private void runConfirmPerformed(AjaxRequestTarget target, ReportType reportType

protected void runReportPerformed(AjaxRequestTarget target, ReportType report) {

if(report.getJasper() != null) {
if(report.getObjectCollection() == null) {
runConfirmPerformed(target, report, null);
return;
}
Expand Down

0 comments on commit c69ec0d

Please sign in to comment.