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
35
36
37
38
39 package fr.paris.lutece.plugins.workflow.modules.reply.web.task;
40
41 import fr.paris.lutece.plugins.workflow.modules.reply.business.config.TaskReplyConfig;
42 import fr.paris.lutece.plugins.workflow.modules.reply.business.task.Reply;
43 import fr.paris.lutece.plugins.workflow.modules.reply.service.IReplyService;
44 import fr.paris.lutece.plugins.workflow.modules.reply.service.ReplyService;
45 import fr.paris.lutece.plugins.workflow.utils.WorkflowUtils;
46 import fr.paris.lutece.plugins.workflow.web.task.AbstractTaskComponent;
47 import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
48 import fr.paris.lutece.portal.service.admin.AdminUserService;
49 import fr.paris.lutece.portal.service.message.AdminMessage;
50 import fr.paris.lutece.portal.service.message.AdminMessageService;
51 import fr.paris.lutece.portal.service.spring.SpringContextService;
52 import fr.paris.lutece.portal.service.template.AppTemplateService;
53 import fr.paris.lutece.portal.service.util.AppPathService;
54 import fr.paris.lutece.util.html.HtmlTemplate;
55 import java.util.HashMap;
56 import java.util.Locale;
57 import java.util.Map;
58 import javax.servlet.http.HttpServletRequest;
59 import org.apache.commons.lang.StringUtils;
60
61
62
63
64
65 public class TaskReplyComponent extends AbstractTaskComponent
66 {
67
68
69 private static final String TEMPLATE_TASK_REPLY_CONFIG = "admin/plugins/workflow/modules/reply/task_reply_config.html";
70 private static final String TEMPLATE_TASK_REPLY_FORM = "admin/plugins/workflow/modules/reply/task_reply_form.html";
71
72
73 private static final String MARK_CONFIG = "config";
74 private static final String MARK_WEBAPP_URL = "webapp_url";
75 private static final String MARK_LOCALE = "locale";
76 private static final String MARK_MESSAGE = "message";
77
78
79 private static final String PARAMETER_REPLY_VALUE = "reply_message";
80
81
82 private static final String MESSAGE_MANDATORY_FIELD = "module.workflow.reply.task_reply_config.message.mandatory.field";
83 private static final String MESSAGE_NO_CONFIGURATION_FOR_TASK_REPLY = "module.workflow.reply.task_reply_config.message.no_configuration_for_task_reply";
84
85 @Override
86 public String getDisplayTaskForm( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
87 {
88 Map<String, Object> model = new HashMap<>( );
89
90 TaskReplyConfig config = this.getTaskConfigService( ).findByPrimaryKey( task.getId( ) );
91 model.put( MARK_CONFIG, config );
92
93 String strMessage = request.getParameter( PARAMETER_REPLY_VALUE + "_" + task.getId( ) );
94
95 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
96 model.put( MARK_LOCALE, AdminUserService.getLocale( request ).getLanguage( ) );
97 model.put( MARK_MESSAGE, strMessage );
98
99 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_REPLY_FORM, locale, model );
100
101 return template.getHtml( );
102 }
103
104 @Override
105 public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
106 {
107 Map<String, Object> model = new HashMap<>( );
108
109 TaskReplyConfig config = this.getTaskConfigService( ).findByPrimaryKey( task.getId( ) );
110 model.put( MARK_CONFIG, config );
111
112 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_REPLY_CONFIG, locale, model );
113
114 return template.getHtml( );
115 }
116
117 @Override
118 public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
119 {
120 TaskReplyConfig config = this.getTaskConfigService( ).findByPrimaryKey( task.getId( ) );
121
122 String strInfo = "";
123 if ( config != null )
124 strInfo = config.getTitle( );
125
126 IReplyService replyService = SpringContextService.getBean( ReplyService.BEAN_SERVICE );
127 Reply reply = replyService.find( nIdHistory, task.getId( ) );
128
129 if ( reply != null )
130 strInfo += " : " + reply.getMessage( );
131
132 return strInfo;
133 }
134
135 @Override
136 public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
137 {
138 throw new UnsupportedOperationException( "Not supported yet." );
139 }
140
141 @Override
142 public String doValidateTask( int nIdResource, String strResourceType, HttpServletRequest request, Locale locale, ITask task )
143 {
144 String strError = WorkflowUtils.EMPTY_STRING;
145 String strReplyMessageValue = request.getParameter( PARAMETER_REPLY_VALUE + "_" + task.getId( ) );
146 TaskReplyConfig config = this.getTaskConfigService( ).findByPrimaryKey( task.getId( ) );
147
148 if ( config == null )
149 {
150 return AdminMessageService.getMessageUrl( request, MESSAGE_NO_CONFIGURATION_FOR_TASK_REPLY, AdminMessage.TYPE_STOP );
151 }
152
153 if ( config.isMandatory( ) && ( ( strReplyMessageValue == null ) || strReplyMessageValue.trim( ).equals( WorkflowUtils.EMPTY_STRING ) ) )
154 {
155 strError = config.getTitle( );
156 }
157
158 if ( StringUtils.isNotBlank( strError ) )
159 {
160 Object [ ] tabRequiredFields = {
161 strError
162 };
163
164 return AdminMessageService.getMessageUrl( request, MESSAGE_MANDATORY_FIELD, tabRequiredFields, AdminMessage.TYPE_STOP );
165 }
166
167 return null;
168 }
169
170 }