1 /*
2 * Copyright (c) 2002-2025, 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.notificationstore.business;
35
36 import java.util.List;
37 import java.util.Optional;
38
39 import org.apache.commons.lang3.StringUtils;
40
41 import fr.paris.lutece.plugins.grubusiness.business.demand.DemandCategory;
42 import fr.paris.lutece.plugins.grubusiness.business.demand.IDemandCategoryDAO;
43 import fr.paris.lutece.portal.service.spring.SpringContextService;
44 import fr.paris.lutece.util.ReferenceList;
45
46 /**
47 * This class provides instances management methods (create, find, ...) for DemandCategory objects
48 */
49 public final class DemandCategoryHome
50 {
51 // Static variable pointed at the DAO instance
52 private static IDemandCategoryDAO _dao = SpringContextService.getBean( "notificationstore.demandCategoryDao" );
53
54 /**
55 * Private constructor - this class need not be instantiated
56 */
57 private DemandCategoryHome( )
58 {
59 }
60
61 /**
62 * Create an instance of the demandCategory class
63 *
64 * @param demandCategory
65 * The instance of the DemandCategory which contains the informations to store
66 * @return The instance of demandCategory which has been created with its primary key.
67 */
68 public static DemandCategory create( DemandCategory demandCategory )
69 {
70 _dao.insert( demandCategory );
71
72 return demandCategory;
73 }
74
75 /**
76 * Update of the demandCategory which is specified in parameter
77 *
78 * @param demandCategory
79 * The instance of the DemandCategory which contains the data to store
80 * @return The instance of the demandCategory which has been updated
81 */
82 public static DemandCategory update( DemandCategory demandCategory )
83 {
84 _dao.store( demandCategory );
85
86 return demandCategory;
87 }
88
89 /**
90 * Remove the demandCategory whose identifier is specified in parameter
91 *
92 * @param nKey
93 * The demandCategory Id
94 */
95 public static void remove( int nKey )
96 {
97 _dao.delete( nKey );
98 }
99
100 /**
101 * Returns an instance of a demandCategory whose identifier is specified in parameter
102 *
103 * @param nKey
104 * The demandCategory primary key
105 * @return an instance of DemandCategory
106 */
107 public static Optional<DemandCategory> findByPrimaryKey( int nKey )
108 {
109 return _dao.load( nKey );
110 }
111
112 /**
113 * Load the data of all the demandCategory objects and returns them as a list
114 *
115 * @return the list which contains the data of all the demandCategory objects
116 */
117 public static List<DemandCategory> getDemandCategoriesList( )
118 {
119 return _dao.selectDemandCategoriesList( );
120 }
121
122 /**
123 * Load the id of all the demandCategory objects and returns them as a list
124 *
125 * @return the list which contains the id of all the demandCategory objects
126 */
127 public static List<Integer> getIdDemandCategoriesList( )
128 {
129 return _dao.selectIdDemandCategoriesList( );
130 }
131
132 /**
133 * Load the data of all the avant objects and returns them as a list
134 *
135 * @param listIds
136 * liste of ids
137 * @return the list which contains the data of all the avant objects
138 */
139 public static List<DemandCategory> getDemandCategoriesListByIds( List<Integer> listIds )
140 {
141 return _dao.selectDemandCategoriesListByIds( listIds );
142 }
143
144 /**
145 * get categories as reference list
146 *
147 * @return
148 */
149 public static ReferenceList getDemandCategoriesReferenceList( )
150 {
151
152 ReferenceList list = new ReferenceList( );
153 list.addItem( StringUtils.EMPTY, StringUtils.EMPTY );
154 ;
155 getDemandCategoriesList( ).stream( ).forEach( c -> list.addItem( c.getCode( ), c.getLabel( ) ) );
156
157 return list;
158 }
159
160 }