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.portal.web.search;
35
36 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
37 import fr.paris.lutece.portal.service.search.IndexationService;
38 import fr.paris.lutece.portal.service.search.SearchIndexer;
39 import fr.paris.lutece.portal.service.security.SecurityTokenService;
40 import fr.paris.lutece.portal.service.template.AppTemplateService;
41 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
42 import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
43 import fr.paris.lutece.util.html.HtmlTemplate;
44
45 import java.util.Collection;
46 import java.util.HashMap;
47
48 import javax.servlet.http.HttpServletRequest;
49
50
51
52
53 public class SearchIndexationJspBean extends AdminFeaturesPageJspBean
54 {
55
56
57
58
59
60 public static final String RIGHT_INDEXER = "CORE_SEARCH_INDEXATION";
61 private static final long serialVersionUID = 2585709013740037568L;
62 private static final String TEMPLATE_MANAGE_INDEXER = "admin/search/manage_search_indexation.html";
63 private static final String TEMPLATE_INDEXER_LOGS = "admin/search/search_indexation_logs.html";
64 private static final String MARK_LOGS = "logs";
65 private static final String MARK_INDEXERS_LIST = "indexers_list";
66
67
68
69
70
71
72
73
74 public String getIndexingProperties( HttpServletRequest request )
75 {
76 HashMap<String, Object> model = new HashMap<>( );
77 Collection<SearchIndexer> listIndexers = IndexationService.getIndexers( );
78 model.put( MARK_INDEXERS_LIST, listIndexers );
79 model.put( SecurityTokenService.MARK_TOKEN, SecurityTokenService.getInstance( ).getToken( request, TEMPLATE_MANAGE_INDEXER ) );
80
81 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_MANAGE_INDEXER, getLocale( ), model );
82
83 return getAdminPage( template.getHtml( ) );
84 }
85
86
87
88
89
90
91
92
93
94
95 public String doIndexing( HttpServletRequest request ) throws AccessDeniedException
96 {
97 if ( !SecurityTokenService.getInstance( ).validate( request, TEMPLATE_MANAGE_INDEXER ) )
98 {
99 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
100 }
101 HashMap<String, Object> model = new HashMap<>( );
102 String strLogs;
103
104 if ( request.getParameter( "incremental" ) != null )
105 {
106 strLogs = IndexationService.processIndexing( false );
107 }
108 else
109 {
110 strLogs = IndexationService.processIndexing( true );
111 }
112
113 model.put( MARK_LOGS, strLogs );
114
115 HtmlTemplate template = AppTemplateService.getTemplate( TEMPLATE_INDEXER_LOGS, null, model );
116
117 return getAdminPage( template.getHtml( ) );
118 }
119 }