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.plugins.blog.service;
35
36 import fr.paris.lutece.plugins.blog.business.Blog;
37 import fr.paris.lutece.plugins.blog.business.BlogFilter;
38 import fr.paris.lutece.plugins.blog.business.BlogHome;
39 import fr.paris.lutece.plugins.blog.business.IndexerAction;
40 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublication;
41 import fr.paris.lutece.plugins.blog.business.portlet.BlogPublicationHome;
42 import fr.paris.lutece.plugins.blog.business.portlet.BlogPortletHome;
43 import fr.paris.lutece.plugins.blog.service.docsearch.BlogSearchService;
44 import fr.paris.lutece.portal.business.portlet.Portlet;
45 import fr.paris.lutece.portal.business.portlet.PortletHome;
46 import fr.paris.lutece.portal.business.portlet.PortletType;
47 import fr.paris.lutece.portal.business.portlet.PortletTypeHome;
48 import fr.paris.lutece.portal.service.plugin.Plugin;
49 import fr.paris.lutece.portal.service.plugin.PluginService;
50
51 import java.util.ArrayList;
52 import java.util.Collection;
53 import java.util.Date;
54 import java.util.HashSet;
55 import java.util.List;
56 import java.util.Locale;
57 import java.util.Set;
58
59 import org.apache.commons.collections.CollectionUtils;
60
61
62
63
64 public class PublishingService
65 {
66 private static PublishingServicePublishingService.html#PublishingService">PublishingService _singleton = new PublishingService( );
67
68
69
70
71
72
73 public static PublishingService getInstance( )
74 {
75 return _singleton;
76 }
77
78
79
80
81
82
83
84
85
86 public void assign( int nBlogId, int nPortletId )
87 {
88 BlogPublicationrtlet/BlogPublication.html#BlogPublication">BlogPublication blogPublication = new BlogPublication( );
89 blogPublication.setIdPortlet( nPortletId );
90 blogPublication.setIdBlog( nBlogId );
91 BlogPublicationHome.create( blogPublication );
92 }
93
94
95
96
97
98
99
100
101
102 public void publish( int nBlogId, int nPortletId )
103 {
104
105 BlogPublication blogPublication = BlogPublicationHome.findDocPublicationByPimaryKey( nPortletId, nBlogId );
106
107 if ( blogPublication != null )
108 {
109 blogPublication.setIdPortlet( nPortletId );
110 blogPublication.setIdBlog( nBlogId );
111 BlogPublicationHome.update( blogPublication );
112
113 }
114
115 BlogSearchService.getInstance( ).addIndexerAction( nBlogId, IndexerAction.TASK_MODIFY );
116
117 }
118
119
120
121
122
123
124
125
126
127 public void unAssign( int nBlogId, int nPortletId )
128 {
129 BlogPublicationHome.remove( nPortletId, nBlogId );
130 }
131
132
133
134
135
136
137
138
139
140
141 public boolean isPublished( int nBlogId, int nPortletId )
142 {
143 BlogPublication blogPublication = BlogPublicationHome.findDocPublicationByPimaryKey( nPortletId, nBlogId );
144
145 return blogPublication != null;
146 }
147
148
149
150
151
152
153
154
155 public boolean isAssigned( int nBlogId )
156 {
157 Collection<BlogPublication> listBlogPublication = BlogPublicationHome.getDocPublicationByIdDoc( nBlogId );
158 return CollectionUtils.isNotEmpty( listBlogPublication );
159 }
160
161
162
163
164
165
166
167
168
169
170 public boolean isAssigned( int nBlogId, int nPortletId )
171 {
172 BlogPublication blogPublication = BlogPublicationHome.findDocPublicationByPimaryKey( nPortletId, nBlogId );
173
174 return ( blogPublication != null );
175 }
176
177
178
179
180
181
182
183
184
185
186 public BlogPublication getBlogPublication( int nPortletId, int nBlogId )
187 {
188 return BlogPublicationHome.findDocPublicationByPimaryKey( nPortletId, nBlogId );
189 }
190
191
192
193
194
195
196 public Collection<Portlet> getBlogsPortlets( )
197 {
198 Plugin plugin = PluginService.getPlugin( BlogPlugin.PLUGIN_NAME );
199 Collection<Portlet> listPortletsAll = new ArrayList<>( );
200
201 for ( PortletType portletType : plugin.getPortletTypes( ) )
202 {
203 listPortletsAll.addAll( PortletHome.findByType( portletType.getId( ) ) );
204 }
205
206 return listPortletsAll;
207 }
208
209
210
211
212
213
214 public Collection<Portlet> getBlogsPortletstoPublish( )
215 {
216 Plugin plugin = PluginService.getPlugin( BlogPlugin.PLUGIN_NAME );
217 Collection<Portlet> listPortletsAll = new ArrayList<>( );
218
219 for ( PortletType portletType : plugin.getPortletTypes( ) )
220 {
221 List<Portlet> listPortlet = PortletHome.findByType( portletType.getId( ) );
222 String className = BlogPortletHome.class.getName( );
223 String strPortletTypeId = PortletTypeHome.getPortletTypeId( className );
224
225 if ( portletType.getId( ).equals( strPortletTypeId ) )
226 {
227 for ( Portlet pt : listPortlet )
228 {
229 if ( CollectionUtils.isEmpty( BlogPublicationHome.getDocPublicationByPortlet( pt.getId( ) ) ) )
230 {
231
232 listPortletsAll.addAll( listPortlet );
233 }
234
235 }
236
237 }
238 else
239 {
240
241 listPortletsAll.addAll( listPortlet );
242 }
243 }
244
245 return listPortletsAll;
246 }
247
248
249
250
251
252
253
254
255 public Collection<Portlet> getPortletsByBlogId( String strBlogId )
256 {
257 Collection<BlogPublication> listBlogPublication = BlogPublicationHome.getDocPublicationByIdDoc( Integer.parseInt( strBlogId ) );
258 Collection<Portlet> listPortlets = new ArrayList<>( );
259
260 for ( BlogPublication blogPublication : listBlogPublication )
261 {
262 listPortlets.add( PortletHome.findByPrimaryKey( blogPublication.getIdPortlet( ) ) );
263 }
264
265 return listPortlets;
266 }
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282 public Collection<Blog> getPublishedBlogsSinceDate( Date datePublishing, Date dateEndPublishing, BlogFilter blogFilter, Locale locale )
283 {
284 if ( datePublishing == null )
285 {
286 return null;
287 }
288
289 Collection<BlogPublication> listBlogPublication = BlogPublicationHome.findSinceDatePublishingAndStatus( datePublishing, dateEndPublishing, 1 );
290
291 if ( CollectionUtils.isEmpty( listBlogPublication ) )
292 {
293 return new ArrayList<>( );
294 }
295
296 Set<Integer> sIds = new HashSet<>( );
297 BlogFilter publishedBlogFilter = blogFilter;
298
299 if ( publishedBlogFilter == null )
300 {
301 publishedBlogFilter = new BlogFilter( );
302 }
303
304 for ( BlogPublication blogPublication : listBlogPublication )
305 {
306 sIds.add( blogPublication.getIdBlog( ) );
307 }
308
309 publishedBlogFilter.setIds( sIds.toArray( new Integer [ sIds.size( )] ) );
310
311 return BlogHome.findByFilter( publishedBlogFilter );
312 }
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327 public static List<Integer> getPublishedBlogsIdsListByPortletIds( int [ ] nPortletsIds, Date datePublishing, Date dateEndPublishing, Plugin plugin )
328 {
329 return BlogPublicationHome.getPublishedBlogsIdsListByPortletIds( nPortletsIds, datePublishing, dateEndPublishing, plugin );
330 }
331
332
333
334
335
336
337
338
339
340
341
342
343 public static List<Integer> getLastPublishedBlogsIdsListByPortletIds( int [ ] nPortletsIds, Date dateUpdated, Plugin plugin )
344 {
345 return BlogPublicationHome.getLastPublishedDocumentsIdsListByPortletIds( nPortletsIds, dateUpdated, plugin );
346 }
347
348 }