Search in sources :

Example 6 with SavedSearch

use of edu.harvard.iq.dataverse.search.savedsearch.SavedSearch in project dataverse by IQSS.

the class CreateSavedSearchCommand method execute.

@Override
public SavedSearch execute(CommandContext ctxt) throws CommandException {
    String query = savedSearchToCreate.getQuery();
    if (query == null) {
        /**
         * @todo This probably shouldn't be the default. We are disallowing
         * wildcard searches. Go fix the DataversePage and make sure the
         * query is set.
         */
        String wildcardSearch = "*";
        savedSearchToCreate.setQuery(wildcardSearch);
    }
    SavedSearch persistedSavedSearch = ctxt.savedSearches().save(savedSearchToCreate);
    if (persistedSavedSearch != null) {
        try {
            DataverseRequest dataverseRequest = new DataverseRequest(savedSearchToCreate.getCreator(), SavedSearchServiceBean.getHttpServletRequest());
            JsonObjectBuilder result = ctxt.savedSearches().makeLinksForSingleSavedSearch(dataverseRequest, persistedSavedSearch, true);
            logger.log(Level.INFO, "result from attempt to make links from saved search: {0}", result.build().toString());
        } catch (SearchException ex) {
            logger.info(ex.getLocalizedMessage());
        }
        return persistedSavedSearch;
    } else {
        return null;
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch) SearchException(edu.harvard.iq.dataverse.search.SearchException) JsonObjectBuilder(javax.json.JsonObjectBuilder)

Example 7 with SavedSearch

use of edu.harvard.iq.dataverse.search.savedsearch.SavedSearch in project dataverse by IQSS.

the class DataversePage method createSavedOfCurrentDataverse.

@Deprecated
private SavedSearch createSavedOfCurrentDataverse(AuthenticatedUser savedSearchCreator) {
    /**
     * Please note that we are relying on the fact that the Solr ID of a
     * dataverse never changes, unlike datasets and files, which will change
     * from "dataset_10_draft" to "dataset_10" when published, for example.
     */
    String queryForCurrentDataverse = SearchFields.ID + ":" + IndexServiceBean.solrDocIdentifierDataverse + dataverse.getId();
    SavedSearch savedSearchToPersist = new SavedSearch(queryForCurrentDataverse, linkingDataverse, savedSearchCreator);
    SavedSearch savedSearchCreated = savedSearchService.add(savedSearchToPersist);
    return savedSearchCreated;
}
Also used : SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch)

Example 8 with SavedSearch

use of edu.harvard.iq.dataverse.search.savedsearch.SavedSearch in project dataverse by IQSS.

the class SavedSearches method makeLinksForSingleSavedSearch.

@PUT
@Path("makelinks/{id}")
public Response makeLinksForSingleSavedSearch(@PathParam("id") long savedSearchIdToLookUp, @QueryParam("debug") boolean debug) {
    SavedSearch savedSearchToMakeLinksFor = savedSearchSvc.find(savedSearchIdToLookUp);
    if (savedSearchToMakeLinksFor == null) {
        return error(BAD_REQUEST, "Count not find saved search id " + savedSearchIdToLookUp);
    }
    try {
        DataverseRequest dataverseRequest = new DataverseRequest(savedSearchToMakeLinksFor.getCreator(), SavedSearchServiceBean.getHttpServletRequest());
        JsonObjectBuilder response = savedSearchSvc.makeLinksForSingleSavedSearch(dataverseRequest, savedSearchToMakeLinksFor, debug);
        return ok(response);
    } catch (CommandException ex) {
        return error(BAD_REQUEST, ex.getLocalizedMessage());
    } catch (SearchException ex) {
        return error(INTERNAL_SERVER_ERROR, ex.getLocalizedMessage());
    }
}
Also used : DataverseRequest(edu.harvard.iq.dataverse.engine.command.DataverseRequest) SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch) SearchException(edu.harvard.iq.dataverse.search.SearchException) CommandException(edu.harvard.iq.dataverse.engine.command.exception.CommandException) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 9 with SavedSearch

use of edu.harvard.iq.dataverse.search.savedsearch.SavedSearch in project dataverse by IQSS.

the class SavedSearches method list.

@GET
@Path("list")
public Response list() {
    JsonArrayBuilder savedSearchesBuilder = Json.createArrayBuilder();
    List<SavedSearch> savedSearches = savedSearchSvc.findAll();
    for (SavedSearch savedSearch : savedSearches) {
        JsonObjectBuilder thisSavedSearch = toJson(savedSearch);
        savedSearchesBuilder.add(thisSavedSearch);
    }
    JsonObjectBuilder response = Json.createObjectBuilder();
    response.add("saved searches", savedSearchesBuilder);
    return ok(response);
}
Also used : SavedSearch(edu.harvard.iq.dataverse.search.savedsearch.SavedSearch) JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

SavedSearch (edu.harvard.iq.dataverse.search.savedsearch.SavedSearch)9 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)4 SearchException (edu.harvard.iq.dataverse.search.SearchException)4 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)3 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)3 SavedSearchFilterQuery (edu.harvard.iq.dataverse.search.savedsearch.SavedSearchFilterQuery)3 JsonObjectBuilder (javax.json.JsonObjectBuilder)3 Path (javax.ws.rs.Path)3 ArrayList (java.util.ArrayList)2 Dataverse (edu.harvard.iq.dataverse.Dataverse)1 CreateSavedSearchCommand (edu.harvard.iq.dataverse.engine.command.impl.CreateSavedSearchCommand)1 LinkDataverseCommand (edu.harvard.iq.dataverse.engine.command.impl.LinkDataverseCommand)1 EJBException (javax.ejb.EJBException)1 JsonArray (javax.json.JsonArray)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 DELETE (javax.ws.rs.DELETE)1 GET (javax.ws.rs.GET)1 POST (javax.ws.rs.POST)1 PUT (javax.ws.rs.PUT)1