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.page;
35  
36  import java.util.Collection;
37  import java.util.List;
38  
39  import fr.paris.lutece.portal.business.portlet.Portlet;
40  import fr.paris.lutece.portal.service.cache.CacheService;
41  import fr.paris.lutece.portal.service.image.ImageResource;
42  import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
43  import fr.paris.lutece.portal.service.spring.SpringContextService;
44  import fr.paris.lutece.util.ReferenceList;
45  
46  /**
47   * This class provides instances management methods (create, find, ...) for Page objects
48   */
49  public final class PageHome
50  {
51      // Static variable pointed at the DAO instance
52      private static IPageDAO _dao = SpringContextService.getBean( "pageDAO" );
53  
54      /**
55       * Creates a new PageHome object.
56       */
57      private PageHome( )
58      {
59      }
60  
61      /**
62       * Creates an instance of page
63       *
64       * @param page
65       *            An instance of page which contains the informations to store
66       * @return The instance of page which has been created with its primary key.
67       */
68      public static Pageef="../../../../../../fr/paris/lutece/portal/business/page/Page.html#Page">Page create( Page page )
69      {
70          _dao.insert( page );
71          CacheService.resetCaches( );
72  
73          return page;
74      }
75  
76      /**
77       * Removes a page and all its contents (the portlets and theirs contents)
78       *
79       * @param nPageId
80       *            The page identifier
81       */
82      public static void remove( int nPageId )
83      {
84          Page page = findByPrimaryKey( nPageId );
85  
86          // remove portlets
87          for ( Portlet portlet : page.getPortlets( ) )
88          {
89              portlet.remove( );
90          }
91  
92          _dao.delete( nPageId );
93          // We remove extensions of the removed page if any
94          ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Page.RESOURCE_TYPE, Integer.toString( nPageId ) );
95  
96          CacheService.resetCaches( );
97      }
98  
99      /**
100      * update of the page which is specified in parameter
101      *
102      * @param page
103      *            the instance of the page which contains the data to store
104      */
105     public static void update( Page page )
106     {
107         _dao.store( page );
108     }
109 
110     // /////////////////////////////////////////////////////////////////////////
111     // Finders
112 
113     /**
114      * Returns an instance of un page whose identifier is specified in parameter
115      *
116      * @param nKey
117      *            the primary key of the page
118      * @return an instance of the class
119      */
120     public static Page findByPrimaryKey( int nKey )
121     {
122         return _dao.load( nKey, true );
123     }
124 
125     /**
126      * Loads a page without portlets from its identifier
127      *
128      * @param nPageId
129      *            the page identifier
130      * @return an instance a the class Page
131      */
132     public static Page getPage( int nPageId )
133     {
134         return _dao.load( nPageId, false );
135     }
136 
137     /**
138      * Loads a page without portlets from its identifier without image content
139      *
140      * @param nPageId
141      *            the page identifier
142      * @return an instance a the class Page
143      */
144     public static Page getPageWithoutImageContent( int nPageId )
145     {
146         return _dao.loadWithoutImageContent( nPageId, false );
147     }
148 
149     /**
150      * Loads a page associated to a portlet
151      * 
152      * @param nPorletId
153      *            The indentifier of the object portlet associate to the page
154      * @return The Instance of the object Page
155      */
156     public static Page getPageByIdPortlet( int nPorletId )
157     {
158         return _dao.loadPageByIdPortlet( nPorletId );
159     }
160 
161     /**
162      * Returns the list of the child pages from the current parent page identifier
163      *
164      * @param nParentPageId
165      *            the current page identifier, parent of childs pages
166      * @return a collection of pages
167      */
168     public static Collection<Page> getChildPages( int nParentPageId )
169     {
170         return _dao.selectChildPages( nParentPageId );
171     }
172 
173     /**
174      * Returns the list of the child pages from the current parent page identifier
175      *
176      * @param nParentPageId
177      *            the ParentPageId identifier
178      * @return page collection
179      */
180     public static Collection<Page> getChildPagesMinimalData( int nParentPageId )
181     {
182         return _dao.selectChildPagesMinimalData( nParentPageId );
183     }
184 
185     /**
186      * Return the list of all the pages from a portal identifier
187      *
188      * @return a collection of pages
189      */
190     public static List<Page> getAllPages( )
191     {
192         return _dao.selectAllPages( );
193     }
194 
195     /**
196      * Returns the list of page
197      *
198      * @return the list of pages
199      */
200     public static ReferenceList getPagesList( )
201     {
202         return _dao.getPagesList( );
203     }
204 
205     /**
206      * Return the list of all the pages filtered by Lutece Role specified in parameter
207      *
208      * @param strRoleKey
209      *            The Lutece Role key
210      * @return a collection of pages
211      */
212     public static Collection<Page> getPagesByRoleKey( String strRoleKey )
213     {
214         return _dao.getPagesByRoleKey( strRoleKey );
215     }
216 
217     /**
218      * Gets an image resource
219      * 
220      * @param nPageId
221      *            The page ID
222      * @return ImageResource
223      */
224     public static ImageResource getImageResource( int nPageId )
225     {
226         return _dao.loadImageResource( nPageId );
227     }
228 
229     /**
230      * Select the max child page order and create the new order for new child page
231      * 
232      * @param nParentPageId
233      *            The parent page Id
234      * @return the new child page order
235      */
236     public static int getNewChildPageOrder( int nParentPageId )
237     {
238         return _dao.selectNewChildPageOrder( nParentPageId );
239     }
240 
241     /**
242      * Check if the page exists
243      * 
244      * @param nPageId
245      *            The Page ID
246      * @return True if the page exists, otherwise false
247      */
248     public static boolean checkPageExist( int nPageId )
249     {
250         return _dao.checkPageExist( nPageId );
251     }
252 
253     /**
254      * Get the last modified page
255      * 
256      * @return the last modified {@link Page}
257      */
258     public static Page getLastModifiedPage( )
259     {
260         return _dao.loadLastModifiedPage( );
261     }
262 
263     /**
264      * get list of children Pages Which Must Change their authorization node
265      * 
266      * @param nIdParentPage
267      *            the id of the parent page
268      * @return an id list
269      */
270     public static List<Integer> getPagesWhichMustChangeAuthorizationNode( int nIdParentPage )
271     {
272         return _dao.selectPageForChangeAutorisationNode( nIdParentPage );
273     }
274 
275     /**
276      * Update the authorization node of the page
277      * 
278      * @param nIdPage
279      *            the page id
280      * @param nIdAuthorizationNode
281      *            the authorization node id
282      */
283     public static void updateAuthorizationNode( int nIdPage, Integer nIdAuthorizationNode )
284     {
285         _dao.updateAutorisationNode( nIdPage, nIdAuthorizationNode );
286     }
287 }