Search in sources :

Example 1 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class SolrIndexUpdater method retrieveLastModified.

public Date retrieveLastModified(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"");
    query.setFields(PROFILE_LAST_MODIFIED_DATE);
    try {
        QueryResponse response = solrServer.query(query);
        List<SolrDocument> results = response.getResults();
        if (results.isEmpty()) {
            return null;
        } else {
            return (Date) results.get(0).getFieldValue(PROFILE_LAST_MODIFIED_DATE);
        }
    } catch (SolrServerException e) {
        throw new NonTransientDataAccessResourceException("Error retrieving last modified date from SOLR Server", e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrDocument(org.apache.solr.common.SolrDocument) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Date(java.util.Date)

Example 2 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class OrgDisambiguatedSolrDaoImpl method findById.

@Override
public OrgDisambiguatedSolrDocument findById(Long id) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORG_DISAMBIGUATED_ID + ":" + id).setFields("*");
    try {
        QueryResponse queryResponse = solrServerReadOnly.query(query);
        if (!queryResponse.getResults().isEmpty()) {
            OrgDisambiguatedSolrDocument document = queryResponse.getBeans(OrgDisambiguatedSolrDocument.class).get(0);
            return document;
        }
    } catch (SolrServerException se) {
        String errorMessage = MessageFormat.format("Error when attempting to retrieve org {0}", new Object[] { id });
        throw new NonTransientDataAccessResourceException(errorMessage, se);
    }
    return null;
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument) SolrQuery(org.apache.solr.client.solrj.SolrQuery)

Example 3 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class SolrDaoImpl method persist.

@Override
public void persist(OrcidSolrDocument orcidSolrDocument) {
    try {
        solrServer.addBean(orcidSolrDocument);
        solrServer.commit();
    } catch (SolrServerException se) {
        throw new NonTransientDataAccessResourceException("Error persisting to SOLR Server", se);
    } catch (IOException ioe) {
        throw new NonTransientDataAccessResourceException("IOException when persisting to SOLR", ioe);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException)

Example 4 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class SolrDaoImpl method findByOrcidAsReader.

@Override
public Reader findByOrcidAsReader(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"").setFields(SCORE, ORCID, PUBLIC_PROFILE);
    query.add("wt", "orcidProfile");
    try {
        QueryResponse queryResponse = solrServerForStreaming.query(query);
        InputStream inputStream = (InputStream) queryResponse.getResponse().get("stream");
        return new InputStreamReader(inputStream, "UTF-8");
    } catch (SolrServerException | SolrException e) {
        String errorMessage = MessageFormat.format("Error when attempting to retrieve stream for orcid {0}", new Object[] { orcid });
        throw new NonTransientDataAccessResourceException(errorMessage, e);
    } catch (UnsupportedEncodingException e) {
        throw new RuntimeException(e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrException(org.apache.solr.common.SolrException)

Example 5 with SolrServerException

use of org.apache.solr.client.solrj.SolrServerException in project ORCID-Source by ORCID.

the class SolrDaoImpl method retrieveLastModified.

@Override
public Date retrieveLastModified(String orcid) {
    SolrQuery query = new SolrQuery();
    query.setQuery(ORCID + ":\"" + orcid + "\"");
    query.setFields(PROFILE_LAST_MODIFIED_DATE);
    try {
        QueryResponse response = solrServer.query(query);
        List<SolrDocument> results = response.getResults();
        if (results.isEmpty()) {
            return null;
        } else {
            return (Date) results.get(0).getFieldValue(PROFILE_LAST_MODIFIED_DATE);
        }
    } catch (SolrServerException e) {
        throw new NonTransientDataAccessResourceException("Error retrieving last modified date from SOLR Server", e);
    }
}
Also used : NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) SolrDocument(org.apache.solr.common.SolrDocument) OrcidSolrDocument(org.orcid.utils.solr.entities.OrcidSolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) SolrServerException(org.apache.solr.client.solrj.SolrServerException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) Date(java.util.Date)

Aggregations

SolrServerException (org.apache.solr.client.solrj.SolrServerException)279 IOException (java.io.IOException)208 SolrQuery (org.apache.solr.client.solrj.SolrQuery)100 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)96 ArrayList (java.util.ArrayList)58 SolrException (org.apache.solr.common.SolrException)56 SolrDocument (org.apache.solr.common.SolrDocument)55 SolrInputDocument (org.apache.solr.common.SolrInputDocument)50 SolrDocumentList (org.apache.solr.common.SolrDocumentList)44 HashMap (java.util.HashMap)30 Map (java.util.Map)28 List (java.util.List)27 UpdateResponse (org.apache.solr.client.solrj.response.UpdateResponse)26 SolrClient (org.apache.solr.client.solrj.SolrClient)23 ModifiableSolrParams (org.apache.solr.common.params.ModifiableSolrParams)23 NamedList (org.apache.solr.common.util.NamedList)21 UpdateRequest (org.apache.solr.client.solrj.request.UpdateRequest)19 Date (java.util.Date)17 HttpSolrClient (org.apache.solr.client.solrj.impl.HttpSolrClient)17 SolrParams (org.apache.solr.common.params.SolrParams)13