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.formengine.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.List; 41 42 43 /** 44 * NoticeHome 45 */ 46 public final class NoticeHome 47 { 48 // Static variable pointed at the DAO instance 49 private static INoticeDAO _dao = (INoticeDAO) SpringContextService.getPluginBean( "formengine", 50 "formengine.noticeDAO" ); 51 52 /** 53 * Private constructor - this class need not be instantiated 54 */ 55 private NoticeHome( ) 56 { 57 } 58 59 /** 60 * Creation of an instance of notice 61 * 62 * @param notice The instance of the Notice which contains the informations to store 63 * @param plugin the Plugin 64 * @return The primary key of the new notice. 65 */ 66 public static int create( Notice notice, Plugin plugin ) 67 { 68 return _dao.insert( notice, plugin ); 69 } 70 71 /** 72 * Copy of an instance of notice 73 * 74 * @param notice The instance of the notice who must copy 75 * @param plugin the Plugin 76 * 77 */ 78 public static void copy( Notice notice, Plugin plugin ) 79 { 80 notice.setIdNotice( create( notice, plugin ) ); 81 } 82 83 /** 84 * Update of the notice which is specified in parameter 85 * 86 * @param notice The instance of the notice which contains the informations to update 87 * @param plugin the Plugin 88 * 89 */ 90 public static void update( Notice notice, Plugin plugin ) 91 { 92 _dao.store( notice, plugin ); 93 } 94 95 /** 96 * Remove the notice whose identifier is specified in parameter 97 * 98 * @param nIdNotice The notice Id 99 * @param plugin the Plugin 100 */ 101 public static void remove( int nIdNotice, Plugin plugin ) 102 { 103 _dao.delete( nIdNotice, plugin ); 104 } 105 106 /////////////////////////////////////////////////////////////////////////// 107 // Finders 108 /** 109 * Returns an instance of a notice whose identifier is specified in parameter 110 * 111 * @param nKey The entry primary key 112 * @param plugin the Plugin 113 * @return an instance of notice 114 */ 115 public static Notice findByPrimaryKey( int nKey, Plugin plugin ) 116 { 117 return _dao.load( nKey, plugin ); 118 } 119 120 /** 121 * Returns an instance of a notice whose identifier is specified in parameter 122 * 123 * @param strTitle The title of the notice 124 * @param plugin the Plugin 125 * @return an instance of notice 126 */ 127 public static ReferenceList findByTitle( String strTitle, Plugin plugin ) 128 { 129 return _dao.getNoticeByTitle( strTitle, plugin ); 130 } 131 132 /** 133 * Load the data of all the notice who verify the filter and returns them in a list 134 * @param filter the filter 135 * @param plugin the plugin 136 * @return the list of form 137 */ 138 public static List<Notice> getNoticeList( NoticeFilter filter, Plugin plugin ) 139 { 140 return _dao.selectNoticeList( filter, plugin ); 141 } 142 143 /** 144 * Load the list of all notice returns them in a reference list 145 * @param plugin the plugin 146 * @return a reference list of enable notice 147 */ 148 public static ReferenceList getNoticeList( Plugin plugin ) 149 { 150 return _dao.getEnableNoticeList( plugin ); 151 } 152 153 /** 154 * Returns true if is enable false otherwise 155 * 156 * @param notice The notice 157 * @param plugin the Plugin 158 * @return true if is enable false otherwise 159 */ 160 public static boolean isEnable( Notice notice, Plugin plugin ) 161 { 162 return _dao.isEnable( notice, plugin ); 163 } 164 165 /** 166 * Finds the last order for the group 167 * @param nIdNoticeGroup the notice group id 168 * @param plugin the plugin 169 * @return the max order, <code>0</code> otherwise. 170 */ 171 public static int findMaxOrderForNoticeGroup( int nIdNoticeGroup, Plugin plugin ) 172 { 173 return _dao.selectMaxOrderByNoticeGroup( nIdNoticeGroup, plugin ); 174 } 175 }