| 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.plugins.parisconnect.web; |
| 35 | |
|
| 36 | |
import fr.paris.lutece.plugins.parisconnect.business.Alert; |
| 37 | |
import fr.paris.lutece.plugins.parisconnect.business.AlertHome; |
| 38 | |
import fr.paris.lutece.plugins.parisconnect.business.CategoryHome; |
| 39 | |
import fr.paris.lutece.portal.service.message.AdminMessage; |
| 40 | |
import fr.paris.lutece.portal.service.message.AdminMessageService; |
| 41 | |
import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller; |
| 42 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.Action; |
| 43 | |
import fr.paris.lutece.portal.util.mvc.commons.annotations.View; |
| 44 | |
import fr.paris.lutece.util.url.UrlItem; |
| 45 | |
|
| 46 | |
import java.util.List; |
| 47 | |
import java.util.Map; |
| 48 | |
import javax.servlet.http.HttpServletRequest; |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
@Controller( controllerJsp = "ManageAlerts.jsp", controllerPath = "jsp/admin/plugins/parisconnect/", right = "PARISCONNECT_MANAGEMENT" ) |
| 54 | 0 | public class AlertJspBean extends ManageParisconnectJspBean |
| 55 | |
{ |
| 56 | |
|
| 57 | |
private static final String TEMPLATE_MANAGE_ALERTS = "/admin/plugins/parisconnect/manage_alerts.html"; |
| 58 | |
private static final String TEMPLATE_CREATE_ALERT = "/admin/plugins/parisconnect/create_alert.html"; |
| 59 | |
private static final String TEMPLATE_MODIFY_ALERT = "/admin/plugins/parisconnect/modify_alert.html"; |
| 60 | |
|
| 61 | |
|
| 62 | |
private static final String PARAMETER_ID_ALERT = "id"; |
| 63 | |
|
| 64 | |
|
| 65 | |
private static final String PROPERTY_PAGE_TITLE_MANAGE_ALERTS = "parisconnect.manage_alerts.pageTitle"; |
| 66 | |
private static final String PROPERTY_PAGE_TITLE_MODIFY_ALERT = "parisconnect.modify_alert.pageTitle"; |
| 67 | |
private static final String PROPERTY_PAGE_TITLE_CREATE_ALERT = "parisconnect.create_alert.pageTitle"; |
| 68 | |
|
| 69 | |
|
| 70 | |
private static final String MARK_ALERT_LIST = "alert_list"; |
| 71 | |
private static final String MARK_ALERT = "parisconnect_alert"; |
| 72 | |
private static final String MARK_CATEGORY_LIST = "category_list"; |
| 73 | |
|
| 74 | |
private static final String JSP_MANAGE_ALERTS = "jsp/admin/plugins/parisconnect/ManageAlerts.jsp"; |
| 75 | |
|
| 76 | |
|
| 77 | |
private static final String MESSAGE_CONFIRM_REMOVE_ALERT = "parisconnect.message.confirmRemoveAlert"; |
| 78 | |
|
| 79 | |
|
| 80 | |
private static final String VALIDATION_ATTRIBUTES_PREFIX = "parisconnect.model.entity.alert.attribute."; |
| 81 | |
|
| 82 | |
|
| 83 | |
private static final String VIEW_MANAGE_ALERTS = "manageAlerts"; |
| 84 | |
private static final String VIEW_CREATE_ALERT = "createAlert"; |
| 85 | |
private static final String VIEW_MODIFY_ALERT = "modifyAlert"; |
| 86 | |
|
| 87 | |
|
| 88 | |
private static final String ACTION_CREATE_ALERT = "createAlert"; |
| 89 | |
private static final String ACTION_MODIFY_ALERT = "modifyAlert"; |
| 90 | |
private static final String ACTION_REMOVE_ALERT = "removeAlert"; |
| 91 | |
private static final String ACTION_CONFIRM_REMOVE_ALERT = "confirmRemoveAlert"; |
| 92 | |
|
| 93 | |
|
| 94 | |
private static final String INFO_ALERT_CREATED = "parisconnect.info.alert.created"; |
| 95 | |
private static final String INFO_ALERT_UPDATED = "parisconnect.info.alert.updated"; |
| 96 | |
private static final String INFO_ALERT_REMOVED = "parisconnect.info.alert.removed"; |
| 97 | |
|
| 98 | |
|
| 99 | |
private Alert _alert; |
| 100 | |
|
| 101 | |
|
| 102 | |
|
| 103 | |
|
| 104 | |
|
| 105 | |
|
| 106 | |
@View( value = VIEW_MANAGE_ALERTS, defaultView = true ) |
| 107 | |
public String getManageAlerts( HttpServletRequest request ) |
| 108 | |
{ |
| 109 | 0 | _alert = null; |
| 110 | 0 | List<Alert> listAlerts = AlertHome.getAlertsList( ); |
| 111 | 0 | Map<String, Object> model = getPaginatedListModel( request, MARK_ALERT_LIST, listAlerts, JSP_MANAGE_ALERTS ); |
| 112 | |
|
| 113 | |
|
| 114 | 0 | model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() ); |
| 115 | |
|
| 116 | 0 | return getPage( PROPERTY_PAGE_TITLE_MANAGE_ALERTS, TEMPLATE_MANAGE_ALERTS, model ); |
| 117 | |
} |
| 118 | |
|
| 119 | |
|
| 120 | |
|
| 121 | |
|
| 122 | |
|
| 123 | |
|
| 124 | |
|
| 125 | |
@View( VIEW_CREATE_ALERT ) |
| 126 | |
public String getCreateAlert( HttpServletRequest request ) |
| 127 | |
{ |
| 128 | 0 | _alert = ( _alert != null ) ? _alert : new Alert( ); |
| 129 | |
|
| 130 | 0 | Map<String, Object> model = getModel( ); |
| 131 | 0 | model.put( MARK_ALERT, _alert ); |
| 132 | 0 | model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() ); |
| 133 | |
|
| 134 | |
|
| 135 | 0 | return getPage( PROPERTY_PAGE_TITLE_CREATE_ALERT, TEMPLATE_CREATE_ALERT, model ); |
| 136 | |
} |
| 137 | |
|
| 138 | |
|
| 139 | |
|
| 140 | |
|
| 141 | |
|
| 142 | |
|
| 143 | |
|
| 144 | |
@Action( ACTION_CREATE_ALERT ) |
| 145 | |
public String doCreateAlert( HttpServletRequest request ) |
| 146 | |
{ |
| 147 | 0 | populate( _alert, request ); |
| 148 | |
|
| 149 | |
|
| 150 | 0 | if ( !validateBean( _alert, VALIDATION_ATTRIBUTES_PREFIX ) ) |
| 151 | |
{ |
| 152 | 0 | return redirectView( request, VIEW_CREATE_ALERT ); |
| 153 | |
} |
| 154 | |
|
| 155 | 0 | AlertHome.create( _alert ); |
| 156 | 0 | addInfo( INFO_ALERT_CREATED, getLocale( ) ); |
| 157 | |
|
| 158 | 0 | return redirectView( request, VIEW_MANAGE_ALERTS ); |
| 159 | |
} |
| 160 | |
|
| 161 | |
|
| 162 | |
|
| 163 | |
|
| 164 | |
|
| 165 | |
|
| 166 | |
|
| 167 | |
|
| 168 | |
@Action( ACTION_CONFIRM_REMOVE_ALERT ) |
| 169 | |
public String getConfirmRemoveAlert( HttpServletRequest request ) |
| 170 | |
{ |
| 171 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) ); |
| 172 | 0 | UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_ALERT ) ); |
| 173 | 0 | url.addParameter( PARAMETER_ID_ALERT, nId ); |
| 174 | |
|
| 175 | 0 | String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_ALERT, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION ); |
| 176 | |
|
| 177 | 0 | return redirect( request, strMessageUrl ); |
| 178 | |
} |
| 179 | |
|
| 180 | |
|
| 181 | |
|
| 182 | |
|
| 183 | |
|
| 184 | |
|
| 185 | |
|
| 186 | |
@Action( ACTION_REMOVE_ALERT ) |
| 187 | |
public String doRemoveAlert( HttpServletRequest request ) |
| 188 | |
{ |
| 189 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) ); |
| 190 | 0 | AlertHome.remove( nId ); |
| 191 | 0 | addInfo( INFO_ALERT_REMOVED, getLocale( ) ); |
| 192 | |
|
| 193 | 0 | return redirectView( request, VIEW_MANAGE_ALERTS ); |
| 194 | |
} |
| 195 | |
|
| 196 | |
|
| 197 | |
|
| 198 | |
|
| 199 | |
|
| 200 | |
|
| 201 | |
|
| 202 | |
@View( VIEW_MODIFY_ALERT ) |
| 203 | |
public String getModifyAlert( HttpServletRequest request ) |
| 204 | |
{ |
| 205 | 0 | int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ALERT ) ); |
| 206 | |
|
| 207 | 0 | if ( _alert == null || ( _alert.getId( ) != nId )) |
| 208 | |
{ |
| 209 | 0 | _alert = AlertHome.findByPrimaryKey( nId ); |
| 210 | |
} |
| 211 | |
|
| 212 | 0 | Map<String, Object> model = getModel( ); |
| 213 | 0 | model.put( MARK_CATEGORY_LIST, CategoryHome.getCategorysReferenceList() ); |
| 214 | |
|
| 215 | 0 | model.put( MARK_ALERT, _alert ); |
| 216 | |
|
| 217 | 0 | return getPage( PROPERTY_PAGE_TITLE_MODIFY_ALERT, TEMPLATE_MODIFY_ALERT, model ); |
| 218 | |
} |
| 219 | |
|
| 220 | |
|
| 221 | |
|
| 222 | |
|
| 223 | |
|
| 224 | |
|
| 225 | |
|
| 226 | |
@Action( ACTION_MODIFY_ALERT ) |
| 227 | |
public String doModifyAlert( HttpServletRequest request ) |
| 228 | |
{ |
| 229 | 0 | populate( _alert, request ); |
| 230 | |
|
| 231 | |
|
| 232 | 0 | if ( !validateBean( _alert, VALIDATION_ATTRIBUTES_PREFIX ) ) |
| 233 | |
{ |
| 234 | 0 | return redirect( request, VIEW_MODIFY_ALERT, PARAMETER_ID_ALERT, _alert.getId( ) ); |
| 235 | |
} |
| 236 | |
|
| 237 | 0 | AlertHome.update( _alert ); |
| 238 | 0 | addInfo( INFO_ALERT_UPDATED, getLocale( ) ); |
| 239 | |
|
| 240 | 0 | return redirectView( request, VIEW_MANAGE_ALERTS ); |
| 241 | |
} |
| 242 | |
} |