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.services;
35
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Locale;
39 import java.util.Map;
40
41 import javax.servlet.http.HttpServletRequest;
42
43 import org.apache.commons.lang.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.modules.database.business.MyAppsDatabaseHome;
48 import fr.paris.lutece.plugins.myapps.modules.database.service.MyAppsDatabasePlugin;
49 import fr.paris.lutece.plugins.myportal.business.Widget;
50 import fr.paris.lutece.plugins.myportal.service.handler.WidgetHandler;
51 import fr.paris.lutece.portal.service.i18n.I18nService;
52 import fr.paris.lutece.portal.service.plugin.Plugin;
53 import fr.paris.lutece.portal.service.plugin.PluginService;
54 import fr.paris.lutece.portal.service.security.LuteceUser;
55 import fr.paris.lutece.portal.service.template.AppTemplateService;
56 import fr.paris.lutece.portal.service.util.AppPropertiesService;
57 import fr.paris.lutece.util.html.HtmlTemplate;
58
59
60
61
62
63
64 public class MyPortalMyAppsWidgetHandler implements WidgetHandler
65 {
66
67 private static final String NAME = "module.myportal.myapps.widget.name";
68 private static final String DESCRIPTION = "module.myportal.myapps.widget.description";
69 private static final boolean IS_CUSTOMIZABLE = true;
70
71
72 private static final String TEMPLATE_WIDGET_MYAPPS = "skin/plugins/myportal/modules/myapps/widget_myapps.html";
73
74
75 private static final String PROPERTY_MYAPPS_URL_RETURN = "myportal-myapps.urlReturn.myapps";
76 private static final String PROPERTY_MYPORTAL_URL_RETURN = "myportal-myapps.urlReturn.myportal";
77
78
79 private static final String MARK_USER_APPLICATIONS = "user_list_applications";
80 private static final String MARK_USER_TYPE_MESSAGERIE = "typeMessagerie";
81
82 private static final String MARK_ID_WIDGET = "id_widget";
83 private static final String MARK_MYAPPS_URL_RETURN = "myapps_url_return";
84 private static final String MARK_MYPORTAL_URL_RETURN = "myportal_url_return";
85 public static final String BUSINESS_INFO_ONLINE_TYPE_MESSAGERIE = "user.business-info.mdpTypeMessagerie";
86
87
88
89
90
91 @Override
92 public String getName( )
93 {
94 return I18nService.getLocalizedString( NAME, Locale.FRENCH );
95 }
96
97
98
99
100 @Override
101 public String getDescription( )
102 {
103 return I18nService.getLocalizedString( DESCRIPTION, Locale.FRENCH );
104 }
105
106
107
108
109 @Override
110 public boolean isCustomizable( )
111 {
112 return IS_CUSTOMIZABLE;
113 }
114
115
116
117
118 @Override
119 public String renderWidget( Widget widget, LuteceUser luteceUser, HttpServletRequest request )
120 {
121
122 String strUserName = ( luteceUser != null ) ? luteceUser.getName( ) : StringUtils.EMPTY;
123 String typeMessagerie= ( luteceUser != null ) ? luteceUser.getUserInfos( ).get( BUSINESS_INFO_ONLINE_TYPE_MESSAGERIE ) : StringUtils.EMPTY;
124 typeMessagerie= ( typeMessagerie != null ) ? typeMessagerie : StringUtils.EMPTY;
125 Plugin plugin = PluginService.getPlugin( MyAppsDatabasePlugin.PLUGIN_NAME );
126 List<MyApps> listUserMyApps = MyAppsDatabaseHome.getMyAppsListByUser( strUserName, plugin );
127
128
129 Map<String, Object> model = new HashMap<String, Object>( );
130 model.put( MARK_USER_TYPE_MESSAGERIE, typeMessagerie );
131 model.put( MARK_USER_APPLICATIONS, listUserMyApps );
132 model.put( MARK_ID_WIDGET, ( widget != null ) ? widget.getIdWidget( ) : NumberUtils.INTEGER_MINUS_ONE );
133 model.put( MARK_MYAPPS_URL_RETURN, AppPropertiesService.getProperty( PROPERTY_MYAPPS_URL_RETURN ) );
134 model.put( MARK_MYPORTAL_URL_RETURN, AppPropertiesService.getProperty( PROPERTY_MYPORTAL_URL_RETURN ) );
135
136
137 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_WIDGET_MYAPPS, request.getLocale( ), model );
138
139 return template.getHtml( );
140 }
141
142 }