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.portal.business.portlet;
35  
36  import java.util.ArrayList;
37  import java.util.Collection;
38  import java.util.List;
39  
40  import fr.paris.lutece.util.ReferenceList;
41  import fr.paris.lutece.util.sql.DAOUtil;
42  
43  /**
44   * This class provides Data Access methods for AliasPortlet objects
45   */
46  public final class AliasPortletDAO implements IAliasPortletDAO
47  {
48      // sql queries
49      private static final String SQL_QUERY_INSERT = "INSERT INTO core_portlet_alias ( id_portlet , id_alias ) VALUES ( ?, ? )";
50      private static final String SQL_QUERY_DELETE = "DELETE FROM core_portlet_alias WHERE id_portlet = ?";
51      private static final String SQL_QUERY_SELECT = "SELECT id_alias FROM core_portlet_alias WHERE id_portlet = ? ";
52      private static final String SQL_QUERY_UPDATE = "UPDATE core_portlet_alias SET id_alias=? WHERE id_portlet = ?";
53      private static final String SQL_QUERY_SELECT_PORTLETS_BY_TYPE = "SELECT  id_portlet, name FROM core_portlet WHERE id_portlet_type = ? ORDER BY name";
54      private static final String SQL_QUERY_SELECT_ALIAS_ID = "SELECT id_alias FROM core_portlet_alias WHERE id_portlet= ? ";
55      private static final String SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST = "SELECT id_portlet, name FROM core_portlet WHERE accept_alias = 1 ";
56      private static final String SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST_DETAIL = "SELECT id_portlet, id_page, name FROM core_portlet WHERE accept_alias = 1 ORDER BY id_page";
57  
58      // /////////////////////////////////////////////////////////////////////////////////////
59      // Access methods to data
60  
61      /**
62       * {@inheritDoc}
63       */
64      public synchronized void insert( Portlet portlet )
65      {
66          AliasPortlet/../../../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet alias = (AliasPortlet) portlet;
67  
68          // insert into the table portlet_alias
69          try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_INSERT ) )
70          {
71              daoUtil.setInt( 1, alias.getId( ) );
72              daoUtil.setInt( 2, alias.getAliasId( ) );
73  
74              daoUtil.executeUpdate( );
75          }
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      public void delete( int nPortletId )
82      {
83          try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_DELETE ) )
84          {
85              daoUtil.setInt( 1, nPortletId );
86  
87              daoUtil.executeUpdate( );
88          }
89      }
90  
91      /**
92       * {@inheritDoc}
93       */
94      public Portlet load( int nIdPortlet )
95      {
96          AliasPortletss/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet portlet = new AliasPortlet( );
97          try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT ) )
98          {
99              daoUtil.setInt( 1, nIdPortlet );
100             daoUtil.executeQuery( );
101 
102             if ( daoUtil.next( ) )
103             {
104                 portlet.setAliasId( daoUtil.getInt( 1 ) );
105             }
106 
107         }
108 
109         return portlet;
110     }
111 
112     /**
113      * {@inheritDoc}
114      */
115     public void store( Portlet portlet )
116     {
117         AliasPortlet./../../../../../fr/paris/lutece/portal/business/portlet/AliasPortlet.html#AliasPortlet">AliasPortlet r = (AliasPortlet) portlet;
118 
119         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_UPDATE ) )
120         {
121             daoUtil.setInt( 1, r.getAliasId( ) );
122             daoUtil.setInt( 2, portlet.getId( ) );
123 
124             daoUtil.executeUpdate( );
125         }
126     }
127 
128     /**
129      * {@inheritDoc}
130      */
131     public ReferenceList selectPortletsByTypeList( String strPortletTypeId )
132     {
133         ReferenceListnceList.html#ReferenceList">ReferenceList list = new ReferenceList( );
134         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_PORTLETS_BY_TYPE ) )
135         {
136             daoUtil.setString( 1, strPortletTypeId );
137             daoUtil.executeQuery( );
138 
139             while ( daoUtil.next( ) )
140             {
141                 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
142             }
143 
144         }
145 
146         return list;
147     }
148 
149     /**
150      * {@inheritDoc}
151      */
152     public int selectAliasId( int nIdPortlet )
153     {
154         int nAliasId = 0;
155         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ALIAS_ID ) )
156         {
157             daoUtil.setInt( 1, nIdPortlet );
158             daoUtil.executeQuery( );
159 
160             if ( daoUtil.next( ) )
161             {
162                 nAliasId = daoUtil.getInt( 1 );
163             }
164 
165         }
166 
167         return nAliasId;
168     }
169 
170     /**
171      * {@inheritDoc}
172      */
173     public ReferenceList selectAcceptAliasPortletRefList( )
174     {
175         ReferenceListnceList.html#ReferenceList">ReferenceList list = new ReferenceList( );
176         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST ) )
177         {
178             daoUtil.executeQuery( );
179 
180             while ( daoUtil.next( ) )
181             {
182                 list.addItem( daoUtil.getInt( 1 ), daoUtil.getString( 2 ) );
183             }
184 
185         }
186 
187         return list;
188     }
189 
190     /**
191      * {@inheritDoc}
192      */
193     public Collection<Portlet> selectAcceptAliasPortletList( )
194     {
195         List<Portlet> list = new ArrayList<>( );
196         try ( DAOUtil/DAOUtil.html#DAOUtil">DAOUtil daoUtil = new DAOUtil( SQL_QUERY_SELECT_ACCEPT_ALIAS_PORTLET_LIST_DETAIL ) )
197         {
198             daoUtil.executeQuery( );
199 
200             while ( daoUtil.next( ) )
201             {
202                 PortletImpless/portlet/PortletImpl.html#PortletImpl">PortletImpl portlet = new PortletImpl( );
203                 portlet.setId( daoUtil.getInt( 1 ) );
204                 portlet.setPageId( daoUtil.getInt( 2 ) );
205                 portlet.setName( daoUtil.getString( 3 ) );
206                 list.add( portlet );
207             }
208 
209         }
210 
211         return list;
212     }
213 
214 }