Search in sources :

Example 6 with SearchException

use of edu.harvard.iq.dataverse.search.SearchException 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 7 with SearchException

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

the class Index method indexStatus.

@GET
@Path("status")
public Response indexStatus() {
    JsonObjectBuilder contentInDatabaseButStaleInOrMissingFromSolr = getContentInDatabaseButStaleInOrMissingFromSolr();
    JsonObjectBuilder contentInSolrButNotDatabase;
    try {
        contentInSolrButNotDatabase = getContentInSolrButNotDatabase();
    } catch (SearchException ex) {
        return error(Response.Status.INTERNAL_SERVER_ERROR, "Can not determine index status. " + ex.getLocalizedMessage() + ". Is Solr down? Exception: " + ex.getCause().getLocalizedMessage());
    }
    JsonObjectBuilder permissionsInDatabaseButStaleInOrMissingFromSolr = getPermissionsInDatabaseButStaleInOrMissingFromSolr();
    JsonObjectBuilder permissionsInSolrButNotDatabase = getPermissionsInSolrButNotDatabase();
    JsonObjectBuilder data = Json.createObjectBuilder().add("contentInDatabaseButStaleInOrMissingFromIndex", contentInDatabaseButStaleInOrMissingFromSolr).add("contentInIndexButNotDatabase", contentInSolrButNotDatabase).add("permissionsInDatabaseButStaleInOrMissingFromIndex", permissionsInDatabaseButStaleInOrMissingFromSolr).add("permissionsInIndexButNotDatabase", permissionsInSolrButNotDatabase);
    return ok(data);
}
Also used : SearchException(edu.harvard.iq.dataverse.search.SearchException) JsonObjectBuilder(javax.json.JsonObjectBuilder) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 8 with SearchException

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

the class DataRetrieverAPI method getTotalCountsFromSolr.

private SolrQueryResponse getTotalCountsFromSolr(DataverseRequest dataverseRequest, MyDataFinder myDataFinder) {
    if (myDataFinder == null) {
        throw new NullPointerException("myDataFinder cannot be null");
    }
    if (dataverseRequest == null) {
        throw new NullPointerException("dataverseRequest cannot be null");
    }
    // -------------------------------------------------------
    // Create new filter params that only check by the User
    // -------------------------------------------------------
    MyDataFilterParams filterParams = new MyDataFilterParams(dataverseRequest, myDataFinder.getRolePermissionHelper());
    if (filterParams.hasError()) {
        logger.severe("getTotalCountsFromSolr. filterParams error: " + filterParams.getErrorMessage());
        return null;
    }
    // -------------------------------------------------------
    // Re-run all of the entity queries (sigh)
    // -------------------------------------------------------
    myDataFinder.initFields();
    myDataFinder.runFindDataSteps(filterParams);
    if (myDataFinder.hasError()) {
        logger.severe("getTotalCountsFromSolr. myDataFinder error: " + myDataFinder.getErrorMessage());
        return null;
    }
    // -------------------------------------------------------
    // Generate filterQueries for total counts
    // -------------------------------------------------------
    List<String> filterQueries = myDataFinder.getSolrFilterQueriesForTotalCounts();
    if (filterQueries == null) {
        logger.severe("getTotalCountsFromSolr. filterQueries was null!");
        return null;
    }
    // msgt("getTotalCountsFromSolr");
    // msgt(StringUtils.join(filterQueries, " AND "));
    // -------------------------------------------------------
    // Run Solr
    // -------------------------------------------------------
    SolrQueryResponse solrQueryResponseForCounts;
    try {
        solrQueryResponseForCounts = searchService.search(dataverseRequest, // subtree, default it to Dataverse for now
        null, // Get everything--always
        "*", // filterQueries,
        filterQueries, SearchFields.NAME_SORT, SortBy.ASCENDING, // paginationStart,
        0, // dataRelatedToMe
        true, // 10 // SearchFields.NUM_SOLR_DOCS_TO_RETRIEVE
        SearchConstants.NUM_SOLR_DOCS_TO_RETRIEVE);
    } catch (SearchException ex) {
        logger.severe("Search for total counts failed with filter query");
        logger.severe("filterQueries: " + StringUtils.join(filterQueries, "(separator)"));
        return null;
    }
    return solrQueryResponseForCounts;
}
Also used : SolrQueryResponse(edu.harvard.iq.dataverse.search.SolrQueryResponse) SearchException(edu.harvard.iq.dataverse.search.SearchException)

Aggregations

SearchException (edu.harvard.iq.dataverse.search.SearchException)8 JsonObjectBuilder (javax.json.JsonObjectBuilder)5 AuthenticatedUser (edu.harvard.iq.dataverse.authorization.users.AuthenticatedUser)4 DataverseRequest (edu.harvard.iq.dataverse.engine.command.DataverseRequest)4 GET (javax.ws.rs.GET)4 Path (javax.ws.rs.Path)4 SolrQueryResponse (edu.harvard.iq.dataverse.search.SolrQueryResponse)3 SavedSearch (edu.harvard.iq.dataverse.search.savedsearch.SavedSearch)3 Dataverse (edu.harvard.iq.dataverse.Dataverse)2 GuestUser (edu.harvard.iq.dataverse.authorization.users.GuestUser)2 User (edu.harvard.iq.dataverse.authorization.users.User)2 CommandException (edu.harvard.iq.dataverse.engine.command.exception.CommandException)2 SolrSearchResult (edu.harvard.iq.dataverse.search.SolrSearchResult)2 JsonArrayBuilder (javax.json.JsonArrayBuilder)2 DataverseRolePermissionHelper (edu.harvard.iq.dataverse.authorization.DataverseRolePermissionHelper)1 LinkDataverseCommand (edu.harvard.iq.dataverse.engine.command.impl.LinkDataverseCommand)1 FacetCategory (edu.harvard.iq.dataverse.search.FacetCategory)1 FacetLabel (edu.harvard.iq.dataverse.search.FacetLabel)1 SortBy (edu.harvard.iq.dataverse.search.SortBy)1 ArrayList (java.util.ArrayList)1