1 /* 2 * Copyright (c) 2002-2016, 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.avatarserver.business; 35 36 import fr.paris.lutece.portal.service.plugin.Plugin; 37 import fr.paris.lutece.portal.service.plugin.PluginService; 38 import fr.paris.lutece.portal.service.spring.SpringContextService; 39 40 import java.util.Collection; 41 42 /** 43 * This class provides instances management methods (create, find, ...) for Avatar objects 44 */ 45 public final class AvatarHome 46 { 47 // Static variable pointed at the DAO instance 48 private static IAvatarDAO _dao = SpringContextService.getBean( "avatarserver.avatarDAO" ); 49 private static Plugin _plugin = PluginService.getPlugin( "avatarserver" ); 50 51 /** 52 * Private constructor - this class need not be instantiated 53 */ 54 private AvatarHome( ) 55 { 56 } 57 58 /** 59 * Returns an instance of a avatar whose identifier is specified in parameter 60 * 61 * @param strHash 62 * The avatar hash created with the email address 63 * @return an instance of Avatar 64 */ 65 public static Avatar findByHash( String strHash ) 66 { 67 return _dao.selectByHash( strHash, _plugin ); 68 } 69 70 /** 71 * Create an instance of the avatar class 72 * 73 * @param avatar 74 * The instance of the Avatar which contains the informations to store 75 * @return The instance of avatar which has been created with its primary key. 76 */ 77 public static Avatar create( Avatar avatar ) 78 { 79 _dao.insert( avatar, _plugin ); 80 81 return avatar; 82 } 83 84 /** 85 * Update of the avatar which is specified in parameter 86 * 87 * @param avatar 88 * The instance of the Avatar which contains the data to store 89 * @return The instance of the avatar which has been updated 90 */ 91 public static Avatar update( Avatar avatar ) 92 { 93 _dao.store( avatar, _plugin ); 94 95 return avatar; 96 } 97 98 /** 99 * Remove the avatar whose identifier is specified in parameter 100 * 101 * @param nAvatarId 102 * The avatar Id 103 */ 104 public static void remove( int nAvatarId ) 105 { 106 _dao.delete( nAvatarId, _plugin ); 107 } 108 109 // ///////////////////////////////////////////////////////////////////////// 110 // Finders 111 112 /** 113 * Returns an instance of a avatar whose identifier is specified in parameter 114 * 115 * @param nKey 116 * The avatar primary key 117 * @return an instance of Avatar 118 */ 119 public static Avatar findByPrimaryKey( int nKey ) 120 { 121 return _dao.load( nKey, _plugin ); 122 } 123 124 /** 125 * Load the data of all the avatar objects and returns them in form of a collection 126 * 127 * @return the collection which contains the data of all the avatar objects 128 */ 129 public static Collection<Avatar> getAvatarsList( ) 130 { 131 return _dao.selectAvatarsList( _plugin ); 132 } 133 }