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.business.rbac.RBAC;
37 import fr.paris.lutece.portal.business.search.SearchParameterHome;
38 import fr.paris.lutece.portal.service.admin.AccessDeniedException;
39 import fr.paris.lutece.portal.service.message.AdminMessage;
40 import fr.paris.lutece.portal.service.message.AdminMessageService;
41 import fr.paris.lutece.portal.service.rbac.RBACService;
42 import fr.paris.lutece.portal.service.search.SearchResourceIdService;
43 import fr.paris.lutece.portal.service.search.SearchService;
44 import fr.paris.lutece.portal.service.security.SecurityTokenService;
45 import fr.paris.lutece.portal.web.admin.AdminFeaturesPageJspBean;
46 import fr.paris.lutece.portal.web.constants.Messages;
47 import fr.paris.lutece.portal.web.dashboard.AdminDashboardJspBean;
48 import fr.paris.lutece.util.ReferenceItem;
49
50 import org.apache.commons.lang3.StringUtils;
51
52 import javax.servlet.http.HttpServletRequest;
53
54
55
56
57 public class SearchJspBean extends AdminFeaturesPageJspBean
58 {
59
60 public static final String RIGHT_SEARCH_MANAGEMENT = "CORE_SEARCH_MANAGEMENT";
61
62
63
64
65 private static final long serialVersionUID = -2095709285081142039L;
66
67
68
69 private static final String EMPTY_STRING = "";
70
71
72 private static final String ANCHOR_ADMIN_DASHBOARDS = "search";
73
74
75 private static final String PARAMETER_CANCEL = "cancel";
76 private static final String PARAMETER_DATE_FILTER = "date_filter";
77 private static final String PARAMETER_DEFAULT_OPERATOR = "default_operator";
78 private static final String PARAMETER_HELP_MESSAGE = "help_message";
79 private static final String PARAMETER_TAG_FILTER = "tag_filter";
80 private static final String PARAMETER_TYPE_FILTER = "type_filter";
81
82
83
84
85
86
87
88
89
90
91 public String doModifyAdvancedParameters( HttpServletRequest request ) throws AccessDeniedException
92 {
93 if ( !RBACService.isAuthorized( SearchService.RESOURCE_TYPE, RBAC.WILDCARD_RESOURCES_ID, SearchResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS,
94 getUser( ) ) )
95 {
96 throw new AccessDeniedException(
97 "User " + getUser( ) + " is not authorized to permission " + SearchResourceIdService.PERMISSION_MANAGE_ADVANCED_PARAMETERS );
98 }
99 if ( !SecurityTokenService.getInstance( ).validate( request, AdminDashboardJspBean.TEMPLATE_MANAGE_DASHBOARDS ) )
100 {
101 throw new AccessDeniedException( ERROR_INVALID_TOKEN );
102 }
103
104 if ( request.getParameter( PARAMETER_CANCEL ) == null )
105 {
106 String strTypeFilter = request.getParameter( PARAMETER_TYPE_FILTER );
107 String strDefaultOperator = request.getParameter( PARAMETER_DEFAULT_OPERATOR );
108 String strHelpMessage = request.getParameter( PARAMETER_HELP_MESSAGE );
109 String strDateFilter = request.getParameter( PARAMETER_DATE_FILTER );
110 String strTagFilter = request.getParameter( PARAMETER_TAG_FILTER );
111
112
113 if ( StringUtils.isBlank( strTypeFilter ) || StringUtils.isBlank( strDefaultOperator ) || StringUtils.isBlank( strDateFilter )
114 || StringUtils.isBlank( strTagFilter ) )
115 {
116 return AdminMessageService.getMessageUrl( request, Messages.MANDATORY_FIELDS, AdminMessage.TYPE_STOP );
117 }
118
119 ReferenceItemceItem.html#ReferenceItem">ReferenceItem param = new ReferenceItem( );
120 param.setCode( PARAMETER_TYPE_FILTER );
121 param.setName( strTypeFilter );
122 SearchParameterHome.update( param );
123
124 param = new ReferenceItem( );
125 param.setCode( PARAMETER_DEFAULT_OPERATOR );
126 param.setName( strDefaultOperator );
127 SearchParameterHome.update( param );
128
129 param = new ReferenceItem( );
130 param.setCode( PARAMETER_HELP_MESSAGE );
131 param.setName( StringUtils.isNotBlank( strHelpMessage ) ? strHelpMessage : EMPTY_STRING );
132 SearchParameterHome.update( param );
133
134 param = new ReferenceItem( );
135 param.setCode( PARAMETER_DATE_FILTER );
136 param.setName( strDateFilter );
137 SearchParameterHome.update( param );
138
139 param = new ReferenceItem( );
140 param.setCode( PARAMETER_TAG_FILTER );
141 param.setName( strTagFilter );
142 SearchParameterHome.update( param );
143 }
144
145 return getAdminDashboardsUrl( request, ANCHOR_ADMIN_DASHBOARDS );
146 }
147 }