001/* 002 * Copyright 2018 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.web.frontoffice.search.requesttime; 017 018import java.util.Optional; 019 020import org.apache.avalon.framework.parameters.Parameters; 021import org.apache.cocoon.environment.Request; 022import org.apache.cocoon.environment.Response; 023import org.slf4j.Logger; 024import org.xml.sax.ContentHandler; 025 026import org.ametys.cms.search.SearchResults; 027import org.ametys.cms.search.solr.SearcherFactory.Searcher; 028import org.ametys.plugins.repository.AmetysObject; 029import org.ametys.web.frontoffice.search.SearchService; 030import org.ametys.web.frontoffice.search.instance.SearchServiceInstance; 031import org.ametys.web.frontoffice.search.requesttime.SearchServiceDebugModeHelper.DebugMode; 032import org.ametys.web.frontoffice.search.requesttime.input.SearchUserInputs; 033import org.ametys.web.frontoffice.search.requesttime.pagination.Pagination; 034import org.ametys.web.repository.page.Page; 035import org.ametys.web.repository.site.Site; 036 037/** 038 * Wrapper of arguments passed to {@link SearchComponent#execute(SearchComponentArguments) SearchComponent#execute} 039 */ 040public class SearchComponentArguments 041{ 042 private ContentHandler _contentHandler; 043 private Parameters _generatorParameters; 044 private SearchServiceInstance _serviceInstance; 045 private SearchService _service; 046 private SearchUserInputs _userInputs; 047 private Request _request; 048 private Response _response; 049 private Pagination _pagination; 050 private Site _currentSite; 051 private Page _currentPage; 052 private String _currentLang; 053 private boolean _launchSearch; 054 private SearchResults<AmetysObject> _results; 055 private SearchResults<AmetysObject> _enumeratedResults; 056 private Searcher _searcher; 057 private Logger _logger; 058 private DebugMode _debugMode; 059 060 /** 061 * Constructor 062 * @param contentHandler the content handler 063 * @param generatorParameters the parameters of the generator 064 * @param serviceInstance the search service instance 065 * @param service the search service 066 * @param userInputs the user inputs 067 * @param request the current request 068 * @param response the response 069 * @param pagination the pagination 070 * @param currentSite the current site 071 * @param currentPage the current page 072 * @param currentLang the current lang 073 * @param launchSearch <code>true</code> if the search has to be launch 074 * @param searcher the searcher 075 * @param logger the logger 076 * @param debugMode the debug mode. Can be null 077 */ 078 protected SearchComponentArguments(ContentHandler contentHandler, 079 Parameters generatorParameters, 080 SearchServiceInstance serviceInstance, 081 SearchService service, 082 SearchUserInputs userInputs, 083 Request request, 084 Response response, 085 Pagination pagination, 086 Site currentSite, 087 Page currentPage, 088 String currentLang, 089 boolean launchSearch, 090 Searcher searcher, 091 Logger logger, 092 DebugMode debugMode) 093 { 094 _contentHandler = contentHandler; 095 _generatorParameters = generatorParameters; 096 _serviceInstance = serviceInstance; 097 _service = service; 098 _userInputs = userInputs; 099 _request = request; 100 _response = response; 101 _pagination = pagination; 102 _currentSite = currentSite; 103 _currentPage = currentPage; 104 _currentLang = currentLang; 105 _launchSearch = launchSearch; 106 _searcher = searcher; 107 _logger = logger; 108 _debugMode = debugMode; 109 } 110 111 /** 112 * Gets the content handler 113 * @return the content handler 114 */ 115 public ContentHandler contentHandler() 116 { 117 return _contentHandler; 118 } 119 120 /** 121 * Gets the parameters of the generator, allowing to change some behaviors depending on the URL the request comes from 122 * @return the parameters of the generator 123 */ 124 public Parameters generatorParameters() 125 { 126 return _generatorParameters; 127 } 128 129 /** 130 * Gets the search service instance 131 * @return the search service instance 132 */ 133 public SearchServiceInstance serviceInstance() 134 { 135 return _serviceInstance; 136 } 137 138 /** 139 * Gets the search service 140 * @return the search service 141 */ 142 public SearchService service() 143 { 144 return _service; 145 } 146 147 /** 148 * Gets the user inputs 149 * @return the user inputs 150 */ 151 public SearchUserInputs userInputs() 152 { 153 return _userInputs; 154 } 155 156 /** 157 * Update the user inputs 158 * @param userInputs the user inputs 159 */ 160 public void updateUserInputs(SearchUserInputs userInputs) 161 { 162 this._userInputs = userInputs; 163 } 164 165 /** 166 * Gets the current request 167 * @return the current request 168 */ 169 public Request request() 170 { 171 return _request; 172 } 173 174 /** 175 * Gets the response 176 * @return the response 177 */ 178 public Response response() 179 { 180 return _response; 181 } 182 183 /** 184 * Gets the pagination 185 * @return the pagination 186 */ 187 public Pagination pagination() 188 { 189 return _pagination; 190 } 191 192 /** 193 * Gets the current site 194 * @return the current site 195 */ 196 public Site currentSite() 197 { 198 return _currentSite; 199 } 200 201 /** 202 * Gets the current page 203 * @return the current page 204 */ 205 public Page currentPage() 206 { 207 return _currentPage; 208 } 209 210 /** 211 * Gets the current lang 212 * @return the current lang 213 */ 214 public String currentLang() 215 { 216 return _currentLang; 217 } 218 219 /** 220 * Returns <code>true</code> if the search has to be launch 221 * @return <code>true</code> if the search has to be launch 222 */ 223 public boolean launchSearch() 224 { 225 return _launchSearch; 226 } 227 228 /** 229 * Sets the results 230 * @param results the results 231 */ 232 public void setResults(SearchResults<AmetysObject> results) 233 { 234 _results = results; 235 } 236 237 /** 238 * Gets the results of the search. Can be empty if search has not been executed yet 239 * @return the results of the search, or an empty optional if search has not been executed yet 240 */ 241 public Optional<SearchResults<AmetysObject>> results() 242 { 243 return Optional.ofNullable(_results); 244 } 245 246 /** 247 * Sets the enumerated results 248 * @param enumeratedResults the enumerated results 249 */ 250 public void setEnumeratedResults(SearchResults<AmetysObject> enumeratedResults) 251 { 252 _enumeratedResults = enumeratedResults; 253 } 254 255 /** 256 * Gets the enumerated results of the search. Can be empty if enumerated search has not been executed yet or computeCriteriaCounts parameter is <code>false</code> 257 * @return the enumerated results of the search, or an empty optional if enumerated search has not been executed yet or computeCriteriaCounts parameter is <code>false</code> 258 */ 259 public Optional<SearchResults<AmetysObject>> enumeratedResults() 260 { 261 return Optional.ofNullable(_enumeratedResults); 262 } 263 264 /** 265 * Gets the searcher 266 * @return the searcher 267 */ 268 public Searcher searcher() 269 { 270 return _searcher; 271 } 272 273 /** 274 * Gets the logger 275 * @return the logger 276 */ 277 public Logger logger() 278 { 279 return _logger; 280 } 281 282 /** 283 * Returns <code>true</code> if debug is activated 284 * @return <code>true</code> if debug is activated 285 */ 286 public boolean isDebug() 287 { 288 return _debugMode != null; 289 } 290 291 /** 292 * Gets the debug mode 293 * @return the debug mode 294 */ 295 public Optional<DebugMode> debugMode() 296 { 297 return Optional.ofNullable(_debugMode); 298 } 299}