Search in sources :

Example 1 with OrgDisambiguatedSolrDocument

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;
}
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 2 with OrgDisambiguatedSolrDocument

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());
}
Also used : ArrayList(java.util.ArrayList) OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument) Test(org.junit.Test)

Example 3 with OrgDisambiguatedSolrDocument

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;
}
Also used : OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument) HashSet(java.util.HashSet) OrgEntity(org.orcid.persistence.jpa.entities.OrgEntity)

Example 4 with OrgDisambiguatedSolrDocument

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;
}
Also used : ArrayList(java.util.ArrayList) OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument) OrgDisambiguated(org.orcid.pojo.OrgDisambiguated)

Example 5 with OrgDisambiguatedSolrDocument

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);
}
Also used : OrgDisambiguatedSolrDocument(org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument)

Aggregations

OrgDisambiguatedSolrDocument (org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 Test (org.junit.Test)1 OrgEntity (org.orcid.persistence.jpa.entities.OrgEntity)1 OrgDisambiguated (org.orcid.pojo.OrgDisambiguated)1 NonTransientDataAccessResourceException (org.springframework.dao.NonTransientDataAccessResourceException)1