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.workflow.modules.alertgru.web;
35
36 import fr.paris.lutece.plugins.workflow.modules.alertgru.business.AlertGruTaskConfig;
37 import fr.paris.lutece.plugins.workflow.modules.alertgru.service.AlertGruService;
38 import fr.paris.lutece.plugins.workflow.modules.alertgru.service.AlertGruTaskConfigService;
39 import fr.paris.lutece.plugins.workflow.modules.alertgru.service.IAlertGruService;
40 import fr.paris.lutece.plugins.workflow.modules.alertgru.service.ServiceConfigTaskForm;
41 import fr.paris.lutece.plugins.workflow.modules.alertgru.utils.constants.Constants;
42 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.AgentAlertConfig;
43 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.BillingAccountBasedSMSAlertConfig;
44 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.BroadcastAlertConfig;
45 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.EmailAlertConfig;
46 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.GuichetAlertConfig;
47 import fr.paris.lutece.plugins.workflow.modules.alertgru.web.alertconfig.impl.SMSAlertConfig;
48 import fr.paris.lutece.plugins.workflow.service.provider.MarkerProviderService;
49 import fr.paris.lutece.plugins.workflow.service.provider.ProviderManagerUtil;
50 import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
51 import fr.paris.lutece.plugins.workflowcore.service.provider.AbstractProviderManager;
52 import fr.paris.lutece.plugins.workflowcore.service.provider.IMarkerProvider;
53 import fr.paris.lutece.plugins.workflowcore.service.provider.InfoMarker;
54 import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
55 import fr.paris.lutece.portal.service.i18n.I18nService;
56 import fr.paris.lutece.portal.service.message.AdminMessage;
57 import fr.paris.lutece.portal.service.message.AdminMessageService;
58 import fr.paris.lutece.portal.service.spring.SpringContextService;
59 import fr.paris.lutece.portal.service.template.AppTemplateService;
60 import fr.paris.lutece.portal.service.util.AppPathService;
61 import fr.paris.lutece.portal.service.util.AppPropertiesService;
62 import fr.paris.lutece.portal.util.mvc.utils.MVCMessage;
63 import fr.paris.lutece.util.ErrorMessage;
64 import fr.paris.lutece.util.ReferenceList;
65 import fr.paris.lutece.util.html.HtmlTemplate;
66 import java.util.ArrayList;
67 import java.util.Arrays;
68 import java.util.Collection;
69 import java.util.HashMap;
70 import java.util.List;
71 import java.util.Map;
72 import javax.servlet.http.HttpServletRequest;
73 import org.apache.commons.lang3.StringUtils;
74
75 public class AlertGruTaskConfigController
76 {
77
78
79 private static final String TEMPLATE_FIRST_STEP = "admin/plugins/workflow/modules/alertgru/task_alert_gru_config_first_step.html";
80 private static final String TEMPLATE_SECOND_STEP = "admin/plugins/workflow/modules/alertgru/task_alert_gru_config_second_step.html";
81
82
83 private static final String MARK_SELECT_PROVIDER = "list_provider";
84 private static final String MARK_LIST_MARKER_PROVIDER = "list_marker_provider";
85 private static final String MARK_LIST_ALERT_CONFIG = "list_alert_config";
86 private static final String MARK_LOCALE = "locale";
87 private static final String MARK_WEBAPP_URL = "webapp_url";
88
89
90 private static final ITaskConfigService _taskAlertGruConfigService = SpringContextService.getBean( AlertGruTaskConfigService.BEAN_SERVICE );
91 private static final IAlertGruService _alertGruService = SpringContextService.getBean( AlertGruService.BEAN_SERVICE );
92
93 private final ITask _task;
94 private AlertGruTaskConfig _config;
95
96
97 private static final String PARAMETER_APPLY = "apply";
98 private static final String PARAMETER_APPLY_MARKER = "apply_marker";
99
100
101 private static final String ACTION_FIRST_STEP_SAVE = "saveFirstStep";
102 private static final String ACTION_SECOND_STEP_SAVE = "saveSecondStep";
103 private static final String ACTION_ADVANCED_CONFIG_SAVE = "saveAdvancedConfig";
104 private static final String ACTION_ADVANCED_CONFIG_CANCEL = "cancelAdvancedConfig";
105 private static final String ACTION_ALERT_CONFIG_ADD = "AddAlertConfig";
106 private static final String ACTION_ALERT_CONFIG_REMOVE_PREFIX = "RemoveAlertConfig_";
107 private static final String ACTION_ALERT_CONFIG_MARKERS = "loadMarkers";
108
109
110 private static final String SESSION_ID_PROVIDER = "alertProviderSession";
111
112
113
114
115
116
117
118 public AlertGruTaskConfigController( ITask task )
119 {
120 _task = task;
121
122 findConfig( );
123 }
124
125
126
127
128 private void findConfig( )
129 {
130 _config = _taskAlertGruConfigService.findByPrimaryKey( _task.getId( ) );
131
132 if ( _config == null )
133 {
134
135 _config = new AlertGruTaskConfig( );
136 }
137 }
138
139
140
141
142
143
144
145
146 private List<IAlertConfig> initAlertConfigs( HttpServletRequest request )
147 {
148 List<IAlertConfig> listAlertConfig = new ArrayList<>( );
149
150 listAlertConfig.add( new AgentAlertConfig( request, _config ) );
151 listAlertConfig.add( new BroadcastAlertConfig( request, _config ) );
152 listAlertConfig.add( new EmailAlertConfig( request, _config ) );
153 listAlertConfig.add( new GuichetAlertConfig( request, _config ) );
154 if ( _config.isBillingAccountBasedSmsNotification( ) )
155 {
156 listAlertConfig.add( new BillingAccountBasedSMSAlertConfig( request, _config ) );
157 }
158 else
159 {
160 listAlertConfig.add( new SMSAlertConfig( request, _config ) );
161 }
162
163 return listAlertConfig;
164 }
165
166
167
168
169
170
171
172
173 public HtmlTemplate buildView( HttpServletRequest request )
174 {
175 HtmlTemplate template = null;
176 View view = new View( request );
177
178 if ( _config.getIdSpringProvider( ) == null || _config.getMarkerAlert( ) == null )
179 {
180 template = view.buildFirstStep( );
181 }
182 else
183 {
184 template = view.buildSecondStep( );
185 }
186
187 return template;
188 }
189
190
191
192
193
194
195
196
197 public String performAction( HttpServletRequest request )
198 {
199 String strErrorUrl = null;
200 String strAction = findAction( request );
201 Action action = new Action( request, strAction );
202
203 if ( ACTION_ALERT_CONFIG_MARKERS.equals( strAction ) )
204 {
205 strErrorUrl = action.loadMarkers( );
206 }
207
208 if ( ACTION_FIRST_STEP_SAVE.equals( strAction ) )
209 {
210 strErrorUrl = action.saveFirstStep( );
211 }
212
213 if ( ACTION_SECOND_STEP_SAVE.equals( strAction ) )
214 {
215 strErrorUrl = action.saveSecondStep( );
216 }
217
218 if ( strAction.startsWith( ACTION_ALERT_CONFIG_REMOVE_PREFIX ) )
219 {
220 strErrorUrl = action.removeAlertConf( );
221 }
222
223 if ( ACTION_ALERT_CONFIG_ADD.equals( strAction ) )
224 {
225 strErrorUrl = action.addAlertConf( );
226 }
227
228 if ( ACTION_ADVANCED_CONFIG_CANCEL.equals( strAction ) )
229 {
230 strErrorUrl = action.cancel( );
231 }
232
233 if ( ACTION_ADVANCED_CONFIG_SAVE.equals( strAction ) )
234 {
235 strErrorUrl = action.saveAdvancedConfig( );
236 }
237
238 return strErrorUrl;
239 }
240
241
242
243
244
245
246
247
248 private String findAction( HttpServletRequest request )
249 {
250 String strAction;
251 if ( !StringUtils.isBlank( request.getParameter( PARAMETER_APPLY_MARKER ) ) )
252 {
253 strAction = request.getParameter( PARAMETER_APPLY_MARKER );
254 }
255 else
256 {
257 strAction = request.getParameter( PARAMETER_APPLY );
258 }
259 if ( StringUtils.isBlank( strAction ) )
260 {
261 strAction = ACTION_SECOND_STEP_SAVE;
262 }
263
264 return strAction;
265 }
266
267
268
269
270
271 private final class View
272 {
273 private final HttpServletRequest _request;
274 private final List<IAlertConfig> _listAlertConfig;
275 private final Map<String, Object> _model;
276
277
278
279
280
281
282
283 private View( HttpServletRequest request )
284 {
285 _request = request;
286 _model = new HashMap<>( );
287
288 _listAlertConfig = initAlertConfigs( request );
289 }
290
291
292
293
294
295
296 private HtmlTemplate buildFirstStep( )
297 {
298 fillModelWithConfig( );
299 fillModelWithGlobalConfig( );
300 if ( _config.getIdSpringProvider( ) != null )
301 {
302 manageAlertGruMarkersInModel( );
303 }
304
305 return AppTemplateService.getTemplate( TEMPLATE_FIRST_STEP, _request.getLocale( ), _model );
306 }
307
308
309
310
311
312
313 private HtmlTemplate buildSecondStep( )
314 {
315 fillModelWithConfig( );
316 fillModelWithRichTextEditorConfig( );
317 fillModelWithAlertConfigs( );
318 fillModelWithMailSenderName( );
319 fillModelWithMailingList( );
320 fillModelWithGlobalConfig( );
321 manageAlertGruMarkersInModel( );
322
323 return AppTemplateService.getTemplate( TEMPLATE_SECOND_STEP, _request.getLocale( ), _model );
324 }
325
326
327
328
329 private void fillModelWithConfig( )
330 {
331 if ( _request.getSession( ).getAttribute( SESSION_ID_PROVIDER ) != null )
332 {
333 _config.setIdSpringProvider( (String) _request.getSession( ).getAttribute( SESSION_ID_PROVIDER ) );
334 }
335 _model.put( Constants.MARK_CONFIG, _config );
336 }
337
338
339
340
341 private void fillModelWithRichTextEditorConfig( )
342 {
343 _model.put( MARK_LOCALE, _request.getLocale( ) );
344 _model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( _request ) );
345 }
346
347
348
349
350 private void fillModelWithAlertConfigs( )
351 {
352 ReferenceList listAlertConfig = ServiceConfigTaskForm.buildReferenceListOfInactiveAlertConfigs( _listAlertConfig, _request.getLocale( ) );
353
354 _model.put( MARK_LIST_ALERT_CONFIG, listAlertConfig );
355 }
356
357
358
359
360 private void fillModelWithGlobalConfig( )
361 {
362 fillModelWithProviders( );
363 fillModelWithMarkerProviders( );
364 fillModelWithAlertInfos( );
365 }
366
367
368
369
370 private void fillModelWithProviders( )
371 {
372 _model.put( MARK_SELECT_PROVIDER, ServiceConfigTaskForm.getProviderReferenceList( _task ) );
373 }
374
375
376
377
378 private void fillModelWithMarkerProviders( )
379 {
380 _model.put( MARK_LIST_MARKER_PROVIDER, MarkerProviderService.getInstance( ).getMarkerProviders( ) );
381 }
382
383
384
385
386 private void fillModelWithMailingList( )
387 {
388 _model.put( Constants.MARK_MAILING_LIST, _alertGruService.getMailingList( _request ) );
389 }
390
391
392
393
394 private void fillModelWithMailSenderName( )
395 {
396 String strDefaultSenderName = AppPropertiesService.getProperty( Constants.PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_NAME );
397
398 _model.put( Constants.MARK_DEFAULT_SENDER_NAME, strDefaultSenderName );
399 }
400
401 private void fillModelWithAlertInfos( )
402 {
403 _model.put( Constants.MARK_STATE_LIST, _alertGruService.getListStates( _task.getAction( ).getId( ) ) );
404
405 }
406
407
408
409
410 private void manageAlertGruMarkersInModel( )
411 {
412 String strIdSpringProvider = _request.getSession( ).getAttribute( SESSION_ID_PROVIDER ) != null
413 ? (String) _request.getSession( ).getAttribute( SESSION_ID_PROVIDER )
414 : _config.getIdSpringProvider( );
415 String strProviderManagerId = ProviderManagerUtil.fetchProviderManagerId( strIdSpringProvider );
416 String strProviderId = ProviderManagerUtil.fetchProviderId( strIdSpringProvider );
417 AbstractProviderManager providerManager = ProviderManagerUtil.fetchProviderManager( strProviderManagerId );
418
419 if ( providerManager != null )
420 {
421 _model.put( Constants.MARK_NOTIFYGRU_MARKERS, findMarkers( providerManager, strProviderId, _config.getMarkerProviders( ) ) );
422 }
423 else
424 {
425 List<ErrorMessage> listErrorMessages = new ArrayList<>( );
426 listErrorMessages.add( new MVCMessage( I18nService.getLocalizedString( Constants.MESSAGE_ERROR_PROVIDER_NOT_FOUND, _request.getLocale( ) ) ) );
427 _model.put( Constants.MARK_MESSAGES_ERROR, listErrorMessages );
428 }
429 }
430
431
432
433
434
435
436
437
438
439
440
441
442 private Collection<InfoMarker> findMarkers( AbstractProviderManager providerManager, String strProviderId, List<String> listMarkerProviderIds )
443 {
444 Collection<InfoMarker> collectionMarkers = providerManager.getProviderDescription( strProviderId ).getMarkerDescriptions( );
445
446 for ( String strMarkerProviderId : listMarkerProviderIds )
447 {
448 IMarkerProvider markerProvider = MarkerProviderService.getInstance( ).find( strMarkerProviderId );
449
450 if ( markerProvider != null )
451 {
452 collectionMarkers.addAll( markerProvider.provideMarkerDescriptions( ) );
453 }
454 }
455
456 return collectionMarkers;
457 }
458
459 }
460
461
462
463
464
465
466
467
468
469
470 private final class Action
471 {
472 private static final String VALUE_CHECKBOX = "on";
473 private static final String PARAMETER_ADDED_ALERT_CONFIG = "added_alert_config";
474 private static final String PARAMETER_REMOVE_SEPARATOR = "_";
475 private static final int PARAMETER_REMOVE_ALERT_CONFIG_NAME_PART = 1;
476
477 private final HttpServletRequest _request;
478 private final List<IAlertConfig> _listAlertConfig;
479 private final AbstractProviderManager _providerManager;
480 private final String _strAction;
481
482
483
484
485
486
487
488
489
490 private Action( HttpServletRequest request, String strAction )
491 {
492 _request = request;
493 _strAction = strAction;
494
495 String strProviderManagerId = ProviderManagerUtil.fetchProviderManagerId( _config.getIdSpringProvider( ) );
496 _providerManager = ProviderManagerUtil.fetchProviderManager( strProviderManagerId );
497
498 _listAlertConfig = initAlertConfigs( request );
499
500 }
501
502
503
504
505
506
507 private String loadMarkers( )
508 {
509 fillConfigWithGlobalConfig( );
510 putProviderInSession( );
511 return null;
512 }
513
514 private void putProviderInSession( )
515 {
516 _request.getSession( ).setAttribute( SESSION_ID_PROVIDER, _request.getParameter( Constants.PARAMETER_SELECT_PROVIDER ) );
517 }
518
519
520
521
522
523
524 private String saveFirstStep( )
525 {
526 String strErrorUrl = validateGlobalConfig( );
527
528 if ( !StringUtils.isEmpty( strErrorUrl ) )
529 {
530 return strErrorUrl;
531 }
532
533 fillConfigWithGlobalConfig( );
534 putProviderInSession( );
535 saveConfig( );
536
537 return null;
538 }
539
540
541
542
543
544
545 private String saveSecondStep( )
546 {
547 String strResult = validateSecondStepConfig( );
548
549 if ( !StringUtils.isEmpty( strResult ) )
550 {
551 return strResult;
552 }
553
554 saveAlertConfigs( );
555 saveConfig( );
556
557 return null;
558
559 }
560
561
562
563
564
565
566 private String saveAdvancedConfig( )
567 {
568 String strErrorUrl = validateGlobalConfig( );
569
570 if ( !StringUtils.isEmpty( strErrorUrl ) )
571 {
572 return strErrorUrl;
573 }
574 fillConfigWithGlobalConfig( );
575 fillConfigWithCrmStatus( );
576 putProviderInSession( );
577 saveConfig( );
578 return null;
579 }
580
581
582
583
584
585
586 private String cancel( )
587 {
588 _request.getSession( ).removeAttribute( SESSION_ID_PROVIDER );
589 return null;
590 }
591
592
593
594
595
596
597 private String addAlertConf( )
598 {
599 String strErrorUrl = validateAlertConfigs( );
600
601 if ( !StringUtils.isEmpty( strErrorUrl ) )
602 {
603 return strErrorUrl;
604 }
605
606 String strNameOfAddedAlertConfig = findNameOfAddedAlertConfig( );
607 IAlertConfig alertConfigAdded = findAlertConfigByName( strNameOfAddedAlertConfig );
608
609 alertConfigAdded.setActive( true );
610
611 fillConfigWithCurrentAlertConfig( alertConfigAdded );
612
613 saveAlertConfigs( );
614 saveConfig( );
615
616 return null;
617 }
618
619
620
621
622
623
624 private String removeAlertConf( )
625 {
626 String strNameOfRemovedAlertConfig = findNameOfRemovedAlertConfig( );
627 IAlertConfig alertConfigRemoved = findAlertConfigByName( strNameOfRemovedAlertConfig );
628
629 alertConfigRemoved.setActive( false );
630 alertConfigRemoved.removeConfig( );
631
632 saveConfig( );
633
634 return null;
635 }
636
637
638
639
640
641
642 private String findNameOfAddedAlertConfig( )
643 {
644 return _request.getParameter( PARAMETER_ADDED_ALERT_CONFIG );
645 }
646
647
648
649
650
651
652 private String findNameOfRemovedAlertConfig( )
653 {
654 return _strAction.split( PARAMETER_REMOVE_SEPARATOR ) [PARAMETER_REMOVE_ALERT_CONFIG_NAME_PART];
655 }
656
657
658
659
660
661
662
663
664 private IAlertConfig findAlertConfigByName( String strName )
665 {
666 IAlertConfig alertConfigFound = null;
667
668 for ( IAlertConfig alertConfig : _listAlertConfig )
669 {
670 if ( alertConfig.getName( ).equals( strName ) )
671 {
672 alertConfigFound = alertConfig;
673 break;
674 }
675 }
676
677 return alertConfigFound;
678 }
679
680
681
682
683
684
685 private String validateGlobalConfig( )
686 {
687 String errUrl;
688 errUrl = validateFieldIsNotNull( Constants.PARAMETER_SUBJECT_ALERT, Constants.MESSAGE_MANDATORY_SUBJECT );
689 if ( StringUtils.isEmpty( errUrl ) )
690 {
691 errUrl = validateFieldIsNotNull( Constants.PARAMETER_SELECT_PROVIDER, Constants.MESSAGE_MANDATORY_PROVIDER );
692 if ( StringUtils.isEmpty( errUrl ) )
693 {
694 errUrl = validateFieldIsNotNull( Constants.PARAMETER_MARKER_ALERT, Constants.MESSAGE_MANDATORY_MARKER );
695 }
696 if ( StringUtils.isEmpty( errUrl ) )
697 {
698 errUrl = validateFieldIsNotNull( Constants.PARAMETER_ALERT_AFTER_BEFORE, Constants.MESSAGE_MANDATORY_ALERT_AFTER );
699 if ( StringUtils.isEmpty( errUrl ) )
700 {
701 errUrl = validateFieldIsNotNull( Constants.PARAMETER_STATE_AFTER, Constants.MESSAGE_MANDATORY_STATE_AFTER );
702 }
703 }
704 }
705 return errUrl;
706 }
707
708
709
710
711
712
713 private String validateFieldIsNotNull( String paramater, String errMessage )
714 {
715 String strErrorUrl = null;
716
717 if ( StringUtils.isEmpty( _request.getParameter( paramater ) ) )
718 {
719 strErrorUrl = buildUrlForMissingField( errMessage );
720 }
721
722 return strErrorUrl;
723 }
724
725
726
727
728
729
730 private String validateSecondStepConfig( )
731 {
732 String strErrorUrl = validateOneAlertConfigIsActive( );
733
734 if ( !StringUtils.isEmpty( strErrorUrl ) )
735 {
736 return strErrorUrl;
737 }
738
739 strErrorUrl = validateAlertConfigs( );
740
741 if ( !StringUtils.isEmpty( strErrorUrl ) )
742 {
743 return strErrorUrl;
744 }
745
746 return null;
747 }
748
749
750
751
752
753
754 private String validateOneAlertConfigIsActive( )
755 {
756 String strErrorUrl = null;
757
758 if ( filterActiveAlertConfigs( ).isEmpty( ) )
759 {
760 strErrorUrl = buildUrlForNoAlertConfig( );
761 }
762
763 return strErrorUrl;
764 }
765
766
767
768
769
770
771 private String validateAlertConfigs( )
772 {
773 return validateAlertConfigs( buildModelForValidation( ) );
774 }
775
776
777
778
779
780
781
782
783 private String validateAlertConfigs( Map<String, Object> model )
784 {
785 String strErrorUrl = null;
786
787 for ( IAlertConfig alertConfig : filterActiveAlertConfigs( ) )
788 {
789 strErrorUrl = alertConfig.getValidator( ).validate( model );
790
791 if ( !StringUtils.isEmpty( strErrorUrl ) )
792 {
793 break;
794 }
795 }
796
797 return strErrorUrl;
798 }
799
800
801
802
803
804
805 private List<IAlertConfig> filterActiveAlertConfigs( )
806 {
807 List<IAlertConfig> listActiveAlertConfigs = new ArrayList<>( );
808
809 for ( IAlertConfig alertConfig : _listAlertConfig )
810 {
811 if ( alertConfig.isActive( ) )
812 {
813 listActiveAlertConfigs.add( alertConfig );
814 }
815 }
816
817 return listActiveAlertConfigs;
818 }
819
820
821
822
823
824
825 private String buildUrlForMissingField( String errMessage )
826 {
827 return AdminMessageService.getMessageUrl( _request, errMessage, AdminMessage.TYPE_STOP );
828 }
829
830
831
832
833
834
835 private String buildUrlForNoAlertConfig( )
836 {
837 return AdminMessageService.getMessageUrl( _request, Constants.MESSAGE_MANDATORY_ONGLET, AdminMessage.TYPE_STOP );
838 }
839
840
841
842
843
844
845 private Map<String, Object> buildModelForValidation( )
846 {
847 String strProviderId = ProviderManagerUtil.fetchProviderId( _config.getIdSpringProvider( ) );
848
849 return markersToModel( _providerManager.getProviderDescription( strProviderId ).getMarkerDescriptions( ) );
850 }
851
852
853
854
855
856
857
858
859 private Map<String, Object> markersToModel( Collection<InfoMarker> collectionAlertMarkers )
860 {
861 Map<String, Object> model = new HashMap<>( );
862
863 for ( InfoMarker alertMarker : collectionAlertMarkers )
864 {
865 model.put( alertMarker.getMarker( ), alertMarker.getDescription( ) );
866 }
867
868 return model;
869 }
870
871
872
873
874 private void fillConfigWithGlobalConfig( )
875 {
876 fillConfigWithProvider( );
877 fillConfigWithMarkerProviders( );
878 fillConfigWithDemandStatus( );
879 fillConfigWithAlertInfos( );
880 fillConfigWithMarkerAlert( );
881 }
882
883
884
885
886 private void fillConfigWithProvider( )
887 {
888 _config.setIdSpringProvider( _request.getParameter( Constants.PARAMETER_SELECT_PROVIDER ) );
889 }
890
891
892
893
894 private void fillConfigWithMarkerProviders( )
895 {
896 String [ ] listMarkerProviders = _request.getParameterValues( Constants.PARAMETER_MARKER_PROVIDERS );
897
898 if ( listMarkerProviders != null )
899 {
900 _config.setMarkerProviders( Arrays.asList( listMarkerProviders ) );
901 }
902 else
903 {
904 _config.setMarkerProviders( null );
905 }
906 }
907
908
909
910
911 private void fillConfigWithDemandStatus( )
912 {
913 int nDemandStatus = ( VALUE_CHECKBOX.equals( _request.getParameter( Constants.PARAMETER_DEMAND_STATUS ) ) ) ? 1 : 0;
914
915 _config.setDemandStatus( nDemandStatus );
916 }
917
918
919
920
921 private void fillConfigWithAlertInfos( )
922 {
923 _config.setDaysToAlert( StringUtils.isNotBlank( _request.getParameter( Constants.PARAMETER_DAYS_TO_ALERT ) )
924 ? Integer.parseInt( _request.getParameter( Constants.PARAMETER_DAYS_TO_ALERT ) )
925 : 0 );
926 _config.setAlertSubject( _request.getParameter( Constants.PARAMETER_SUBJECT_ALERT ) );
927 _config.setIdStateAfter( StringUtils.isNotBlank( _request.getParameter( Constants.PARAMETER_STATE_AFTER ) )
928 ? Integer.parseInt( _request.getParameter( Constants.PARAMETER_STATE_AFTER ) )
929 : 0 );
930 _config.setAlertAfterBefore( _request.getParameter( Constants.PARAMETER_ALERT_AFTER_BEFORE ) );
931 }
932
933
934
935
936 private void fillConfigWithMarkerAlert( )
937 {
938 _config.setMarkerAlert( _request.getParameter( Constants.PARAMETER_MARKER_ALERT ) );
939 }
940
941
942
943
944 private void fillConfigWithCrmStatus( )
945 {
946 String strCrmStatusId = _request.getParameter( Constants.PARAMETER_CRM_STATUS_ID );
947 int nCrmStatusId = ( ( StringUtils.equals( strCrmStatusId, "1" ) ) || ( StringUtils.equals( strCrmStatusId, "0" ) ) )
948 ? Integer.parseInt( strCrmStatusId )
949 : 1;
950
951 _config.setCrmStatusId( nCrmStatusId );
952 }
953
954
955
956
957
958
959
960 private void fillConfigWithCurrentAlertConfig( IAlertConfig alertConfig )
961 {
962 int nCurrentTabIndex = ServiceConfigTaskForm.getTabIndex( alertConfig.getName( ) );
963 _config.setSetOnglet( nCurrentTabIndex );
964 }
965
966
967
968
969 private void saveAlertConfigs( )
970 {
971 for ( IAlertConfig alertConfig : filterActiveAlertConfigs( ) )
972 {
973 alertConfig.addConfig( );
974 }
975 }
976
977
978
979
980 private void saveConfig( )
981 {
982 boolean bCreate = false;
983
984 if ( _config.getIdTask( ) == 0 )
985 {
986 _config.setIdTask( _task.getId( ) );
987 bCreate = true;
988 }
989
990 if ( bCreate )
991 {
992 _taskAlertGruConfigService.create( _config );
993 }
994 else
995 {
996 _taskAlertGruConfigService.update( _config );
997 }
998 }
999 }
1000
1001 }