1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.appointment.business.rule;
35
36 import java.sql.Statement;
37
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.util.sql.DAOUtil;
40
41
42
43
44
45
46
47 public final class FormRuleDAO implements IFormRuleDAO
48 {
49
50 private static final String SQL_QUERY_INSERT = "INSERT INTO appointment_form_rule ( is_captcha_enabled, is_mandatory_email_enabled, is_active_authentication, nb_days_before_new_appointment, min_time_before_appointment, nb_max_appointments_per_user, nb_days_for_max_appointments_per_user, bo_overbooking, id_form) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?)";
51 private static final String SQL_QUERY_UPDATE = "UPDATE appointment_form_rule SET is_captcha_enabled = ?, is_mandatory_email_enabled = ?, is_active_authentication = ?, nb_days_before_new_appointment = ?, min_time_before_appointment = ?, nb_max_appointments_per_user = ?, nb_days_for_max_appointments_per_user = ?, bo_overbooking=? , id_form = ? WHERE id_form_rule = ?";
52 private static final String SQL_QUERY_DELETE = "DELETE FROM appointment_form_rule WHERE id_form_rule = ?";
53 private static final String SQL_QUERY_DELETE_BY_ID_FORM = "DELETE FROM appointment_form_rule WHERE id_form = ?";
54 private static final String SQL_QUERY_SELECT_COLUMNS = "SELECT id_form_rule, is_captcha_enabled, is_mandatory_email_enabled, is_active_authentication, nb_days_before_new_appointment, min_time_before_appointment, nb_max_appointments_per_user, nb_days_for_max_appointments_per_user, bo_overbooking, id_form FROM appointment_form_rule";
55 private static final String SQL_QUERY_SELECT = SQL_QUERY_SELECT_COLUMNS + " WHERE id_form_rule = ?";
56 private static final String SQL_QUERY_SELECT_BY_ID_FORM = SQL_QUERY_SELECT_COLUMNS + " WHERE id_form = ?";
57
58 @Override
59 public synchronized void insert( FormRule formRule, Plugin plugin )
60 {
61 try ( DAOUtil daoUtil = buildDaoUtil( SQL_QUERY_INSERT, formRule, plugin, true ) )
62 {
63 daoUtil.executeUpdate( );
64 if ( daoUtil.nextGeneratedKey( ) )
65 {
66 formRule.setIdFormRule( daoUtil.getGeneratedKeyInt( 1 ) );
67 }
68 }
69 }
70
71 @Override
72 public void update( FormRule formRule, Plugin plugin )
73 {
74 try ( DAOUtil daoUtil = buildDaoUtil( SQL_QUERY_UPDATE, formRule, plugin, false ) )
75 {
76 daoUtil.executeUpdate( );
77 }
78 }
79
80 @Override
81 public void delete( int nIdFormRule, Plugin plugin )
82 {
83 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE, plugin ) )
84 {
85 daoUtil.setInt( 1, nIdFormRule );
86 daoUtil.executeUpdate( );
87 }
88 }
89
90 @Override
91 public void deleteByIdFom( int nIdForm, Plugin plugin )
92 {
93 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE_BY_ID_FORM, plugin ) )
94 {
95 daoUtil.setInt( 1, nIdForm );
96 daoUtil.executeUpdate( );
97 }
98 }
99
100 @Override
101 public FormRule select( int nIdFormRule, Plugin plugin )
102 {
103 FormRule formRule = null;
104 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT, plugin ) )
105 {
106 daoUtil.setInt( 1, nIdFormRule );
107 daoUtil.executeQuery( );
108 if ( daoUtil.next( ) )
109 {
110 formRule = buildFormRule( daoUtil );
111 }
112 }
113 return formRule;
114 }
115
116 @Override
117 public FormRule findByIdForm( int nIdForm, Plugin plugin )
118 {
119 FormRule formRule = null;
120 try ( DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_BY_ID_FORM, plugin ) )
121 {
122 daoUtil.setInt( 1, nIdForm );
123 daoUtil.executeQuery( );
124 if ( daoUtil.next( ) )
125 {
126 formRule = buildFormRule( daoUtil );
127 }
128 }
129 return formRule;
130 }
131
132
133
134
135
136
137
138
139 private FormRule buildFormRule( DAOUtil daoUtil )
140 {
141 int nIndex = 1;
142 FormRule/appointment/business/rule/FormRule.html#FormRule">FormRule formRule = new FormRule( );
143 formRule.setIdFormRule( daoUtil.getInt( nIndex++ ) );
144 formRule.setIsCaptchaEnabled( daoUtil.getBoolean( nIndex++ ) );
145 formRule.setIsMandatoryEmailEnabled( daoUtil.getBoolean( nIndex++ ) );
146 formRule.setIsActiveAuthentication( daoUtil.getBoolean( nIndex++ ) );
147 formRule.setNbDaysBeforeNewAppointment( daoUtil.getInt( nIndex++ ) );
148 formRule.setMinTimeBeforeAppointment( daoUtil.getInt( nIndex++ ) );
149 formRule.setNbMaxAppointmentsPerUser( daoUtil.getInt( nIndex++ ) );
150 formRule.setNbDaysForMaxAppointmentsPerUser( daoUtil.getInt( nIndex++ ) );
151 formRule.setBoOverbooking( daoUtil.getBoolean( nIndex++ ) );
152 formRule.setIdForm( daoUtil.getInt( nIndex ) );
153 return formRule;
154 }
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170 private DAOUtil buildDaoUtil( String query, FormRule formRule, Plugin plugin, boolean isInsert )
171 {
172 int nIndex = 1;
173 DAOUtil daoUtil = null;
174 if ( isInsert )
175 {
176 daoUtil = new DAOUtil( query, Statement.RETURN_GENERATED_KEYS, plugin );
177 }
178 else
179 {
180 daoUtil = new DAOUtil( query, plugin );
181 }
182 daoUtil.setBoolean( nIndex++, formRule.getIsCaptchaEnabled( ) );
183 daoUtil.setBoolean( nIndex++, formRule.getIsMandatoryEmailEnabled( ) );
184 daoUtil.setBoolean( nIndex++, formRule.getIsActiveAuthentication( ) );
185 daoUtil.setInt( nIndex++, formRule.getNbDaysBeforeNewAppointment( ) );
186 daoUtil.setInt( nIndex++, formRule.getMinTimeBeforeAppointment( ) );
187 daoUtil.setInt( nIndex++, formRule.getNbMaxAppointmentsPerUser( ) );
188 daoUtil.setInt( nIndex++, formRule.getNbDaysForMaxAppointmentsPerUser( ) );
189 daoUtil.setBoolean( nIndex++, formRule.getBoOverbooking( ) );
190 daoUtil.setInt( nIndex++, formRule.getIdForm( ) );
191 if ( !isInsert )
192 {
193 daoUtil.setInt( nIndex, formRule.getIdFormRule( ) );
194 }
195 return daoUtil;
196 }
197 }