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.rss.business; 35 36 import fr.paris.lutece.portal.business.portlet.Portlet; 37 import fr.paris.lutece.portal.business.portlet.PortletHome; 38 import fr.paris.lutece.portal.business.stylesheet.StyleSheet; 39 import fr.paris.lutece.portal.service.spring.SpringContextService; 40 41 import java.util.Collection; 42 import java.util.List; 43 44 45 /** 46 * This class provides instances management methods (create, find, ...) 47 * for rss objects. 48 */ 49 public final class RssGeneratedFileHome 50 { 51 // Static variable pointed at the DAO instance 52 private static IRssGeneratedFileDAO../../fr/paris/lutece/plugins/rss/business/IRssGeneratedFileDAO.html#IRssGeneratedFileDAO">IRssGeneratedFileDAO _dao = (IRssGeneratedFileDAO) SpringContextService.getPluginBean( "rss", 53 "rssGeneratedFileDAO" ); 54 55 /** 56 * Creates a new RssFileHome object. 57 */ 58 private RssGeneratedFileHome( ) 59 { 60 } 61 62 /** 63 * Loads the data of a pushrss object from the table 64 * 65 * @return pushRss The instance of an RssFile's object 66 * @param nKey The identifier of the pushrss file 67 */ 68 public static RssGeneratedFile findByPrimaryKey( int nKey ) 69 { 70 return _dao.load( nKey ); 71 } 72 73 /** 74 * Updates the record in the rss_generation table 75 * 76 * @param pushRss The Instance of the object RssFile 77 */ 78 public static void update( RssGeneratedFile pushRss ) 79 { 80 _dao.store( pushRss ); 81 } 82 83 /** 84 * Updates pushrss's state in the table and doesn't modify the update date 85 * 86 * @param pushRss The Instance of the object RssFile 87 */ 88 public static void updateState( RssGeneratedFile pushRss ) 89 { 90 _dao.updateState( pushRss ); 91 } 92 93 /** 94 * Creates a new push RSS object in the database. 95 * 96 * @return pushRss The object 97 * @param pushRss The Instance of the object RssFile 98 */ 99 public static RssGeneratedFile/../../../fr/paris/lutece/plugins/rss/business/RssGeneratedFile.html#RssGeneratedFile">RssGeneratedFile create( RssGeneratedFile pushRss ) 100 { 101 _dao.insert( pushRss ); 102 103 return pushRss; 104 } 105 106 /** 107 * Removes the push RSS object whose identifier is specified in parameter 108 * 109 * @param nRssFileId The identifier of the pushRss object 110 */ 111 public static void remove( int nRssFileId ) 112 { 113 _dao.delete( nRssFileId ); 114 } 115 116 /** 117 * Returns the list of the RSS Files 118 * 119 * @return the list in form of a List object 120 */ 121 public static List<RssGeneratedFile> getRssFileList( ) 122 { 123 List<RssGeneratedFile> rssGeneratedFileList = _dao.selectRssFileList( ); 124 125 for ( RssGeneratedFile rssGeneratedFile : rssGeneratedFileList ) 126 { 127 if ( rssGeneratedFile.getPortletId( ) != 0 ) 128 { 129 Portlet portlet = PortletHome.findByPrimaryKey( rssGeneratedFile.getPortletId( ) ); 130 131 if ( portlet != null ) 132 { 133 rssGeneratedFile.setPortletName( portlet.getName( ) ); 134 } 135 } 136 } 137 138 return rssGeneratedFileList; 139 } 140 141 /** 142 * Reads the portlet's name 143 * 144 * @return The name of the portlet 145 * @param nPortletId the identifier of the portlet 146 */ 147 public static String getPortletName( int nPortletId ) 148 { 149 return _dao.selectRssFilePortletName( nPortletId ); 150 } 151 152 /** 153 * Returns the stylesheet for RSS files 154 * 155 * @return the stylesheet 156 * @param nStylesheetId the identifier of the Stylesheet 157 */ 158 public static StyleSheet getRssXsl( int nStylesheetId ) 159 { 160 return _dao.selectXslFile( nStylesheetId ); 161 } 162 163 /////////////////////////////////////////////////////////////////////////// 164 // Finders 165 166 /** 167 * Returns a collection of portlets for which there isn't any RSS files 168 * 169 * @return the portlets in form of Collection 170 */ 171 public static Collection findArticlesPortlets( ) 172 { 173 return _dao.selectRssPortlets( ); 174 } 175 176 /** 177 * Returns a collection of portlets for which there isn't any RSS files 178 * 179 * @return the portlets in form of Collection 180 */ 181 public static Collection findAllArticlesPortlets( ) 182 { 183 return _dao.selectAllRssPortlets( ); 184 } 185 186 /** 187 * Returns all the documents of a portlet whose identifier is specified in parameter 188 * 189 * @param nPortletId the identifier of the portlet 190 * @return List of articles objects 191 */ 192 public static List findDocumentsByPortlet( int nPortletId ) 193 { 194 return _dao.selectDocumentsByPortlet( nPortletId ); 195 } 196 197 /////////////////////////////////////////////////////////////////////////// 198 // Controllers 199 200 /** 201 * Checks if a pushrss object exist for this portlet identifier 202 * 203 * @return true if a pushRss file exist for this portlet 204 * @param nPortletId The identifier of the portlet 205 */ 206 public static boolean checkExistPushrssByPortlet( int nPortletId ) 207 { 208 return _dao.checkExistPushrssByPortlet( nPortletId ); 209 } 210 211 /** 212 * Tests before create if a push rss object exist with the same name 213 * 214 * @return true if the name already exists 215 * @param strRssFileName The push RSS file's name 216 */ 217 public static boolean checkRssFileFileName( String strRssFileName ) 218 { 219 return _dao.checkRssFileFileName( strRssFileName ); 220 } 221 222 /** 223 * Tests if the portlet has not been deleted 224 * 225 * @return true if the name already exists 226 * @param nPortletId The portlet identifier for this RSS file 227 */ 228 public static boolean checkRssFilePortlet( int nPortletId ) 229 { 230 return _dao.checkRssFilePortlet( nPortletId ); 231 } 232 }