Skip to content

Commit

Permalink
[SYNCOPE-1815] Further Macro improvements (#713)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilgrosso committed May 15, 2024
1 parent b1bc931 commit 58f9e1a
Show file tree
Hide file tree
Showing 39 changed files with 728 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;

/**
* An {@link AjaxFormComponentUpdatingBehavior} not showin veil.
* An {@link AjaxFormComponentUpdatingBehavior} not showing veil.
*/
public abstract class IndicatorAjaxFormComponentUpdatingBehavior
extends AjaxFormComponentUpdatingBehavior implements IAjaxIndicatorAware {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ protected void onUpdate(final AjaxRequestTarget target) {
}
}

public AjaxPasswordFieldPanel setResetPassword(final boolean resetPassword) {
((PasswordTextField) field).setResetPassword(resetPassword);
return this;
}

@Override
public FieldPanel<String> addRequiredLabel() {
if (!isRequired()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,34 @@
package org.apache.syncope.client.ui.commons.panels;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.syncope.client.ui.commons.MapChoiceRenderer;
import org.apache.syncope.client.ui.commons.markup.html.form.AbstractFieldPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxCheckBoxPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDateTimeFieldPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxDropDownChoicePanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPalettePanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxPasswordFieldPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxSpinnerFieldPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.AjaxTextFieldPanel;
import org.apache.syncope.client.ui.commons.markup.html.form.FieldPanel;
import org.apache.syncope.common.lib.form.FormProperty;
import org.apache.syncope.common.lib.form.FormPropertyValue;
import org.apache.syncope.common.lib.form.SyncopeForm;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.LoadableDetachableModel;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.model.util.ListModel;
import org.apache.wicket.validation.validator.PatternValidator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -53,47 +59,36 @@ public class SyncopeFormPanel<F extends SyncopeForm> extends Panel {
public SyncopeFormPanel(final String id, final F form) {
super(id);

IModel<List<FormProperty>> formProps = new LoadableDetachableModel<>() {
ListModel<FormProperty> model = new ListModel<>(new ArrayList<>());
model.getObject().addAll(form.getProperties());

private static final long serialVersionUID = 3169142472626817508L;

@Override
protected List<FormProperty> load() {
return form.getProperties();
}
};

ListView<FormProperty> propView = new ListView<>("propView", formProps) {
ListView<FormProperty> propView = new ListView<>("propView", model) {

private static final long serialVersionUID = 9101744072914090143L;

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void populateItem(final ListItem<FormProperty> item) {
FormProperty prop = item.getModelObject();

String label = StringUtils.isBlank(prop.getName()) ? prop.getId() : prop.getName();

FieldPanel field;
AbstractFieldPanel<?> field;
switch (prop.getType()) {
case Boolean:
field = new AjaxDropDownChoicePanel("value", label, new PropertyModel<String>(prop, "value") {
field = new AjaxCheckBoxPanel("value", label, new PropertyModel<Boolean>(prop, "value") {

private static final long serialVersionUID = -3743432456095828573L;

@Override
public String getObject() {
return StringUtils.isBlank(prop.getValue())
? null
: prop.getValue().equals("true") ? "Yes" : "No";
public Boolean getObject() {
return BooleanUtils.toBoolean(prop.getValue());
}

@Override
public void setObject(final String object) {
prop.setValue(String.valueOf(object.equalsIgnoreCase("yes")));
public void setObject(final Boolean object) {
prop.setValue(BooleanUtils.toStringTrueFalse(object));
}

}, false).setChoices(List.of("Yes", "No"));
}, false);
break;

case Date:
Expand Down Expand Up @@ -122,25 +117,56 @@ public void setObject(final Date object) {
break;

case Enum:
field = new AjaxDropDownChoicePanel(
field = new AjaxDropDownChoicePanel<>(
"value", label, new PropertyModel<String>(prop, "value"), false).
setChoiceRenderer(new MapChoiceRenderer(prop.getEnumValues().stream().
collect(Collectors.toMap(
FormPropertyValue::getKey,
FormPropertyValue::getValue)))).
setChoices(prop.getEnumValues().stream().
map(FormPropertyValue::getKey).collect(Collectors.toList()));
setChoices(prop.getEnumValues().stream().map(FormPropertyValue::getKey).toList());
break;

case Dropdown:
field = new AjaxDropDownChoicePanel(
"value", label, new PropertyModel<String>(prop, "value"), false).
setChoiceRenderer(new MapChoiceRenderer(prop.getDropdownValues().stream().
collect(Collectors.toMap(
FormPropertyValue::getKey,
FormPropertyValue::getValue)))).
setChoices(prop.getDropdownValues().stream().
map(FormPropertyValue::getKey).collect(Collectors.toList()));
if (prop.isDropdownFreeForm()) {
field = new AjaxTextFieldPanel("value", label, new PropertyModel<>(prop, "value"), false);
((AjaxTextFieldPanel) field).setChoices(prop.getDropdownValues().stream().
map(FormPropertyValue::getKey).toList());
} else if (prop.isDropdownSingleSelection()) {
field = new AjaxDropDownChoicePanel<>(
"value", label, new PropertyModel<String>(prop, "value"), false).
setChoiceRenderer(new MapChoiceRenderer(prop.getDropdownValues().stream().
collect(Collectors.toMap(
FormPropertyValue::getKey,
FormPropertyValue::getValue)))).
setChoices(prop.getDropdownValues().stream().
map(FormPropertyValue::getKey).toList());
} else {
field = new AjaxPalettePanel.Builder<String>().setName(label).
setRenderer(new MapChoiceRenderer(prop.getDropdownValues().stream().
collect(Collectors.toMap(
FormPropertyValue::getKey,
FormPropertyValue::getValue)))).build(
"value",
new IModel<List<String>>() {

private static final long serialVersionUID = 1015030402166681242L;

@Override
public List<String> getObject() {
return Optional.ofNullable(prop.getValue()).
map(v -> List.of(v.split(";"))).
orElse(null);
}

@Override
public void setObject(final List<String> object) {
prop.setValue(Optional.ofNullable(object).
map(v -> v.stream().collect(Collectors.joining(";"))).
orElse(null));
}
}, new ListModel<>(prop.getDropdownValues().stream().
map(FormPropertyValue::getKey).toList()));
}
break;

case Long:
Expand All @@ -167,12 +193,15 @@ public void setObject(final Long object) {
break;

case Password:
field = new AjaxPasswordFieldPanel("value", label, new PropertyModel<>(prop, "value"), false);
field = new AjaxPasswordFieldPanel("value", label, new PropertyModel<>(prop, "value"), false).
setResetPassword(false);
break;

case String:
default:
field = new AjaxTextFieldPanel("value", label, new PropertyModel<>(prop, "value"), false);
Optional.ofNullable(prop.getStringRegEx()).
ifPresent(re -> ((AjaxTextFieldPanel) field).addValidator(new PatternValidator(re)));
break;
}

Expand All @@ -184,7 +213,6 @@ public void setObject(final Long object) {
item.add(field);
}
};

add(propView);
add(propView.setReuseItems(true));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@
<span wicket:id="value">[value]</span>
</div>

<wicket:child/>
<wicket:child/>
</wicket:panel>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public void onException(final Exception e) {

message = getApplication().getResourceSettings().getLocalizer().
getString(message, null, null, null, null, message);
error(message);
error(message.replace("\n", "<br/>"));
}

public MediaType getMediaType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ protected void onClickDelete(final AjaxRequestTarget target, final RealmTO realm
target.add(content);
} catch (Exception e) {
LOG.error("While deleting realm", e);
// Escape line breaks
SyncopeConsoleSession.get().error(e.getMessage().replace("\n", " "));
SyncopeConsoleSession.get().onException(e);
}
((BaseWebPage) Realms.this.getPage()).getNotificationPanel().refresh(target);
}
Expand Down
Loading

0 comments on commit 58f9e1a

Please sign in to comment.