PageHome.java

  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. import java.util.Collection;
  36. import java.util.List;

  37. import fr.paris.lutece.portal.business.portlet.Portlet;
  38. import fr.paris.lutece.portal.service.cache.CacheService;
  39. import fr.paris.lutece.portal.service.image.ImageResource;
  40. import fr.paris.lutece.portal.service.resource.ExtendableResourceRemovalListenerService;
  41. import fr.paris.lutece.portal.service.spring.SpringContextService;
  42. import fr.paris.lutece.util.ReferenceList;

  43. /**
  44.  * This class provides instances management methods (create, find, ...) for Page objects
  45.  */
  46. public final class PageHome
  47. {
  48.     // Static variable pointed at the DAO instance
  49.     private static IPageDAO _dao = SpringContextService.getBean( "pageDAO" );

  50.     /**
  51.      * Creates a new PageHome object.
  52.      */
  53.     private PageHome( )
  54.     {
  55.     }

  56.     /**
  57.      * Creates an instance of page
  58.      *
  59.      * @param page
  60.      *            An instance of page which contains the informations to store
  61.      * @return The instance of page which has been created with its primary key.
  62.      */
  63.     public static Page create( Page page )
  64.     {
  65.         _dao.insert( page );
  66.         CacheService.resetCaches( );

  67.         return page;
  68.     }

  69.     /**
  70.      * Removes a page and all its contents (the portlets and theirs contents)
  71.      *
  72.      * @param nPageId
  73.      *            The page identifier
  74.      */
  75.     public static void remove( int nPageId )
  76.     {
  77.         Page page = findByPrimaryKey( nPageId );

  78.         // remove portlets
  79.         for ( Portlet portlet : page.getPortlets( ) )
  80.         {
  81.             portlet.remove( );
  82.         }

  83.         _dao.delete( nPageId );
  84.         // We remove extensions of the removed page if any
  85.         ExtendableResourceRemovalListenerService.doRemoveResourceExtentions( Page.RESOURCE_TYPE, Integer.toString( nPageId ) );

  86.         CacheService.resetCaches( );
  87.     }

  88.     /**
  89.      * update of the page which is specified in parameter
  90.      *
  91.      * @param page
  92.      *            the instance of the page which contains the data to store
  93.      */
  94.     public static void update( Page page )
  95.     {
  96.         _dao.store( page );
  97.     }

  98.     // /////////////////////////////////////////////////////////////////////////
  99.     // Finders

  100.     /**
  101.      * Returns an instance of un page whose identifier is specified in parameter
  102.      *
  103.      * @param nKey
  104.      *            the primary key of the page
  105.      * @return an instance of the class
  106.      */
  107.     public static Page findByPrimaryKey( int nKey )
  108.     {
  109.         return _dao.load( nKey, true );
  110.     }

  111.     /**
  112.      * Loads a page without portlets from its identifier
  113.      *
  114.      * @param nPageId
  115.      *            the page identifier
  116.      * @return an instance a the class Page
  117.      */
  118.     public static Page getPage( int nPageId )
  119.     {
  120.         return _dao.load( nPageId, false );
  121.     }

  122.     /**
  123.      * Loads a page without portlets from its identifier without image content
  124.      *
  125.      * @param nPageId
  126.      *            the page identifier
  127.      * @return an instance a the class Page
  128.      */
  129.     public static Page getPageWithoutImageContent( int nPageId )
  130.     {
  131.         return _dao.loadWithoutImageContent( nPageId, false );
  132.     }

  133.     /**
  134.      * Loads a page associated to a portlet
  135.      *
  136.      * @param nPorletId
  137.      *            The indentifier of the object portlet associate to the page
  138.      * @return The Instance of the object Page
  139.      */
  140.     public static Page getPageByIdPortlet( int nPorletId )
  141.     {
  142.         return _dao.loadPageByIdPortlet( nPorletId );
  143.     }

  144.     /**
  145.      * Returns the list of the child pages from the current parent page identifier
  146.      *
  147.      * @param nParentPageId
  148.      *            the current page identifier, parent of childs pages
  149.      * @return a collection of pages
  150.      */
  151.     public static Collection<Page> getChildPages( int nParentPageId )
  152.     {
  153.         return _dao.selectChildPages( nParentPageId );
  154.     }

  155.     /**
  156.      * Returns the list of the child pages from the current parent page identifier
  157.      *
  158.      * @param nParentPageId
  159.      *            the ParentPageId identifier
  160.      * @return page collection
  161.      */
  162.     public static Collection<Page> getChildPagesMinimalData( int nParentPageId )
  163.     {
  164.         return _dao.selectChildPagesMinimalData( nParentPageId );
  165.     }

  166.     /**
  167.      * Return the list of all the pages from a portal identifier
  168.      *
  169.      * @return a collection of pages
  170.      */
  171.     public static List<Page> getAllPages( )
  172.     {
  173.         return _dao.selectAllPages( );
  174.     }

  175.     /**
  176.      * Returns the list of page
  177.      *
  178.      * @return the list of pages
  179.      */
  180.     public static ReferenceList getPagesList( )
  181.     {
  182.         return _dao.getPagesList( );
  183.     }

  184.     /**
  185.      * Return the list of all the pages filtered by Lutece Role specified in parameter
  186.      *
  187.      * @param strRoleKey
  188.      *            The Lutece Role key
  189.      * @return a collection of pages
  190.      */
  191.     public static Collection<Page> getPagesByRoleKey( String strRoleKey )
  192.     {
  193.         return _dao.getPagesByRoleKey( strRoleKey );
  194.     }

  195.     /**
  196.      * Gets an image resource
  197.      *
  198.      * @param nPageId
  199.      *            The page ID
  200.      * @return ImageResource
  201.      */
  202.     public static ImageResource getImageResource( int nPageId )
  203.     {
  204.         return _dao.loadImageResource( nPageId );
  205.     }

  206.     /**
  207.      * Select the max child page order and create the new order for new child page
  208.      *
  209.      * @param nParentPageId
  210.      *            The parent page Id
  211.      * @return the new child page order
  212.      */
  213.     public static int getNewChildPageOrder( int nParentPageId )
  214.     {
  215.         return _dao.selectNewChildPageOrder( nParentPageId );
  216.     }

  217.     /**
  218.      * Check if the page exists
  219.      *
  220.      * @param nPageId
  221.      *            The Page ID
  222.      * @return True if the page exists, otherwise false
  223.      */
  224.     public static boolean checkPageExist( int nPageId )
  225.     {
  226.         return _dao.checkPageExist( nPageId );
  227.     }

  228.     /**
  229.      * Get the last modified page
  230.      *
  231.      * @return the last modified {@link Page}
  232.      */
  233.     public static Page getLastModifiedPage( )
  234.     {
  235.         return _dao.loadLastModifiedPage( );
  236.     }

  237.     /**
  238.      * get list of children Pages Which Must Change their authorization node
  239.      *
  240.      * @param nIdParentPage
  241.      *            the id of the parent page
  242.      * @return an id list
  243.      */
  244.     public static List<Integer> getPagesWhichMustChangeAuthorizationNode( int nIdParentPage )
  245.     {
  246.         return _dao.selectPageForChangeAutorisationNode( nIdParentPage );
  247.     }

  248.     /**
  249.      * Update the authorization node of the page
  250.      *
  251.      * @param nIdPage
  252.      *            the page id
  253.      * @param nIdAuthorizationNode
  254.      *            the authorization node id
  255.      */
  256.     public static void updateAuthorizationNode( int nIdPage, Integer nIdAuthorizationNode )
  257.     {
  258.         _dao.updateAutorisationNode( nIdPage, nIdAuthorizationNode );
  259.     }
  260. }