View Javadoc
1   /*
2    * Copyright (c) 2002-2015, 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.reply.business.config;
35  
36  import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
37  import fr.paris.lutece.plugins.workflowcore.business.config.ITaskConfigDAO;
38  import fr.paris.lutece.util.sql.DAOUtil;
39  
40  /**
41   * This class is a data access object for {@link fr.paris.lutece.plugins.workflow.modules.ticketing.business.config.TaskReplyConfig}
42   *
43   */
44  public class TaskReplyConfigDAO implements ITaskConfigDAO<TaskReplyConfig>
45  {
46      private static final String SQL_QUERY_FIND_BY_PRIMARY_KEY = "SELECT id_task, is_mandatory, is_rich_text, title, default_message "
47              + " FROM workflow_task_reply_cf WHERE id_task = ?";
48      private static final String SQL_QUERY_INSERT = "INSERT INTO  workflow_task_reply_cf"
49              + " (id_task, is_mandatory, is_rich_text, title, default_message) VALUES (?, ?, ?, ?, ? )";
50      private static final String SQL_QUERY_UPDATE = "UPDATE workflow_task_reply_cf" + " SET id_task = ?, is_mandatory = ?, is_rich_text = ?, title = ?, default_message = ? "
51              + " WHERE id_task = ?";
52      private static final String SQL_QUERY_DELETE = "DELETE FROM workflow_task_reply_cf  WHERE id_task = ?";
53  
54      /**
55       * {@inheritDoc}
56       */
57      @Override
58      public void delete( int nIdTask )
59      {
60          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, WorkflowUtils.getPlugin( ) );
61  
62          daoUtil.setInt( 1, nIdTask );
63          daoUtil.executeUpdate( );
64          daoUtil.free( );
65      }
66  
67      /**
68       * {@inheritDoc}
69       */
70      @Override
71      public void insert( TaskReplyConfig config )
72      {
73          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT, WorkflowUtils.getPlugin( ) );
74  
75          int index=1;
76          daoUtil.setInt(     index++, config.getIdTask( ) );
77          daoUtil.setInt( index++, config.isMandatory( )?1:0 );
78          daoUtil.setInt( index++, config.isRichText( )?1:0 );
79          daoUtil.setString(  index++, config.getTitle( ) );
80          daoUtil.setString(  index++, config.getDefaultMessage( ) );
81  
82          daoUtil.executeUpdate( );
83          daoUtil.free( );
84      }
85  
86      /**
87       * {@inheritDoc}
88       */
89      @Override
90      public TaskReplyConfig load( int nIdTask )
91      {
92          TaskReplyConfig config = null;
93          DAOUtil daoUtil = new DAOUtil( SQL_QUERY_FIND_BY_PRIMARY_KEY, WorkflowUtils.getPlugin( ) );
94  
95          daoUtil.setInt( 1, nIdTask );
96  
97          daoUtil.executeQuery( );
98  
99          if ( daoUtil.next( ) )
100         {
101             config = new TaskReplyConfig( );
102             
103             int index =1;
104             config.setIdTask( daoUtil.getInt( index++ ) );
105             config.setMandatory( daoUtil.getInt( index++ )==1 );
106             config.setRichText( daoUtil.getInt( index++ )==1 );
107             config.setTitle( daoUtil.getString( index++ ) );
108             config.setDefaultMessage( daoUtil.getString( index++ ) );
109         }
110 
111         daoUtil.free( );
112 
113         return config;
114     }
115 
116     /**
117      * {@inheritDoc}
118      */
119     @Override
120     public void store( TaskReplyConfig config )
121     {
122         DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE, WorkflowUtils.getPlugin( ) );
123 
124         int index = 1;
125         
126         daoUtil.setInt(     index++, config.getIdTask( ) );
127         daoUtil.setInt( index++, config.isMandatory( )?1:0 );
128         daoUtil.setInt( index++, config.isRichText( )?1:0 );
129         daoUtil.setString(  index++, config.getTitle( ) );
130         daoUtil.setString(  index++, config.getDefaultMessage( ) );
131         
132         daoUtil.setInt( index++, config.getIdTask( ) );
133 
134         daoUtil.executeUpdate( );
135         daoUtil.free( );
136     }
137 }