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.participatorybudget.web.notify;
35
36 import java.util.HashMap;
37 import java.util.Locale;
38 import java.util.Map;
39
40 import javax.inject.Inject;
41 import javax.inject.Named;
42 import javax.servlet.http.HttpServletRequest;
43
44 import org.apache.commons.lang.StringUtils;
45
46 import fr.paris.lutece.plugins.participatorybudget.business.notify.TaskNotifyDocumentbpConfig;
47 import fr.paris.lutece.plugins.participatorybudget.service.notify.TaskNotifyDocumentbp;
48 import fr.paris.lutece.plugins.workflow.web.task.NoFormTaskComponent;
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.template.AppTemplateService;
52 import fr.paris.lutece.portal.service.util.AppPathService;
53 import fr.paris.lutece.portal.service.util.AppPropertiesService;
54 import fr.paris.lutece.util.html.HtmlTemplate;
55
56
57
58
59
60
61 public class NotifyDocumentbpTaskComponent extends NoFormTaskComponent
62 {
63
64
65 public static final String PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_NAME = "workflow-notifydocumentbp.notification_mail.default_sender_name";
66 public static final String PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_EMAIL = "workflow-notifydocumentbp.notification_mail.default_sender_email";
67
68
69 public static final String PARAMETER_SUBJECT = "subject";
70 public static final String PARAMETER_MESSAGE = "message";
71 public static final String PARAMETER_SENDER_NAME = "sender_name";
72 public static final String PARAMETER_SENDER_EMAIL = "sender_email";
73 public static final String PARAMETER_RECIPIENTS_CC = "recipients_cc";
74 public static final String PARAMETER_RECIPIENTS_BCC = "recipients_bcc";
75 public static final String PARAMETER_FOLLOWERS = "followers";
76 public static final String PARAMETER_ABONNES = "abonnes";
77
78
79 public static final String MARK_WEBAPP_URL = "webapp_url";
80 public static final String MARK_LOCALE = "locale";
81
82
83 public static final String MARK_CONFIG = "config";
84 public static final String MARK_DEFAULT_SENDER_NAME = "default_sender_name";
85 public static final String MARK_DEFAULT_SENDER_EMAIL = "default_sender_email";
86 private static final String MARK_FALSE = "false";
87
88
89 private static final String TEMPLATE_TASK_NOTIFY_DIRECTORY_CONFIG = "admin/plugins/workflow/modules/notifydocumentbp/task_notifydocumentbp_config.html";
90
91
92 @Inject
93 @Named( TaskNotifyDocumentbp.CONFIG_SERVICE_BEAN_NAME )
94 private ITaskConfigService _taskNotifyIdeationConfigService;
95
96
97
98
99 @Override
100 public String doSaveConfig( HttpServletRequest request, Locale locale, ITask task )
101 {
102 String strSenderName = request.getParameter( PARAMETER_SENDER_NAME );
103 String strSenderEmail = request.getParameter( PARAMETER_SENDER_EMAIL );
104 String strSubject = request.getParameter( PARAMETER_SUBJECT );
105 String strMessage = request.getParameter( PARAMETER_MESSAGE );
106 String strRecipientsCc = request.getParameter( PARAMETER_RECIPIENTS_CC );
107 String strRecipientsBcc = request.getParameter( PARAMETER_RECIPIENTS_BCC );
108 String strFollowers = ( request.getParameter( PARAMETER_FOLLOWERS ) == null ) ? MARK_FALSE : request.getParameter( PARAMETER_FOLLOWERS );
109 String strSumbitters = ( request.getParameter( PARAMETER_ABONNES ) == null ) ? MARK_FALSE : request.getParameter( PARAMETER_ABONNES );
110
111 TaskNotifyDocumentbpConfig config = _taskNotifyIdeationConfigService.findByPrimaryKey( task.getId( ) );
112 Boolean bCreate = false;
113
114 if ( config == null )
115 {
116 config = new TaskNotifyDocumentbpConfig( );
117 config.setIdTask( task.getId( ) );
118 bCreate = true;
119 }
120
121 config.setMessage( strMessage );
122 config.setSenderName( strSenderName );
123 config.setSenderEmail( strSenderEmail );
124 config.setSubject( strSubject );
125 config.setRecipientsCc( StringUtils.isNotEmpty( strRecipientsCc ) ? strRecipientsCc : StringUtils.EMPTY );
126 config.setRecipientsBcc( StringUtils.isNotEmpty( strRecipientsBcc ) ? strRecipientsBcc : StringUtils.EMPTY );
127 config.setAbonnes( Boolean.parseBoolean( strSumbitters ) );
128
129 if ( bCreate )
130 {
131 _taskNotifyIdeationConfigService.create( config );
132 }
133 else
134 {
135 _taskNotifyIdeationConfigService.update( config );
136 }
137
138 return null;
139 }
140
141
142
143
144 @Override
145 public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
146 {
147 TaskNotifyDocumentbpConfig config = _taskNotifyIdeationConfigService.findByPrimaryKey( task.getId( ) );
148 String strDefaultSenderName = AppPropertiesService.getProperty( PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_NAME );
149 String strDefaultSenderEmail = AppPropertiesService.getProperty( PROPERTY_NOTIFY_MAIL_DEFAULT_SENDER_EMAIL );
150
151 Map<String, Object> model = new HashMap<String, Object>( );
152
153 model.put( MARK_CONFIG, config );
154 model.put( MARK_DEFAULT_SENDER_NAME, strDefaultSenderName );
155 model.put( MARK_DEFAULT_SENDER_EMAIL, strDefaultSenderEmail );
156 model.put( MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
157 model.put( MARK_LOCALE, locale );
158
159 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_NOTIFY_DIRECTORY_CONFIG, locale, model );
160
161 return template.getHtml( );
162 }
163
164
165
166
167 @Override
168 public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
169 {
170
171 return null;
172 }
173
174
175
176
177 @Override
178 public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
179 {
180
181 return null;
182 }
183 }