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.plugins.dbpage.business; 35 36 import fr.paris.lutece.portal.service.plugin.Plugin; 37 import fr.paris.lutece.portal.service.spring.SpringContextService; 38 import fr.paris.lutece.util.ReferenceList; 39 40 import java.util.Collection; 41 import java.util.List; 42 43 44 /** 45 * This class provides instances management methods (create, find, ...) for DbPageDatabaseSection objects 46 */ 47 public final class DbPageDatabaseSectionHome 48 { 49 // Static variable pointed at the DAO instance 50 private static IDbPageDatabaseSectionDAO _dao = (IDbPageDatabaseSectionDAO) SpringContextService.getPluginBean( "dbpage", 51 "dbPageDatabaseSectionDAO" ); 52 53 /** 54 * Private constructor - this class need not be instantiated 55 */ 56 private DbPageDatabaseSectionHome( ) 57 { 58 } 59 60 /** 61 * Creation of an instance of dbPageDatabaseSection 62 * @param plugin The plugin object 63 * @param dbPageDatabaseSection The instance of the dbPageDatabaseSection which contains the informations to store 64 * @return The instance of dbPageDatabaseSection which has been created with its primary key. 65 */ 66 public static DbPageDatabaseSection create( DbPageDatabaseSection dbPageDatabaseSection, Plugin plugin ) 67 { 68 _dao.insert( dbPageDatabaseSection, plugin ); 69 70 return dbPageDatabaseSection; 71 } 72 73 /** 74 * Update of the dbPageDatabaseSection which is specified in parameter 75 * @param plugin The plugin object 76 * @param dbPageDatabaseSection The instance of the dbPageDatabaseSection which contains the data to store 77 * @return The instance of the dbPageDatabaseSection which has been updated 78 */ 79 public static DbPageDatabaseSection update( DbPageDatabaseSection dbPageDatabaseSection, Plugin plugin ) 80 { 81 _dao.store( dbPageDatabaseSection, plugin ); 82 83 return dbPageDatabaseSection; 84 } 85 86 /** 87 * Remove the DbPageDatabaseSection whose identifier is specified in parameter 88 * @param plugin The plugin object 89 * @param nDbPageDatabaseSectionId The DbPageDatabaseSection Id 90 */ 91 public static void remove( int nDbPageDatabaseSectionId, Plugin plugin ) 92 { 93 _dao.delete( nDbPageDatabaseSectionId, plugin ); 94 } 95 96 /////////////////////////////////////////////////////////////////////////// 97 // Finders 98 99 /** 100 * Returns an instance of a dbPageDatabaseSection whose identifier is specified in parameter 101 * @param plugin The plugin object 102 * @param nKey The Primary key of the dbPageDatabaseSection 103 * @return An instance of dbPageDatabaseSection 104 */ 105 public static DbPageDatabaseSection findByPrimaryKey( int nKey, Plugin plugin ) 106 { 107 return _dao.load( nKey, plugin ); 108 } 109 110 /** 111 * Returns a list of dbPageDatabaseSections objects 112 * @return A list of dbPageDatabaseSections 113 * @param plugin The plugin object 114 */ 115 public static List<DbPageDatabaseSection> findDbPageDatabaseSectionsList( Plugin plugin ) 116 { 117 return _dao.selectDbPageDatabaseSectionList( plugin ); 118 } 119 120 /** 121 * This method is used to find the sections of a dbpage 122 * @param nPageId The id of the dbpage 123 * @param plugin The plugin object 124 * @return List of DbPageDatabaseSection 125 */ 126 public static List<DbPageDatabaseSection> findSectionsByPage( int nPageId, Plugin plugin ) 127 { 128 return _dao.loadSectionsByPageId( nPageId, plugin ); 129 } 130 131 /** 132 * This method is used to find the sections of a dbpage 133 * @param strRoleKey The role key 134 * @param plugin The plugin object 135 * @return Collection of DbPageDatabaseSection 136 */ 137 public static Collection<DbPageDatabaseSection> findSectionsByRoleKey( String strRoleKey, Plugin plugin ) 138 { 139 return _dao.loadSectionsByRoleKey( strRoleKey, plugin ); 140 } 141 142 /** 143 * Returns the number of Sections in a DbPage 144 * @param plugin The plugin 145 * @param nDbPageId The identifier of the DbPage 146 * @return The number of sections in the DbPage 147 */ 148 public static int countNumberSections( int nDbPageId, Plugin plugin ) 149 { 150 return _dao.countSections( nDbPageId, plugin ); 151 } 152 153 /** 154 * This method allows to fetch a representation of the orders of a section in a dbpage 155 * @param nDbPageId The dbPage identifier 156 * @param plugin The plugin object 157 * @return A list of sections representing the order 158 */ 159 public static ReferenceList findOrderComboList( int nDbPageId, Plugin plugin ) 160 { 161 return _dao.selectOrderList( nDbPageId, plugin ); 162 } 163 164 /** 165 * Update the order of a section 166 * @param plugin The plugin object 167 * @param nPageId the identifier of the page 168 * @param nNewOrder the new number of order 169 * @param nIdSection the Identifier of a scetion 170 */ 171 public static void getModifySectionOrder( int nPageId, int nNewOrder, int nIdSection, Plugin plugin ) 172 { 173 _dao.getModifySectionOrder( nPageId, nNewOrder, nIdSection, plugin ); 174 } 175 176 /** 177 * Search the order of a section 178 * @return int the id by a given order 179 * @param plugin The plugin object 180 * @param nItemOrder the number of orders of sections in the page 181 * @param nPageId the identifier of the page 182 */ 183 public static int getIdByOrder( int nPageId, int nItemOrder, Plugin plugin ) 184 { 185 return _dao.selectIdByOrder( nPageId, nItemOrder, plugin ); 186 } 187 188 /** 189 * Get the maximum order on a page 190 * @return int the id by a given order 191 * @param plugin The plugin object 192 * @param nPageId the identifier of the page 193 */ 194 public static int getMaxIdByOrder( int nPageId, Plugin plugin ) 195 { 196 return _dao.selectMaxIdOrder( nPageId, plugin ); 197 } 198 199 /** 200 * Reorder two sections 201 * @param nIdSection1 The first section id 202 * @param nOrderSection1 first section order 203 * @param nIdSection2 second section id 204 * @param nOrderSection2 second section order 205 * @param plugin he plugin object 206 */ 207 public static void reorderSections( int nIdSection1, int nOrderSection1, int nIdSection2, int nOrderSection2, 208 Plugin plugin ) 209 { 210 _dao.reorderSections( nIdSection1, nOrderSection1, nIdSection2, nOrderSection2, plugin ); 211 } 212 213 public static boolean isSectionInPage(String strPageName, String strSection ,Plugin plugin ) 214 { 215 return _dao.isSectionInPage(strPageName, strSection, plugin); 216 } 217 }