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;
}
}
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;
}
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());
}
}
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);
}
Aggregations