View Javadoc
1   /*
2    * Copyright (c) 2002-2014, Mairie de 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.notifycrm.business;
35  
36  import fr.paris.lutece.plugins.workflow.modules.notifycrm.service.NotifyCRMPlugin;
37  import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
38  import fr.paris.lutece.util.sql.DAOUtil;
39  
40  
41  /**
42   *
43   * TaskNotifyCRMConfigDAO
44   *
45   */
46  public class TaskNotifyCRMConfigDAO implements ITaskConfigDAO<TaskNotifyCRMConfig>
47  {
48      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = " SELECT id_task, id_directory, position_directory_entry_id_demand, position_directory_entry_user_guid, send_notification, sender_name, subject, message, status_text,position_directory_entry_crm_web_app_code " +
49          " FROM task_notify_crm_cf  WHERE id_task = ? ";
50      private static final String SQL_QUERY_INSERT = " INSERT INTO task_notify_crm_cf( id_task, id_directory, position_directory_entry_id_demand, position_directory_entry_user_guid, send_notification, sender_name, subject, message, status_text, position_directory_entry_crm_web_app_code )" +
51          " VALUES ( ?,?,?,?,?,?,?,?,?,?) ";
52      private static final String SQL_QUERY_UPDATE = "UPDATE task_notify_crm_cf SET id_directory = ?, position_directory_entry_id_demand = ?, position_directory_entry_user_guid = ?, send_notification = ?, sender_name = ?, subject = ?, message = ?, status_text = ?,  position_directory_entry_crm_web_app_code = ? " +
53          " WHERE id_task = ? ";
54      private static final String SQL_QUERY_DELETE = " DELETE FROM task_notify_crm_cf WHERE id_task = ? ";
55  
56      /**
57       * {@inheritDoc}
58       */
59      @Override
60      public synchronized void insert( TaskNotifyCRMConfig config )
61      {
62          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, NotifyCRMPlugin.getPlugin(  ) );
63  
64          int nIndex = 1;
65  
66          daoUtil.setInt( nIndex++, config.getIdTask(  ) );
67          daoUtil.setInt( nIndex++, config.getIdDirectory(  ) );
68          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryIdDemand(  ) );
69          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryUserGuid(  ) );
70          daoUtil.setBoolean( nIndex++, config.getSendNotification(  ) );
71          daoUtil.setString( nIndex++, config.getSenderName(  ) );
72          daoUtil.setString( nIndex++, config.getSubject(  ) );
73          daoUtil.setString( nIndex++, config.getMessage(  ) );
74          daoUtil.setString( nIndex++, config.getStatusText(  ) );
75          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryCrmWebAppCode() );
76  
77          daoUtil.executeUpdate(  );
78          daoUtil.free(  );
79      }
80  
81      /**
82       * {@inheritDoc}
83       */
84      @Override
85      public void store( TaskNotifyCRMConfig config )
86      {
87          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, NotifyCRMPlugin.getPlugin(  ) );
88  
89          int nIndex = 1;
90  
91          daoUtil.setInt( nIndex++, config.getIdDirectory(  ) );
92          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryIdDemand(  ) );
93          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryUserGuid(  ) );
94          daoUtil.setBoolean( nIndex++, config.getSendNotification(  ) );
95          daoUtil.setString( nIndex++, config.getSenderName(  ) );
96          daoUtil.setString( nIndex++, config.getSubject(  ) );
97          daoUtil.setString( nIndex++, config.getMessage(  ) );
98          daoUtil.setString( nIndex++, config.getStatusText(  ) );
99          daoUtil.setInt( nIndex++, config.getPositionEntryDirectoryCrmWebAppCode() );
100 
101         daoUtil.setInt( nIndex++, config.getIdTask(  ) );
102         daoUtil.executeUpdate(  );
103         daoUtil.free(  );
104     }
105 
106     /**
107      * {@inheritDoc}
108      */
109     @Override
110     public TaskNotifyCRMConfig load( int nIdTask )
111     {
112         TaskNotifyCRMConfig config = null;
113         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, NotifyCRMPlugin.getPlugin(  ) );
114 
115         daoUtil.setInt( 1, nIdTask );
116 
117         daoUtil.executeQuery(  );
118 
119         int nIndex = 1;
120 
121         if ( daoUtil.next(  ) )
122         {
123             config = new TaskNotifyCRMConfig(  );
124             config.setIdTask( daoUtil.getInt( nIndex++ ) );
125             config.setIdDirectory( daoUtil.getInt( nIndex++ ) );
126             config.setPositionEntryDirectoryIdDemand( daoUtil.getInt( nIndex++ ) );
127             config.setPositionEntryDirectoryUserGuid( daoUtil.getInt( nIndex++ ) );
128             config.setSendNotification( daoUtil.getBoolean( nIndex++ ) );
129             config.setSenderName( daoUtil.getString( nIndex++ ) );
130             config.setSubject( daoUtil.getString( nIndex++ ) );
131             config.setMessage( daoUtil.getString( nIndex++ ) );
132             config.setStatusText( daoUtil.getString( nIndex++ ) );
133             config.setPositionEntryDirectoryCrmWebAppCode(daoUtil.getInt( nIndex++ ));
134         }
135 
136         daoUtil.free(  );
137 
138         return config;
139     }
140 
141     /**
142      * {@inheritDoc}
143      */
144     @Override
145     public void delete( int nIdTask )
146     {
147         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, NotifyCRMPlugin.getPlugin(  ) );
148 
149         daoUtil.setInt( 1, nIdTask );
150         daoUtil.executeUpdate(  );
151         daoUtil.free(  );
152     }
153 }