use of edu.harvard.iq.dataverse.engine.command.impl.CreateSavedSearchCommand in project dataverse by IQSS.
the class DataversePage method saveSavedSearch.
public String saveSavedSearch() {
if (linkingDataverseId == null) {
JsfHelper.addErrorMessage("You must select a linking dataverse.");
return "";
}
linkingDataverse = dataverseService.find(linkingDataverseId);
AuthenticatedUser savedSearchCreator = getAuthenticatedUser();
if (savedSearchCreator == null) {
String msg = "Only authenticated users can save a search.";
logger.severe(msg);
JsfHelper.addErrorMessage(msg);
return returnRedirect();
}
SavedSearch savedSearch = new SavedSearch(searchIncludeFragment.getQuery(), linkingDataverse, savedSearchCreator);
savedSearch.setSavedSearchFilterQueries(new ArrayList<>());
for (String filterQuery : searchIncludeFragment.getFilterQueriesDebug()) {
/**
* @todo Why are there null's here anyway? Turn on debug and figure
* this out.
*/
if (filterQuery != null && !filterQuery.isEmpty()) {
SavedSearchFilterQuery ssfq = new SavedSearchFilterQuery(filterQuery, savedSearch);
savedSearch.getSavedSearchFilterQueries().add(ssfq);
}
}
CreateSavedSearchCommand cmd = new CreateSavedSearchCommand(dvRequestService.getDataverseRequest(), linkingDataverse, savedSearch);
try {
commandEngine.submit(cmd);
List<String> arguments = new ArrayList<>();
String linkString = "<a href=\"/dataverse/" + linkingDataverse.getAlias() + "\">" + StringEscapeUtils.escapeHtml(linkingDataverse.getDisplayName()) + "</a>";
arguments.add(linkString);
String successMessageString = BundleUtil.getStringFromBundle("dataverse.saved.search.success", arguments);
JsfHelper.addSuccessMessage(successMessageString);
return returnRedirect();
} catch (CommandException ex) {
String msg = "There was a problem linking this search to yours: " + ex;
logger.severe(msg);
JsfHelper.addErrorMessage(BundleUtil.getStringFromBundle("dataverse.saved.search.failure") + " " + ex);
return returnRedirect();
}
}
Aggregations