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.myportal.modules.myapps.web;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.lang3.StringUtils;
44 import org.apache.commons.lang3.math.NumberUtils;
45
46 import fr.paris.lutece.plugins.myapps.business.MyApps;
47 import fr.paris.lutece.plugins.myapps.business.MyAppsUser;
48 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabase;
49 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseFilter;
50 import fr.paris.lutece.plugins.myapps.modules.database.business.MyAppsDatabaseUser;
51 import fr.paris.lutece.plugins.myapps.modules.database.service.MyAppsDatabasePlugin;
52 import fr.paris.lutece.plugins.myapps.modules.database.service.MyAppsDatabaseService;
53 import fr.paris.lutece.plugins.myapps.modules.database.utils.constants.MyAppsDatabaseConstants;
54 import fr.paris.lutece.plugins.myportal.modules.myapps.services.MyPortalMyAppsService;
55 import fr.paris.lutece.plugins.myportal.service.WidgetContentService;
56 import fr.paris.lutece.portal.service.i18n.I18nService;
57 import fr.paris.lutece.portal.service.message.SiteMessage;
58 import fr.paris.lutece.portal.service.message.SiteMessageException;
59 import fr.paris.lutece.portal.service.message.SiteMessageService;
60 import fr.paris.lutece.portal.service.plugin.Plugin;
61 import fr.paris.lutece.portal.service.plugin.PluginService;
62 import fr.paris.lutece.portal.service.security.LuteceUser;
63 import fr.paris.lutece.portal.service.security.SecurityService;
64 import fr.paris.lutece.portal.service.security.UserNotSignedException;
65 import fr.paris.lutece.portal.service.spring.SpringContextService;
66 import fr.paris.lutece.portal.service.template.AppTemplateService;
67 import fr.paris.lutece.portal.service.util.AppPathService;
68 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
69 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
70 import fr.paris.lutece.portal.util.mvc.xpage.MVCApplication;
71 import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
72 import fr.paris.lutece.portal.web.constants.Messages;
73 import fr.paris.lutece.portal.web.xpages.XPage;
74 import fr.paris.lutece.util.html.HtmlTemplate;
75 import fr.paris.lutece.util.url.UrlItem;
76
77
78
79
80
81
82 @Controller( xpageName = "myportal-myapps" )
83 public class MyPortalMyAppsXPage extends MVCApplication
84 {
85
86
87
88
89 private static final long serialVersionUID = 5491988303257261581L;
90
91
92 private static final String TEMPLATE_MANAGE_USER_MYAPPS = "/skin/plugins/myportal/modules/myapps/manage_user_myapps.html";
93 private static final String TEMPLATE_INSERT_USER_MYAPPS = "/skin/plugins/myportal/modules/myapps/insert_user_myapps.html";
94 private static final String TEMPLATE_MODIFY_USER_MYAPPS = "/skin/plugins/myportal/modules/myapps/modify_user_myapps.html";
95
96
97 private static final String VIEW_MANAGE_USER_MYAPPS = "manage_user_myapps";
98 private static final String VIEW_INSERT_USER_MYAPPS = "insert_user_myapps";
99 private static final String VIEW_MODIFY_USER_MYAPPS = "modify_user_myapps";
100 private static final String VIEW_CONFIRM_REMOVE_USER_MYAPPS = "confirm_remove_user_myapps";
101
102
103 private static final String ACTION_DO_INSERT = "do_insert_user_myapps";
104 private static final String ACTION_DO_MODIFY_USER_MYAPPS = "do_modify_user_myapps";
105 private static final String ACTION_DO_REMOVE_USER_MYAPPS = "do_remove_user_myapps";
106
107
108 private static final String PARAMETER_BACK = "back";
109 private static final String PARAMETER_MYPORTAL_URL_RETURN = "myportal_url_return";
110 private static final String PARAMETER_MYAPP_ID = "myapp_id";
111 private static final String PARAMETER_USER_LOGIN = "user_login";
112 private static final String PARAMETER_USER_PASSWORD = "user_password";
113 private static final String PARAMETER_USER_EXTRA_DATA = "user_extra_data";
114 private static final String PARAMETER_MYAPP_CODE_CATEGORY = "myapp_code_category";
115 private static final String PARAMETER_FROM_WIDGET = "from_widget";
116 private static final String PARAMETER_MYAPPS_ORDER = "application_order";
117 private static final String PARAMETER_ID_WIDGET = "id_widget";
118
119
120 private static final String MARK_MYAPP = "myapp";
121 private static final String MARK_MYAPP_USER = "myapp_user";
122 private static final String MARK_MYPORTAL_URL_RETURN = "myportal_url_return";
123 private static final String MARK_ENABLED_MYAPPS_LIST = "enabled_myapps_list";
124 private static final String MARK_DISABLED_MYAPPS_LIST = "disabled_myapps_list";
125 private static final String MARK_MYAPP_CATEGORY = "myapp_category";
126 private static final String MARK_USER_MYAPPS_ORDER_LIST = "myapps_order_list";
127 private static final String MARK_MYAPPS_CURRENT_ORDER = "myapps_current_order";
128
129
130 private static final String MESSAGE_ERROR = "module.myapps.database.message.error";
131 private static final String MESSAGE_APPLICATION_ADDED = "module.myportal.myapps.message.applicationAdded";
132 private static final String MESSAGE_CONFIRM_REMOVE_MYAPPS = "module.myportal.myapps.message.confirmRemoveMyApps";
133 private static final String MESSAGE_MYAPPS_SUCCESS_MODIFY = "module.myportal.myapps.message.modificationMade";
134 private static final String MESSAGE_MYAPPS_SUCCESS_REMOVE = "module.myportal.myapps.message.myAppsRemove";
135
136
137 private static final String MANAGE_USER_MYAPPS_TITLE_PAGE = "module.myportal.myapps.manage_user_myapps.pageTitle";
138 private static final String MANAGE_USER_MYAPPS_PATH_PAGE = "module.myportal.myapps.manage_user_myapps.pagePathLabel";
139 private static final String INSERT_USER_MYAPPS_TITLE_PAGE = "module.myportal.myapps.insert_user_myapps.pageTitle";
140 private static final String INSERT_USER_MYAPPS_PATH_PAGE = "module.myportal.myapps.insert_user_myapps.pagePathLabel";
141 private static final String MODIFY_USER_MYAPPS_TITLE_PAGE = "module.myportal.myapps.modify_user_myapps.pageTitle";
142 private static final String MODIFY_USER_MYAPPS_PATH_PAGE = "module.myportal.myapps.modify_user_myapps.pageTitle";
143
144
145 private static final String SITE_URL = "jsp/site/";
146
147
148 private List<Integer> _listUserApplicationOrder = new ArrayList<>( );
149 private final MyPortalMyAppsService _myPortalMyAppsService = SpringContextService.getBean( MyPortalMyAppsService.BEAN_NAME );
150 private final WidgetContentService _widgetContentService = SpringContextService.getBean( WidgetContentService.BEAN_NAME );
151
152
153
154
155
156
157
158
159
160 @View( value = VIEW_MANAGE_USER_MYAPPS, defaultView = true )
161 public XPage getManageUserMyApps( HttpServletRequest request ) throws UserNotSignedException
162 {
163
164 String strBackParameter = request.getParameter( PARAMETER_BACK );
165 String strBaseUrl = AppPathService.getBaseUrl( request );
166 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
167 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
168
169 if ( strBackParameter != null && StringUtils.isNotBlank( strMyPortalUrlReturn ) )
170 {
171 return redirect( request, strBaseUrl + strMyPortalUrlReturn );
172 }
173
174 LuteceUser user = getUser( request );
175 XPage page = new XPage( );
176 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
177 String strMyAppCategory = request.getParameter( PARAMETER_MYAPP_CODE_CATEGORY );
178
179
180 MyAppsDatabaseFilter filter = new MyAppsDatabaseFilter( );
181 filter.setUserName( user.getName( ) );
182 filter.setCategory( strMyAppCategory );
183 List<MyApps> listEnabledMyApps = _myPortalMyAppsService.getOrderedMyAppsList( user.getName( ) );
184 List<MyApps> listDisabledMyApps = MyAppsDatabaseService.getInstance( ).selectMyAppsList( filter, plugin );
185 listDisabledMyApps.removeAll( listEnabledMyApps );
186
187
188 Map<String, Object> model = new HashMap<String, Object>( );
189 fillCommons( model );
190 model.put( MARK_ENABLED_MYAPPS_LIST, listEnabledMyApps );
191 model.put( MARK_DISABLED_MYAPPS_LIST, listDisabledMyApps );
192 model.put( MARK_MYAPP_CATEGORY, strMyAppCategory );
193 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
194 model.put( PARAMETER_ID_WIDGET, strIdWidget );
195
196
197 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_USER_MYAPPS, request.getLocale( ), model );
198 page.setContent( template.getHtml( ) );
199 page.setTitle( I18nService.getLocalizedString( MANAGE_USER_MYAPPS_TITLE_PAGE, request.getLocale( ) ) );
200 page.setPathLabel( I18nService.getLocalizedString( MANAGE_USER_MYAPPS_PATH_PAGE, request.getLocale( ) ) );
201
202
203 return page;
204 }
205
206
207
208
209
210
211
212
213
214
215 @View( VIEW_INSERT_USER_MYAPPS )
216 public XPage getInsertUserMyApps( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
217 {
218 XPage page = new XPage( );
219 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
220 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
221
222 String strMyAppId = request.getParameter( PARAMETER_MYAPP_ID );
223 String strMyAppCategory = request.getParameter( PARAMETER_MYAPP_CODE_CATEGORY );
224 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
225
226 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
227 {
228
229 int nMyAppId = Integer.parseInt( strMyAppId );
230 MyAppsDatabase myApp = (MyAppsDatabase) MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppId, plugin );
231
232 if ( myApp != null )
233 {
234
235 String strUserName = getUser( request ).getName( );
236 _listUserApplicationOrder = _myPortalMyAppsService.getOrderedMyAppsIdList( strUserName );
237
238
239 Map<String, Object> model = new HashMap<String, Object>( );
240 model.put( MARK_MYAPP, myApp );
241 model.put( MARK_MYAPP_CATEGORY, strMyAppCategory );
242 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
243 model.put( MARK_USER_MYAPPS_ORDER_LIST, _myPortalMyAppsService.getUserListOrderForCreation( strUserName ) );
244 model.put( PARAMETER_ID_WIDGET, strIdWidget );
245
246
247 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_INSERT_USER_MYAPPS, request.getLocale( ), model );
248 page.setContent( template.getHtml( ) );
249 page.setTitle( I18nService.getLocalizedString( INSERT_USER_MYAPPS_TITLE_PAGE, request.getLocale( ) ) );
250 page.setPathLabel( I18nService.getLocalizedString( INSERT_USER_MYAPPS_PATH_PAGE, request.getLocale( ) ) );
251
252
253 return page;
254 }
255 else
256 {
257
258 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
259 }
260 }
261 else
262 {
263
264 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
265 }
266
267
268 return redirectView( request, VIEW_MANAGE_USER_MYAPPS );
269 }
270
271
272
273
274
275
276
277
278
279
280 @Action( ACTION_DO_INSERT )
281 public XPage doInsertUserMyApps( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
282 {
283 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
284
285 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
286
287 Map<String, String> model = new HashMap<String, String>( );
288 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
289 model.put( PARAMETER_ID_WIDGET, strIdWidget );
290
291
292 String strBackParameter = request.getParameter( PARAMETER_BACK );
293 if ( strBackParameter != null )
294 {
295 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
296 }
297
298
299 LuteceUser luteceUser = getUser( request );
300 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
301 MyAppsDatabaseUser myAppsUser = getMyAppsDatabaseUserInfo( request, luteceUser, plugin );
302
303 if ( myAppsUser != null )
304 {
305
306 int nIdWidget = Integer.parseInt( strIdWidget );
307 _widgetContentService.removeCache( nIdWidget, luteceUser );
308
309
310 MyAppsDatabaseService.getInstance( ).createMyAppUser( myAppsUser, plugin );
311
312
313 List<Integer> listNewMyAppsOrder = _myPortalMyAppsService.manageMyAppsNewOrderList( _listUserApplicationOrder, myAppsUser );
314 _myPortalMyAppsService.manageMyAppsReordering( listNewMyAppsOrder, luteceUser.getName( ) );
315
316
317 _listUserApplicationOrder = listNewMyAppsOrder;
318 }
319
320
321 addInfo( MESSAGE_APPLICATION_ADDED, request.getLocale( ) );
322 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
323 }
324
325
326
327
328
329
330
331
332
333
334 @View( VIEW_MODIFY_USER_MYAPPS )
335 public XPage getModifyUserMyApps( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
336 {
337
338 String strMyAppId = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_ID );
339 String strMyAppCategory = request.getParameter( MyAppsDatabaseConstants.PARAMETER_MYAPP_CODE_CATEGORY );
340 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
341 String strFromWidget = request.getParameter( PARAMETER_FROM_WIDGET );
342 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
343
344 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
345 {
346 String strUserName = getUser( request ).getName( );
347
348
349 int nMyAppId = Integer.parseInt( strMyAppId );
350 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
351 MyApps myApp = MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppId, plugin );
352 MyAppsUser myAppUser = MyAppsDatabaseService.getInstance( ).getCredential( nMyAppId, strUserName, plugin );
353
354 if ( ( myApp != null ) && ( myAppUser != null ) )
355 {
356
357 _listUserApplicationOrder = _myPortalMyAppsService.getOrderedMyAppsIdList( strUserName );
358 int nOrder = _listUserApplicationOrder.indexOf( nMyAppId ) + 1;
359
360
361 Map<String, Object> model = new HashMap<String, Object>( );
362 model.put( MARK_MYAPP, myApp );
363 model.put( MARK_MYAPP_CATEGORY, strMyAppCategory );
364 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
365 model.put( MARK_MYAPP_USER, myAppUser );
366 model.put( PARAMETER_FROM_WIDGET, strFromWidget );
367 model.put( MARK_MYAPPS_CURRENT_ORDER, nOrder );
368 model.put( MARK_USER_MYAPPS_ORDER_LIST, _myPortalMyAppsService.getUserListOrder( strUserName ) );
369 model.put( PARAMETER_ID_WIDGET, strIdWidget );
370
371
372 XPage page = new XPage( );
373 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MODIFY_USER_MYAPPS, request.getLocale( ), model );
374 page.setContent( template.getHtml( ) );
375 page.setTitle( I18nService.getLocalizedString( MODIFY_USER_MYAPPS_TITLE_PAGE, request.getLocale( ) ) );
376 page.setPathLabel( I18nService.getLocalizedString( MODIFY_USER_MYAPPS_PATH_PAGE, request.getLocale( ) ) );
377
378
379 return page;
380 }
381 else
382 {
383
384 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
385 }
386 }
387 else
388 {
389
390 SiteMessageService.setMessage( request, MESSAGE_ERROR, SiteMessage.TYPE_STOP );
391 }
392
393
394 return redirectView( request, VIEW_MANAGE_USER_MYAPPS );
395 }
396
397
398
399
400
401
402
403
404
405
406 @Action( ACTION_DO_MODIFY_USER_MYAPPS )
407 public XPage doModifyUserMyApps( HttpServletRequest request ) throws SiteMessageException, UserNotSignedException
408 {
409 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
410 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
411
412 Map<String, String> model = new HashMap<String, String>( );
413 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
414 model.put( PARAMETER_ID_WIDGET, strIdWidget );
415
416
417 String strBackParameter = request.getParameter( PARAMETER_BACK );
418 if ( strBackParameter != null )
419 {
420 String strFromWidget = request.getParameter( PARAMETER_FROM_WIDGET );
421 if ( StringUtils.isNotBlank( strFromWidget ) )
422 {
423 return redirect( request, AppPathService.getBaseUrl( request ) + strMyPortalUrlReturn );
424 }
425 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
426 }
427
428
429 LuteceUser luteceUser = getUser( request );
430 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
431 MyAppsDatabaseUser myAppsUser = getMyAppsDatabaseUserInfo( request, getUser( request ), plugin );
432
433 if ( myAppsUser != null )
434 {
435
436 int nIdWidget = Integer.parseInt( strIdWidget );
437 _widgetContentService.removeCache( nIdWidget, luteceUser );
438
439
440 MyAppsDatabaseService.getInstance( ).updateMyAppUser( myAppsUser, plugin );
441
442
443 List<Integer> listNewMyAppsOrder = _myPortalMyAppsService.manageMyAppsNewOrderList( _listUserApplicationOrder, myAppsUser );
444 _myPortalMyAppsService.manageMyAppsReordering( listNewMyAppsOrder, luteceUser.getName( ) );
445
446
447 _listUserApplicationOrder = listNewMyAppsOrder;
448
449
450 String strFromWidget = request.getParameter( PARAMETER_FROM_WIDGET );
451 if ( StringUtils.isNotBlank( strFromWidget ) )
452 {
453 return redirect( request, AppPathService.getBaseUrl( request ) + strMyPortalUrlReturn );
454 }
455
456
457 addInfo( MESSAGE_MYAPPS_SUCCESS_MODIFY, request.getLocale( ) );
458 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
459 }
460
461
462 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
463 }
464
465
466
467
468
469
470
471
472
473 @View( VIEW_CONFIRM_REMOVE_USER_MYAPPS )
474 public XPage getConfirmRemoveUserMyApps( HttpServletRequest request ) throws SiteMessageException
475 {
476
477 String strUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
478 String strIdMyApp = request.getParameter( PARAMETER_MYAPP_ID );
479 String strFromWidget = request.getParameter( PARAMETER_FROM_WIDGET );
480 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
481
482
483 UrlItem url = new UrlItem( SITE_URL + getActionUrl( ACTION_DO_REMOVE_USER_MYAPPS ) );
484 url.addParameter( PARAMETER_MYAPP_ID, strIdMyApp );
485 url.addParameter( PARAMETER_MYPORTAL_URL_RETURN, strUrlReturn );
486 url.addParameter( PARAMETER_ID_WIDGET, strIdWidget );
487 if ( StringUtils.isNotBlank( strFromWidget ) )
488 {
489 url.addParameter( PARAMETER_FROM_WIDGET, strFromWidget );
490 }
491
492 SiteMessageService.setMessage( request, MESSAGE_CONFIRM_REMOVE_MYAPPS, SiteMessage.TYPE_CONFIRMATION, url.getUrl( ), null );
493 SiteMessage siteMessage = SiteMessageService.getMessage( request );
494
495
496 return redirect( request, siteMessage.getText( request.getLocale( ) ) );
497 }
498
499
500
501
502
503
504
505
506
507 @Action( ACTION_DO_REMOVE_USER_MYAPPS )
508 public XPage doRemoveUserMyApps( HttpServletRequest request ) throws UserNotSignedException
509 {
510 String strMyAppId = request.getParameter( PARAMETER_MYAPP_ID );
511 String strMyPortalUrlReturn = request.getParameter( PARAMETER_MYPORTAL_URL_RETURN );
512 String strIdWidget = request.getParameter( PARAMETER_ID_WIDGET );
513
514 Map<String, String> model = new HashMap<String, String>( );
515 model.put( MARK_MYPORTAL_URL_RETURN, strMyPortalUrlReturn );
516 model.put( PARAMETER_ID_WIDGET, strIdWidget );
517
518 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
519 {
520
521
522 LuteceUser luteceUser = getUser( request );
523 _listUserApplicationOrder = _myPortalMyAppsService.getOrderedMyAppsIdList( luteceUser.getName( ) );
524
525
526 int nIdWidget = Integer.parseInt( strIdWidget );
527 _widgetContentService.removeCache( nIdWidget, luteceUser );
528
529
530 int nMyAppId = Integer.parseInt( strMyAppId );
531 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
532 MyAppsDatabaseService.getInstance( ).removeMyAppUser( nMyAppId, luteceUser.getName( ), plugin );
533
534
535 List<Integer> listNewMyAppsOrder = new ArrayList<>( _listUserApplicationOrder );
536 listNewMyAppsOrder.remove( (Integer) nMyAppId );
537
538 _myPortalMyAppsService.manageMyAppsReordering( listNewMyAppsOrder, luteceUser.getName( ) );
539
540
541 _listUserApplicationOrder = listNewMyAppsOrder;
542
543
544 String strFromWidget = request.getParameter( PARAMETER_FROM_WIDGET );
545 if ( StringUtils.isNotBlank( strFromWidget ) )
546 {
547 return redirect( request, AppPathService.getBaseUrl( request ) + strMyPortalUrlReturn );
548 }
549
550
551 addInfo( MESSAGE_MYAPPS_SUCCESS_REMOVE, request.getLocale( ) );
552 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
553 }
554
555 return redirect( request, VIEW_MANAGE_USER_MYAPPS, model );
556 }
557
558
559
560
561
562
563
564
565
566
567 private LuteceUser getUser( HttpServletRequest request ) throws UserNotSignedException
568 {
569 LuteceUser user = SecurityService.getInstance( ).getRemoteUser( request );
570
571 if ( user == null )
572 {
573 throw new UserNotSignedException( );
574 }
575
576 return user;
577 }
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592 private MyAppsDatabaseUser getMyAppsDatabaseUserInfo( HttpServletRequest request, LuteceUser user, Plugin plugin ) throws SiteMessageException
593 {
594 MyAppsDatabaseUser myAppsUser = null;
595 String strMyAppId = request.getParameter( PARAMETER_MYAPP_ID );
596 String strUserLogin = request.getParameter( PARAMETER_USER_LOGIN );
597 String strPassword = request.getParameter( PARAMETER_USER_PASSWORD );
598 String strExtraData = request.getParameter( PARAMETER_USER_EXTRA_DATA );
599 String strApplicationOrder = request.getParameter( PARAMETER_MYAPPS_ORDER );
600
601 if ( StringUtils.isNotBlank( strMyAppId ) && StringUtils.isNumeric( strMyAppId ) )
602 {
603 int nMyAppId = Integer.parseInt( strMyAppId );
604 MyAppsDatabase myApp = (MyAppsDatabase) MyAppsDatabaseService.getInstance( ).findByPrimaryKey( nMyAppId, plugin );
605
606
607 if ( myApp != null
608 && !( StringUtils.isNotBlank( myApp.getCode( ) ) && StringUtils.isBlank( strUserLogin ) || StringUtils.isNotBlank( myApp.getPassword( ) )
609 && StringUtils.isBlank( strPassword ) )
610 && ( ( StringUtils.isNotBlank( myApp.getData( ) ) && StringUtils.isNotBlank( strExtraData ) ) || ( StringUtils.isBlank( myApp.getData( ) ) || StringUtils
611 .isBlank( myApp.getDataHeading( ) ) ) ) )
612 {
613 String strUserName = user.getName( );
614 myAppsUser = (MyAppsDatabaseUser) MyAppsDatabaseService.getInstance( ).getCredential( nMyAppId, strUserName, plugin );
615
616 if ( myAppsUser == null )
617 {
618 myAppsUser = new MyAppsDatabaseUser( );
619 }
620 myAppsUser.setName( strUserName );
621 myAppsUser.setIdApplication( nMyAppId );
622 myAppsUser.setStoredUserName( ( strUserLogin != null ) ? strUserLogin : StringUtils.EMPTY );
623 myAppsUser.setStoredUserPassword( ( strPassword != null ) ? strPassword : StringUtils.EMPTY );
624 myAppsUser.setStoredUserData( ( strExtraData != null ) ? strExtraData : StringUtils.EMPTY );
625 myAppsUser.setApplicationOrder( NumberUtils.toInt( strApplicationOrder, NumberUtils.INTEGER_ONE ) );
626 }
627 else
628 {
629 SiteMessageService.setMessage( request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP );
630 }
631 }
632 else
633 {
634 SiteMessageService.setMessage( request, Messages.MANDATORY_FIELDS, SiteMessage.TYPE_STOP );
635 }
636
637 return myAppsUser;
638 }
639 }