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.workflow.modules.appointment.business;
35  
36  import fr.paris.lutece.plugins.workflow.modules.appointment.service.WorkflowAppointmentPlugin;
37  import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
38  import fr.paris.lutece.util.sql.DAOUtil;
39  
40  /**
41   *
42   * TaskNotifyAppointmentConfigDAO
43   *
44   */
45  public class TaskNotifyAdminAppointmentConfigDAO implements ITaskConfigDAO<TaskNotifyAdminAppointmentConfig>
46  {
47      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_task,id_admin_user,sender_name,sender_email,subject,message,recipients_cc,recipients_bcc,id_action_cancel,id_action_validate,ical_notification,create_notif,location FROM workflow_task_notify_admin_appointment_cf WHERE id_task=?";
48      private static final String SQL_QUERY_INSERT = "INSERT INTO workflow_task_notify_admin_appointment_cf( "
49              + "id_task,id_admin_user,sender_name,sender_email,subject,message,recipients_cc,recipients_bcc,id_action_cancel,id_action_validate,ical_notification, create_notif, location) "
50              + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?)";
51      private static final String SQL_QUERY_UPDATE = "UPDATE workflow_task_notify_admin_appointment_cf "
52              + " SET id_admin_user = ?, sender_name = ?, sender_email = ?, subject = ?, message = ?, recipients_cc = ?, recipients_bcc = ?, id_action_cancel = ?, id_action_validate = ?, ical_notification = ?, create_notif = ?, location = ? WHERE id_task = ? ";
53      private static final String SQL_QUERY_DELETE = "DELETE FROM workflow_task_notify_admin_appointment_cf WHERE id_task = ? ";
54  
55      /**
56       * {@inheritDoc}
57       */
58      @Override
59      public synchronized void insert( TaskNotifyAdminAppointmentConfig config )
60      {
61          try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, WorkflowAppointmentPlugin.getPlugin( ) ) )
62          {
63              int nIndex = 1;
64  
65              daoUtil.setInt( nIndex++, config.getIdTask( ) );
66              daoUtil.setInt( nIndex++, config.getIdAdminUser( ) );
67              daoUtil.setString( nIndex++, config.getSenderName( ) );
68              daoUtil.setString( nIndex++, config.getSenderEmail( ) );
69              daoUtil.setString( nIndex++, config.getSubject( ) );
70              daoUtil.setString( nIndex++, config.getMessage( ) );
71              daoUtil.setString( nIndex++, config.getRecipientsCc( ) );
72              daoUtil.setString( nIndex++, config.getRecipientsBcc( ) );
73              daoUtil.setInt( nIndex++, config.getIdActionCancel( ) );
74              daoUtil.setInt( nIndex++, config.getIdActionValidate( ) );
75              daoUtil.setBoolean( nIndex++, config.getSendICalNotif( ) );
76              daoUtil.setBoolean( nIndex++, config.getCreateNotif( ) );
77              daoUtil.setString( nIndex, config.getLocation( ) );
78  
79              daoUtil.executeUpdate( );
80          }
81      }
82  
83      /**
84       * {@inheritDoc}
85       */
86      @Override
87      public void store( TaskNotifyAdminAppointmentConfig config )
88      {
89          try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, WorkflowAppointmentPlugin.getPlugin( ) ) )
90          {
91              int nIndex = 1;
92              daoUtil.setInt( nIndex++, config.getIdAdminUser( ) );
93              daoUtil.setString( nIndex++, config.getSenderName( ) );
94              daoUtil.setString( nIndex++, config.getSenderEmail( ) );
95              daoUtil.setString( nIndex++, config.getSubject( ) );
96              daoUtil.setString( nIndex++, config.getMessage( ) );
97              daoUtil.setString( nIndex++, config.getRecipientsCc( ) );
98              daoUtil.setString( nIndex++, config.getRecipientsBcc( ) );
99              daoUtil.setInt( nIndex++, config.getIdActionCancel( ) );
100             daoUtil.setInt( nIndex++, config.getIdActionValidate( ) );
101             daoUtil.setBoolean( nIndex++, config.getSendICalNotif( ) );
102             daoUtil.setBoolean( nIndex++, config.getCreateNotif( ) );
103             daoUtil.setString( nIndex++, config.getLocation( ) );
104 
105             daoUtil.setInt( nIndex, config.getIdTask( ) );
106             daoUtil.executeUpdate( );
107         }
108     }
109 
110     /**
111      * {@inheritDoc}
112      */
113     @Override
114     public TaskNotifyAdminAppointmentConfig load( int nIdTask )
115     {
116         TaskNotifyAdminAppointmentConfig config = null;
117         try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, WorkflowAppointmentPlugin.getPlugin( ) ) )
118         {
119             daoUtil.setInt( 1, nIdTask );
120 
121             daoUtil.executeQuery( );
122             if ( daoUtil.next( ) )
123             {
124                 int nIndex = 1;
125                 config = new TaskNotifyAdminAppointmentConfig( );
126                 config.setIdTask( daoUtil.getInt( nIndex++ ) );
127                 config.setIdAdminUser( daoUtil.getInt( nIndex++ ) );
128                 config.setSenderName( daoUtil.getString( nIndex++ ) );
129                 config.setSenderEmail( daoUtil.getString( nIndex++ ) );
130                 config.setSubject( daoUtil.getString( nIndex++ ) );
131                 config.setMessage( daoUtil.getString( nIndex++ ) );
132                 config.setRecipientsCc( daoUtil.getString( nIndex++ ) );
133                 config.setRecipientsBcc( daoUtil.getString( nIndex++ ) );
134                 config.setIdActionCancel( daoUtil.getInt( nIndex++ ) );
135                 config.setIdActionValidate( daoUtil.getInt( nIndex++ ) );
136                 config.setSendICalNotif( daoUtil.getBoolean( nIndex++ ) );
137                 config.setCreateNotif( daoUtil.getBoolean( nIndex++ ) );
138                 config.setLocation( daoUtil.getString( nIndex ) );
139             }
140         }
141         return config;
142     }
143 
144     /**
145      * {@inheritDoc}
146      */
147     @Override
148     public void delete( int nIdTask )
149     {
150         try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, WorkflowAppointmentPlugin.getPlugin( ) ) )
151         {
152             daoUtil.setInt( 1, nIdTask );
153             daoUtil.executeUpdate( );
154         }
155     }
156 }