Skip to content

Commit

Permalink
Endpoint to fetch org info is done, working on unit testing
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Oct 20, 2023
1 parent 6b49808 commit 5162de2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class OrcidSolrOrgsClient {

private static final String SOLR_SELF_SERVICE_ORGS_QUERY = "(org-disambiguated-id-from-source:%s)^50.0 (org-disambiguated-name%s)^50.0 (org-disambiguated-name-string:%s)^25.0";


private static final String SOLR_ORG_BY_ROR_ID_QUERY = "org-disambiguated-id-from-source:%s";

public OrgDisambiguatedSolrDocument findById(Long id) {
SolrQuery query = new SolrQuery();
Expand Down Expand Up @@ -93,4 +93,19 @@ public List<OrgDisambiguatedSolrDocument> getOrgsForSelfService(String searchTer
throw new NonTransientDataAccessResourceException(errorMessage, se);
}
}

public OrgDisambiguatedSolrDocument getOrgByRorId(String rorId) {
SolrQuery query = new SolrQuery();
// Escape the : on the email domain to be able to search in solr
query.setQuery(SOLR_ORG_BY_ROR_ID_QUERY.replace("%s", rorId.replace(":", "\\:")));
query.addOrUpdateSort("score", ORDER.desc);
try {
QueryResponse queryResponse = solrReadOnlyOrgsClient.query(query);
List<OrgDisambiguatedSolrDocument> result = queryResponse.getBeans(OrgDisambiguatedSolrDocument.class);
return (result == null || result.isEmpty()) ? null : result.get(0);
} catch (SolrServerException | IOException se) {
String errorMessage = MessageFormat.format("Error when attempting to search for orgs by ror id, with ror id {0}", new Object[] { rorId });
throw new NonTransientDataAccessResourceException(errorMessage, se);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package org.orcid.frontend.web.controllers;

import java.util.List;

import javax.annotation.Resource;
import javax.ws.rs.core.MediaType;

import org.orcid.core.common.manager.EmailDomainManager;
import org.orcid.core.manager.OrgDisambiguatedManager;
import org.orcid.core.solr.OrcidSolrOrgsClient;
import org.orcid.core.utils.OrcidStringUtils;
import org.orcid.persistence.jpa.entities.EmailDomainEntity;
import org.orcid.pojo.OrgDisambiguated;
import org.orcid.utils.solr.entities.OrgDisambiguatedSolrDocument;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -27,7 +25,7 @@ public class EmailDomainController {
private EmailDomainManager emailDomainManager;

@Resource
private OrgDisambiguatedManager orgDisambiguatedManager;
private OrcidSolrOrgsClient orcidSolrOrgsClient;

@RequestMapping(value = "/find-category", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON)
public @ResponseBody ObjectNode findCategory(@RequestParam("domain") String domain) {
Expand Down Expand Up @@ -62,19 +60,16 @@ public class EmailDomainController {

EmailDomainEntity ede = emailDomainManager.findByEmailDoman(domain);
if(ede != null) {
String emailDomain = ede.getEmailDomain();
if(emailDomain != null && !emailDomain.isBlank()) {
// Escape the : on the email domain to be able to search in solr
emailDomain = emailDomain.replace(":", "\\:");
String searchTerm = "org-disambiguated-id-from-source:" + emailDomain;
List<OrgDisambiguated> orgsInfo = orgDisambiguatedManager.searchOrgsFromSolr(searchTerm, 0, 1, false);
if(orgsInfo != null && !orgsInfo.isEmpty()) {
String rorId = ede.getRorId();
if(rorId != null && !rorId.isBlank()) {
OrgDisambiguatedSolrDocument orgInfo = orcidSolrOrgsClient.getOrgByRorId(rorId);
if(orgInfo != null) {
// Pick the first result
OrgDisambiguated firstOrg = orgsInfo.get(0);
response.put("ROR", domain);
response.put("Org Name", firstOrg.getValue());
response.put("Country", firstOrg.getCountry());
response.put("City", firstOrg.getCity());
response.put("Domain", domain);
response.put("ROR", rorId);
response.put("Org Name", orgInfo.getOrgDisambiguatedName());
response.put("Country", orgInfo.getOrgDisambiguatedCountry());
response.put("City", orgInfo.getOrgDisambiguatedCity());
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion orcid-web/src/main/resources/orcid-frontend-security.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,9 @@
<sec:intercept-url pattern="/countryNamesToCountryCodes.json(\?.*)?"
access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/email-domain/find-category(\?.*)?"
access="IS_AUTHENTICATED_ANONYMOUSLY" />
access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/email-domain/find-org(\?.*)?"
access="IS_AUTHENTICATED_ANONYMOUSLY" />
<sec:intercept-url pattern="/developer-tools"
access="ROLE_USER"/>
<sec:intercept-url pattern="/developer-tools/.*"
Expand Down

0 comments on commit 5162de2

Please sign in to comment.