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.htmldocs.service;
35
36 import fr.paris.lutece.plugins.htmldocs.business.HtmlDoc;
37 import fr.paris.lutece.plugins.htmldocs.business.HtmlDocFilter;
38 import fr.paris.lutece.plugins.htmldocs.business.HtmlDocHome;
39 import fr.paris.lutece.plugins.htmldocs.business.IndexerAction;
40 import fr.paris.lutece.plugins.htmldocs.business.portlet.HtmlDocPublication;
41 import fr.paris.lutece.plugins.htmldocs.business.portlet.HtmlDocPublicationHome;
42 import fr.paris.lutece.plugins.htmldocs.business.portlet.HtmldocsPortletHome;
43 import fr.paris.lutece.plugins.htmldocs.service.docsearch.HtmlDocSearchService;
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.List;
55 import java.util.Locale;
56
57
58
59
60
61 public class PublishingService
62 {
63 private static PublishingService _singleton = new PublishingService( );
64
65
66
67
68
69
70 public static PublishingService getInstance( )
71 {
72 return _singleton;
73 }
74
75
76
77
78
79
80
81 public void assign( int nDocumentId, int nPortletId )
82 {
83 HtmlDocPublication documentPublication = new HtmlDocPublication( );
84 documentPublication.setIdPortlet( nPortletId );
85 documentPublication.setIdDocument( nDocumentId );
86 HtmlDocPublicationHome.create( documentPublication );
87 }
88
89
90
91
92
93
94
95 public void publish( int nDocumentId, int nPortletId )
96 {
97
98 HtmlDocPublication documentPublication = HtmlDocPublicationHome.findDocPublicationByPimaryKey( nPortletId, nDocumentId );
99
100 if ( documentPublication != null )
101 {
102 documentPublication.setIdPortlet( nPortletId );
103 documentPublication.setIdDocument( nDocumentId );
104 HtmlDocPublicationHome.update( documentPublication );
105
106
107 }
108
109 HtmlDocSearchService.getInstance( ).addIndexerAction( nDocumentId, IndexerAction.TASK_MODIFY, HtmldocsPlugin.getPlugin() );
110
111 }
112
113
114
115
116
117
118
119
120 public void unAssign( int nDocumentId, int nPortletId )
121 {
122 HtmlDocPublicationHome.remove( nPortletId, nDocumentId );
123 }
124
125
126
127
128
129
130
131
132 public boolean isPublished( int nDocumentId, int nPortletId )
133 {
134 HtmlDocPublication documentPublication = HtmlDocPublicationHome.findDocPublicationByPimaryKey( nPortletId, nDocumentId );
135
136 return documentPublication != null ?true:false;
137 }
138
139
140
141
142
143
144
145 public boolean isAssigned( int nDocumentId )
146 {
147 Collection<HtmlDocPublication> listDocumentPublication = HtmlDocPublicationHome.getDocPublicationByIdDoc( nDocumentId );
148
149 return ( listDocumentPublication.size( ) > 0 );
150 }
151
152
153
154
155
156
157
158 public boolean isAssigned( int nDocumentId, int nPortletId )
159 {
160 HtmlDocPublication documentPublication = HtmlDocPublicationHome.findDocPublicationByPimaryKey( nPortletId, nDocumentId );
161
162 return ( documentPublication != null );
163 }
164
165
166
167
168
169
170
171 public HtmlDocPublication getDocumentPublication( int nPortletId, int nDocumentId )
172 {
173 return HtmlDocPublicationHome.findDocPublicationByPimaryKey( nPortletId, nDocumentId );
174 }
175
176
177
178
179
180
181 public Collection<Portlet> getHtmlDocsPortlets( )
182 {
183 Plugin plugin = PluginService.getPlugin( HtmldocsPlugin.PLUGIN_NAME );
184 Collection<Portlet> listPortletsAll = new ArrayList<Portlet>( );
185
186 for ( PortletType portletType : plugin.getPortletTypes( ) )
187 {
188 listPortletsAll.addAll( PortletHome.findByType( portletType.getId( ) ) );
189 }
190
191 return listPortletsAll;
192 }
193
194
195
196
197
198
199 public Collection<Portlet> getHtmlDocsPortletstoPublish( )
200 {
201 Plugin plugin = PluginService.getPlugin( HtmldocsPlugin.PLUGIN_NAME );
202 Collection<Portlet> listPortletsAll = new ArrayList<Portlet>( );
203
204 for ( PortletType portletType : plugin.getPortletTypes( ) )
205 {
206 List<Portlet> listPortlet=PortletHome.findByType( portletType.getId( ) );
207 String className = HtmldocsPortletHome.class.getName( );
208 String strPortletTypeId = PortletTypeHome.getPortletTypeId( className );
209
210 if(portletType.getId( ).equals(strPortletTypeId)){
211 for(Portlet pt:listPortlet){
212 if(HtmlDocPublicationHome.getDocPublicationByPortlet(pt.getId()).size( ) == 0){
213
214 listPortletsAll.addAll( listPortlet );
215 }
216
217 }
218
219 }else{
220
221 listPortletsAll.addAll( listPortlet );
222 }
223 }
224
225 return listPortletsAll;
226 }
227
228
229
230
231
232
233
234 public Collection<Portlet> getPortletsByDocumentId( String strDocumentId )
235 {
236 Collection<HtmlDocPublication> listDocumentPublication = HtmlDocPublicationHome.getDocPublicationByIdDoc( Integer.parseInt( strDocumentId ) );
237 Collection<Portlet> listPortlets = new ArrayList<Portlet>( );
238
239 for ( HtmlDocPublication documentPublication : listDocumentPublication )
240 {
241 listPortlets.add( PortletHome.findByPrimaryKey( documentPublication.getIdPortlet( ) ) );
242 }
243
244 return listPortlets;
245 }
246
247
248
249
250
251
252
253
254
255
256
257 public Collection<HtmlDoc> getPublishedDocumentsSinceDate( Date datePublishing, Date dateEndPublishing, HtmlDocFilter documentFilter,
258 Locale locale )
259 {
260 if ( datePublishing == null )
261 {
262 return null;
263 }
264
265 Collection<HtmlDocPublication> listDocumentPublication = HtmlDocPublicationHome.findSinceDatePublishingAndStatus( datePublishing,dateEndPublishing,
266 1 );
267
268 if ( ( listDocumentPublication == null ) || ( listDocumentPublication.size( ) == 0 ) )
269 {
270 return new ArrayList<HtmlDoc>( );
271 }
272
273 int[] arrayIds = new int[listDocumentPublication.size( )];
274 int i = 0;
275 HtmlDocFilter publishedDocumentFilter = documentFilter;
276
277 if ( publishedDocumentFilter == null )
278 {
279 publishedDocumentFilter = new HtmlDocFilter( );
280 }
281
282 for ( HtmlDocPublication documentPublication : listDocumentPublication )
283 {
284 arrayIds[i++] = documentPublication.getIdDocument( );
285 }
286
287 publishedDocumentFilter.setIds( arrayIds );
288
289 Collection<HtmlDoc> listDocuments = HtmlDocHome.findByFilter( publishedDocumentFilter, locale );
290
291 return listDocuments;
292 }
293
294
295
296
297
298
299
300
301
302 public static List<Integer> getPublishedDocumentsIdsListByPortletIds( int[] nPortletsIds, Date datePublishing, Date dateEndPublishing, Plugin plugin )
303 {
304 return HtmlDocPublicationHome.getPublishedDocumentsIdsListByPortletIds( nPortletsIds, datePublishing, dateEndPublishing, plugin );
305 }
306
307 }