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.notifycrmnoesb.web;
35
36 import java.lang.reflect.InvocationTargetException;
37 import java.util.HashMap;
38 import java.util.Locale;
39 import java.util.Map;
40 import java.util.Set;
41
42 import javax.servlet.http.HttpServletRequest;
43 import javax.validation.ConstraintViolation;
44
45 import org.apache.commons.beanutils.BeanUtils;
46 import org.apache.commons.lang.StringUtils;
47
48 import fr.paris.lutece.plugins.workflow.modules.notifycrmnoesb.business.TaskNotifyCRMConfig;
49 import fr.paris.lutece.plugins.workflow.modules.notifycrmnoesb.service.INotifyCRMService;
50 import fr.paris.lutece.plugins.workflow.modules.notifycrmnoesb.util.constants.NotifyCRMConstants;
51 import fr.paris.lutece.plugins.workflow.web.task.NoFormTaskComponent;
52 import fr.paris.lutece.plugins.workflowcore.service.config.ITaskConfigService;
53 import fr.paris.lutece.plugins.workflowcore.service.task.ITask;
54 import fr.paris.lutece.portal.service.message.AdminMessage;
55 import fr.paris.lutece.portal.service.message.AdminMessageService;
56 import fr.paris.lutece.portal.service.spring.SpringContextService;
57 import fr.paris.lutece.portal.service.template.AppTemplateService;
58 import fr.paris.lutece.portal.service.util.AppLogService;
59 import fr.paris.lutece.portal.service.util.AppPathService;
60 import fr.paris.lutece.portal.web.constants.Messages;
61 import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
62 import fr.paris.lutece.util.html.HtmlTemplate;
63
64
65
66
67
68
69
70 public class NotifyCRMTaskComponent extends NoFormTaskComponent
71 {
72 private static final String TEMPLATE_TASK_NOTIFY_CRM_CONFIG = "admin/plugins/workflow/modules/notifycrmnoesb/task_notify_crm_config.html";
73
74 private static final String BEAN_NOTIFY_CRM_SERVICE = "workflow-notifycrmnoesb.notifyCRMService";
75
76
77
78
79
80 @Override
81 public String doSaveConfig( HttpServletRequest request, Locale locale, ITask task )
82 {
83
84
85 ITaskConfigService taskNotifyCRMConfigService = (ITaskConfigService)SpringContextService.getBean( NotifyCRMConstants.BEAN_TASK_CONFIG_SERVICE );
86 TaskNotifyCRMConfig config = taskNotifyCRMConfigService.findByPrimaryKey( task.getId( ) );
87
88 boolean bCreate = false;
89 if ( config == null )
90 {
91 config = new TaskNotifyCRMConfig( );
92 config.setIdTask( task.getId( ) );
93 bCreate = true;
94 }
95
96 try
97 {
98 BeanUtils.populate( config, request.getParameterMap( ) );
99 }
100 catch ( IllegalAccessException | InvocationTargetException e )
101 {
102 AppLogService.error( "NotifyCRMTaskComponent - Unable to fetch data from request", e );
103 }
104
105 String strApply = request.getParameter( NotifyCRMConstants.PARAMETER_APPLY );
106
107
108 if ( StringUtils.isEmpty( strApply ) )
109 {
110
111 Set<ConstraintViolation<TaskNotifyCRMConfig>> constraintViolations = BeanValidationUtil.validate( config );
112
113 if ( constraintViolations.size( ) > 0 )
114 {
115 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
116 }
117 }
118
119 if ( bCreate )
120 {
121 taskNotifyCRMConfigService.create( config );
122 }
123 else
124 {
125 taskNotifyCRMConfigService.update( config );
126 }
127
128 return null;
129 }
130
131
132
133
134 @Override
135 public String getDisplayConfigForm( HttpServletRequest request, Locale locale, ITask task )
136 {
137 ITaskConfigService taskNotifyCRMConfigService = (ITaskConfigService)SpringContextService.getBean( NotifyCRMConstants.BEAN_TASK_CONFIG_SERVICE );
138 INotifyCRMService notifyCRMService = (INotifyCRMService)SpringContextService.getBean( BEAN_NOTIFY_CRM_SERVICE );
139
140 Map<String, Object> model = new HashMap<String, Object>( );
141
142 model.put( NotifyCRMConstants.MARK_CONFIG, taskNotifyCRMConfigService.findByPrimaryKey( task.getId( ) ) );
143 model.put( NotifyCRMConstants.MARK_LIST_MARKERS, notifyCRMService.getListMarkers( ) );
144 model.put( NotifyCRMConstants.MARK_WEBAPP_URL, AppPathService.getBaseUrl( request ) );
145
146
147 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_TASK_NOTIFY_CRM_CONFIG, locale, model );
148
149 return template.getHtml( );
150 }
151
152
153
154
155 @Override
156 public String getDisplayTaskInformation( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
157 {
158 return null;
159 }
160
161
162
163
164 @Override
165 public String getTaskInformationXml( int nIdHistory, HttpServletRequest request, Locale locale, ITask task )
166 {
167 return null;
168 }
169 }