View Javadoc
1   /*
2    * Copyright (c) 2002-2023, City of Paris
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions
7    * are met:
8    *
9    *  1. Redistributions of source code must retain the above copyright notice
10   *     and the following disclaimer.
11   *
12   *  2. Redistributions in binary form must reproduce the above copyright notice
13   *     and the following disclaimer in the documentation and/or other materials
14   *     provided with the distribution.
15   *
16   *  3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17   *     contributors may be used to endorse or promote products derived from
18   *     this software without specific prior written permission.
19   *
20   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23   * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24   * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27   * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28   * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29   * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30   * POSSIBILITY OF SUCH DAMAGE.
31   *
32   * License 1.0
33   */
34  package fr.paris.lutece.plugins.workflow.modules.appointmentants.web;
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 org.apache.commons.lang3.StringUtils;
43  
44  import fr.paris.lutece.plugins.workflow.modules.appointmentants.business.history.TaskAntsAppointmentHistory;
45  import fr.paris.lutece.plugins.workflow.modules.appointmentants.service.WorkflowAppointmentAntsPlugin;
46  import fr.paris.lutece.plugins.workflow.modules.appointmentants.service.history.ITaskAntsAppointmentHistoryService;
47  import fr.paris.lutece.plugins.workflow.modules.appointmentants.service.history.TaskAntsAppointmentHistoryService;
48  import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
49  import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
50  import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
51  import fr.paris.lutece.portal.service.i18n.I18nService;
52  
53  /**
54   * 
55   * Component used to handle the interface / visual aspect of the "Delete ANTS appointment" task
56   *
57   */
58  public class TaskDeleteAntsAppointmentComponent extends AbstractTaskAntsAppointmentComponent
59  {
60  	/**
61  	 * Task's configuration service
62  	 */
63  	@Inject
64  	@Named( WorkflowAppointmentAntsPlugin.BEAN_CONFIG )
65  	private ITaskConfigService _config;
66  
67  	/**
68  	 * Task's history service
69  	 */
70  	@Inject
71  	@Named( TaskAntsAppointmentHistoryService.BEAN_SERVICE )
72  	private ITaskAntsAppointmentHistoryService _antsAppointmentHistoryService;
73  
74  	/**
75  	 * Task Title
76  	 */
77  	private static final String PROPERTY_TASK_TITLE = "module.workflow.appointmentants.delete_appointment.task_title";
78  
79  	/**
80  	 * Task's history messages
81  	 */
82  	private static final String MESSAGE_TASK_APPOINTMENT_DELETED_SUCCESS = "module.workflow.appointmentants.delete_appointment.message.appointmentDeletionSuccess";
83  	private static final String MESSAGE_TASK_APPOINTMENT_DELETED_FAILURE = "module.workflow.appointmentants.delete_appointment.message.appointmentDeletionFailure";
84  	private static final String MESSAGE_TASK_APPOINTMENT_NO_ANTS_NUMBER = "module.workflow.appointmentants.ants_appointment.message.noAntsApplicationNumber";
85  
86  	/**
87       * {@inheritDoc}
88       */
89  	@Override
90  	public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
91  	{
92  		String taskTitle = I18nService.getLocalizedString( PROPERTY_TASK_TITLE, locale );
93  
94  		return getDisplayConfigForm( request, taskTitle, locale, task, _config );
95  	}
96  
97  	/**
98       * {@inheritDoc}
99       */
100     @Override
101     public String doSaveConfig( HttpServletRequest request, Locale locale, ITask task )
102     {
103         return doSaveConfig( request, task, _config );
104     }
105 
106     /**
107      * {@inheritDoc}
108      */
109 	@Override
110 	public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
111 	{
112 		// Retrieve the task's history
113 		TaskAntsAppointmentHistory taskAppointmentHistory = _antsAppointmentHistoryService.findByPrimaryKey(
114 				nIdHistory,
115 				task.getId( ),
116 				WorkflowUtils.getPlugin( ) );
117 
118 		// If the task has history data, display it in the appointment's history
119 		if( taskAppointmentHistory != null )
120 		{
121 			Object[] args = new Object[1];
122 			// Get the ANTS application numbers to be displayed in the task's history
123 			if( StringUtils.isNotBlank( taskAppointmentHistory.getAntsApplicationNumbers( ) ) )
124 			{
125 				args[0] = taskAppointmentHistory.getAntsApplicationNumbers( );
126 			}
127 			// If there are no ANTS application numbers, then display a specific message instead
128 			else
129 			{
130 				args[0] = I18nService.getLocalizedString(
131 						MESSAGE_TASK_APPOINTMENT_NO_ANTS_NUMBER,
132 						locale );
133 			}
134 
135 			// Return the message to be displayed in the task's history informations
136 			return I18nService.getLocalizedString(
137 					taskAppointmentHistory.isTaskSuccessful( ) ? MESSAGE_TASK_APPOINTMENT_DELETED_SUCCESS : MESSAGE_TASK_APPOINTMENT_DELETED_FAILURE,
138 					args,
139 					locale );
140 		}
141 		// If the task has no history data, nothing will be displayed
142 		return StringUtils.EMPTY;
143 	}
144 }