Search in sources :

Example 1 with NonTransientDataAccessResourceException

use of org.springframework.dao.NonTransientDataAccessResourceException 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 NonTransientDataAccessResourceException

use of org.springframework.dao.NonTransientDataAccessResourceException 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 NonTransientDataAccessResourceException

use of org.springframework.dao.NonTransientDataAccessResourceException in project ORCID-Source by ORCID.

the class OrcidSearchManagerImpl method findPublicProfileById.

@Override
public OrcidMessage findPublicProfileById(String orcid) {
    OrcidMessage om = null;
    try {
        if (cachingSource.equals(DB)) {
            OrcidProfile orcidProfile = orcidProfileCacheManager.retrievePublic(orcid);
            orcidProfile.setOrcidInternal(null);
            om = new OrcidMessage(orcidProfile);
        } else {
            try (Reader reader = solrDao.findByOrcidAsReader(orcid)) {
                if (reader != null) {
                    BufferedReader br = new BufferedReader(reader);
                    om = OrcidMessage.unmarshall(br);
                }
            }
        }
    } catch (NonTransientDataAccessResourceException e) {
        throw new OrcidSearchException("Error searching by id: " + orcid, e);
    } catch (IOException e) {
        throw new OrcidSearchException("Error closing stream for id: " + orcid, e);
    }
    if (om == null)
        throw new OrcidSearchException("Result is null");
    return om;
}
Also used : OrcidProfile(org.orcid.jaxb.model.message.OrcidProfile) NonTransientDataAccessResourceException(org.springframework.dao.NonTransientDataAccessResourceException) OrcidSearchException(org.orcid.core.exception.OrcidSearchException) OrcidMessage(org.orcid.jaxb.model.message.OrcidMessage) BufferedReader(java.io.BufferedReader) Reader(java.io.Reader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Example 4 with NonTransientDataAccessResourceException

use of org.springframework.dao.NonTransientDataAccessResourceException 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 5 with NonTransientDataAccessResourceException

use of org.springframework.dao.NonTransientDataAccessResourceException 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)

Aggregations

NonTransientDataAccessResourceException (org.springframework.dao.NonTransientDataAccessResourceException)16 SolrServerException (org.apache.solr.client.solrj.SolrServerException)13 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)8 IOException (java.io.IOException)7 SolrQuery (org.apache.solr.client.solrj.SolrQuery)7 SolrDocument (org.apache.solr.common.SolrDocument)4 OrcidSolrDocument (org.orcid.utils.solr.entities.OrcidSolrDocument)4 BufferedReader (java.io.BufferedReader)2 Reader (java.io.Reader)2 Date (java.util.Date)2 OrcidSearchException (org.orcid.core.exception.OrcidSearchException)2 OrcidMessage (org.orcid.jaxb.model.message.OrcidMessage)2 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)2 OrcidSolrResult (org.orcid.utils.solr.entities.OrcidSolrResult)2 File (java.io.File)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1