1 /*
2 * Copyright (c) 2002-2022, 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.termofservice.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 Entry objects
49 */
50 public final class EntryHome
51 {
52 // Static variable pointed at the DAO instance
53 private static IEntryDAO _dao = SpringContextService.getBean( "termofservice.entryDAO" );
54 private static Plugin _plugin = PluginService.getPlugin( "termofservice" );
55
56 /**
57 * Private constructor - this class need not be instantiated
58 */
59 private EntryHome( )
60 {
61 }
62
63 /**
64 * Create an instance of the entry class
65 * @param entry The instance of the Entry which contains the informations to store
66 * @return The instance of entry which has been created with its primary key.
67 */
68 public static Entryf="../../../../../../fr/paris/lutece/plugins/termofservice/business/Entry.html#Entry">Entry create( Entry entry )
69 {
70 _dao.insert( entry, _plugin );
71
72 return entry;
73 }
74
75 /**
76 * Update of the entry which is specified in parameter
77 * @param entry The instance of the Entry which contains the data to store
78 * @return The instance of the entry which has been updated
79 */
80 public static Entryf="../../../../../../fr/paris/lutece/plugins/termofservice/business/Entry.html#Entry">Entry update( Entry entry )
81 {
82 _dao.store( entry, _plugin );
83
84 return entry;
85 }
86
87 /**
88 * Remove the entry whose identifier is specified in parameter
89 * @param nKey The entry Id
90 */
91 public static void remove( int nKey )
92 {
93 _dao.delete( nKey, _plugin );
94 }
95
96 /**
97 * Publish the entry whose identifier is specified in parameter
98 * @param nKey The identifier of the Entry to publish
99 */
100 public static void publishEntry( int nKey )
101 {
102 _dao.publish( nKey, _plugin );
103 }
104
105 /**
106 * Unpublish all entries
107 */
108 public static void unpublishAllEntries ( )
109 {
110 _dao.unpublishAll( _plugin );
111 }
112
113 /**
114 * Returns an instance of a entry whose identifier is specified in parameter
115 * @param nKey The entry primary key
116 * @return an instance of Entry
117 */
118 public static Optional<Entry> findByPrimaryKey( int nKey )
119 {
120 return _dao.load( nKey, _plugin );
121 }
122
123 /**
124 * Returns an instance of a entry whose identifier is specified in parameter
125 * @param nKey The entry primary key
126 * @return an instance of Entry
127 */
128 public static Optional<Entry> findByLastVersion( )
129 {
130 return _dao.loadLastVersion( _plugin );
131 }
132
133 /**
134 * Returns an instance of a published entry
135 * @return an instance of published Entry
136 */
137 public static Optional<Entry> findPublishedEntry( )
138 {
139 return _dao.loadPublishedEntry( _plugin );
140 }
141
142 /**
143 * Load the data of all the entry objects and returns them as a list
144 * @return the list which contains the data of all the entry objects
145 */
146 public static List<Entry> getEntrysList( )
147 {
148 return _dao.selectEntrysList( _plugin );
149 }
150
151 /**
152 * Load the id of all the entry objects and returns them as a list
153 * @return the list which contains the id of all the entry objects
154 */
155 public static List<Integer> getIdEntrysList( )
156 {
157 return _dao.selectIdEntrysList( _plugin );
158 }
159
160 /**
161 * Load the data of all the entry objects and returns them as a referenceList
162 * @return the referenceList which contains the data of all the entry objects
163 */
164 public static ReferenceList getEntrysReferenceList( )
165 {
166 return _dao.selectEntrysReferenceList( _plugin );
167 }
168
169
170 /**
171 * Load the data of all the avant objects and returns them as a list
172 * @param listIds liste of ids
173 * @return the list which contains the data of all the avant objects
174 */
175 public static List<Entry> getEntrysListByIds( List<Integer> listIds )
176 {
177 return _dao.selectEntrysListByIds( _plugin, listIds );
178 }
179
180 }
181