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