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.appointmentants.service;
35
36 import java.util.ArrayList;
37 import java.util.List;
38 import java.util.Locale;
39
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import javax.servlet.http.HttpServletRequest;
43
44 import fr.paris.lutece.api.user.User;
45 import fr.paris.lutece.plugins.appointment.service.AppointmentResponseService;
46 import fr.paris.lutece.plugins.genericattributes.business.Response;
47 import fr.paris.lutece.plugins.workflow.modules.appointmentants.business.history.TaskAntsAppointmentHistory;
48 import fr.paris.lutece.plugins.workflow.modules.appointmentants.service.history.ITaskAntsAppointmentHistoryService;
49 import fr.paris.lutece.plugins.workflow.modules.appointmentants.service.history.TaskAntsAppointmentHistoryService;
50 import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
51 import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
52 import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
53 import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
54 import fr.paris.lutece.plugins.workflowcore.service.resource.ResourceHistoryService;
55 import fr.paris.lutece.plugins.workflowcore.service.task.SimpleTask;
56 import fr.paris.lutece.portal.service.i18n.I18nService;
57 import fr.paris.lutece.portal.service.util.AppLogService;
58
59
60
61
62
63
64 public class TaskAddAntsAppointment extends SimpleTask
65 {
66 public static final String CLASS_NAME = WorkflowAppointmentAntsPlugin.PLUGIN_NAME + "TaskAddAntsAppointment";
67
68 @Inject
69 @Named( ResourceHistoryService.BEAN_SERVICE )
70 private IResourceHistoryService _resourceHistoryService;
71
72
73
74
75 @Inject
76 @Named( WorkflowAppointmentAntsPlugin.BEAN_CONFIG )
77 private ITaskConfigService _config;
78
79
80
81
82 @Inject
83 @Named( TaskAntsAppointmentService.BEAN_SERVICE )
84 private ITaskAntsAppointmentService _antsAppointmentService;
85
86
87
88
89 @Inject
90 @Named( TaskAntsAppointmentHistoryService.BEAN_SERVICE )
91 private ITaskAntsAppointmentHistoryService _antsAppointmentHistoryService;
92
93
94
95
96 private static final String PROPERTY_LABEL_TITLE = "module.workflow.appointmentants.add_appointment.task_title";
97
98
99
100
101 @Override
102 public boolean processTaskWithResult( int nIdResourceHistory, HttpServletRequest request, Locale locale, User user )
103 {
104
105 ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdResourceHistory );
106
107
108 boolean isTaskResultPositive = false;
109
110
111 TaskAntsAppointmentHistory antsAppointmentHistory = new TaskAntsAppointmentHistory( );
112
113 try
114 {
115 isTaskResultPositive = _antsAppointmentService.createAntsAppointment( request, resourceHistory.getIdResource( ), this.getId( ), antsAppointmentHistory );
116 }
117 catch ( Exception e )
118 {
119 AppLogService.error( CLASS_NAME, e );
120 }
121
122 saveTaskHistory( antsAppointmentHistory, nIdResourceHistory, isTaskResultPositive );
123 return isTaskResultPositive;
124 }
125
126
127
128
129
130
131
132
133
134
135
136 private void saveTaskHistory( TaskAntsAppointmentHistory antsAppointmentHistory, int idResourceHistory, boolean isTaskSuccessful )
137 {
138 antsAppointmentHistory.setIdResourceHistory( idResourceHistory );
139 antsAppointmentHistory.setIdTask( this.getId( ) );
140 antsAppointmentHistory.setTaskSuccessState( isTaskSuccessful );
141
142 _antsAppointmentHistoryService.create( antsAppointmentHistory, WorkflowUtils.getPlugin( ) );
143 }
144
145
146
147
148 @Override
149 public String getTitle( Locale locale )
150 {
151 return I18nService.getLocalizedString( PROPERTY_LABEL_TITLE, locale );
152 }
153
154
155
156
157 @Override
158 public void doRemoveConfig( )
159 {
160 _config.remove( this.getId( ) );
161 _antsAppointmentHistoryService.removeByTask( this.getId( ), WorkflowUtils.getPlugin( ) );
162 }
163
164
165
166
167 @Override
168 public void doRemoveTaskInformation( int nIdHistory )
169 {
170 _antsAppointmentHistoryService.removeByHistory( nIdHistory, this.getId( ), WorkflowUtils.getPlugin( ) );
171 }
172 }