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