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.genericalert.daemon;
35
36 import java.util.List;
37
38 import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
39 import fr.paris.lutece.plugins.genericalert.service.TaskNotifyReminder;
40 import fr.paris.lutece.plugins.workflowcore.business.action.Action;
41 import fr.paris.lutece.plugins.workflowcore.business.action.ActionFilter;
42 import fr.paris.lutece.plugins.workflowcore.business.state.State;
43 import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceWorkflow;
44 import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceWorkflowFilter;
45 import fr.paris.lutece.plugins.workflowcore.business.workflow.Workflow;
46 import fr.paris.lutece.plugins.workflowcore.business.workflow.WorkflowFilter;
47 import fr.paris.lutece.plugins.workflowcore.service.action.ActionService;
48 import fr.paris.lutece.plugins.workflowcore.service.action.IActionService;
49 import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceWorkflowService;
50 import fr.paris.lutece.plugins.workflowcore.service.resource.ResourceWorkflowService;
51 import fr.paris.lutece.plugins.workflowcore.service.workflow.IWorkflowService;
52 import fr.paris.lutece.portal.service.daemon.Daemon;
53 import fr.paris.lutece.portal.service.spring.SpringContextService;
54 import fr.paris.lutece.portal.service.util.AppLogService;
55
56
57
58
59
60 public class AppointmentReminderDaemon extends Daemon
61 {
62
63 private TaskNotifyReminder _taskReminder = SpringContextService.getBean( "genericalert.taskNotifyReminder" );
64
65 @Override
66 public void run( )
67 {
68
69 IWorkflowService workflowService = SpringContextService.getBean( fr.paris.lutece.plugins.workflowcore.service.workflow.WorkflowService.BEAN_SERVICE );
70 WorkflowFilter workflowFilter = new WorkflowFilter( );
71
72 workflowFilter.setIsEnabled( 1 );
73
74 List<Workflow> listWorkflows = workflowService.getListWorkflowsByFilter( workflowFilter );
75 IResourceWorkflowService resourceWorkflowService = SpringContextService.getBean( ResourceWorkflowService.BEAN_SERVICE );
76
77 for ( Workflow workflow : listWorkflows )
78 {
79 IActionService actionService = SpringContextService.getBean( ActionService.BEAN_SERVICE );
80 ActionFilter filter = new ActionFilter( );
81
82 filter.setAutomaticReflexiveAction( true );
83 filter.setIdWorkflow( workflow.getId( ) );
84
85 List<Action> listAutomaticActions = actionService.getListActionByFilter( filter );
86
87 for ( Action action : listAutomaticActions )
88 {
89 ResourceWorkflowFilter filt = new ResourceWorkflowFilter( );
90 filt.setIdWorkflow( workflow.getId( ) );
91 filt.setResourceType( Appointment.APPOINTMENT_RESOURCE_TYPE );
92
93 for( int idStateBefore : action.getListIdStateBefore() )
94 {
95 filt.setIdState( idStateBefore );
96
97 List<ResourceWorkflow> listResource = resourceWorkflowService.getListResourceWorkflowByFilter( filt );
98
99 for ( ResourceWorkflow resource : listResource )
100 {
101 try
102 {
103 _taskReminder.sendReminder( resource.getIdResource( ), resource.getResourceType( ), action.getId( ), workflow.getId( ) );
104
105 }
106 catch( Exception e )
107 {
108
109 AppLogService.error( "notify reminder appointment: {}", e.getMessage( ) , e );
110 }
111
112 }
113 }
114 }
115 }
116 }
117
118 }