Search in sources :

Example 1 with CreateSavedSearchCommand

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();
    }
}
Also used : CreateSavedSearchCommand(edu.harvard.iq.dataverse.engine.command.impl.CreateSavedSearchCommand) SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch) SavedSearchFilterQuery(edu.harvard.iq.dataverse.search.savedsearch.SavedSearchFilterQuery) ArrayList(java.util.ArrayList) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) AuthenticatedUser(edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)

Aggregations

AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)1 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)1 CreateSavedSearchCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateSavedSearchCommand)1 SavedSearch (edu.harvard.iq.dataverse.search.savedsearch.SavedSearch)1 SavedSearchFilterQuery (edu.harvard.iq.dataverse.search.savedsearch.SavedSearchFilterQuery)1 ArrayList (java.util.ArrayList)1