*/
private void putSavedSearches(HttpServletRequest request,
HttpServletResponse response, RequestContext context)
throws SearchException, IOException, JSONException {
ISearchSaveRepository saveRpstry =
SearchSaveRpstryFactory.getSearchSaveRepository();
if(saveRpstry instanceof GptRepository) {
((GptRepository) saveRpstry).setRequestContext(context);
}
SavedSearchCriterias savedSearchCriterias =
saveRpstry.getSavedList(context.getUser());
if(savedSearchCriterias.size() >=
SearchConfig.getConfiguredInstance().getMaxSavedSearches()) {
MessageBroker messageBroker =
new FacesContextBroker(request,response).extractMessageBroker();
String message =
messageBroker.getMessage("catalog.search.error.maxSavedSearchesReached")
.getSummary();
writeSavedSearches(request, response, context, message);
return;
}
String body = IOUtils.toString(request.getInputStream(), "UTF-8");
Map<String, String> paramMap = urlToParamMap(body);
String name = "";
String criteria = "";
name = paramMap.get("name");
if("".equals(Val.chkStr(name))) {
MessageBroker messageBroker =
new FacesContextBroker(request,response).extractMessageBroker();
String message =
messageBroker.getMessage("catalog.search.savedSearches.noSaveName")
.getSummary();
writeSavedSearches(request, response, context, message);
return;
}
criteria = Val.chkStr(paramMap.get("criteria"));
if(criteria.contains("?")) {
criteria = criteria.substring(criteria.indexOf("?"));
criteria = criteria.replace("?", "");
}
saveRpstry.save(name, criteria, context.getUser());
writeSavedSearches(request, response, context);
}