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