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.myapps.web;
35
36 import fr.paris.lutece.plugins.myapps.business.MyApps;
37 import fr.paris.lutece.plugins.myapps.service.MyAppsManager;
38 import fr.paris.lutece.plugins.myapps.service.MyAppsProvider;
39 import fr.paris.lutece.plugins.myapps.service.parameter.MyAppsParameterService;
40 import fr.paris.lutece.portal.service.i18n.I18nService;
41 import fr.paris.lutece.portal.service.message.SiteMessageException;
42 import fr.paris.lutece.portal.service.plugin.Plugin;
43 import fr.paris.lutece.portal.service.security.LuteceUser;
44 import fr.paris.lutece.portal.service.security.SecurityService;
45 import fr.paris.lutece.portal.service.security.UserNotSignedException;
46 import fr.paris.lutece.portal.service.template.AppTemplateService;
47 import fr.paris.lutece.portal.web.xpages.XPage;
48 import fr.paris.lutece.portal.web.xpages.XPageApplication;
49 import fr.paris.lutece.util.ReferenceItem;
50 import fr.paris.lutece.util.html.HtmlTemplate;
51 import fr.paris.lutece.util.sort.AttributeComparator;
52
53 import java.util.ArrayList;
54 import java.util.Collections;
55 import java.util.HashMap;
56 import java.util.List;
57 import java.util.Map;
58
59 import javax.servlet.http.HttpServletRequest;
60
61
62
63
64
65
66
67 public class MyAppsApp implements XPageApplication
68 {
69
70 private static final String TEMPLATE_MYAPPS_IN_DIVIDED_LISTS = "skin/plugins/myapps/page_myapps_in_divided_lists.html";
71 private static final String TEMPLATE_MYAPPS_IN_ONE_LIST = "skin/plugins/myapps/page_myapps_in_one_list.html";
72
73
74 private static final String MARK_MYAPPS_PROVIDERS_LIST = "myapps_providers_list";
75 private static final String MARK_USER_NAME = "user_name";
76 private static final String MARK_LOCALE = "locale";
77 private static final String MARK_MYAPPS_LIST = "myapps_list";
78 private static final String MARK_IS_ASC_SORT = "is_asc_sort";
79
80
81 private static final String PARAMETER_IS_SHOWN_IN_ONE_LIST = "is_shown_in_one_list";
82 private static final String PARAMETER_IS_ASC_SORT = "is_asc_sort";
83 private static final String PARAMETER_NAME = "name";
84
85
86 private static final String PROPERTY_PAGE_TITLE = "myapps.page_myapps.pageTitle";
87 private static final String PROPERTY_PAGE_PATH = "myapps.page_myapps.pagePathLabel";
88
89
90
91
92
93
94
95
96
97
98
99 public XPage getPage( HttpServletRequest request, int nMode, Plugin plugin )
100 throws SiteMessageException, UserNotSignedException
101 {
102 XPage page = new XPage( );
103 page.setTitle( I18nService.getLocalizedString( PROPERTY_PAGE_TITLE, request.getLocale( ) ) );
104 page.setPathLabel( I18nService.getLocalizedString( PROPERTY_PAGE_PATH, request.getLocale( ) ) );
105
106 page = getManageMyAppsPage( page, request, plugin );
107
108 return page;
109 }
110
111
112
113
114
115
116
117
118
119
120 private XPage getManageMyAppsPage( XPage page, HttpServletRequest request, Plugin plugin )
121 throws UserNotSignedException
122 {
123 LuteceUser user = SecurityService.getInstance( ).getRemoteUser( request );
124
125 if ( user != null )
126 {
127 ReferenceItem isShownInOneList = MyAppsParameterService.getInstance( )
128 .getParamDefaultValue( PARAMETER_IS_SHOWN_IN_ONE_LIST,
129 plugin );
130 ReferenceItem isAscSort = MyAppsParameterService.getInstance( )
131 .getParamDefaultValue( PARAMETER_IS_ASC_SORT, plugin );
132 List<MyAppsProvider> listProviders = MyAppsManager.getInstance( ).getProvidersList( );
133
134 HtmlTemplate template;
135 Map<String, Object> model = new HashMap<String, Object>( );
136 model.put( MARK_USER_NAME, user.getName( ) );
137 model.put( MARK_LOCALE, request.getLocale( ) );
138 model.put( MARK_MYAPPS_PROVIDERS_LIST, listProviders );
139
140
141 if ( isShownInOneList.isChecked( ) )
142 {
143 List<MyApps> listMyApps = new ArrayList<MyApps>( );
144
145 for ( MyAppsProvider provider : listProviders )
146 {
147 listMyApps.addAll( provider.getMyAppsListByUserName( user.getName( ), isAscSort.isChecked( ) ) );
148 }
149
150 Collections.sort( listMyApps, new AttributeComparator( PARAMETER_NAME, isAscSort.isChecked( ) ) );
151 model.put( MARK_MYAPPS_LIST, listMyApps );
152 template = AppTemplateService.getTemplate( TEMPLATE_MYAPPS_IN_ONE_LIST, request.getLocale( ), model );
153 }
154 else
155 {
156 model.put( MARK_IS_ASC_SORT, isAscSort.isChecked( ) );
157 template = AppTemplateService.getTemplate( TEMPLATE_MYAPPS_IN_DIVIDED_LISTS, request.getLocale( ),
158 model );
159 }
160
161 page.setContent( template.getHtml( ) );
162 }
163 else
164 {
165 throw new UserNotSignedException( );
166 }
167
168 return page;
169 }
170 }