2222import de .agilecoders .wicket .extensions .markup .html .bootstrap .form .checkbox .bootstraptoggle .BootstrapToggleConfig ;
2323import java .io .Serializable ;
2424import java .text .ParseException ;
25- import java .util .ArrayList ;
2625import java .util .Arrays ;
2726import java .util .Date ;
2827import java .util .List ;
28+ import java .util .Locale ;
2929import java .util .Map ;
3030import java .util .Optional ;
3131import java .util .function .Consumer ;
3535import org .apache .commons .lang3 .time .DateFormatUtils ;
3636import org .apache .commons .lang3 .time .FastDateFormat ;
3737import org .apache .commons .lang3 .tuple .Pair ;
38+ import org .apache .syncope .client .console .SyncopeConsoleSession ;
3839import org .apache .syncope .client .console .panels .search .SearchClause .Comparator ;
3940import org .apache .syncope .client .console .panels .search .SearchClause .Operator ;
4041import org .apache .syncope .client .console .panels .search .SearchClause .Type ;
5253import org .apache .syncope .common .lib .SyncopeConstants ;
5354import org .apache .syncope .common .lib .to .GroupTO ;
5455import org .apache .syncope .common .lib .to .PlainSchemaTO ;
55- import org .apache .syncope .common .lib .to .RelationshipTypeTO ;
5656import org .apache .syncope .common .lib .types .AttrSchemaType ;
5757import org .apache .wicket .AttributeModifier ;
5858import org .apache .wicket .Component ;
7676import org .apache .wicket .model .Model ;
7777import org .apache .wicket .model .PropertyModel ;
7878import org .apache .wicket .spring .injection .annot .SpringBean ;
79+ import org .apache .wicket .util .convert .ConversionException ;
80+ import org .apache .wicket .util .convert .IConverter ;
81+ import org .springframework .util .CollectionUtils ;
7982
8083public class SearchClausePanel extends FieldPanel <SearchClause > {
8184
@@ -121,15 +124,15 @@ default List<String> properties() {
121124 default void setFieldAccess (
122125 FieldPanel <String > value ,
123126 AjaxTextFieldPanel property ,
124- LoadableDetachableModel <List <String >> properties ) {
127+ LoadableDetachableModel <List <Pair < String , String > >> properties ) {
125128
126129 value .setEnabled (true );
127130 value .setModelObject (StringUtils .EMPTY );
128131 property .setEnabled (true );
129132
130133 // reload properties list
131134 properties .detach ();
132- property .setChoices (properties .getObject ());
135+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
133136 }
134137 }
135138
@@ -163,7 +166,7 @@ default void setFieldAccess(
163166
164167 protected final LoadableDetachableModel <List <Comparator >> comparators ;
165168
166- protected final LoadableDetachableModel <List <String >> properties ;
169+ protected final LoadableDetachableModel <List <Pair < String , String > >> properties ;
167170
168171 protected final Fragment operatorFragment ;
169172
@@ -277,46 +280,63 @@ protected List<Comparator> load() {
277280 private static final long serialVersionUID = 5275935387613157437L ;
278281
279282 @ Override
280- protected List <String > load () {
283+ protected List <Pair < String , String > > load () {
281284 if (field .getModel ().getObject () == null || field .getModel ().getObject ().getType () == null ) {
282285 return List .of ();
283286 }
284287
285288 switch (field .getModel ().getObject ().getType ()) {
286289 case ATTRIBUTE :
287- List <String > names = new ArrayList <>(dnames .getObject ().keySet ());
288- if (anames != null && anames .getObject () != null && !anames .getObject ().isEmpty ()) {
289- names .addAll (anames .getObject ().keySet ());
290+ Locale locale = SyncopeConsoleSession .get ().getLocale ();
291+ List <Pair <String , String >> names = dnames .getObject ().entrySet ().stream ().
292+ map (item -> Pair .of (
293+ item .getKey (),
294+ Optional .ofNullable (item .getValue ().getLabel (locale )).orElse (item .getKey ()))).
295+ collect (Collectors .toList ());
296+ if (anames != null && !CollectionUtils .isEmpty (anames .getObject ())) {
297+ names .addAll (anames .getObject ().entrySet ().stream ().
298+ map (item -> Pair .of (
299+ item .getKey (),
300+ Optional .ofNullable (item .getValue ().getLabel (locale )).orElse (item .getKey ()))).
301+ collect (Collectors .toList ()));
290302 }
291- return names .stream ().sorted ().collect (Collectors .toList ());
303+ return names .stream ().
304+ sorted (java .util .Comparator .comparing (name -> name .getValue ().toLowerCase ())).
305+ collect (Collectors .toList ());
292306
293307 case GROUP_MEMBERSHIP :
294- return groupInfo .getLeft ().getObject ();
308+ return groupInfo .getLeft ().getObject ().stream ().
309+ map (item -> Pair .of (item , item )).collect (Collectors .toList ());
295310
296311 case ROLE_MEMBERSHIP :
297312 return Optional .ofNullable (roleNames ).
298- map (r -> r .getObject ().stream ().sorted ().collect (Collectors .toList ())).
313+ map (r -> r .getObject ().stream ().sorted ().map (item -> Pair .of (item , item )).
314+ collect (Collectors .toList ())).
299315 orElse (List .of ());
300316
301317 case PRIVILEGE :
302318 return Optional .ofNullable (privilegeNames ).
303- map (p -> p .getObject ().stream ().sorted ().collect (Collectors .toList ())).
319+ map (p -> p .getObject ().stream ().sorted ().map (item -> Pair .of (item , item )).
320+ collect (Collectors .toList ())).
304321 orElse (List .of ());
305322
306323 case AUX_CLASS :
307- return auxClassNames .getObject ().stream ().
308- sorted ( ).collect (Collectors .toList ());
324+ return auxClassNames .getObject ().stream ().sorted ().
325+ map ( item -> Pair . of ( item , item ) ).collect (Collectors .toList ());
309326
310327 case RESOURCE :
311- return resourceNames .getObject ().stream ().
312- sorted ( ).collect (Collectors .toList ());
328+ return resourceNames .getObject ().stream ().sorted ().
329+ map ( item -> Pair . of ( item , item ) ).collect (Collectors .toList ());
313330
314331 case RELATIONSHIP :
315- return relationshipTypeRestClient .list ().stream ().
316- map (RelationshipTypeTO ::getKey ).collect (Collectors .toList ());
332+ return relationshipTypeRestClient .list ().stream ().sorted ().
333+ map (item -> Pair .of (item .getKey (), item .getKey ())).
334+ collect (Collectors .toList ());
317335
318336 case CUSTOM :
319- return customizer .properties ();
337+ return customizer .properties ().stream ().
338+ map (item -> Pair .of (item , item )).
339+ collect (Collectors .toList ());
320340
321341 default :
322342 return List .of ();
@@ -439,10 +459,40 @@ protected void onUpdate(final AjaxRequestTarget target) {
439459 operatorContainer .add (searchButtonFragment );
440460 }
441461
442- AjaxTextFieldPanel property = new AjaxTextFieldPanel (
443- "property" , "property" , new PropertyModel <>(searchClause , "property" ), true );
462+ AjaxTextFieldPanel property = new AjaxTextFieldPanel ("property" , "property" ,
463+ new PropertyModel <>(searchClause , "property" ), true ) {
464+
465+ private static final long serialVersionUID = -7157802546272668001L ;
466+
467+ @ Override
468+ protected Optional <IConverter <String >> getConverter () {
469+ return Optional .of (new IConverter <String >() {
470+
471+ private static final long serialVersionUID = -2754107934642211828L ;
472+
473+ @ Override
474+ public String convertToObject (final String label , final Locale locale ) throws ConversionException {
475+ return properties .getObject ().stream ().
476+ filter (property -> property .getValue ().equalsIgnoreCase (label )).
477+ findFirst ().
478+ map (Pair ::getKey ).
479+ orElse (label );
480+ }
481+
482+ @ Override
483+ public String convertToString (final String key , final Locale locale ) {
484+ return properties .getObject ().stream ().
485+ filter (property -> property .getKey ().equalsIgnoreCase (key )).
486+ findFirst ().
487+ map (Pair ::getValue ).
488+ orElse (key );
489+ }
490+ });
491+ }
492+ };
493+
444494 property .hideLabel ().setOutputMarkupId (true ).setEnabled (true );
445- property .setChoices (properties .getObject ());
495+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getValue ). collect ( Collectors . toList ()) );
446496 field .add (property );
447497
448498 property .getField ().add (PREVENT_DEFAULT_RETURN );
@@ -457,7 +507,8 @@ protected void onEvent(final AjaxRequestTarget target) {
457507
458508 String [] inputAsArray = property .getField ().getInputAsArray ();
459509 if (ArrayUtils .isEmpty (inputAsArray )) {
460- property .setChoices (properties .getObject ());
510+ property .setChoices (properties .getObject ().stream ().map (Pair ::getKey )
511+ .collect (Collectors .toList ()));
461512 } else if (groupInfo .getRight ().getObject () > Constants .MAX_GROUP_LIST_SIZE ) {
462513 String inputValue = inputAsArray .length > 1 && inputAsArray [1 ] != null
463514 ? inputAsArray [1 ]
@@ -621,7 +672,9 @@ private void setFieldAccess(
621672
622673 // reload properties list
623674 properties .detach ();
624- property .setChoices (properties .getObject ());
675+ property .setChoices (
676+ properties .getObject ().stream ().
677+ map (Pair ::getValue ).collect (Collectors .toList ()));
625678 break ;
626679
627680 case ROLE_MEMBERSHIP :
@@ -630,7 +683,7 @@ private void setFieldAccess(
630683
631684 // reload properties list
632685 properties .detach ();
633- property .setChoices (properties .getObject ());
686+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
634687 break ;
635688
636689 case PRIVILEGE :
@@ -639,7 +692,7 @@ private void setFieldAccess(
639692
640693 // reload properties list
641694 properties .detach ();
642- property .setChoices (properties .getObject ());
695+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
643696 break ;
644697
645698 case GROUP_MEMBERSHIP :
@@ -648,7 +701,7 @@ private void setFieldAccess(
648701
649702 // reload properties list
650703 properties .detach ();
651- property .setChoices (properties .getObject ());
704+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
652705 break ;
653706
654707 case GROUP_MEMBER :
@@ -664,7 +717,7 @@ private void setFieldAccess(
664717
665718 // reload properties list
666719 properties .detach ();
667- property .setChoices (properties .getObject ());
720+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
668721 break ;
669722
670723 case RELATIONSHIP :
@@ -674,7 +727,7 @@ private void setFieldAccess(
674727
675728 // reload properties list
676729 properties .detach ();
677- property .setChoices (properties .getObject ());
730+ property .setChoices (properties .getObject (). stream (). map ( Pair :: getKey ). collect ( Collectors . toList ()) );
678731 break ;
679732
680733 case CUSTOM :
0 commit comments