View Javadoc
1   /*
2    * Copyright (c) 2002-2022, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.appointment.web;
35  
36  import java.util.Map;
37  import javax.servlet.http.HttpServletRequest;
38  import fr.paris.lutece.plugins.appointment.business.comment.CommentNotificationConfig;
39  import fr.paris.lutece.plugins.appointment.business.comment.CommentNotificationHome;
40  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
41  import fr.paris.lutece.portal.util.mvc.admin.MVCAdminJspBean;
42  import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
43  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
44  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
45  
46  /**
47   * This class provides the user interface to manage calendar templates
48   * 
49   * @author Laurent Payen
50   *
51   */
52  @Controller( controllerJsp = CommentNotificationJspBean.CONTROLLER_JSP, controllerPath = CommentNotificationJspBean.CONTROLLER_PATH, right = CommentJspBean.RIGHT_MANAGECOMMENTTFORM )
53  public class CommentNotificationJspBean extends MVCAdminJspBean
54  {
55      private static final long serialVersionUID = 1995349998868975731L;
56  
57      /**
58       * Folder of the JSP of this controller
59       */
60      public static final String CONTROLLER_PATH = "jsp/admin/plugins/appointment/";
61      /**
62       * Name of the JSP of this controller
63       */
64      public static final String CONTROLLER_JSP = "NotificationCommentConfig.jsp";
65      /**
66       * URL of the JSP of this controller
67       */
68      public static final String JSP_URL_MANAGE_CALENDAR_TEMPLATE = CONTROLLER_PATH + CONTROLLER_JSP;
69      // templates
70      private static final String TEMPLATE_NOTIFICATION_CONFIG = "/admin/plugins/appointment/notification/task_notification_config.html";
71      private static final String TEMPLATE_MANAGE_NOTIFICATION_CONFIG = "/admin/plugins/appointment/notification/manage_notification_config.html";
72  
73      // Marks
74      private static final String MARK_CONFIG = "config";
75      private static final String MARK_LIST_CONFIG = "list_config";
76  
77      // Parameters
78      private static final String PARAMETER_TYPE = "type";
79  
80      // Messages
81      private static final String INFO_COMMENT_UPDATED = "appointment.info.comment.updated";
82      // Properties
83      private static final String PROPERTY_PAGE_TITLE_MANAGE_COMMENTS = "task_notify_appointment_comment_config.title";
84      // View
85      private static final String VIEW_NOTIFIACTION_CONFIG = "notificationConfig";
86      private static final String VIEW_MODIFY_NOTIFIACTION_CONFIG = "modifyNotificationCommentConfig";
87      // Actions
88      private static final String ACTION_DO_UPDATE_NOTIFICATION_CONFIG = "updateNotificationCommentConfig";
89      // Session variables
90      private CommentNotificationConfig _commentNotificationConfig;
91  
92      /**
93       * Get the page to manage comment notification.
94       * 
95       * @param request
96       *            The request
97       * @return The HTML code to display
98       * @throws AccessDeniedException
99       */
100     @View( value = VIEW_NOTIFIACTION_CONFIG, defaultView = true )
101     public String getNotificationCommentConfig( HttpServletRequest request )
102     {
103         _commentNotificationConfig = null;
104         Map<String, Object> model = getModel( );
105         model.put( MARK_LIST_CONFIG, CommentNotificationHome.loadCommentNotificationConfig( ) );
106         return getPage( PROPERTY_PAGE_TITLE_MANAGE_COMMENTS, TEMPLATE_MANAGE_NOTIFICATION_CONFIG, model );
107 
108     }
109 
110     /**
111      * Get the page to edite comment notification.
112      * 
113      * @param request
114      *            The request
115      * @return The HTML code to display
116      * @throws AccessDeniedException
117      */
118     @View( value = VIEW_MODIFY_NOTIFIACTION_CONFIG )
119     public String getModifyNotificationCommentConfig( HttpServletRequest request )
120     {
121         String type = request.getParameter( PARAMETER_TYPE );
122         _commentNotificationConfig = CommentNotificationHome.loadCommentNotificationConfigByType( type );
123         Map<String, Object> model = getModel( );
124         model.put( MARK_CONFIG, _commentNotificationConfig );
125         return getPage( PROPERTY_PAGE_TITLE_MANAGE_COMMENTS, TEMPLATE_NOTIFICATION_CONFIG, model );
126 
127     }
128 
129     /**
130      * Update the notification config
131      * 
132      * @param request
133      *            The request
134      * @return The next URL to redirect to
135      * @throws AccessDeniedException
136      */
137     @Action( ACTION_DO_UPDATE_NOTIFICATION_CONFIG )
138     public String doUpdateNotificationCommentConfig( HttpServletRequest request )
139     {
140         populate( _commentNotificationConfig, request );
141         CommentNotificationHome.update( _commentNotificationConfig );
142         addInfo( INFO_COMMENT_UPDATED, getLocale( ) );
143         return redirectView( request, VIEW_NOTIFIACTION_CONFIG );
144     }
145 
146 }