View Javadoc
1   /*
2    * Copyright (c) 2002-2020, 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.appcenter.business.prerequisite;
35  
36  import fr.paris.lutece.plugins.workflow.service.WorkflowPlugin;
37  import fr.paris.lutece.plugins.workflowcore.business.prerequisite.IPrerequisiteConfig;
38  import fr.paris.lutece.plugins.workflowcore.business.prerequisite.IPrerequisiteConfigDAO;
39  import fr.paris.lutece.portal.service.plugin.PluginService;
40  import fr.paris.lutece.util.sql.DAOUtil;
41  import java.sql.Statement;
42  
43  public class PrerequisiteValidationConfigDAO implements IPrerequisiteConfigDAO
44  {
45      private static final String INSERT_VALIDATION_PREREQUISITE = " INSERT INTO workflow_prerequisite_validation_cf ( id_prerequisite, id_task, status ) VALUES ( ?, ?, ? ) ";
46      private static final String UPDATE_VALIDATION_PREREQUISITE = " UPDATE workflow_prerequisite_validation_cf SET id_task = ?, status = ? WHERE id_prerequisite = ? ";
47      private static final String DELETE_VALIDATION_PREREQUISITE = " DELETE FROM workflow_prerequisite_validation_cf WHERE id_prerequisite = ? ";
48      private static final String SELECT_VALIDATION_PREREQUISITE = " SELECT id_prerequisite, id_task, status FROM workflow_prerequisite_validation_cf WHERE id_prerequisite = ?";
49  
50      /**
51       * {@inheritDoc}
52       */
53      @Override
54      public void createConfig( IPrerequisiteConfig config )
55      {
56          DAOUtil daoUtil = new DAOUtil( INSERT_VALIDATION_PREREQUISITE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
57          try
58          {
59              daoUtil.setInt( 1, config.getIdPrerequisite( ) );
60              daoUtil.setInt( 2, ( (PrerequisiteValidationConfig) config ).getIdTask( ) );
61              daoUtil.setInt( 3, ( (PrerequisiteValidationConfig) config ).getStatus( ) );
62              daoUtil.executeUpdate( );
63          }
64          finally
65          {
66              daoUtil.free( );
67          }
68      }
69  
70      /**
71       * {@inheritDoc}
72       */
73      @Override
74      public void updateConfig( IPrerequisiteConfig config )
75      {
76          DAOUtil daoUtil = new DAOUtil( UPDATE_VALIDATION_PREREQUISITE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
77          daoUtil.setInt( 1, ( (PrerequisiteValidationConfig) config ).getIdTask( ) );
78          daoUtil.setInt( 2, ( (PrerequisiteValidationConfig) config ).getStatus( ) );
79          daoUtil.setInt( 3, config.getIdPrerequisite( ) );
80          daoUtil.executeUpdate( );
81          daoUtil.free( );
82      }
83  
84      /**
85       * {@inheritDoc}
86       */
87      @Override
88      public void removeConfig( int nIdPrerequisite )
89      {
90          DAOUtil daoUtil = new DAOUtil( DELETE_VALIDATION_PREREQUISITE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
91          daoUtil.setInt( 1, nIdPrerequisite );
92          daoUtil.executeUpdate( );
93          daoUtil.free( );
94      }
95  
96      /**
97       * {@inheritDoc}
98       */
99      @Override
100     public IPrerequisiteConfig findByPrimaryKey( int nIdPrerequisite )
101     {
102         DAOUtil daoUtil = new DAOUtil( SELECT_VALIDATION_PREREQUISITE, PluginService.getPlugin( WorkflowPlugin.PLUGIN_NAME ) );
103         daoUtil.setInt( 1, nIdPrerequisite );
104 
105         PrerequisiteValidationConfig config = null;
106         daoUtil.executeQuery( );
107 
108         if ( daoUtil.next( ) )
109         {
110             config = new PrerequisiteValidationConfig( );
111             config.setIdPrerequisite( daoUtil.getInt( 1 ) );
112             config.setIdTask( daoUtil.getInt( 2 ) );
113             config.setStatus( daoUtil.getInt( 3 ) );
114         }
115 
116         daoUtil.free( );
117 
118         return config;
119     }
120 }