1 /*
2 * Copyright (c) 2002-2023, 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
35
36 package fr.paris.lutece.plugins.geocodes.business;
37
38 import fr.paris.lutece.portal.service.plugin.Plugin;
39 import fr.paris.lutece.portal.service.plugin.PluginService;
40 import fr.paris.lutece.portal.service.spring.SpringContextService;
41 import fr.paris.lutece.util.ReferenceList;
42
43
44 import java.util.List;
45 import java.util.Optional;
46
47 /**
48 * This class provides instances management methods (create, find, ...) for Country objects
49 */
50 public final class CountryHome
51 {
52 // Static variable pointed at the DAO instance
53 private static ICountryDAO _dao = SpringContextService.getBean( "geocodes.countryDAO" );
54 private static Plugin _plugin = PluginService.getPlugin( "geocodes" );
55
56 /**
57 * Private constructor - this class need not be instantiated
58 */
59 private CountryHome( )
60 {
61 }
62
63 /**
64 * Create an instance of the country class
65 * @param country The instance of the Country which contains the informations to store
66 * @return The instance of country which has been created with its primary key.
67 */
68 public static Country"../../../../../../fr/paris/lutece/plugins/geocodes/business/Country.html#Country">Country create( Country country )
69 {
70 _dao.insert( country, _plugin );
71
72 return country;
73 }
74
75 /**
76 * Update of the country which is specified in parameter
77 * @param country The instance of the Country which contains the data to store
78 * @return The instance of the country which has been updated
79 */
80 public static Country"../../../../../../fr/paris/lutece/plugins/geocodes/business/Country.html#Country">Country update( Country country )
81 {
82 _dao.store( country, _plugin );
83
84 return country;
85 }
86
87 /**
88 * Remove the country whose identifier is specified in parameter
89 * @param nKey The country Id
90 */
91 public static void remove( int nKey )
92 {
93 _dao.delete( nKey, _plugin );
94 }
95
96 /**
97 * Returns an instance of a country whose identifier is specified in parameter
98 * @param nKey The country primary key
99 * @return an instance of Country
100 */
101 public static Optional<Country> findByPrimaryKey( int nKey )
102 {
103 return _dao.load( nKey, _plugin );
104 }
105
106 /**
107 * Returns an instance of a country whose identifier is specified in parameter
108 * @param nKey The country primary key
109 * @return an instance of Country
110 */
111 public static Optional<Country> findByCode( String strCode )
112 {
113 return _dao.loadByCode( strCode, _plugin );
114 }
115
116 /**
117 * Load the data of all the country objects and returns them as a list
118 * @return the list which contains the data of all the country objects
119 */
120 public static List<Country> getCountriesList( )
121 {
122 return _dao.selectCountriesList( _plugin );
123 }
124
125 /**
126 * Load the data of all the country objects and returns them as a list
127 * @return the list which contains the data of all the country objects
128 */
129 public static List<Country> getCountriesListByName( String strSearch )
130 {
131 return _dao.selectCountriesListByValue( strSearch, _plugin );
132 }
133
134
135 /**
136 * Load the id of all the country objects and returns them as a list
137 * @return the list which contains the id of all the country objects
138 */
139 public static List<Integer> getIdCountriesList( )
140 {
141 return _dao.selectIdCountriesList( _plugin );
142 }
143
144 /**
145 * Load the data of all the country objects and returns them as a referenceList
146 * @return the referenceList which contains the data of all the country objects
147 */
148 public static ReferenceList getCountriesReferenceList( )
149 {
150 return _dao.selectCountriesReferenceList( _plugin );
151 }
152
153
154 /**
155 * Load the data of all the avant objects and returns them as a list
156 * @param listIds liste of ids
157 * @return the list which contains the data of all the avant objects
158 */
159 public static List<Country> getCountriesListByIds( List<Integer> listIds )
160 {
161 return _dao.selectCountriesListByIds( _plugin, listIds );
162 }
163
164 }
165