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.appointment.modules.resource.service.workflow;
35
36 import fr.paris.lutece.plugins.appointment.business.appointment.Appointment;
37 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentFormResourceType;
38 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentFormResourceTypeHome;
39 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentResource;
40 import fr.paris.lutece.plugins.appointment.modules.resource.business.AppointmentResourceHome;
41 import fr.paris.lutece.plugins.appointment.modules.resource.business.workflow.SetAppointmentResourceHistory;
42 import fr.paris.lutece.plugins.appointment.modules.resource.business.workflow.SetAppointmentResourceHistoryHome;
43 import fr.paris.lutece.plugins.appointment.modules.resource.business.workflow.TaskSetAppointmentResourceConfig;
44 import fr.paris.lutece.plugins.appointment.service.AppointmentService;
45 import fr.paris.lutece.plugins.workflowcore.business.resource.ResourceHistory;
46 import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
47 import fr.paris.lutece.plugins.workflowcore.service.resource.IResourceHistoryService;
48 import fr.paris.lutece.plugins.workflowcore.service.task.SimpleTask;
49 import fr.paris.lutece.portal.service.i18n.I18nService;
50
51 import org.apache.commons.lang.StringUtils;
52
53 import java.util.Locale;
54
55 import javax.inject.Inject;
56 import javax.inject.Named;
57 import javax.servlet.http.HttpServletRequest;
58
59
60
61
62 public class TaskSetAppointmentResource extends SimpleTask
63 {
64
65
66
67 public static final String CONFIG_SERVICE_BEAN_NAME = "appointment-resource.taskSetAppointmentResourceConfigService";
68
69
70 private static final String MESSAGE_SET_APPOINTMENT_RESOURCE_TASK_DESCRIPTION = "module.appointment.resource.task_set_appointment_resource_config.taskDescription";
71
72
73 private static final String PARAMETER_ID_RESOURCE = "idResource_";
74
75
76 @Inject
77 private IResourceHistoryService _resourceHistoryService;
78 @Inject
79 @Named( CONFIG_SERVICE_BEAN_NAME )
80 private ITaskConfigService _taskSetAppointmentResourceConfigService;
81
82
83
84
85 @Override
86 public void processTask( int nIdResourceHistory, HttpServletRequest request, Locale locale )
87 {
88 ResourceHistory resourceHistory = _resourceHistoryService.findByPrimaryKey( nIdResourceHistory );
89 TaskSetAppointmentResourceConfig config = _taskSetAppointmentResourceConfigService.findByPrimaryKey( this.getId( ) );
90
91 if ( config == null )
92 {
93 return;
94 }
95
96 String strIdResource = request.getParameter( PARAMETER_ID_RESOURCE + config.getIdFormResourceType( ) );
97
98 if ( StringUtils.isNotEmpty( strIdResource ) )
99 {
100 Appointment appointment = AppointmentService.findAppointmentById( resourceHistory.getIdResource( ) );
101
102 AppointmentResource appResource = AppointmentResourceHome.findByPrimaryKey( appointment.getIdAppointment( ), config.getIdFormResourceType( ) );
103
104 if ( appResource != null )
105 {
106 appResource.setIdResource( strIdResource );
107 AppointmentResourceHome.update( appResource );
108 }
109 else
110 {
111 appResource = new AppointmentResource( );
112 appResource.setIdAppointment( appointment.getIdAppointment( ) );
113 appResource.setIdAppointmentFormResourceType( config.getIdFormResourceType( ) );
114 appResource.setIdResource( strIdResource );
115 AppointmentResourceHome.insert( appResource );
116 }
117
118 SetAppointmentResourceHistoryodules/resource/business/workflow/SetAppointmentResourceHistory.html#SetAppointmentResourceHistory">SetAppointmentResourceHistory history = new SetAppointmentResourceHistory( );
119 history.setIdHistory( nIdResourceHistory );
120 history.setIdAppointment( appResource.getIdAppointment( ) );
121 history.setIdFormResourceType( appResource.getIdAppointmentFormResourceType( ) );
122 history.setIdResource( appResource.getIdResource( ) );
123 SetAppointmentResourceHistoryHome.create( history );
124 }
125 }
126
127
128
129
130 @Override
131 public String getTitle( Locale locale )
132 {
133 TaskSetAppointmentResourceConfig config = _taskSetAppointmentResourceConfigService.findByPrimaryKey( getId( ) );
134
135 if ( config == null )
136 {
137 return StringUtils.EMPTY;
138 }
139
140 AppointmentFormResourceType resourceType = AppointmentFormResourceTypeHome.findByPrimaryKey( config.getIdFormResourceType( ) );
141 Object [ ] args = {
142 ( resourceType != null ) ? resourceType.getDescription( ) : StringUtils.EMPTY
143 };
144
145 return I18nService.getLocalizedString( MESSAGE_SET_APPOINTMENT_RESOURCE_TASK_DESCRIPTION, args, locale );
146 }
147
148
149
150
151 @Override
152 public void doRemoveConfig( )
153 {
154 _taskSetAppointmentResourceConfigService.remove( getId( ) );
155 }
156 }