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.calendar.business.category;
35
36 import fr.paris.lutece.portal.service.image.ImageResource;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.portal.service.spring.SpringContextService;
39
40 import java.util.Collection;
41
42
43 /**
44 * This class provides instances management methods (create, find, ...) for
45 * Category objects
46 */
47 public final class CategoryHome
48 {
49 // Static variable pointed at the DAO instance
50 private static ICategoryDAO _dao = (ICategoryDAO) SpringContextService.getBean( "calendar.categoryDAO" );
51
52 /**
53 * Private constructor - this class need not be instantiated
54 */
55 private CategoryHome( )
56 {
57 }
58
59 /**
60 * Returns the category list
61 * @param plugin Plugin
62 * @return Collection of Category (empty collection is no result)
63 */
64 public static Collection<Category> findAll( Plugin plugin )
65 {
66 Collection<Category> categoryList = _dao.selectAll( plugin );
67
68 return categoryList;
69 }
70
71 /**
72 * Create a new Category
73 * @param category The new Category
74 * @param plugin Plugin
75 */
76 public static void create( Category category, Plugin plugin )
77 {
78 _dao.insert( category, plugin );
79 }
80
81 /**
82 * Find the data of Category from the table
83 * @param nIdCategory The id of the category
84 * @param plugin Plugin
85 * @return The Instance of the object Category of null if no category match
86 */
87 public static Category find( int nIdCategory, Plugin plugin )
88 {
89 return _dao.load( nIdCategory, plugin );
90 }
91
92 /**
93 * Find the data of Category from the table
94 * @param strCategoryName The id of the category
95 * @param plugin Plugin
96 * @return The Collection of Category (empty collection is no result)
97 */
98 public static Collection<Category> findByName( String strCategoryName, Plugin plugin )
99 {
100 return _dao.selectByName( strCategoryName, plugin );
101 }
102
103 /**
104 * Remove a record from the table
105 * @param nIdCategory The identifier of the object Category
106 * @param plugin Plugin
107 */
108 public static void remove( int nIdCategory, Plugin plugin )
109 {
110 _dao.delete( nIdCategory, plugin );
111 }
112
113 /**
114 * Update the record in the table
115 * @param category The instance of the Category to update
116 * @param plugin Plugin
117 */
118 public static void update( Category category, Plugin plugin )
119 {
120 _dao.store( category, plugin );
121 }
122
123 /**
124 * Find the number of documents linked to a category
125 * @param nIdCategory The category id
126 * @param plugin Plugin
127 * @return count of id document
128 */
129 public static int findCountIdEvents( int nIdCategory, Plugin plugin )
130 {
131 return _dao.selectCountIdEvents( nIdCategory, plugin );
132 }
133
134 /**
135 * Return the image resource for the specified category id
136 * @param nCategoryId The identifier of Category object
137 * @param plugin Plugin
138 * @return ImageResource
139 */
140 public static ImageResource getImageResource( int nCategoryId, Plugin plugin )
141 {
142 return _dao.loadImageResource( nCategoryId, plugin );
143 }
144
145 /**
146 * Load the data of Category for an event from the table
147 * @param nIdEvent The identifier of the event
148 * @param plugin Plugin
149 * @return The Instance of the object Category
150 */
151 public static Collection<Category> findByEvent( int nIdEvent, Plugin plugin )
152 {
153 return _dao.selectByEvent( nIdEvent, plugin );
154 }
155 }