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.tagcloud.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.ArrayList; 41 import java.util.Collection; 42 43 44 /** 45 * This class provides instances management methods (create, find, ...) for Tags objects 46 */ 47 public final class TagHome 48 { 49 // Static variable pointed at the DAO instance 50 private static ITagDAO"../../../../../../fr/paris/lutece/plugins/tagcloud/business/ITagDAO.html#ITagDAO">ITagDAO _dao = (ITagDAO) SpringContextService.getPluginBean( "tagcloud", "tagsDAO" ); 51 52 /** 53 * Private constructor - this class needs not be instantiated 54 */ 55 private TagHome( ) 56 { 57 } 58 59 /** 60 * Create an instance of the tags class 61 * @param tag The tag 62 * @param plugin the Plugin 63 * @return The instance of tags which has been created with its primary key. 64 */ 65 public static Tagref="../../../../../../fr/paris/lutece/plugins/tagcloud/business/Tag.html#Tag">Tag create( Tag tag, Plugin plugin ) 66 { 67 _dao.insert( tag, plugin ); 68 69 return tag; 70 } 71 72 /** 73 * Update of the tags which is specified in parameter 74 * @param tags The instance of the Tags which contains the data to store 75 * @param plugin the Plugin 76 * @return The instance of the tags which has been updated 77 */ 78 public static Tagref="../../../../../../fr/paris/lutece/plugins/tagcloud/business/Tag.html#Tag">Tag update( Tag tags, Plugin plugin ) 79 { 80 _dao.store( tags, plugin ); 81 82 return tags; 83 } 84 85 /** 86 * Remove the tags whose identifier is specified in parameter 87 * @param nCloudId The cloud if 88 * @param nTagId The tags Id 89 * @param plugin the Plugin 90 */ 91 public static void removeTag( int nTagId, int nCloudId, Plugin plugin ) 92 { 93 _dao.deleteTag( nTagId, nCloudId, plugin ); 94 } 95 96 /////////////////////////////////////////////////////////////////////////// 97 // Finders 98 99 /** 100 * Tag instance whose identifier is specified in parameter 101 * @param nCloudId The cloud id 102 * @param nTagId The tag identifier 103 * @param plugin the Plugin 104 * @return Instance of tags 105 */ 106 public static Tag findByPrimaryKey( int nCloudId, int nTagId, Plugin plugin ) 107 { 108 return _dao.load( nCloudId, nTagId, plugin ); 109 } 110 111 /** 112 * Finds a list of tags by cloud 113 * @param nCloudId the id of the cloud 114 * @param plugin The plugin 115 * @return an ArrayList 116 */ 117 public static ArrayList<Tag> findTagsByCloud( int nCloudId, Plugin plugin ) 118 { 119 return _dao.loadByCloud( nCloudId, plugin ); 120 } 121 122 /** 123 * Load the data of all the tags objects and returns them in form of a collection 124 * @param plugin the Plugin 125 * @return the collection which contains the data of all the tags objects 126 */ 127 public static Collection<Tag> getTagList( Plugin plugin ) 128 { 129 return _dao.selectTagList( plugin ); 130 } 131 132 /** 133 * Load the data of all the tags objects and returns them in form of a collection 134 * @param plugin the Plugin 135 * @return the collection which contains the data of all the tags objects 136 */ 137 public static Collection<TagCloud> getTagClouds( Plugin plugin ) 138 { 139 return _dao.selectTagClouds( plugin ); 140 } 141 142 /** 143 * A list of tag clouds 144 * @param plugin The plugin 145 * @return a ReferenceList 146 */ 147 public static ReferenceList getAllTagClouds( Plugin plugin ) 148 { 149 return _dao.selectAllTagClouds( plugin ); 150 } 151 152 /** 153 * Load the data of all the tags objects and returns them in form of a collection 154 * @param nCloudId The cloud id 155 * @param plugin the Plugin 156 * @return the collection which contains the data of all the tags objects 157 */ 158 public static TagCloud findCloudById( int nCloudId, Plugin plugin ) 159 { 160 return _dao.selectCloudById( nCloudId, plugin ); 161 } 162 163 /** 164 * Creates a nes tagcloud 165 * @param tagCloud The tagcloud 166 * @param plugin The plugin 167 * @return The tagcloud 168 */ 169 public static TagCloud../../../../../../fr/paris/lutece/plugins/tagcloud/business/TagCloud.html#TagCloud">TagCloud create( TagCloud tagCloud, Plugin plugin ) 170 { 171 _dao.insert( tagCloud, plugin ); 172 173 return tagCloud; 174 } 175 176 /** 177 * Update of the tagCloud which is specified in parameter 178 * 179 * @return The instance of the tags which has been updated 180 * @param tagCloud The tagcloud 181 * @param plugin the Plugin 182 */ 183 public static TagCloud../../../../../../fr/paris/lutece/plugins/tagcloud/business/TagCloud.html#TagCloud">TagCloud update( TagCloud tagCloud, Plugin plugin ) 184 { 185 _dao.store( tagCloud, plugin ); 186 187 return tagCloud; 188 } 189 190 /** 191 * Removes the cloud 192 * @param nCloudId The identifier of the cloud 193 * @param plugin The plugin 194 */ 195 public static void removeCloud( int nCloudId, Plugin plugin ) 196 { 197 _dao.deleteCloud( nCloudId, plugin ); 198 } 199 }