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.broadcastproxy.web;
35
36 import java.util.ArrayList;
37 import java.util.HashMap;
38 import java.util.List;
39 import java.util.Locale;
40 import java.util.Map;
41
42 import javax.servlet.http.HttpServletRequest;
43
44 import org.apache.commons.lang3.StringUtils;
45
46 import fr.paris.lutece.plugins.broadcastproxy.business.SubscriptionLinkHome;
47 import fr.paris.lutece.plugins.broadcastproxy.service.BroadcastService;
48 import fr.paris.lutece.plugins.mydashboard.service.MyDashboardComponent;
49 import fr.paris.lutece.portal.service.fileimage.FileImagePublicService;
50 import fr.paris.lutece.portal.service.i18n.I18nService;
51 import fr.paris.lutece.portal.service.security.LuteceUser;
52 import fr.paris.lutece.portal.service.security.SecurityService;
53 import fr.paris.lutece.portal.service.template.AppTemplateService;
54 import fr.paris.lutece.portal.service.util.AppPropertiesService;
55 import fr.paris.lutece.portal.util.mvc.utils.MVCMessage;
56 import fr.paris.lutece.portal.web.l10n.LocaleService;
57 import fr.paris.lutece.util.ErrorMessage;
58 import fr.paris.lutece.util.html.HtmlTemplate;
59
60 public class MyDashboardBroadcastproxy extends MyDashboardComponent
61 {
62
63
64
65 private static final long serialVersionUID = 1L;
66
67
68 private static final String PROPERTY_MYDASHBOARD_DESCRIPTION = "broadcastproxy.component.broadcastproxy.description";
69
70 private static final String MARK_BROADCASTPROXY = "broadcastproxy";
71 private static final String MARK_LUTECE_USER = "user";
72 private static final String MARK_INFOS = "infos";
73 private static final String MARK_LIST_SUBSCRIPTIONS = "listSubscriptions";
74
75
76 private List<ErrorMessage> _listInfos = new ArrayList<>( );
77
78
79 private static final String MYDASHBOARD_BROADCASTPROXY_ID = "broadcastproxy.myDashboard";
80 private static final String KEY_USER_INFO_MAIL = "broadcastproxy.userInfoKeys.mail";
81
82
83 private static final String TEMPLATE_DASHBOARD = "skin/plugins/mydashboard/modules/broadcastproxy/broadcastproxy_mydashboard.html";
84
85
86 private LuteceUser _luteceUser;
87
88 @Override
89 public String getDashboardData( HttpServletRequest request )
90 {
91 _listInfos.clear( );
92 Map<String, Object> model = new HashMap<>( );
93
94 if ( SecurityService.isAuthenticationEnable( ) )
95 {
96 _luteceUser = SecurityService.getInstance( ).getRegisteredUser( request );
97 if ( _luteceUser != null )
98 {
99 model.put( MARK_LUTECE_USER, _luteceUser );
100 }
101 }
102
103 if ( _luteceUser != null )
104 {
105 String userMail = _luteceUser.getEmail( );
106 if ( StringUtils.isBlank( userMail ) )
107 {
108 String mailUserInfoKey = AppPropertiesService.getProperty( KEY_USER_INFO_MAIL );
109 if ( !StringUtils.isBlank( mailUserInfoKey ) )
110 {
111 userMail = _luteceUser.getUserInfo( mailUserInfoKey );
112 }
113 }
114 FileImagePublicService.init( );
115 BroadcastService broadcastService = BroadcastService.getInstance( );
116 model.put( MARK_BROADCASTPROXY, broadcastService.getName( ) );
117 model.put( MARK_LIST_SUBSCRIPTIONS, SubscriptionLinkHome.getSubscriptionLinksList( ) );
118
119 model.put( MARK_INFOS, _listInfos );
120 }
121
122 HtmlTemplate t = AppTemplateService.getTemplate( TEMPLATE_DASHBOARD, LocaleService.getUserSelectedLocale( request ), model );
123
124 return t.getHtml( );
125 }
126
127 @Override
128 public String getComponentId( )
129 {
130 return MYDASHBOARD_BROADCASTPROXY_ID;
131 }
132
133 @Override
134 public String getComponentDescription( Locale locale )
135 {
136 return I18nService.getLocalizedString( PROPERTY_MYDASHBOARD_DESCRIPTION, locale );
137 }
138
139
140
141
142
143
144
145 protected void addInfo( String strMessage )
146 {
147 _listInfos.add( new MVCMessage( strMessage ) );
148 }
149
150
151
152
153
154
155
156
157
158 protected void addInfo( String strMessageKey, Locale locale )
159 {
160 _listInfos.add( new MVCMessage( I18nService.getLocalizedString( strMessageKey, locale ) ) );
161 }
162 }