2020
2121import de .agilecoders .wicket .core .markup .html .bootstrap .dialog .Modal ;
2222import java .io .Serializable ;
23+ import java .lang .reflect .Field ;
24+ import java .time .OffsetDateTime ;
2325import java .util .ArrayList ;
2426import java .util .Collection ;
2527import java .util .Collections ;
28+ import java .util .Date ;
2629import java .util .Iterator ;
2730import java .util .List ;
2831import java .util .Optional ;
4548import org .apache .syncope .client .console .tasks .RealmPropagationTasks ;
4649import org .apache .syncope .client .console .tasks .TemplatesTogglePanel ;
4750import org .apache .syncope .client .console .wicket .extensions .markup .html .repeater .data .table .AttrColumn ;
51+ import org .apache .syncope .client .console .wicket .extensions .markup .html .repeater .data .table .BooleanPropertyColumn ;
52+ import org .apache .syncope .client .console .wicket .extensions .markup .html .repeater .data .table .DatePropertyColumn ;
4853import org .apache .syncope .client .console .wicket .extensions .markup .html .repeater .data .table .KeyPropertyColumn ;
4954import org .apache .syncope .client .console .wicket .markup .html .bootstrap .dialog .BaseModal ;
5055import org .apache .syncope .client .console .wicket .markup .html .form .ActionLink ;
8388import org .apache .wicket .request .cycle .RequestCycle ;
8489import org .apache .wicket .request .mapper .parameter .PageParameters ;
8590import org .apache .wicket .spring .injection .annot .SpringBean ;
91+ import org .springframework .util .ReflectionUtils ;
8692
8793public class RealmDirectoryPanel
8894 extends DirectoryPanel <RealmTO , RealmTO , RealmDirectoryPanel .RealmDataProvider , RealmRestClient > {
@@ -154,35 +160,63 @@ protected String paginatorRowsKey() {
154160
155161 @ Override
156162 protected List <IColumn <RealmTO , String >> getColumns () {
157- List <String > selectedColumns = PreferenceManager .getList (IdRepoConstants .PREF_REALM_DETAILS_VIEW );
158- selectedColumns .retainAll (RealmDisplayAttributesModalPanel .AVAILABLE_COLUMNS );
159- if (selectedColumns .isEmpty ()) {
160- selectedColumns = new ArrayList <>(RealmDisplayAttributesModalPanel .DEFAULT_COLUMNS );
161- PreferenceManager .setList (IdRepoConstants .PREF_REALM_DETAILS_VIEW , selectedColumns );
162- }
163- List <String > selectedPlainSchemas = PreferenceManager .getList (IdRepoConstants .PREF_REALM_PLAIN_ATTRS_VIEW );
164- selectedPlainSchemas .retainAll (plainSchemas .stream ().map (PlainSchemaTO ::getKey ).toList ());
163+ List <IColumn <RealmTO , String >> columns = new ArrayList <>();
164+ columns .add (new KeyPropertyColumn <>(
165+ new ResourceModel (Constants .KEY_FIELD_NAME , Constants .KEY_FIELD_NAME ), Constants .KEY_FIELD_NAME ));
166+
167+ List <IColumn <RealmTO , String >> prefcolumns = new ArrayList <>();
168+ PreferenceManager .getList (IdRepoConstants .PREF_REALM_DETAILS_VIEW ).stream ().
169+ filter (name -> !Constants .KEY_FIELD_NAME .equalsIgnoreCase (name )).
170+ forEach (name -> addPropertyColumn (
171+ name ,
172+ ReflectionUtils .findField (RealmTO .class , name ),
173+ prefcolumns ));
174+
175+ PreferenceManager .getList (IdRepoConstants .PREF_REALM_PLAIN_ATTRS_VIEW ).stream ().
176+ map (a -> plainSchemas .stream ().filter (p -> p .getKey ().equals (a )).findFirst ()).
177+ flatMap (Optional ::stream ).
178+ forEach (s -> prefcolumns .add (new AttrColumn <>(
179+ s .getKey (), s .getLabel (SyncopeConsoleSession .get ().getLocale ()), SchemaType .PLAIN )));
180+
181+ PreferenceManager .getList (IdRepoConstants .PREF_REALM_DER_ATTRS_VIEW ).stream ().
182+ map (a -> derSchemas .stream ().filter (p -> p .getKey ().equals (a )).findFirst ()).
183+ flatMap (Optional ::stream ).
184+ forEach (s -> prefcolumns .add (new AttrColumn <>(
185+ s .getKey (), s .getLabel (SyncopeConsoleSession .get ().getLocale ()), SchemaType .DERIVED )));
186+
187+ // Add defaults in case of no selection
188+ if (prefcolumns .isEmpty ()) {
189+ for (String name : RealmDisplayAttributesModalPanel .DEFAULT_COLUMNS ) {
190+ addPropertyColumn (
191+ name ,
192+ ReflectionUtils .findField (RealmTO .class , name ),
193+ prefcolumns );
194+ }
165195
166- List <String > selectedDerSchemas = PreferenceManager .getList (IdRepoConstants .PREF_REALM_DER_ATTRS_VIEW );
167- selectedDerSchemas .retainAll (derSchemas .stream ().map (DerSchemaTO ::getKey ).toList ());
196+ PreferenceManager .setList (
197+ IdRepoConstants .PREF_REALM_DETAILS_VIEW ,
198+ RealmDisplayAttributesModalPanel .DEFAULT_COLUMNS );
199+ }
168200
169- List <IColumn <RealmTO , String >> columns = new ArrayList <>();
170- selectedColumns .forEach (column -> addPropertyColumn (column , columns ));
171- plainSchemas .stream ().
172- filter (schema -> selectedPlainSchemas .contains (schema .getKey ())).
173- forEach (schema -> columns .add (new AttrColumn <>(
174- schema .getKey (), schema .getLabel (getLocale ()), SchemaType .PLAIN )));
175-
176- derSchemas .stream ().
177- filter (schema -> selectedDerSchemas .contains (schema .getKey ())).
178- forEach (schema -> columns .add (new AttrColumn <>(
179- schema .getKey (), schema .getLabel (getLocale ()), SchemaType .DERIVED )));
201+ columns .addAll (prefcolumns );
180202 return columns ;
181203 }
182204
183- protected void addPropertyColumn (final String name , final List <IColumn <RealmTO , String >> columns ) {
205+ protected void addPropertyColumn (
206+ final String name ,
207+ final Field field ,
208+ final List <IColumn <RealmTO , String >> columns ) {
209+
184210 if (Constants .KEY_FIELD_NAME .equalsIgnoreCase (name )) {
185- columns .add (new KeyPropertyColumn <>(new StringResourceModel (Constants .KEY_FIELD_NAME , this ), name ));
211+ columns .add (new KeyPropertyColumn <>(new ResourceModel (name , name ), name , name ));
212+ } else if (field != null && !field .isSynthetic ()
213+ && (field .getType ().equals (Boolean .class ) || field .getType ().equals (boolean .class ))) {
214+
215+ columns .add (new BooleanPropertyColumn <>(new ResourceModel (name , name ), name , name ));
216+ } else if (field != null && !field .isSynthetic ()
217+ && (field .getType ().equals (Date .class ) || field .getType ().equals (OffsetDateTime .class ))) {
218+
219+ columns .add (new DatePropertyColumn <>(new ResourceModel (name , name ), name , name ));
186220 } else {
187221 columns .add (new PropertyColumn <>(new ResourceModel (name , name ), name , name ));
188222 }
@@ -201,8 +235,8 @@ public void onClick(final AjaxRequestTarget target, final Serializable ignore) {
201235 displayAttributeModal ,
202236 page .getPageReference (),
203237 RealmDisplayAttributesModalPanel .AVAILABLE_COLUMNS ,
204- plainSchemas .stream ().map (PlainSchemaTO ::getKey ).toList (),
205- derSchemas .stream ().map (DerSchemaTO ::getKey ).toList ())));
238+ plainSchemas .stream ().map (PlainSchemaTO ::getKey ).sorted (). toList (),
239+ derSchemas .stream ().map (DerSchemaTO ::getKey ).sorted (). toList ())));
206240 displayAttributeModal .header (new ResourceModel ("any.attr.display" ));
207241 displayAttributeModal .show (true );
208242 }
0 commit comments