use of org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument 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.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument in project ORCID-Source by ORCID.
the class OrgDisambiguatedSolrDaoTest method testPesistAndFindById.
@Test
public void testPesistAndFindById() {
OrgDisambiguatedSolrDocument doc = new OrgDisambiguatedSolrDocument();
doc.setOrgDisambiguatedId(1L);
doc.setOrgDisambiguatedName("Test org name");
doc.setOrgDisambiguatedCity("Haywards Heath");
doc.setOrgDisambiguatedRegion("West Sussex");
doc.setOrgDisambiguatedCountry("GB");
List<String> orgNames = new ArrayList<>();
orgNames.add("Test org name");
orgNames.add("Test organisation name");
doc.setOrgNames(orgNames);
orgDisambiguatedSolrDao.persist(doc);
OrgDisambiguatedSolrDocument result = orgDisambiguatedSolrDao.findById(1L);
assertNotNull(result);
assertEquals(1L, result.getOrgDisambiguatedId().longValue());
assertEquals("Test org name", result.getOrgDisambiguatedName());
}
use of org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerImpl method convertEntityToDocument.
private OrgDisambiguatedSolrDocument convertEntityToDocument(OrgDisambiguatedEntity entity) {
OrgDisambiguatedSolrDocument document = new OrgDisambiguatedSolrDocument();
document.setOrgDisambiguatedId(entity.getId());
document.setOrgDisambiguatedName(entity.getName());
document.setOrgDisambiguatedCity(entity.getCity());
document.setOrgDisambiguatedRegion(entity.getRegion());
if (entity.getCountry() != null)
document.setOrgDisambiguatedCountry(entity.getCountry().value());
document.setOrgDisambiguatedType(entity.getOrgType());
document.setOrgDisambiguatedPopularity(entity.getPopularity());
Set<String> orgNames = new HashSet<>();
orgNames.add(entity.getName());
Set<OrgEntity> orgs = entity.getOrgs();
if (orgs != null) {
for (OrgEntity org : orgs) {
orgNames.add(org.getName());
}
}
document.setOrgNames(new ArrayList<>(orgNames));
if (FUNDING_ORG_TYPE.equals(entity.getSourceType()) || hasFundrefExternalIdentifier(entity.getExternalIdentifiers())) {
document.setFundingOrg(true);
} else {
document.setFundingOrg(false);
}
return document;
}
use of org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerImpl method searchOrgsFromSolr.
@Override
public List<OrgDisambiguated> searchOrgsFromSolr(String searchTerm, int firstResult, int maxResult, boolean fundersOnly) {
List<OrgDisambiguatedSolrDocument> docs = orgDisambiguatedSolrDao.getOrgs(searchTerm, firstResult, maxResult, fundersOnly);
List<OrgDisambiguated> ret = new ArrayList<OrgDisambiguated>();
for (OrgDisambiguatedSolrDocument doc : docs) {
OrgDisambiguated org = new OrgDisambiguated();
org.setValue(doc.getOrgDisambiguatedName());
org.setCity(doc.getOrgDisambiguatedCity());
org.setRegion(doc.getOrgDisambiguatedRegion());
org.setCountry(doc.getOrgDisambiguatedCountry());
org.setOrgType(doc.getOrgDisambiguatedType());
org.setDisambiguatedAffiliationIdentifier(Long.toString(doc.getOrgDisambiguatedId()));
ret.add(org);
}
return ret;
}
use of org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument in project ORCID-Source by ORCID.
the class OrgDisambiguatedManagerImpl method processDisambiguatedOrg.
private void processDisambiguatedOrg(OrgDisambiguatedEntity entity) {
LOGGER.info("About to index disambiguated org, id={}", entity.getId());
OrgDisambiguatedSolrDocument document = convertEntityToDocument(entity);
if (OrganizationStatus.DEPRECATED.name().equals(entity.getStatus())) {
orgDisambiguatedSolrDao.remove(document.getOrgDisambiguatedId());
} else {
orgDisambiguatedSolrDao.persist(document);
}
orgDisambiguatedDao.updateIndexingStatus(entity.getId(), IndexingStatus.DONE);
}
Aggregations