1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.web.features;
35
36 import fr.paris.lutece.portal.business.right.FeatureGroup;
37 import fr.paris.lutece.portal.business.right.FeatureGroupHome;
38 import fr.paris.lutece.portal.business.right.RightHome;
39 import fr.paris.lutece.portal.business.user.AdminUser;
40 import fr.paris.lutece.portal.service.dashboard.admin.AdminDashboardComponent;
41 import fr.paris.lutece.portal.service.i18n.I18nService;
42 import fr.paris.lutece.portal.service.security.SecurityTokenService;
43 import fr.paris.lutece.portal.service.template.AppTemplateService;
44 import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
45 import fr.paris.lutece.util.ReferenceList;
46 import fr.paris.lutece.util.html.HtmlTemplate;
47 import java.util.ArrayList;
48 import java.util.Collection;
49 import java.util.HashMap;
50 import java.util.List;
51 import java.util.Locale;
52 import java.util.Map;
53 import javax.servlet.http.HttpServletRequest;
54
55
56
57
58 public class FeaturesAdminDashboardComponent extends AdminDashboardComponent
59 {
60 private static final String TEMPLATE_FEATURES_ADMINDASHBOARD = "admin/dashboard/admin/features_admindashboard.html";
61 private static final String MARK_FEATURE_NO_GROUP = "no_group";
62 private static final String MARK_FEATURE_GROUP_LIST = "feature_group_list";
63 private static final String MARK_FEATURE_GROUP = "feature_group";
64 private static final String MARK_GROUPS_LIST = "groups_list";
65 private static final String MARK_ORDER_LIST = "order_list";
66 private static final String MARK_EXTERNAL_FEATURES_LIST = "external_features_list";
67 private static final String MARK_RIGHT_LIST = "feature_list";
68 private static final String MARK_ORDER_IS_OK = "order_list_state";
69
70 private static final String NO_GROUP_DESCRIPTION = "portal.features.nogroup.description";
71 private static final String NO_GROUP_LABEL = "portal.features.nogroup.label";
72 private static final int NO_GROUP_ORDER = 0;
73 private static final String NO_GROUP_ID = null;
74
75
76
77
78 @Override
79 public String getDashboardData( AdminUser user, HttpServletRequest request )
80 {
81 List<FeatureGroup> listGroups = FeatureGroupHome.getFeatureGroupsList( );
82 Map<String, Object> model = new HashMap<>( );
83 model.put( MARK_FEATURE_NO_GROUP, getNoGroup( user.getLocale( ) ) );
84 model.put( MARK_FEATURE_GROUP_LIST, getRefListFeatureGroups( user.getLocale( ) ) );
85 model.put( MARK_ORDER_LIST, getOrderRefList( ) );
86 model.put( MARK_GROUPS_LIST, listGroups );
87 model.put( MARK_EXTERNAL_FEATURES_LIST, RightHome.getExternalRightList( ) );
88 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, AdminDashboardJspBean.TEMPLATE_MANAGE_DASHBOARDS ) );
89
90 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_FEATURES_ADMINDASHBOARD, user.getLocale( ), model );
91
92 return template.getHtml( );
93
94 }
95
96
97
98
99
100
101 private ReferenceList getOrderRefList( )
102 {
103 int nGroupsCount = FeatureGroupHome.getFeatureGroupsCount( );
104 ReferenceListt.html#ReferenceList">ReferenceList listOrders = new ReferenceList( );
105
106 for ( int i = 0; i < nGroupsCount; i++ )
107 {
108 listOrders.addItem( i + 1, Integer.toString( i + 1 ) );
109 }
110
111 return listOrders;
112 }
113
114
115
116
117
118
119
120
121 private Map<String, Object> getNoGroup( Locale locale )
122 {
123 FeatureGroupss/right/FeatureGroup.html#FeatureGroup">FeatureGroup noGroup = new FeatureGroup( );
124 noGroup.setLocale( locale );
125 noGroup.setId( NO_GROUP_ID );
126 noGroup.setOrder( NO_GROUP_ORDER );
127 noGroup.setDescriptionKey( NO_GROUP_DESCRIPTION );
128 noGroup.setLabelKey( NO_GROUP_LABEL );
129
130 Map<String, Object> groupMap = new HashMap<>( );
131 groupMap.put( MARK_FEATURE_GROUP, noGroup );
132 groupMap.put( MARK_RIGHT_LIST, I18nService.localizeCollection( RightHome.getRightsList( noGroup.getId( ) ), locale ) );
133 groupMap.put( MARK_ORDER_IS_OK, RightHome.checkFeatureOrders( noGroup.getId( ) ) );
134
135 return groupMap;
136 }
137
138
139
140
141
142
143
144
145 private Collection<HashMap<String, Object>> getRefListFeatureGroups( Locale locale )
146 {
147 Collection<HashMap<String, Object>> colGroupMap = new ArrayList<>( );
148 Collection<FeatureGroup> colGroups = FeatureGroupHome.getFeatureGroupsList( );
149
150 for ( FeatureGroup fg : colGroups )
151 {
152 HashMap<String, Object> groupMap = new HashMap<>( );
153 groupMap.put( MARK_FEATURE_GROUP, fg );
154 groupMap.put( MARK_RIGHT_LIST, I18nService.localizeCollection( RightHome.getRightsList( fg.getId( ) ), locale ) );
155 groupMap.put( MARK_ORDER_IS_OK, RightHome.checkFeatureOrders( fg.getId( ) ) );
156 colGroupMap.add( groupMap );
157 }
158
159 return colGroupMap;
160 }
161
162 }