Skip to content

Commit

Permalink
[SYNCOPE-1859] SearchPanel displays the schema keys and doesn't consi…
Browse files Browse the repository at this point in the history
…der translations
  • Loading branch information
mdisabatino authored and ilgrosso committed Feb 1, 2025
1 parent 1e1d662 commit 46628f6
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import de.agilecoders.wicket.core.markup.html.bootstrap.components.TooltipConfig;
import java.util.Iterator;
import java.util.List;
import java.util.Optional;
import java.util.regex.Pattern;
import org.apache.syncope.client.ui.commons.Constants;
import org.apache.syncope.client.ui.commons.ajax.form.IndicatorAjaxFormComponentUpdatingBehavior;
Expand All @@ -33,6 +34,7 @@
import org.apache.wicket.extensions.ajax.markup.html.autocomplete.IAutoCompleteRenderer;
import org.apache.wicket.model.IModel;
import org.apache.wicket.model.ResourceModel;
import org.apache.wicket.util.convert.IConverter;

public class AjaxTextFieldPanel extends TextFieldPanel implements Cloneable {

Expand Down Expand Up @@ -82,6 +84,14 @@ protected Iterator<String> getChoices(final String input) {
}
};
}

@SuppressWarnings("unchecked")
@Override
public <C> IConverter<C> getConverter(final Class<C> type) {
return AjaxTextFieldPanel.this.getConverter().
map(converter -> (IConverter<C>)converter).
orElseGet(() -> super.getConverter(type));
}
};
setHTMLInputNotAllowed();
add(field.setLabel(new ResourceModel(name, name)).setOutputMarkupId(true));
Expand All @@ -105,6 +115,10 @@ public void setChoices(final List<String> choices) {
}
}

protected Optional<IConverter<String>> getConverter() {
return Optional.empty();
}

public FieldPanel<String> enableJexlHelp() {
questionMarkJexlHelp.setVisible(true);
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
import de.agilecoders.wicket.extensions.markup.html.bootstrap.form.checkbox.bootstraptoggle.BootstrapToggleConfig;
import java.io.Serializable;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.function.Consumer;
Expand All @@ -35,6 +35,7 @@
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.FastDateFormat;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.syncope.client.console.SyncopeConsoleSession;
import org.apache.syncope.client.console.panels.search.SearchClause.Comparator;
import org.apache.syncope.client.console.panels.search.SearchClause.Operator;
import org.apache.syncope.client.console.panels.search.SearchClause.Type;
Expand All @@ -53,7 +54,6 @@
import org.apache.syncope.common.lib.SyncopeConstants;
import org.apache.syncope.common.lib.to.GroupTO;
import org.apache.syncope.common.lib.to.PlainSchemaTO;
import org.apache.syncope.common.lib.to.RelationshipTypeTO;
import org.apache.syncope.common.lib.types.AttrSchemaType;
import org.apache.wicket.AttributeModifier;
import org.apache.wicket.Component;
Expand All @@ -77,6 +77,9 @@
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.convert.ConversionException;
import org.apache.wicket.util.convert.IConverter;
import org.springframework.util.CollectionUtils;

public class SearchClausePanel extends FieldPanel<SearchClause> {

Expand Down Expand Up @@ -122,15 +125,15 @@ default List<String> properties() {
default void setFieldAccess(
FieldPanel<String> value,
AjaxTextFieldPanel property,
LoadableDetachableModel<List<String>> properties) {
LoadableDetachableModel<List<Pair<String, String>>> properties) {

value.setEnabled(true);
value.setModelObject(StringUtils.EMPTY);
property.setEnabled(true);

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
}
}

Expand Down Expand Up @@ -164,7 +167,7 @@ default void setFieldAccess(

protected final LoadableDetachableModel<List<Comparator>> comparators;

protected final LoadableDetachableModel<List<String>> properties;
protected final LoadableDetachableModel<List<Pair<String, String>>> properties;

protected final Fragment operatorFragment;

Expand Down Expand Up @@ -278,46 +281,63 @@ protected List<Comparator> load() {
private static final long serialVersionUID = 5275935387613157437L;

@Override
protected List<String> load() {
protected List<Pair<String, String>> load() {
if (field.getModel().getObject() == null || field.getModel().getObject().getType() == null) {
return List.of();
}

switch (field.getModel().getObject().getType()) {
case ATTRIBUTE:
List<String> names = new ArrayList<>(dnames.getObject().keySet());
if (anames != null && anames.getObject() != null && !anames.getObject().isEmpty()) {
names.addAll(anames.getObject().keySet());
Locale locale = SyncopeConsoleSession.get().getLocale();
List<Pair<String, String>> names = dnames.getObject().entrySet().stream().
map(item -> Pair.of(
item.getKey(),
Optional.ofNullable(item.getValue().getLabel(locale)).orElse(item.getKey()))).
collect(Collectors.toList());
if (anames != null && !CollectionUtils.isEmpty(anames.getObject())) {
names.addAll(anames.getObject().entrySet().stream().
map(item -> Pair.of(
item.getKey(),
Optional.ofNullable(item.getValue().getLabel(locale)).orElse(item.getKey()))).
collect(Collectors.toList()));
}
return names.stream().sorted().collect(Collectors.toList());
return names.stream().
sorted(java.util.Comparator.comparing(name -> name.getValue().toLowerCase())).
collect(Collectors.toList());

case GROUP_MEMBERSHIP:
return groupInfo.getLeft().getObject();
return groupInfo.getLeft().getObject().stream().
map(item -> Pair.of(item, item)).collect(Collectors.toList());

case ROLE_MEMBERSHIP:
return Optional.ofNullable(roleNames).
map(r -> r.getObject().stream().sorted().collect(Collectors.toList())).
map(r -> r.getObject().stream().sorted().map(item -> Pair.of(item, item)).
collect(Collectors.toList())).
orElse(List.of());

case PRIVILEGE:
return Optional.ofNullable(privilegeNames).
map(p -> p.getObject().stream().sorted().collect(Collectors.toList())).
map(p -> p.getObject().stream().sorted().map(item -> Pair.of(item, item)).
collect(Collectors.toList())).
orElse(List.of());

case AUX_CLASS:
return auxClassNames.getObject().stream().
sorted().collect(Collectors.toList());
return auxClassNames.getObject().stream().sorted().
map(item -> Pair.of(item, item)).collect(Collectors.toList());

case RESOURCE:
return resourceNames.getObject().stream().
sorted().collect(Collectors.toList());
return resourceNames.getObject().stream().sorted().
map(item -> Pair.of(item, item)).collect(Collectors.toList());

case RELATIONSHIP:
return relationshipTypeRestClient.list().stream().
map(RelationshipTypeTO::getKey).collect(Collectors.toList());
return relationshipTypeRestClient.list().stream().sorted().
map(item -> Pair.of(item.getKey(), item.getKey())).
collect(Collectors.toList());

case CUSTOM:
return customizer.properties();
return customizer.properties().stream().
map(item -> Pair.of(item, item)).
collect(Collectors.toList());

default:
return List.of();
Expand Down Expand Up @@ -439,10 +459,40 @@ protected void onUpdate(final AjaxRequestTarget target) {
operatorContainer.add(searchButtonFragment);
}

AjaxTextFieldPanel property = new AjaxTextFieldPanel(
"property", "property", new PropertyModel<>(searchClause, "property"), true);
AjaxTextFieldPanel property = new AjaxTextFieldPanel("property", "property",
new PropertyModel<>(searchClause, "property"), true) {

private static final long serialVersionUID = -7157802546272668001L;

@Override
protected Optional<IConverter<String>> getConverter() {
return Optional.of(new IConverter<String>() {

private static final long serialVersionUID = -2754107934642211828L;

@Override
public String convertToObject(final String label, final Locale locale) throws ConversionException {
return properties.getObject().stream().
filter(property -> property.getValue().equalsIgnoreCase(label)).
findFirst().
map(Pair::getKey).
orElse(label);
}

@Override
public String convertToString(final String key, final Locale locale) {
return properties.getObject().stream().
filter(property -> property.getKey().equalsIgnoreCase(key)).
findFirst().
map(Pair::getValue).
orElse(key);
}
});
}
};

property.hideLabel().setOutputMarkupId(true).setEnabled(true);
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getValue).collect(Collectors.toList()));
field.add(property);

property.getField().add(PREVENT_DEFAULT_RETURN);
Expand All @@ -457,7 +507,8 @@ protected void onEvent(final AjaxRequestTarget target) {

String[] inputAsArray = property.getField().getInputAsArray();
if (ArrayUtils.isEmpty(inputAsArray)) {
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey)
.collect(Collectors.toList()));
} else if (groupInfo.getRight().getObject() > Constants.MAX_GROUP_LIST_SIZE) {
String inputValue = inputAsArray.length > 1 && inputAsArray[1] != null
? inputAsArray[1]
Expand Down Expand Up @@ -621,7 +672,9 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(
properties.getObject().stream().
map(Pair::getValue).collect(Collectors.toList()));
break;

case ROLE_MEMBERSHIP:
Expand All @@ -630,7 +683,7 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
break;

case PRIVILEGE:
Expand All @@ -639,7 +692,7 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
break;

case GROUP_MEMBERSHIP:
Expand All @@ -648,7 +701,7 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
break;

case GROUP_MEMBER:
Expand All @@ -664,7 +717,7 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
break;

case RELATIONSHIP:
Expand All @@ -674,7 +727,7 @@ private void setFieldAccess(

// reload properties list
properties.detach();
property.setChoices(properties.getObject());
property.setChoices(properties.getObject().stream().map(Pair::getKey).collect(Collectors.toList()));
break;

case CUSTOM:
Expand Down

0 comments on commit 46628f6

Please sign in to comment.