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.directory.business.rss;
35
36 import fr.paris.lutece.plugins.directory.business.Directory;
37 import fr.paris.lutece.plugins.directory.business.DirectoryHome;
38 import fr.paris.lutece.plugins.directory.business.EntryFilter;
39 import fr.paris.lutece.plugins.directory.business.EntryHome;
40 import fr.paris.lutece.plugins.directory.business.Field;
41 import fr.paris.lutece.plugins.directory.business.FieldHome;
42 import fr.paris.lutece.plugins.directory.business.IEntry;
43 import fr.paris.lutece.plugins.directory.business.Record;
44 import fr.paris.lutece.plugins.directory.business.RecordField;
45 import fr.paris.lutece.plugins.directory.business.RecordFieldFilter;
46 import fr.paris.lutece.plugins.directory.business.RecordFieldHome;
47 import fr.paris.lutece.plugins.directory.service.DirectoryPlugin;
48 import fr.paris.lutece.plugins.directory.service.directorysearch.DirectorySearchService;
49 import fr.paris.lutece.plugins.directory.service.record.IRecordService;
50 import fr.paris.lutece.plugins.directory.service.record.RecordService;
51 import fr.paris.lutece.plugins.directory.utils.DirectoryUtils;
52 import fr.paris.lutece.plugins.workflowcore.business.state.State;
53 import fr.paris.lutece.portal.business.rss.FeedResource;
54 import fr.paris.lutece.portal.business.rss.FeedResourceImage;
55 import fr.paris.lutece.portal.business.rss.FeedResourceItem;
56 import fr.paris.lutece.portal.business.rss.IFeedResource;
57 import fr.paris.lutece.portal.business.rss.IFeedResourceImage;
58 import fr.paris.lutece.portal.business.rss.IFeedResourceItem;
59 import fr.paris.lutece.portal.business.rss.ResourceRss;
60 import fr.paris.lutece.portal.service.admin.AdminUserService;
61 import fr.paris.lutece.portal.service.i18n.I18nService;
62 import fr.paris.lutece.portal.service.message.AdminMessage;
63 import fr.paris.lutece.portal.service.message.AdminMessageService;
64 import fr.paris.lutece.portal.service.plugin.Plugin;
65 import fr.paris.lutece.portal.service.plugin.PluginService;
66 import fr.paris.lutece.portal.service.spring.SpringContextService;
67 import fr.paris.lutece.portal.service.template.AppTemplateService;
68 import fr.paris.lutece.portal.service.util.AppPropertiesService;
69 import fr.paris.lutece.portal.service.workflow.WorkflowService;
70 import fr.paris.lutece.util.ReferenceItem;
71 import fr.paris.lutece.util.ReferenceList;
72 import fr.paris.lutece.util.html.HtmlTemplate;
73 import fr.paris.lutece.util.url.UrlItem;
74
75 import java.util.ArrayList;
76 import java.util.Collection;
77 import java.util.HashMap;
78 import java.util.List;
79 import java.util.Locale;
80 import java.util.Map;
81
82 import javax.servlet.http.HttpServletRequest;
83
84
85
86
87
88 public class DirectoryResourceRss extends ResourceRss
89 {
90 public static final String PROPERTY_RSS_STORAGE_FOLDER_PATH = "rss.storage.folder.path";
91 public static final String PROPERTY_STORAGE_DIRECTORY_NAME = "rss.storage.directory.name";
92
93
94 private static final String TEMPLATE_TASK_EVALUATION_CREATE_CONFIG = "admin/plugins/directory/rss/resource_create_config.html";
95 private static final String TEMPLATE_TASK_EVALUATION_MODIFY_CONFIG = "admin/plugins/directory/rss/resource_modify_config.html";
96 private static final String TEMPLATE_RSS_IMAGE = "admin/plugins/directory/rss/rss_image.html";
97
98
99 private static final String MARK_DIRECTORY_LIST = "directory_list";
100 private static final String MARK_DIRECTORY_LIST_DEFAULT_ITEM = "directory_list_default_item";
101 private static final String MARK_RSS_SITE_ID_DIRECTORY = "id_directory";
102 private static final String MARK_RSS_SITE_ID_RECORD = "id_record";
103 private static final String MARK_ENTRY_LIST = "entry_list";
104 private static final String MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM = "entry_list_title_default_item";
105 private static final String MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM = "entry_list_description_default_item";
106 private static final String MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM = "entry_list_image_default_item";
107 private static final String MARK_ENTRY_LIST_LINK_DEFAULT_ITEM = "entry_list_link_default_item";
108 private static final String MARK_ENTRY_LIST_IMAGE = "entry_list_image";
109 private static final String MARK_ENTRY_LIST_FILTER = "entry_list_filter";
110 private static final String MARK_ENTRY_LIST_LINK = "entry_list_link";
111 private static final String MARK_ENTRY_FILTER_1 = "entry_filter_1";
112 private static final String MARK_ENTRY_FILTER_2 = "entry_filter_2";
113 private static final String MARK_WORKFLOW_STATE_LIST = "workflow_state_list";
114 private static final String MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM = "workflow_state_list_default_item";
115 private static final String MARK_RSS_SITE_TITLE = "entry_title";
116 private static final String MARK_RSS_SITE_DESCRIPTION_ITEM = "entry_description";
117 private static final String MARK_RSS_SITE_LINK_ITEM = "entry_link";
118 private static final String MARK_RSS_SITE_IMAGE_ITEM = "entry_image";
119 private static final String MARK_RSS_SITE_DATE = "date";
120 private static final String MARK_RSS_SITE_DATE_MODIFICATION = "date_modification";
121 private static final String MARK_LOCALE = "locale";
122 private static final String MARK_RECORD_FIELD_FILTER_1 = "recordField_filter_1";
123 private static final String MARK_RECORD_FIELD_FILTER_2 = "recordField_filter_2";
124 private static final String MARK_RSS_SITE_IMAGE_HEIGHT_ITEM = "entry_image_height";
125 private static final String MARK_RSS_SITE_IMAGE_WIDTH_ITEM = "entry_image_width";
126
127
128 private static final String PARAMETER_ID_DIRECTORY = "id_directory";
129 private static final String PARAMETER_ID_ENTRY_TITLE = "id_entry_title";
130 private static final String PARAMETER_ID_ENTRY_DESCRIPTION = "id_entry_description";
131 private static final String PARAMETER_ID_WORKFLOW_STATE = "id_workflow_state";
132 private static final String PARAMETER_ID_ENTRY_IMAGE = "id_entry_image";
133 private static final String PARAMETER_ID_ENTRY_LINK = "id_entry_link";
134 private static final String PARAMETER_ID_ENTRY_FILTER_1 = "id_entry_filter_1";
135 private static final String PARAMETER_ID_ENTRY_FILTER_2 = "id_entry_filter_2";
136 private static final String PARAMETER_PAGE = "page";
137 private static final String PARAMETER_ID_DIRECTORY_RECORD = "id_directory_record";
138 private static final String PARAMETER_VIEW_DIRECTORY_RECORD = "view_directory_record";
139
140
141 private static final String FIELD_ID_DIRECTORY = "directory.resource_rss.label_directory";
142 private static final String FIELD_ID_ENTRY_TITLE = "directory.resource_rss.label_entry_title";
143 private static final String FIELD_ID_ENTRY_DESCRIPTION = "directory.resource_rss.label_entry_description";
144
145
146 private static final String MESSAGE_MANDATORY_FIELD = "directory.message.mandatory.field";
147 private static final String MESSAGE_NO_REFRESH = "directory.message.no_refresh";
148 private static final String MESSAGE_NO_REFRESH_FILTER = "directory.message.no_refresh_filter";
149 private static final String TEMPLATE_PUSH_RSS_XML = "admin/plugins/directory/rss/rss_xml.html";
150 private static final String MARK_ITEM_LIST = "itemList";
151 private static final String MARK_RSS_SITE_NAME = "site_name";
152 private static final String MARK_RSS_FILE_LANGUAGE = "file_language";
153 private static final String MARK_RSS_SITE_URL = "site_url";
154 private static final String MARK_RSS_SITE_DESCRIPTION = "site_description";
155 private static final String PROPERTY_SITE_LANGUAGE = "rss.language";
156 private static final String PROPERTY_WEBAPP_PROD_URL = "lutece.prod.url";
157 private static final String PROPERTY_ACCEPT_DIRECTORY_TYPE = "directory.resource_rss.entry_accept";
158 private static final String PROPERTY_ACCEPT_DIRECTORY_TYPE_FOR_LINK = "directory.resource_rss.entry_accept_for_link";
159 private static final String PROPERTY_ENTRY_DIRECTORY_TYPE_IMAGE = "directory.resource_rss.entry_type_image";
160 private static final String CONSTANT_DIRECTORY = "directory";
161 private static final String ID = "id";
162 private static final String NAME = "name";
163 private static final String EMPTY_STRING = "";
164
165
166
167
168 @Override
169 public boolean contentResourceRss( )
170 {
171 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
172
173 if ( DirectoryHome.getDirectoryList( pluginDirectory ) != null )
174 {
175 return true;
176 }
177
178 return false;
179 }
180
181
182
183
184 @Override
185 public void doSaveConfig( HttpServletRequest request, Locale locale )
186 {
187 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
188
189 String idDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
190 String idEntryDescription = request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION );
191 String idEntryTitle = request.getParameter( PARAMETER_ID_ENTRY_TITLE );
192 String idWorkflowState = request.getParameter( PARAMETER_ID_WORKFLOW_STATE );
193 String idEntryImage = request.getParameter( PARAMETER_ID_ENTRY_IMAGE );
194 String idEntryLink = request.getParameter( PARAMETER_ID_ENTRY_LINK );
195 String idEntryFilter1 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 );
196 String idEntryFilter2 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 );
197 String strValueFilter1 = request.getParameter( idEntryFilter1 );
198 String strValueFilter2 = request.getParameter( idEntryFilter2 );
199
200 DirectoryResourceRssConfig config = new DirectoryResourceRssConfig( );
201 config.setIdRss( this.getId( ) );
202 config.setIdDirectory( DirectoryUtils.convertStringToInt( idDirectory ) );
203 config.setIdEntryTitle( DirectoryUtils.convertStringToInt( idEntryTitle ) );
204 config.setIdEntryDescription( DirectoryUtils.convertStringToInt( idEntryDescription ) );
205 config.setIdEntryImage( DirectoryUtils.convertStringToInt( idEntryImage ) );
206 config.setIdEntryLink( DirectoryUtils.convertStringToInt( idEntryLink ) );
207 config.setIdEntryFilter1( DirectoryUtils.convertStringToInt( idEntryFilter1 ) );
208 config.setIdEntryFilter2( DirectoryUtils.convertStringToInt( idEntryFilter2 ) );
209 config.setValueFilter1( strValueFilter1 );
210 config.setValueFilter2( strValueFilter2 );
211 config.setIdWorkflowState( DirectoryUtils.convertStringToInt( idWorkflowState ) );
212
213 DirectoryResourceRssConfigHome.create( config, pluginDirectory );
214 }
215
216
217
218
219 @Override
220 public void doUpdateConfig( HttpServletRequest request, Locale locale )
221 {
222 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
223
224 String idDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
225 String idEntryDescription = request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION );
226 String idEntryTitle = request.getParameter( PARAMETER_ID_ENTRY_TITLE );
227 String idWorkflowState = request.getParameter( PARAMETER_ID_WORKFLOW_STATE );
228 String idEntryImage = request.getParameter( PARAMETER_ID_ENTRY_IMAGE );
229 String idEntryLink = request.getParameter( PARAMETER_ID_ENTRY_LINK );
230 String idEntryFilter1 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 );
231 String idEntryFilter2 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 );
232 String strValueFilter1 = request.getParameter( idEntryFilter1 );
233 String strValueFilter2 = request.getParameter( idEntryFilter2 );
234
235 DirectoryResourceRssConfig config = new DirectoryResourceRssConfig( );
236 config.setIdRss( this.getId( ) );
237 config.setIdDirectory( DirectoryUtils.convertStringToInt( idDirectory ) );
238 config.setIdEntryTitle( DirectoryUtils.convertStringToInt( idEntryTitle ) );
239 config.setIdEntryDescription( DirectoryUtils.convertStringToInt( idEntryDescription ) );
240 config.setIdEntryImage( DirectoryUtils.convertStringToInt( idEntryImage ) );
241 config.setIdEntryLink( DirectoryUtils.convertStringToInt( idEntryLink ) );
242 config.setIdEntryFilter1( DirectoryUtils.convertStringToInt( idEntryFilter1 ) );
243 config.setIdEntryFilter2( DirectoryUtils.convertStringToInt( idEntryFilter2 ) );
244 config.setValueFilter1( strValueFilter1 );
245 config.setValueFilter2( strValueFilter2 );
246 config.setIdWorkflowState( DirectoryUtils.convertStringToInt( idWorkflowState ) );
247
248 DirectoryResourceRssConfigHome.update( config, pluginDirectory );
249 }
250
251
252
253
254 @Override
255 public String doValidateConfigForm( HttpServletRequest request, Locale locale )
256 {
257 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
258 String strError = DirectoryUtils.EMPTY_STRING;
259 String idDirectory = request.getParameter( PARAMETER_ID_DIRECTORY );
260 String idEntryDescription = request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION );
261 String idEntryTitle = request.getParameter( PARAMETER_ID_ENTRY_TITLE );
262 String idEntryFilter1 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 );
263 String idEntryFilter2 = request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 );
264
265 if ( idDirectory == null )
266 {
267 strError = FIELD_ID_DIRECTORY;
268 }
269 else
270 if ( idEntryTitle == null )
271 {
272 strError = FIELD_ID_ENTRY_TITLE;
273 }
274 else
275 if ( idEntryDescription == null )
276 {
277 strError = FIELD_ID_ENTRY_DESCRIPTION;
278 }
279
280 if ( !strError.equals( DirectoryUtils.EMPTY_STRING ) )
281 {
282 Object [ ] tabRequiredFields = {
283 I18nService.getLocalizedString( strError, locale )
284 };
285
286 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
287 }
288
289 IEntry entryTitle = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( idEntryTitle ), pluginDirectory );
290 IEntry entryDescription = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( idEntryDescription ), pluginDirectory );
291
292 if ( ( entryTitle != null ) && ( entryDescription != null )
293 && ( entryTitle.getDirectory( ).getIdDirectory( ) != DirectoryUtils.convertStringToInt( idDirectory ) ) )
294 {
295 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_REFRESH, AdminMessage.TYPE_STOP );
296 }
297 else
298 if ( entryDescription.getDirectory( ).getIdDirectory( ) != DirectoryUtils.convertStringToInt( idDirectory ) )
299 {
300 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_REFRESH, AdminMessage.TYPE_STOP );
301 }
302 else
303 if ( ( DirectoryUtils.convertStringToInt( idEntryFilter1 ) != DirectoryUtils.CONSTANT_ID_NULL )
304 && ( request.getParameter( idEntryFilter1 ) == null ) )
305 {
306 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_REFRESH_FILTER, AdminMessage.TYPE_STOP );
307 }
308 else
309 if ( ( DirectoryUtils.convertStringToInt( idEntryFilter2 ) != DirectoryUtils.CONSTANT_ID_NULL )
310 && ( request.getParameter( idEntryFilter2 ) == null ) )
311 {
312 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_REFRESH_FILTER, AdminMessage.TYPE_STOP );
313 }
314
315 Directory directory = DirectoryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( idDirectory ), pluginDirectory );
316 this.setName( directory.getTitle( ) );
317 this.setDescription( directory.getDescription( ) );
318
319 return null;
320 }
321
322
323
324
325 @Override
326 public String getDisplayCreateConfigForm( HttpServletRequest request, Locale locale )
327 {
328 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
329 ReferenceList directoryList = DirectoryHome.getDirectoryList( pluginDirectory );
330 HashMap<String, Object> model = new HashMap<String, Object>( );
331
332 String strEntryTypeImage = AppPropertiesService.getProperty( PROPERTY_ENTRY_DIRECTORY_TYPE_IMAGE );
333 int entryTypeImage = DirectoryUtils.convertStringToInt( strEntryTypeImage );
334 String strAcceptEntryType = AppPropertiesService.getProperty( PROPERTY_ACCEPT_DIRECTORY_TYPE );
335 String [ ] strTabAcceptEntryType = strAcceptEntryType.split( "," );
336 String strAcceptEntryTypeForLink = AppPropertiesService.getProperty( PROPERTY_ACCEPT_DIRECTORY_TYPE_FOR_LINK );
337 String [ ] strTabAcceptEntryTypeForLink = strAcceptEntryTypeForLink.split( "," );
338
339 int nIdDirectory = -1;
340
341 if ( request.getParameter( PARAMETER_ID_DIRECTORY ) != null )
342 {
343 nIdDirectory = DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_DIRECTORY ) );
344 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_IMAGE ) ) );
345 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_TITLE ) ) );
346 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION ) ) );
347 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_LINK ) ) );
348 model.put( MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_WORKFLOW_STATE ) ) );
349 }
350 else
351 if ( !directoryList.isEmpty( ) && ( directoryList.get( 0 ) != null ) )
352 {
353 nIdDirectory = DirectoryUtils.convertStringToInt( directoryList.get( 0 ).getCode( ) );
354 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
355 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
356 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
357 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
358 model.put( MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
359 }
360
361 if ( nIdDirectory != DirectoryUtils.CONSTANT_ID_NULL )
362 {
363 ReferenceList referenceEntryLink = new ReferenceList( );
364 ReferenceList referenceEntryImage = new ReferenceList( );
365 ReferenceList referenceEntry = new ReferenceList( );
366 ReferenceList referenceEntryFilter = new ReferenceList( );
367 EntryFilter filter = new EntryFilter( );
368 filter.setIdDirectory( nIdDirectory );
369 model.put( MARK_DIRECTORY_LIST_DEFAULT_ITEM, String.valueOf( nIdDirectory ) );
370
371 List<IEntry> entryList = EntryHome.getEntryList( filter, pluginDirectory );
372
373 for ( IEntry entry : entryList )
374 {
375 for ( int i = 0; i < strTabAcceptEntryType.length; i++ )
376 {
377 if ( entry.getEntryType( ).getIdType( ) == Integer.parseInt( strTabAcceptEntryType [i] ) )
378 {
379 if ( entry.isMandatory( ) )
380 {
381 referenceEntry.addItem( entry.getIdEntry( ), entry.getTitle( ) );
382 }
383
384 referenceEntryFilter.addItem( entry.getIdEntry( ), entry.getTitle( ) );
385 }
386 }
387
388 for ( int i = 0; i < strTabAcceptEntryTypeForLink.length; i++ )
389 {
390 if ( entry.getEntryType( ).getIdType( ) == Integer.parseInt( strTabAcceptEntryTypeForLink [i] ) )
391 {
392 referenceEntryLink.addItem( entry.getIdEntry( ), entry.getTitle( ) );
393 }
394 }
395
396 if ( entry.getEntryType( ).getIdType( ) == entryTypeImage )
397 {
398 referenceEntryImage.addItem( entry.getIdEntry( ), entry.getTitle( ) );
399 }
400 }
401
402 if ( !referenceEntryLink.isEmpty( ) )
403 {
404 referenceEntryLink.addItem( -1, "" );
405 model.put( MARK_ENTRY_LIST_LINK, referenceEntryLink );
406 }
407
408 if ( !referenceEntryImage.isEmpty( ) )
409 {
410 referenceEntryImage.addItem( -1, "" );
411 model.put( MARK_ENTRY_LIST_IMAGE, referenceEntryImage );
412 }
413
414 if ( !referenceEntryFilter.isEmpty( ) )
415 {
416 referenceEntryFilter.addItem( -1, "" );
417 model.put( MARK_ENTRY_LIST_FILTER, referenceEntryFilter );
418 model.put( MARK_LOCALE, locale );
419
420 if ( request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 ) != null )
421 {
422 IEntry entry = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 ) ),
423 pluginDirectory );
424 model.put( MARK_ENTRY_FILTER_1, entry );
425 }
426
427 if ( request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 ) != null )
428 {
429 IEntry entry = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 ) ),
430 pluginDirectory );
431 model.put( MARK_ENTRY_FILTER_2, entry );
432 }
433 }
434
435 model.put( MARK_ENTRY_LIST, referenceEntry );
436
437 Directory directory = DirectoryHome.findByPrimaryKey( nIdDirectory, pluginDirectory );
438
439 if ( WorkflowService.getInstance( ).isAvailable( ) && ( directory != null ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) )
440 {
441 Collection<State> listState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ),
442 AdminUserService.getAdminUser( request ) );
443 ReferenceList referenceListState = ReferenceList.convert( listState, ID, NAME, true );
444 referenceListState.addItem( -1, "" );
445 model.put( MARK_WORKFLOW_STATE_LIST, referenceListState );
446 }
447 }
448 else
449 {
450 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
451 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
452 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
453 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
454 model.put( MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
455 model.put( MARK_DIRECTORY_LIST_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
456 model.put( MARK_ENTRY_LIST, new ArrayList<ReferenceItem>( ) );
457 }
458
459 model.put( MARK_DIRECTORY_LIST, directoryList );
460
461 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_EVALUATION_CREATE_CONFIG, locale, model );
462
463 return template.getHtml( );
464 }
465
466
467
468
469 @Override
470 public String getDisplayModifyConfigForm( HttpServletRequest request, Locale locale )
471 {
472 String strEntryTypeImage = AppPropertiesService.getProperty( PROPERTY_ENTRY_DIRECTORY_TYPE_IMAGE );
473 int entryTypeImage = DirectoryUtils.convertStringToInt( strEntryTypeImage );
474
475 String strAcceptEntryType = AppPropertiesService.getProperty( PROPERTY_ACCEPT_DIRECTORY_TYPE );
476 String [ ] strTabAcceptEntryType = strAcceptEntryType.split( "," );
477
478 String strAcceptEntryTypeForLink = AppPropertiesService.getProperty( PROPERTY_ACCEPT_DIRECTORY_TYPE_FOR_LINK );
479 String [ ] strTabAcceptEntryTypeForLink = strAcceptEntryTypeForLink.split( "," );
480
481 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
482 ReferenceList directoryList = DirectoryHome.getDirectoryList( pluginDirectory );
483
484 DirectoryResourceRssConfig directoryResourceRssConfig = DirectoryResourceRssConfigHome.findByPrimaryKey( this.getId( ), pluginDirectory );
485 HashMap<String, Object> model = new HashMap<String, Object>( );
486
487 ReferenceList referenceEntryImage = new ReferenceList( );
488 ReferenceList referenceEntry = new ReferenceList( );
489 ReferenceList referenceEntryLink = new ReferenceList( );
490 ReferenceList referenceEntryFilter = new ReferenceList( );
491 EntryFilter filter = new EntryFilter( );
492
493 if ( request.getParameter( PARAMETER_ID_DIRECTORY ) != null )
494 {
495 int idDirectory = DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_DIRECTORY ) );
496 filter.setIdDirectory( idDirectory );
497 model.put( MARK_DIRECTORY_LIST_DEFAULT_ITEM, idDirectory );
498
499 Directory directory = DirectoryHome.findByPrimaryKey( idDirectory, pluginDirectory );
500
501 if ( WorkflowService.getInstance( ).isAvailable( ) && ( directory != null ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) )
502 {
503 Collection<State> listState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ),
504 AdminUserService.getAdminUser( request ) );
505 ReferenceList referenceListState = ReferenceList.convert( listState, ID, NAME, true );
506 referenceListState.addItem( -1, "" );
507 model.put( MARK_WORKFLOW_STATE_LIST, referenceListState );
508 }
509 }
510 else
511 {
512 Directory directory = DirectoryHome.findByPrimaryKey( directoryResourceRssConfig.getIdDirectory( ), pluginDirectory );
513 filter.setIdDirectory( directory.getIdDirectory( ) );
514 model.put( MARK_DIRECTORY_LIST_DEFAULT_ITEM, directoryResourceRssConfig.getIdDirectory( ) );
515
516 if ( WorkflowService.getInstance( ).isAvailable( ) && ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) )
517 {
518 Collection<State> listState = WorkflowService.getInstance( ).getAllStateByWorkflow( directory.getIdWorkflow( ),
519 AdminUserService.getAdminUser( request ) );
520 ReferenceList referenceListState = ReferenceList.convert( listState, ID, NAME, true );
521 referenceListState.addItem( -1, "" );
522 model.put( MARK_WORKFLOW_STATE_LIST, referenceListState );
523 }
524 }
525
526 List<IEntry> entryList = EntryHome.getEntryList( filter, pluginDirectory );
527
528 for ( IEntry entry : entryList )
529 {
530 for ( int i = 0; i < strTabAcceptEntryType.length; i++ )
531 {
532 if ( entry.getEntryType( ).getIdType( ) == Integer.parseInt( strTabAcceptEntryType [i] ) )
533 {
534 if ( entry.isMandatory( ) )
535 {
536 referenceEntry.addItem( entry.getIdEntry( ), entry.getTitle( ) );
537 }
538
539 referenceEntryFilter.addItem( entry.getIdEntry( ), entry.getTitle( ) );
540 }
541 }
542
543 for ( int i = 0; i < strTabAcceptEntryTypeForLink.length; i++ )
544 {
545 if ( entry.getEntryType( ).getIdType( ) == Integer.parseInt( strTabAcceptEntryTypeForLink [i] ) )
546 {
547 referenceEntryLink.addItem( entry.getIdEntry( ), entry.getTitle( ) );
548 }
549 }
550
551 if ( entry.getEntryType( ).getIdType( ) == entryTypeImage )
552 {
553 referenceEntryImage.addItem( entry.getIdEntry( ), entry.getTitle( ) );
554 }
555 }
556
557 if ( !referenceEntryLink.isEmpty( ) )
558 {
559 referenceEntryLink.addItem( -1, "" );
560 model.put( MARK_ENTRY_LIST_LINK, referenceEntryLink );
561 }
562
563 if ( !referenceEntryImage.isEmpty( ) )
564 {
565 referenceEntryImage.addItem( -1, "" );
566 model.put( MARK_ENTRY_LIST_IMAGE, referenceEntryImage );
567 }
568
569 if ( !referenceEntryFilter.isEmpty( ) )
570 {
571 referenceEntryFilter.addItem( -1, "" );
572 model.put( MARK_ENTRY_LIST_FILTER, referenceEntryFilter );
573 model.put( MARK_LOCALE, locale );
574 }
575
576 if ( request.getParameter( PARAMETER_ID_DIRECTORY ) != null )
577 {
578 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_IMAGE ) ) );
579 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_TITLE ) ) );
580 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION ) ) );
581 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_LINK ) ) );
582 model.put( MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM, DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_WORKFLOW_STATE ) ) );
583
584 if ( request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 ) != null )
585 {
586 IEntry entry = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 ) ),
587 pluginDirectory );
588 model.put( MARK_ENTRY_FILTER_1, entry );
589 }
590
591 if ( request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 ) != null )
592 {
593 IEntry entry = EntryHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 ) ),
594 pluginDirectory );
595 model.put( MARK_ENTRY_FILTER_2, entry );
596 }
597 }
598 else
599 if ( directoryResourceRssConfig != null )
600 {
601 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, directoryResourceRssConfig.getIdEntryImage( ) );
602 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, directoryResourceRssConfig.getIdEntryTitle( ) );
603 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, directoryResourceRssConfig.getIdEntryDescription( ) );
604 model.put( MARK_WORKFLOW_STATE_LIST_DEFAULT_ITEM, directoryResourceRssConfig.getIdWorkflowState( ) );
605 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, directoryResourceRssConfig.getIdEntryLink( ) );
606
607 if ( directoryResourceRssConfig.getIdEntryFilter1( ) != DirectoryUtils.CONSTANT_ID_NULL )
608 {
609 IEntry entry = EntryHome.findByPrimaryKey( directoryResourceRssConfig.getIdEntryFilter1( ), pluginDirectory );
610 model.put( MARK_ENTRY_FILTER_1, entry );
611
612 RecordField recordField = new RecordField( );
613 recordField.setEntry( entry );
614
615 if ( DirectoryUtils.convertStringToInt( directoryResourceRssConfig.getValueFilter1( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
616 {
617 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( directoryResourceRssConfig.getValueFilter1( ) ),
618 pluginDirectory );
619 recordField.setField( field );
620 }
621
622 recordField.setValue( directoryResourceRssConfig.getValueFilter1( ) );
623
624 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
625 recordFieldList.add( recordField );
626 model.put( MARK_RECORD_FIELD_FILTER_1, recordFieldList );
627 }
628
629 if ( directoryResourceRssConfig.getIdEntryFilter2( ) != DirectoryUtils.CONSTANT_ID_NULL )
630 {
631 IEntry entry = EntryHome.findByPrimaryKey( directoryResourceRssConfig.getIdEntryFilter2( ), pluginDirectory );
632 model.put( MARK_ENTRY_FILTER_2, entry );
633
634 RecordField recordField = new RecordField( );
635 recordField.setEntry( entry );
636
637 if ( DirectoryUtils.convertStringToInt( directoryResourceRssConfig.getValueFilter2( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
638 {
639 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( directoryResourceRssConfig.getValueFilter2( ) ),
640 pluginDirectory );
641 recordField.setField( field );
642 }
643
644 recordField.setValue( directoryResourceRssConfig.getValueFilter2( ) );
645
646 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
647 recordFieldList.add( recordField );
648 model.put( MARK_RECORD_FIELD_FILTER_2, recordFieldList );
649 }
650 }
651 else
652 {
653 model.put( MARK_ENTRY_LIST_IMAGE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
654 model.put( MARK_DIRECTORY_LIST_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
655 model.put( MARK_ENTRY_LIST_TITLE_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
656 model.put( MARK_ENTRY_LIST_DESCRIPTION_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
657 model.put( MARK_ENTRY_LIST_LINK_DEFAULT_ITEM, DirectoryUtils.CONSTANT_ID_NULL );
658 }
659
660 model.put( MARK_DIRECTORY_LIST, directoryList );
661 model.put( MARK_ENTRY_LIST, referenceEntry );
662
663 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_EVALUATION_MODIFY_CONFIG, locale, model );
664
665 return template.getHtml( );
666 }
667
668
669
670
671
672
673 @Deprecated
674 @Override
675 public String createHtmlRss( )
676 {
677 HashMap<String, Object> model = new HashMap<String, Object>( );
678 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
679 DirectoryResourceRssConfig config = DirectoryResourceRssConfigHome.findByPrimaryKey( this.getId( ), pluginDirectory );
680 Directory directory = DirectoryHome.findByPrimaryKey( config.getIdDirectory( ), pluginDirectory );
681
682
683 String strRssFileLanguage = AppPropertiesService.getProperty( PROPERTY_SITE_LANGUAGE );
684
685 String strWebAppUrl = AppPropertiesService.getProperty( PROPERTY_WEBAPP_PROD_URL );
686 String strSiteUrl = strWebAppUrl;
687 model.put( MARK_RSS_SITE_NAME, directory.getTitle( ) );
688 model.put( MARK_RSS_FILE_LANGUAGE, strRssFileLanguage );
689 model.put( MARK_RSS_SITE_URL, strSiteUrl );
690 model.put( MARK_RSS_SITE_DESCRIPTION, directory.getDescription( ) );
691
692 Locale locale = new Locale( strRssFileLanguage );
693
694 RecordFieldFilter filter = new RecordFieldFilter( );
695 filter.setIdDirectory( directory.getIdDirectory( ) );
696
697 HashMap<String, List<RecordField>> mapSearchQuery = new HashMap<String, List<RecordField>>( );
698
699 if ( config.getIdEntryFilter1( ) != DirectoryUtils.CONSTANT_ID_NULL )
700 {
701 IEntry entry = EntryHome.findByPrimaryKey( config.getIdEntryFilter1( ), pluginDirectory );
702 RecordField recordField = new RecordField( );
703 recordField.setEntry( entry );
704
705 if ( DirectoryUtils.convertStringToInt( config.getValueFilter1( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
706 {
707 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( config.getValueFilter1( ) ), pluginDirectory );
708 recordField.setField( field );
709 }
710
711 recordField.setValue( config.getValueFilter1( ) );
712
713 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
714 recordFieldList.add( recordField );
715
716 mapSearchQuery.put( Integer.toString( config.getIdEntryFilter1( ) ), recordFieldList );
717 }
718
719 if ( config.getIdEntryFilter2( ) != DirectoryUtils.CONSTANT_ID_NULL )
720 {
721 IEntry entry = EntryHome.findByPrimaryKey( config.getIdEntryFilter2( ), pluginDirectory );
722 RecordField recordField = new RecordField( );
723 recordField.setEntry( entry );
724
725 if ( DirectoryUtils.convertStringToInt( config.getValueFilter2( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
726 {
727 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( config.getValueFilter2( ) ), pluginDirectory );
728 recordField.setField( field );
729 }
730
731 recordField.setValue( config.getValueFilter2( ) );
732
733 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
734 recordFieldList.add( recordField );
735
736 mapSearchQuery.put( Integer.toString( config.getIdEntryFilter2( ) ), recordFieldList );
737 }
738
739 List<Integer> listResultRecordId = DirectorySearchService.getInstance( ).getSearchResults( directory, mapSearchQuery, null, null, null, filter,
740 pluginDirectory );
741
742 if ( ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) && ( config.getIdWorkflowState( ) != DirectoryUtils.CONSTANT_ID_NULL )
743 && WorkflowService.getInstance( ).isAvailable( ) )
744 {
745 List<Integer> listTmpResultRecordId = WorkflowService.getInstance( ).getAuthorizedResourceList( Record.WORKFLOW_RESOURCE_TYPE,
746 directory.getIdWorkflow( ), config.getIdWorkflowState( ), Integer.valueOf( directory.getIdDirectory( ) ), null );
747
748 listResultRecordId = DirectoryUtils.retainAll( listResultRecordId, listTmpResultRecordId );
749 }
750
751 List<HashMap<String, Object>> listItem = new ArrayList<HashMap<String, Object>>( );
752 IRecordService recordService = SpringContextService.getBean( RecordService.BEAN_SERVICE );
753
754 for ( Integer idRecord : listResultRecordId )
755 {
756 Record record = recordService.findByPrimaryKey( idRecord, pluginDirectory );
757 RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
758 recordFieldFilter.setIdDirectory( config.getIdDirectory( ) );
759 recordFieldFilter.setIdRecord( idRecord );
760
761 recordFieldFilter.setIdEntry( config.getIdEntryTitle( ) );
762
763 List<RecordField> recordFieldList = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
764 RecordField recordFieldTitle = recordFieldList.get( 0 );
765
766 recordFieldFilter.setIdEntry( config.getIdEntryDescription( ) );
767
768 List<RecordField> recordFieldList2 = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
769 RecordField recordFieldDescription = recordFieldList2.get( 0 );
770
771 recordFieldFilter.setIdEntry( config.getIdEntryImage( ) );
772
773 List<RecordField> recordFieldListImage = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
774 RecordField recordFieldImage = null;
775
776 if ( !recordFieldListImage.isEmpty( ) )
777 {
778 recordFieldImage = recordFieldListImage.get( 0 );
779 }
780
781 recordFieldFilter.setIdEntry( config.getIdEntryLink( ) );
782
783 List<RecordField> recordFieldListLink = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
784 RecordField recordFieldLink = null;
785
786 if ( !recordFieldListLink.isEmpty( ) )
787 {
788 recordFieldLink = recordFieldListLink.get( 0 );
789 }
790
791 if ( ( recordFieldTitle != null ) && ( recordFieldDescription != null ) )
792 {
793 HashMap<String, Object> item = new HashMap<String, Object>( );
794 item.put( MARK_RSS_SITE_ID_RECORD, idRecord );
795
796 if ( recordFieldTitle.getValue( ) != null )
797 {
798 item.put( MARK_RSS_SITE_TITLE, recordFieldTitle.getValue( ) );
799 }
800 else
801 {
802 item.put( MARK_RSS_SITE_TITLE, recordFieldTitle.getField( ).getValue( ) );
803 }
804
805 if ( recordFieldDescription.getValue( ) != null )
806 {
807 item.put( MARK_RSS_SITE_DESCRIPTION_ITEM, recordFieldDescription.getValue( ) );
808 }
809 else
810 {
811 item.put( MARK_RSS_SITE_DESCRIPTION_ITEM, recordFieldDescription.getField( ).getValue( ) );
812 }
813
814 if ( ( recordFieldImage != null ) && ( recordFieldImage.getFile( ) != null ) )
815 {
816 item.put( MARK_RSS_SITE_IMAGE_ITEM, recordFieldImage.getFile( ).getIdFile( ) );
817
818 if ( ( recordFieldImage.getEntry( ) != null ) && ( recordFieldImage.getEntry( ).getDisplayHeight( ) != -1 ) )
819 {
820 item.put( MARK_RSS_SITE_IMAGE_HEIGHT_ITEM, recordFieldImage.getEntry( ).getDisplayHeight( ) );
821 }
822
823 if ( ( recordFieldImage.getEntry( ) != null ) && ( recordFieldImage.getEntry( ).getDisplayWidth( ) != -1 ) )
824 {
825 item.put( MARK_RSS_SITE_IMAGE_WIDTH_ITEM, recordFieldImage.getEntry( ).getDisplayWidth( ) );
826 }
827 }
828
829 if ( ( recordFieldLink != null ) && ( recordFieldLink.getValue( ) != null ) )
830 {
831 item.put( MARK_RSS_SITE_LINK_ITEM, recordFieldLink.getValue( ) );
832 }
833
834 item.put( MARK_RSS_SITE_DATE, record.getDateCreation( ) );
835 item.put( MARK_RSS_SITE_DATE_MODIFICATION, record.getDateModification( ) );
836 listItem.add( item );
837 }
838 }
839
840 model.put( MARK_ITEM_LIST, listItem );
841 model.put( MARK_RSS_SITE_ID_DIRECTORY, config.getIdDirectory( ) );
842
843 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_PUSH_RSS_XML, locale, model );
844
845 return template.getHtml( );
846 }
847
848
849
850
851 @Override
852 public void deleteResourceRssConfig( int idResourceRss )
853 {
854 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
855 DirectoryResourceRssConfigHome.remove( idResourceRss, pluginDirectory );
856 }
857
858
859
860
861 @Override
862 public Map<String, String> getParameterToApply( HttpServletRequest request )
863 {
864 Map<String, String> map = new HashMap<String, String>( );
865
866 map.put( PARAMETER_ID_DIRECTORY, request.getParameter( PARAMETER_ID_DIRECTORY ) );
867 map.put( PARAMETER_ID_ENTRY_FILTER_1, request.getParameter( PARAMETER_ID_ENTRY_FILTER_1 ) );
868 map.put( PARAMETER_ID_ENTRY_FILTER_2, request.getParameter( PARAMETER_ID_ENTRY_FILTER_2 ) );
869 map.put( PARAMETER_ID_ENTRY_TITLE, request.getParameter( PARAMETER_ID_ENTRY_TITLE ) );
870 map.put( PARAMETER_ID_ENTRY_DESCRIPTION, request.getParameter( PARAMETER_ID_ENTRY_DESCRIPTION ) );
871 map.put( PARAMETER_ID_ENTRY_IMAGE, request.getParameter( PARAMETER_ID_ENTRY_IMAGE ) );
872 map.put( PARAMETER_ID_ENTRY_LINK, request.getParameter( PARAMETER_ID_ENTRY_LINK ) );
873 map.put( PARAMETER_ID_WORKFLOW_STATE, request.getParameter( PARAMETER_ID_WORKFLOW_STATE ) );
874
875 return map;
876 }
877
878
879
880
881 @Override
882 public boolean checkResource( )
883 {
884 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
885 DirectoryResourceRssConfig config = DirectoryResourceRssConfigHome.findByPrimaryKey( this.getId( ), pluginDirectory );
886 Directory directory = DirectoryHome.findByPrimaryKey( config.getIdDirectory( ), pluginDirectory );
887 IEntry entryTitle = EntryHome.findByPrimaryKey( config.getIdEntryTitle( ), pluginDirectory );
888 IEntry entryDescription = EntryHome.findByPrimaryKey( config.getIdEntryDescription( ), pluginDirectory );
889
890 return ( ( directory != null ) && ( entryDescription != null ) && ( entryTitle != null ) );
891 }
892
893
894
895
896 @Override
897 public IFeedResource getFeed( )
898 {
899
900 String strRssFileLanguage = AppPropertiesService.getProperty( PROPERTY_SITE_LANGUAGE );
901
902 String strWebAppUrl = AppPropertiesService.getProperty( PROPERTY_WEBAPP_PROD_URL );
903 String strSiteUrl = strWebAppUrl;
904
905 Plugin pluginDirectory = PluginService.getPlugin( DirectoryPlugin.PLUGIN_NAME );
906 DirectoryResourceRssConfig config = DirectoryResourceRssConfigHome.findByPrimaryKey( this.getId( ), pluginDirectory );
907 Directory directory = DirectoryHome.findByPrimaryKey( config.getIdDirectory( ), pluginDirectory );
908
909 IFeedResource resource = new FeedResource( );
910 resource.setTitle( directory.getTitle( ) );
911 resource.setDescription( directory.getDescription( ) );
912 resource.setLink( strSiteUrl );
913 resource.setLanguage( strRssFileLanguage );
914
915 IFeedResourceImage image = new FeedResourceImage( );
916 image.setUrl( strSiteUrl + "/images/local/skin/valid-rss.png" );
917 image.setLink( strSiteUrl );
918 image.setTitle( directory.getTitle( ) );
919
920 resource.setImage( image );
921
922 Locale locale = new Locale( strRssFileLanguage );
923
924 RecordFieldFilter filter = new RecordFieldFilter( );
925 filter.setIdDirectory( directory.getIdDirectory( ) );
926 filter.setSortOrder( RecordFieldFilter.ORDER_DESC );
927
928 HashMap<String, List<RecordField>> mapSearchQuery = new HashMap<String, List<RecordField>>( );
929
930 if ( config.getIdEntryFilter1( ) != DirectoryUtils.CONSTANT_ID_NULL )
931 {
932 IEntry entry = EntryHome.findByPrimaryKey( config.getIdEntryFilter1( ), pluginDirectory );
933 RecordField recordField = new RecordField( );
934 recordField.setEntry( entry );
935
936 if ( DirectoryUtils.convertStringToInt( config.getValueFilter1( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
937 {
938 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( config.getValueFilter1( ) ), pluginDirectory );
939 recordField.setField( field );
940 }
941
942 recordField.setValue( config.getValueFilter1( ) );
943
944 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
945 recordFieldList.add( recordField );
946
947 mapSearchQuery.put( Integer.toString( config.getIdEntryFilter1( ) ), recordFieldList );
948 }
949
950 if ( config.getIdEntryFilter2( ) != DirectoryUtils.CONSTANT_ID_NULL )
951 {
952 IEntry entry = EntryHome.findByPrimaryKey( config.getIdEntryFilter2( ), pluginDirectory );
953 RecordField recordField = new RecordField( );
954 recordField.setEntry( entry );
955
956 if ( DirectoryUtils.convertStringToInt( config.getValueFilter2( ) ) != DirectoryUtils.CONSTANT_ID_NULL )
957 {
958 Field field = FieldHome.findByPrimaryKey( DirectoryUtils.convertStringToInt( config.getValueFilter2( ) ), pluginDirectory );
959 recordField.setField( field );
960 }
961
962 recordField.setValue( config.getValueFilter2( ) );
963
964 List<RecordField> recordFieldList = new ArrayList<RecordField>( );
965 recordFieldList.add( recordField );
966
967 mapSearchQuery.put( Integer.toString( config.getIdEntryFilter2( ) ), recordFieldList );
968 }
969
970 List<Integer> listResultRecordId = DirectorySearchService.getInstance( ).getSearchResults( directory, mapSearchQuery, null, null, null, filter,
971 pluginDirectory );
972
973 if ( ( directory.getIdWorkflow( ) != DirectoryUtils.CONSTANT_ID_NULL ) && ( config.getIdWorkflowState( ) != DirectoryUtils.CONSTANT_ID_NULL )
974 && WorkflowService.getInstance( ).isAvailable( ) )
975 {
976 List<Integer> listTmpResultRecordId = WorkflowService.getInstance( ).getAuthorizedResourceList( Record.WORKFLOW_RESOURCE_TYPE,
977 directory.getIdWorkflow( ), config.getIdWorkflowState( ), Integer.valueOf( directory.getIdDirectory( ) ), null );
978
979 listResultRecordId = DirectoryUtils.retainAll( listResultRecordId, listTmpResultRecordId );
980 }
981
982 List<IFeedResourceItem> listItems = new ArrayList<IFeedResourceItem>( );
983 IRecordService recordService = SpringContextService.getBean( RecordService.BEAN_SERVICE );
984
985 for ( Integer idRecord : listResultRecordId )
986 {
987 Record record = recordService.findByPrimaryKey( idRecord, pluginDirectory );
988 RecordFieldFilter recordFieldFilter = new RecordFieldFilter( );
989 recordFieldFilter.setIdDirectory( config.getIdDirectory( ) );
990 recordFieldFilter.setIdRecord( idRecord );
991
992 recordFieldFilter.setIdEntry( config.getIdEntryTitle( ) );
993
994 List<RecordField> recordFieldList = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
995 RecordField recordFieldTitle = recordFieldList.get( 0 );
996
997 recordFieldFilter.setIdEntry( config.getIdEntryDescription( ) );
998
999 List<RecordField> recordFieldList2 = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
1000 RecordField recordFieldDescription = recordFieldList2.get( 0 );
1001
1002 recordFieldFilter.setIdEntry( config.getIdEntryImage( ) );
1003
1004 List<RecordField> recordFieldListImage = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
1005 RecordField recordFieldImage = null;
1006
1007 if ( !recordFieldListImage.isEmpty( ) )
1008 {
1009 recordFieldImage = recordFieldListImage.get( 0 );
1010 }
1011
1012 recordFieldFilter.setIdEntry( config.getIdEntryLink( ) );
1013
1014 List<RecordField> recordFieldListLink = RecordFieldHome.getRecordFieldList( recordFieldFilter, pluginDirectory );
1015 RecordField recordFieldLink = null;
1016
1017 if ( !recordFieldListLink.isEmpty( ) )
1018 {
1019 recordFieldLink = recordFieldListLink.get( 0 );
1020 }
1021
1022 if ( ( recordFieldTitle != null ) && ( recordFieldDescription != null ) )
1023 {
1024 IFeedResourceItem item = new FeedResourceItem( );
1025
1026
1027
1028 String strImageDescription;
1029
1030 if ( ( recordFieldImage != null ) && ( recordFieldImage.getFile( ) != null ) )
1031 {
1032 Map<String, Object> model = new HashMap<String, Object>( );
1033 model.put( MARK_RSS_SITE_IMAGE_ITEM, recordFieldImage.getFile( ).getIdFile( ) );
1034 model.put( MARK_RSS_SITE_URL, strSiteUrl );
1035
1036 if ( ( recordFieldImage.getEntry( ) != null ) && ( recordFieldImage.getEntry( ).getDisplayHeight( ) != -1 ) )
1037 {
1038 model.put( MARK_RSS_SITE_IMAGE_HEIGHT_ITEM, recordFieldImage.getEntry( ).getDisplayHeight( ) );
1039 }
1040
1041 if ( ( recordFieldImage.getEntry( ) != null ) && ( recordFieldImage.getEntry( ).getDisplayWidth( ) != -1 ) )
1042 {
1043 model.put( MARK_RSS_SITE_IMAGE_WIDTH_ITEM, recordFieldImage.getEntry( ).getDisplayWidth( ) );
1044 }
1045
1046 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_RSS_IMAGE, locale, model );
1047 strImageDescription = template.getHtml( );
1048 }
1049 else
1050 {
1051 strImageDescription = EMPTY_STRING;
1052 }
1053
1054 if ( recordFieldTitle.getValue( ) != null )
1055 {
1056 item.setTitle( recordFieldTitle.getValue( ) );
1057 }
1058 else
1059 {
1060 item.setTitle( recordFieldTitle.getField( ).getValue( ) );
1061 }
1062
1063 if ( recordFieldDescription.getValue( ) != null )
1064 {
1065 item.setDescription( strImageDescription + recordFieldDescription.getValue( ) );
1066 }
1067 else
1068 {
1069 item.setDescription( strImageDescription + recordFieldDescription.getField( ).getValue( ) );
1070 }
1071
1072 if ( ( recordFieldLink != null ) && ( recordFieldLink.getValue( ) != null ) )
1073 {
1074 item.setLink( recordFieldLink.getValue( ) );
1075 }
1076 else
1077 {
1078 UrlItem urlItem = new UrlItem( strSiteUrl + "/jsp/site/Portal.jsp" );
1079 urlItem.addParameter( PARAMETER_PAGE, CONSTANT_DIRECTORY );
1080 urlItem.addParameter( PARAMETER_ID_DIRECTORY_RECORD, record.getIdRecord( ) );
1081 urlItem.addParameter( PARAMETER_VIEW_DIRECTORY_RECORD, directory.getIdDirectory( ) );
1082
1083 item.setLink( urlItem.getUrl( ) );
1084 }
1085
1086 item.setGUID( item.getLink( ) );
1087
1088 item.setDate( record.getDateCreation( ) );
1089
1090 listItems.add( item );
1091 }
1092 }
1093
1094 resource.setItems( listItems );
1095
1096 return resource;
1097 }
1098 }