1 /*
2 * Copyright (c) 2002-2021, 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.announce.business;
35
36 import fr.paris.lutece.plugins.announce.service.AnnouncePlugin;
37 import fr.paris.lutece.portal.service.plugin.Plugin;
38 import fr.paris.lutece.portal.service.plugin.PluginService;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.util.ReferenceList;
41
42 import java.util.Collection;
43 import java.util.Locale;
44
45 /**
46 * Home for sectors
47 */
48 public final class SectorHome
49 {
50 // Static variable pointed at the DAO instance
51 private static ISectorDAO _dao = SpringContextService.getBean( "announce.sectorDAO" );
52 private static Plugin _plugin = PluginService.getPlugin( AnnouncePlugin.PLUGIN_NAME );
53
54 /** Creates a new instance of SectorHome */
55 private SectorHome( )
56 {
57 }
58
59 /**
60 * Creation of an instance of sector
61 *
62 * @param sector
63 * The instance of the sector which contains the informations to store
64 * @param plugin
65 * The Plugin object
66 * @return The instance of sector which has been created with its primary key.
67 */
68 public static Sector="../../../../../../fr/paris/lutece/plugins/announce/business/Sector.html#Sector">Sector create( Sector sector, Plugin plugin )
69 {
70 _dao.insert( sector, plugin );
71
72 return sector;
73 }
74
75 /**
76 * Update of the sector which is specified in parameter
77 *
78 * @param sector
79 * The instance of the sector which contains the informations to store
80 * @param plugin
81 * The Plugin object
82 * @return The instance of the sector which has been updated
83 */
84 public static Sector="../../../../../../fr/paris/lutece/plugins/announce/business/Sector.html#Sector">Sector update( Sector sector, Plugin plugin )
85 {
86 _dao.store( sector, plugin );
87
88 return sector;
89 }
90
91 /**
92 * Remove the Sector whose identifier is specified in parameter
93 *
94 * @param sector
95 * The Sector object to remove
96 * @param plugin
97 * The Plugin object
98 */
99 public static void remove( Sector sector, Plugin plugin )
100 {
101 _dao.delete( sector, plugin );
102 }
103
104 // /////////////////////////////////////////////////////////////////////////
105 // Finders
106 // /////////////////////////////////////////////////////////////////////////
107
108 /**
109 * Returns an instance of a sector whose identifier is specified in parameter
110 *
111 * @param nKey
112 * The Primary key of the sector
113 * @return An instance of sector
114 */
115 public static Sector findByPrimaryKey( int nKey )
116 {
117 return _dao.load( nKey, _plugin );
118 }
119
120 /**
121 * Returns a collection of sectors objects
122 *
123 * @return A collection of sectors
124 */
125 public static Collection<Sector> findAll( )
126 {
127 return _dao.selectAll( _plugin );
128 }
129
130 /**
131 * Returns a referenceList of sectors
132 *
133 * @return A referenceList of sectors
134 */
135 public static ReferenceList findReferenceList( )
136 {
137 return _dao.selectReferenceList( _plugin );
138 }
139
140 /**
141 * Returns identifier in a distinct order
142 *
143 * @return The order
144 * @param nOrder
145 * The order number
146 */
147 public static int getIdByOrder( int nOrder )
148 {
149 return _dao.selectIdByOrder( nOrder, _plugin );
150 }
151
152 /**
153 * Returns the order
154 *
155 * @param nOrder
156 * the order
157 * @return the order
158 */
159 public static int getOrderById( int nOrder )
160 {
161 return _dao.selectOrderById( nOrder, _plugin );
162 }
163
164 /**
165 * Update the order of a sector
166 *
167 * @param nOrder
168 * The order of a sector
169 * @param nIdSector
170 * The id of the sector to update
171 */
172 public static void updateOrder( int nOrder, int nIdSector )
173 {
174 _dao.storeOrder( nOrder, nIdSector, _plugin );
175 }
176
177 /**
178 * Get the maximum order of sectors
179 *
180 * @return The maximum order of sectors
181 */
182 public static int getMaxOrderSector( )
183 {
184 return _dao.selectMaxOrder( _plugin );
185 }
186
187 /**
188 * Selects the reference list with the i18n string at the top (for front)
189 *
190 * @param locale
191 * The locale
192 * @return A referenceList of sectors
193 */
194 public static ReferenceList findLocaleReferenceList( Locale locale )
195 {
196 return _dao.selectLocaleReferenceList( _plugin, locale );
197 }
198 }