1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.portal.business.portlet;
35
36 import fr.paris.lutece.portal.business.stylesheet.StyleSheet;
37 import fr.paris.lutece.portal.service.portlet.PortletEvent;
38 import fr.paris.lutece.portal.service.portlet.PortletEventListener;
39 import fr.paris.lutece.portal.service.spring.SpringContextService;
40 import fr.paris.lutece.portal.service.util.AppLogService;
41 import fr.paris.lutece.portal.service.util.AppPropertiesService;
42 import fr.paris.lutece.util.ReferenceList;
43
44 import java.util.Collection;
45 import java.util.List;
46
47
48
49
50 public abstract class PortletHome implements PortletHomeInterface
51 {
52 private static final String PROPERTY_PORTLET_CREATION_STATUS = "lutece.portlet.creation.status";
53 private static final int CONSTANT_DEFAULT_STATUS = Portlet.STATUS_PUBLISHED;
54
55
56 private static IPortletDAO _dao = SpringContextService.getBean( "portletDAO" );
57
58
59
60
61
62
63
64
65
66
67
68 public static Portlet findByPrimaryKey( int nKey )
69 {
70 Portlet portlet = _dao.load( nKey );
71 String strHomeClass = portlet.getHomeClassName( );
72 Portlet p = null;
73
74 try
75 {
76 PortletHomeInterface../../fr/paris/lutece/portal/business/portlet/PortletHomeInterface.html#PortletHomeInterface">PortletHomeInterface home = (PortletHomeInterface) Class.forName( strHomeClass ).newInstance( );
77 p = home.getDAO( ).load( nKey );
78 p.copy( portlet );
79 }
80 catch( IllegalAccessException | InstantiationException | ClassNotFoundException e )
81 {
82 AppLogService.error( e.getMessage( ), e );
83 }
84
85 return p;
86 }
87
88
89
90
91
92
93
94
95 public static List<Portlet> findByType( String strIdPortletType )
96 {
97 return _dao.selectPortletsByType( strIdPortletType );
98 }
99
100
101
102
103
104
105
106
107 public static Collection<PortletImpl> getPortletsListbyName( String strPortletName )
108 {
109 return _dao.selectPortletsListbyName( strPortletName );
110 }
111
112
113
114
115
116
117
118
119
120
121 static StyleSheet getXsl( int nIdPortlet, int nIdMode )
122 {
123 return _dao.selectXslFile( nIdPortlet, nIdMode );
124 }
125
126
127
128
129
130
131
132
133 public static ReferenceList getStylesList( String strIdPortletType )
134 {
135 return _dao.selectStylesList( strIdPortletType );
136 }
137
138
139
140
141
142
143
144
145 public static Collection<Portlet> getPortletsByRoleKey( String strRole )
146 {
147 return _dao.selectPortletsByRole( strRole );
148 }
149
150
151
152
153
154
155
156
157 public synchronized Portlet"../../../../../../fr/paris/lutece/portal/business/portlet/Portlet.html#Portlet">Portlet create( Portlet portlet )
158 {
159 portlet.setStatus( AppPropertiesService.getPropertyInt( PROPERTY_PORTLET_CREATION_STATUS, CONSTANT_DEFAULT_STATUS ) );
160
161
162 _dao.insert( portlet );
163
164
165 getDAO( ).insert( portlet );
166
167
168 invalidate( portlet );
169
170 return portlet;
171 }
172
173
174
175
176
177
178
179 public synchronized void remove( Portlet portlet )
180 {
181
182 getDAO( ).delete( portlet.getId( ) );
183
184
185 _dao.delete( portlet.getId( ) );
186
187
188 invalidate( portlet );
189 }
190
191
192
193
194
195
196
197 public void update( Portlet portlet )
198 {
199 getDAO( ).store( portlet );
200 _dao.store( portlet );
201
202
203 invalidate( portlet );
204 }
205
206
207
208
209
210
211
212 public static void invalidate( Portlet portlet )
213 {
214 PortletEventice/portlet/PortletEvent.html#PortletEvent">PortletEvent event = new PortletEvent( PortletEvent.INVALIDATE, portlet.getId( ), portlet.getPageId( ) );
215 notifyListeners( event );
216
217
218 Collection<Portlet> listAliases = getAliasList( portlet.getId( ) );
219
220 for ( Portlet alias : listAliases )
221 {
222 PortletEventortlet/PortletEvent.html#PortletEvent">PortletEvent eventAlias = new PortletEvent( PortletEvent.INVALIDATE, alias.getId( ), alias.getPageId( ) );
223 notifyListeners( eventAlias );
224 }
225 }
226
227
228
229
230
231
232
233 public static void invalidate( int nIdPortlet )
234 {
235 Portlet portlet = findByPrimaryKey( nIdPortlet );
236 if ( portlet != null )
237 {
238 invalidate( portlet );
239 }
240 }
241
242
243
244
245
246
247
248
249 public static boolean hasAlias( int nIdPortlet )
250 {
251 return _dao.hasAlias( nIdPortlet );
252 }
253
254
255
256
257
258
259
260
261
262 public static void updateStatus( Portlet portlet, int nStatus )
263 {
264
265 _dao.updateStatus( portlet, nStatus );
266
267
268 invalidate( portlet );
269 }
270
271
272
273
274
275
276
277
278 public static void updatePosition( Portlet portlet, int nColumn, int nOrder )
279 {
280
281 _dao.updatePosition( portlet, nColumn, nOrder );
282
283
284 invalidate( portlet );
285 }
286
287
288
289
290
291
292
293
294 public static PortletType getPortletType( String strPortletTypeId )
295 {
296 return _dao.selectPortletType( strPortletTypeId );
297 }
298
299
300
301
302
303
304
305
306 public static Collection<PortletImpl> getPortletListByStyle( int nStyleId )
307 {
308 return _dao.selectPortletListByStyle( nStyleId );
309 }
310
311
312
313
314
315
316
317
318 public static Collection<Portlet> getAliasList( int nPortletId )
319 {
320 return _dao.selectAliasesForPortlet( nPortletId );
321 }
322
323
324
325
326
327
328 public static Portlet getLastModifiedPortlet( )
329 {
330 return _dao.loadLastModifiedPortlet( );
331 }
332
333
334
335
336
337
338
339 public static void notifyListeners( PortletEvent event )
340 {
341 for ( PortletEventListener listener : SpringContextService.getBeansOfType( PortletEventListener.class ) )
342 {
343 listener.processPortletEvent( event );
344 }
345 }
346
347
348
349
350
351
352
353
354
355
356 public static List<Integer> getUsedOrdersForColumns( int pageId, int columnId )
357 {
358 return _dao.getUsedOrdersForColumns( pageId, columnId );
359 }
360 }