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.dashboard;
35
36 import javax.servlet.http.HttpServletRequest;
37
38 import org.apache.commons.lang3.StringUtils;
39
40 import fr.paris.lutece.portal.business.dashboard.DashboardFactory;
41 import fr.paris.lutece.portal.business.dashboard.DashboardHome;
42 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
43 import fr.paris.lutece.portal.service.dashboard.DashboardService;
44 import fr.paris.lutece.portal.service.dashboard.IDashboardComponent;
45 import fr.paris.lutece.portal.service.message.AdminMessage;
46 import fr.paris.lutece.portal.service.message.AdminMessageService;
47 import fr.paris.lutece.portal.service.security.SecurityTokenService;
48 import fr.paris.lutece.portal.service.util.AppLogService;
49 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
50 import fr.paris.lutece.portal.web.constants.Messages;
51 import fr.paris.lutece.util.string.StringUtil;
52
53
54
55
56
57 public class DashboardJspBean extends AdminFeaturesPageJspBean
58 {
59
60 public static final String RIGHT_MANAGE_DASHBOARD = "CORE_DASHBOARD_MANAGEMENT";
61
62
63 private static final String PARAMETER_DASHBOARD_NAME = "dashboard_name";
64 private static final String PARAMETER_DASHBOARD_COLUMN = "dashboard_column";
65 private static final String PARAMETER_DASHBOARD_ORDER = "dashboard_order";
66 private static final String PARAMETER_COLUMN = "column";
67
68
69 private static final String MESSAGE_DASHBOARD_NOT_FOUND = "portal.dashboard.message.dashboardNotFound";
70
71
72 private static final String TEMPLATE_MANAGE_DASHBOARDS = "/admin/dashboard/manage_dashboards.html";
73
74
75 private static final String ANCHOR_ADMIN_DASHBOARDS = "adminHomePageManagement";
76 private transient DashboardService _service = DashboardService.getInstance( );
77
78
79
80
81
82
83
84
85
86
87 public String doReorderColumn( HttpServletRequest request ) throws AccessDeniedException
88 {
89 String strColumnName = request.getParameter( PARAMETER_COLUMN );
90
91 if ( StringUtils.isBlank( strColumnName ) )
92 {
93 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
94 }
95
96 int nColumn;
97
98 try
99 {
100 nColumn = Integer.parseInt( strColumnName );
101 }
102 catch( NumberFormatException nfe )
103 {
104 AppLogService.error( "DashboardJspBean.doReorderColumn : {}", nfe.getMessage( ), nfe );
105
106 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
107 }
108 if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_MANAGE_DASHBOARDS ) )
109 {
110 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
111 }
112 getDashboardService( ).doReorderColumn( nColumn );
113
114 return getAdminDashboardsUrl( request, ANCHOR_ADMIN_DASHBOARDS );
115 }
116
117
118
119
120
121
122
123
124
125
126 public String doMoveDashboard( HttpServletRequest request ) throws AccessDeniedException
127 {
128 String strDashboardName = request.getParameter( PARAMETER_DASHBOARD_NAME );
129
130 if ( StringUtils.isBlank( strDashboardName ) )
131 {
132 return AdminMessageService.getMessageUrl( request, MESSAGE_DASHBOARD_NOT_FOUND, AdminMessage.TYPE_STOP );
133 }
134
135
136 IDashboardComponent dashboard = DashboardHome.findByPrimaryKey( strDashboardName );
137 int nOldOrder = 0;
138 int nOldColumn = 0;
139 boolean bCreate = false;
140
141 if ( dashboard == null )
142 {
143 bCreate = true;
144
145 if ( AppLogService.isDebugEnabled( ) )
146 {
147 AppLogService.debug( "Dashboard " + strDashboardName + " has no property set. Retrieving from SpringContext" );
148 }
149
150 dashboard = DashboardFactory.getDashboardComponent( strDashboardName );
151
152 if ( dashboard == null )
153 {
154 return AdminMessageService.getMessageUrl( request, MESSAGE_DASHBOARD_NOT_FOUND, AdminMessage.TYPE_STOP );
155 }
156 }
157 else
158 {
159 nOldOrder = dashboard.getOrder( );
160 nOldColumn = dashboard.getZone( );
161 }
162 if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_MANAGE_DASHBOARDS ) )
163 {
164 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
165 }
166
167 String strOrder = request.getParameter( PARAMETER_DASHBOARD_ORDER );
168 String strColumn = request.getParameter( PARAMETER_DASHBOARD_COLUMN );
169
170 int nOrder = StringUtil.getIntValue( strOrder, -1 );
171 int nColumn = StringUtil.getIntValue( strColumn, -1 );
172
173 dashboard.setOrder( nOrder );
174 dashboard.setZone( nColumn );
175
176 getDashboardService( ).doMoveDashboard( dashboard, nOldColumn, nOldOrder, bCreate );
177
178 return getAdminDashboardsUrl( request, ANCHOR_ADMIN_DASHBOARDS );
179 }
180
181 private DashboardService getDashboardService( )
182 {
183 if ( _service == null )
184 {
185 _service = DashboardService.getInstance( );
186 }
187
188 return _service;
189 }
190 }