1 /* 2 * Copyright (c) 2002-2020, 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.plugins.quicklinks.business; 35 36 import java.util.Collection; 37 import java.util.HashMap; 38 import java.util.Locale; 39 import java.util.Map; 40 41 import javax.servlet.http.HttpServletRequest; 42 43 import fr.paris.lutece.portal.service.plugin.Plugin; 44 import fr.paris.lutece.portal.service.util.AppLogService; 45 46 public class Entry implements IEntry, Cloneable 47 { 48 private static final String EMPTY_STRING = ""; 49 private int _nIdQuicklinks; 50 private int _nId; 51 private int _nIdOrder; 52 private EntryType _entryType; 53 private int _nIdParent; 54 55 /** 56 * @return the _nIdParent 57 */ 58 public int getIdParent( ) 59 { 60 return _nIdParent; 61 } 62 63 /** 64 * @param nIdParent 65 * the _nIdParent to set 66 */ 67 public void setIdParent( int nIdParent ) 68 { 69 _nIdParent = nIdParent; 70 } 71 72 /* 73 * (non-Javadoc) 74 * 75 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getIdQuicklinks() 76 */ 77 public int getIdQuicklinks( ) 78 { 79 return _nIdQuicklinks; 80 } 81 82 /* 83 * (non-Javadoc) 84 * 85 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#setIdQuicklinks(int) 86 */ 87 public void setIdQuicklinks( int nIdQuicklinks ) 88 { 89 _nIdQuicklinks = nIdQuicklinks; 90 } 91 92 /* 93 * (non-Javadoc) 94 * 95 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getIdEntry() 96 */ 97 public int getId( ) 98 { 99 return _nId; 100 } 101 102 /* 103 * (non-Javadoc) 104 * 105 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#setIdEntry(int) 106 */ 107 public void setId( int nIdEntry ) 108 { 109 _nId = nIdEntry; 110 } 111 112 /* 113 * (non-Javadoc) 114 * 115 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getIdOrder() 116 */ 117 public int getIdOrder( ) 118 { 119 return _nIdOrder; 120 } 121 122 /* 123 * (non-Javadoc) 124 * 125 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#setIdOrder(int) 126 */ 127 public void setIdOrder( int nIdOrder ) 128 { 129 _nIdOrder = nIdOrder; 130 } 131 132 /* 133 * (non-Javadoc) 134 * 135 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getType() 136 */ 137 public EntryType getEntryType( ) 138 { 139 return _entryType; 140 } 141 142 /* 143 * (non-Javadoc) 144 * 145 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#setType(int) 146 */ 147 public void setEntryType( EntryType entryType ) 148 { 149 _entryType = entryType; 150 } 151 152 // ############ Abstract methods ############ 153 154 /* 155 * (non-Javadoc) 156 * 157 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getTitle() 158 */ 159 public String getTitle( ) 160 { 161 return null; 162 } 163 164 /* 165 * (non-Javadoc) 166 * 167 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#setTitle(java.lang.String) 168 */ 169 public void setTitle( String strTitle ) 170 { 171 } 172 173 /** 174 * Clone the entry 175 */ 176 public IEntry clone( ) throws CloneNotSupportedException 177 { 178 throw new CloneNotSupportedException( ); 179 } 180 181 /** 182 * Copy an Entry 183 * 184 * @param nIdQuicklinks 185 * The {@link Quicklinks} identifier 186 * @param plugin 187 * the {@link Plugin} 188 * @return The {@link IEntry} copy 189 */ 190 public IEntry copy( int nIdQuicklinks, Plugin plugin ) 191 { 192 return copy( nIdQuicklinks, plugin, null ); 193 } 194 195 /** 196 * Copy an Entry 197 * 198 * @param nIdQuicklinks 199 * The {@link Quicklinks} identifier 200 * @param plugin 201 * the {@link Plugin} 202 * @param strNewName 203 * The new name 204 * @return The {@link IEntry} copy 205 */ 206 public IEntry copy( int nIdQuicklinks, Plugin plugin, String strNewName ) 207 { 208 IEntry copy = null; 209 210 try 211 { 212 copy = this.clone( ); 213 } 214 catch( CloneNotSupportedException e ) 215 { 216 AppLogService.error( "Object Entry does not support clone process." ); 217 } 218 219 // Update title 220 copy.setIdQuicklinks( nIdQuicklinks ); 221 222 if ( ( strNewName != null ) && !strNewName.equals( EMPTY_STRING ) ) 223 { 224 copy.setTitle( strNewName ); 225 } 226 227 copy = EntryHome.create( copy, plugin ); 228 229 for ( IEntry entry : EntryHome.findByParentId( this.getId( ), plugin ) ) 230 { 231 entry.setIdParent( copy.getId( ) ); 232 entry.copy( nIdQuicklinks, plugin ); 233 } 234 235 return copy; 236 } 237 238 /* 239 * (non-Javadoc) 240 * 241 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getHtml(fr.paris.lutece.portal.service.plugin.Plugin, java.util.Locale) 242 */ 243 public String getHtml( Plugin plugin, Locale locale ) 244 { 245 return null; 246 } 247 248 /* 249 * (non-Javadoc) 250 * 251 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getChilds(fr.paris.lutece.portal.service.plugin.Plugin) 252 */ 253 public Collection<IEntry> getChilds( Plugin plugin ) 254 { 255 return EntryHome.findByParentId( getId( ), plugin ); 256 } 257 258 /* 259 * (non-Javadoc) 260 * 261 * @see fr.paris.lutece.plugins.quicklinks.business.IEntry#getParent(fr.paris.lutece.portal.service.plugin.Plugin) 262 */ 263 public IEntry getParent( Plugin plugin ) 264 { 265 return EntryHome.findByPrimaryKey( getIdParent( ), plugin ); 266 } 267 268 /** 269 * Set the specific parameters for the entry 270 * 271 * @param request 272 * the {@link HttpServletRequest} 273 * @return The i18n message if error occurs, null else 274 */ 275 public String setSpecificParameters( HttpServletRequest request ) 276 { 277 return null; 278 } 279 280 /** 281 * Get the specific parameters for the entry 282 * 283 * @param request 284 * the {@link HttpServletRequest} 285 * @param model 286 * The {@link HashMap} model 287 * @param plugin 288 * The {@link Plugin} 289 */ 290 public void getSpecificParameters( HttpServletRequest request, Map<String, Object> model, Plugin plugin ) 291 { 292 } 293 294 /** 295 * Load the specific parameters 296 * 297 * @param plugin 298 * The {@link Plugin} 299 */ 300 public void loadSpecificParameters( Plugin plugin ) 301 { 302 } 303 304 /** 305 * Create the specific parameters 306 * 307 * @param plugin 308 * The {@link Plugin} 309 */ 310 public void createSpecificParameters( Plugin plugin ) 311 { 312 } 313 314 /** 315 * Remove the specific parameters 316 * 317 * @param plugin 318 * The {@link Plugin} 319 */ 320 public void removeSpecificParameters( Plugin plugin ) 321 { 322 } 323 324 /** 325 * Update the specific parameters 326 * 327 * @param plugin 328 * The {@link Plugin} 329 */ 330 public void updateSpecificParameters( Plugin plugin ) 331 { 332 } 333 }