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.forms.business;
35
36 import fr.paris.lutece.plugins.forms.service.cache.FormsCacheService;
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
43 import java.util.List;
44 import java.util.Locale;
45 import java.util.Optional;
46
47 /**
48 * This class provides instances management methods (create, find, ...) for ControlGroup objects
49 */
50 public final class ControlGroupHome
51 {
52 // Static variable pointed at the DAO instance
53 private static IControlGroupDAO _dao = SpringContextService.getBean( "forms.controlGroupDAO" );
54 private static FormsCacheService _cache = SpringContextService.getBean( "forms.cacheService" );
55 private static Plugin _plugin = PluginService.getPlugin( "forms" );
56
57 /**
58 * Private constructor - this class need not be instantiated
59 */
60 private ControlGroupHome( )
61 {
62 }
63
64 /**
65 * Create an instance of the controlGroup class
66 * @param controlGroup The instance of the ControlGroup which contains the informations to store
67 * @return The instance of controlGroup which has been created with its primary key.
68 */
69 public static ControlGroup./../../../../fr/paris/lutece/plugins/forms/business/ControlGroup.html#ControlGroup">ControlGroup create( ControlGroup controlGroup )
70 {
71 _dao.insert( controlGroup, _plugin );
72 _cache.putInCache( _cache.getControlGroupCacheKey( controlGroup.getId( ) ), controlGroup );
73 return controlGroup;
74 }
75
76 /**
77 * Update of the controlGroup which is specified in parameter
78 * @param controlGroup The instance of the ControlGroup which contains the data to store
79 * @return The instance of the controlGroup which has been updated
80 */
81 public static ControlGroup./../../../../fr/paris/lutece/plugins/forms/business/ControlGroup.html#ControlGroup">ControlGroup update( ControlGroup controlGroup )
82 {
83 _dao.store( controlGroup, _plugin );
84 _cache.putInCache( _cache.getControlGroupCacheKey( controlGroup.getId( ) ), controlGroup );
85 return controlGroup;
86 }
87
88 /**
89 * Remove the controlGroup whose identifier is specified in parameter
90 * @param nKey The controlGroup Id
91 */
92 public static void remove( int nKey )
93 {
94 _dao.delete( nKey, _plugin );
95 _cache.removeKey( _cache.getControlGroupCacheKey( nKey ) );
96 }
97
98 /**
99 * Returns an instance of a controlGroup whose identifier is specified in parameter
100 * @param nKey The controlGroup primary key
101 * @return an instance of ControlGroup
102 */
103 public static Optional<ControlGroup> findByPrimaryKey( int nKey )
104 {
105 String cacheKey = _cache.getControlGroupCacheKey( nKey );
106 @SuppressWarnings( "unchecked" )
107 Optional<ControlGroup> controlGroup = ( Optional<ControlGroup> ) _cache.getFromCache( cacheKey );
108 if ( controlGroup == null )
109 {
110 controlGroup = _dao.load( nKey, _plugin );
111 _cache.putInCache( cacheKey, controlGroup );
112 }
113 return controlGroup;
114 }
115
116 /**
117 * Load the data of all the controlGroup objects and returns them as a list
118 * @return the list which contains the data of all the controlGroup objects
119 */
120 public static List<ControlGroup> getControlGroupsList( )
121 {
122 return _dao.selectControlGroupsList( _plugin );
123 }
124
125 /**
126 * Load the id of all the controlGroup objects and returns them as a list
127 * @return the list which contains the id of all the controlGroup objects
128 */
129 public static List<Integer> getIdControlGroupsList( )
130 {
131 return _dao.selectIdControlGroupsList( _plugin );
132 }
133
134 /**
135 * Load the data of all the controlGroup objects and returns them as a referenceList
136 * @return the referenceList which contains the data of all the controlGroup objects
137 */
138 public static ReferenceList getControlGroupsReferenceList( )
139 {
140 return _dao.selectControlGroupsReferenceList( _plugin );
141 }
142
143 /**
144 * Load the data of all the logical operators from enum and returns them as a referenceList
145 * @param locale TODO
146 * @return the referenceList which contains the data of all the logical operators objects
147 */
148 public static ReferenceList getLogicalOperatorsReferenceList(Locale locale )
149 {
150 return _dao.selectLogicalOperatorsReferenceList(locale);
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<ControlGroup> getControlGroupsListByIds( List<Integer> listIds )
160 {
161 return _dao.selectControlGroupsListByIds( _plugin, listIds );
162 }
163
164 }
165