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.service;
35  
36  import org.apache.commons.lang3.StringUtils;
37  
38  import fr.paris.lutece.plugins.appointment.business.message.FormMessage;
39  import fr.paris.lutece.plugins.appointment.business.message.FormMessageHome;
40  import fr.paris.lutece.portal.service.util.AppPropertiesService;
41  
42  /**
43   * Service class of the form message
44   * 
45   * @author Laurent Payen
46   *
47   */
48  public final class FormMessageService
49  {
50  
51      /**
52       * Private constructor - this class does not need to be instantiated
53       */
54      private FormMessageService( )
55      {
56      }
57  
58      /**
59       * Name of the bean of the service
60       */
61      public static final String BEAN_NAME = "appointment.formMessageService";
62  
63      private static final String PROPERTY_DEFAULT_CALENDAR_TITLE = "appointment.formMessages.defaultCalendarTitle";
64      private static final String PROPERTY_DEFAULT_FIELD_FIRST_NAME_TITLE = "appointment.formMessages.defaultFieldFirstNameTitle";
65      private static final String PROPERTY_DEFAULT_FIELD_FIRST_NAME_HELP = "appointment.formMessages.defaultFieldFirstNameHelp";
66      private static final String PROPERTY_DEFAULT_FIELD_LAST_NAME_TITLE = "appointment.formMessages.defaultFieldLastNameTitle";
67      private static final String PROPERTY_DEFAULT_FIELD_LAST_NAME_HELP = "appointment.formMessages.defaultFieldLastNameHelp";
68      private static final String PROPERTY_DEFAULT_FIELD_EMAIL_TITLE = "appointment.formMessages.defaultFieldEmailTitle";
69      private static final String PROPERTY_DEFAULT_FIELD_EMAIL_HELP = "appointment.formMessages.defaultFieldEmailHelp";
70      private static final String PROPERTY_DEFAULT_FIELD_CONFIRMATION_EMAIL_TITLE = "appointment.formMessages.defaultFieldConfirmationEmailTitle";
71      private static final String PROPERTY_DEFAULT_FIELD_CONFIRMATION_EMAIL_HELP = "appointment.formMessages.defaultFieldConfirmationEmailHelp";
72      private static final String PROPERTY_DEFAULT_URL_REDIRECTION = "appointment.formMessages.defaultUrlRedirection";
73      private static final String PROPERTY_DEFAULT_LABEL_BUTTON_REDIRECT = "appointment.formMessages.defaultLabelButtonRedirect";
74      private static final String PROPERTY_DEFAULT_TEXT_APPOINTMENT_CREATED = "appointment.formMessages.defaultTextAppointmentCreated";
75      private static final String PROPERTY_DEFAULT_TEXT_APPOINTMENT_CANCELED = "appointment.formMessages.defaultTextAppointmentCanceled";
76      private static final String PROPERTY_DEFAULT_NO_AVAILABLE_SLOT = "appointment.formMessages.defaultNoAvailableSlot";
77      private static final String PROPERTY_DEFAULT_CALENDAR_DESCRIPTION = "appointment.formMessages.defaultCalendarDescription";
78      private static final String PROPERTY_DEFAULT_CALENDAR_RESERVE_LABEL = "appointment.formMessages.defaultCalendarReserveLabel";
79      private static final String PROPERTY_DEFAULT_CALENDAR_FULL_LABEL = "appointment.formMessages.defaultCalendarFullLabel";
80  
81      /**
82       * Create a default form message for a form
83       * 
84       * @param nIdForm
85       *            the form Id
86       */
87      public static void createFormMessageWithDefaultValues( int nIdForm )
88      {
89          FormMessage formMessage = getDefaultAppointmentFormMessage( );
90          formMessage.setIdForm( nIdForm );
91          FormMessageHome.create( formMessage );
92      }
93  
94      /**
95       * Save a form message
96       * 
97       * @param formMessage
98       *            the form message to save
99       */
100     public static void saveFormMessage( FormMessage formMessage )
101     {
102         FormMessageHome.create( formMessage );
103     }
104 
105     /**
106      * Get the default form message with values loaded from properties.
107      * 
108      * @return The default form message. The form message is not associated with any appointment form
109      */
110     public static FormMessage getDefaultAppointmentFormMessage( )
111     {
112         FormMessageent/business/message/FormMessage.html#FormMessage">FormMessage formMessage = new FormMessage( );
113         formMessage.setCalendarTitle( AppPropertiesService.getProperty( PROPERTY_DEFAULT_CALENDAR_TITLE, StringUtils.EMPTY ) );
114         formMessage.setFieldFirstNameTitle( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_FIRST_NAME_TITLE, StringUtils.EMPTY ) );
115         formMessage.setFieldFirstNameHelp( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_FIRST_NAME_HELP, StringUtils.EMPTY ) );
116         formMessage.setFieldLastNameTitle( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_LAST_NAME_TITLE, StringUtils.EMPTY ) );
117         formMessage.setFieldLastNameHelp( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_LAST_NAME_HELP, StringUtils.EMPTY ) );
118         formMessage.setFieldEmailTitle( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_EMAIL_TITLE, StringUtils.EMPTY ) );
119         formMessage.setFieldEmailHelp( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_EMAIL_HELP, StringUtils.EMPTY ) );
120         formMessage.setFieldConfirmationEmail( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_CONFIRMATION_EMAIL_TITLE, StringUtils.EMPTY ) );
121         formMessage.setFieldConfirmationEmailHelp( AppPropertiesService.getProperty( PROPERTY_DEFAULT_FIELD_CONFIRMATION_EMAIL_HELP, StringUtils.EMPTY ) );
122         formMessage.setUrlRedirectAfterCreation( AppPropertiesService.getProperty( PROPERTY_DEFAULT_URL_REDIRECTION, StringUtils.EMPTY ) );
123         formMessage.setLabelButtonRedirection( AppPropertiesService.getProperty( PROPERTY_DEFAULT_LABEL_BUTTON_REDIRECT, StringUtils.EMPTY ) );
124         formMessage.setTextAppointmentCreated( AppPropertiesService.getProperty( PROPERTY_DEFAULT_TEXT_APPOINTMENT_CREATED, StringUtils.EMPTY ) );
125         formMessage.setTextAppointmentCanceled( AppPropertiesService.getProperty( PROPERTY_DEFAULT_TEXT_APPOINTMENT_CANCELED, StringUtils.EMPTY ) );
126         formMessage.setNoAvailableSlot( AppPropertiesService.getProperty( PROPERTY_DEFAULT_NO_AVAILABLE_SLOT, StringUtils.EMPTY ) );
127         formMessage.setCalendarDescription( AppPropertiesService.getProperty( PROPERTY_DEFAULT_CALENDAR_DESCRIPTION, StringUtils.EMPTY ) );
128         formMessage.setCalendarReserveLabel( AppPropertiesService.getProperty( PROPERTY_DEFAULT_CALENDAR_RESERVE_LABEL, StringUtils.EMPTY ) );
129         formMessage.setCalendarFullLabel( AppPropertiesService.getProperty( PROPERTY_DEFAULT_CALENDAR_FULL_LABEL, StringUtils.EMPTY ) );
130 
131         return formMessage;
132     }
133 
134     /**
135      * Find the form messages of a form
136      * 
137      * @param nIdForm
138      *            the form id
139      * @return the form message object
140      */
141     public static FormMessage findFormMessageByIdForm( int nIdForm )
142     {
143         return FormMessageHome.findByIdForm( nIdForm );
144     }
145 
146     /**
147      * Update a form message
148      * 
149      * @param formMessage
150      *            the formMessage updated
151      */
152     public static void updateFormMessage( FormMessage formMessage )
153     {
154         FormMessageHome.update( formMessage );
155     }
156 
157 }