Skip to content

Commit

Permalink
Endpoint to get org info
Browse files Browse the repository at this point in the history
  • Loading branch information
amontenegro committed Oct 20, 2023
1 parent f6a57f1 commit 6b49808
Showing 1 changed file with 38 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
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.utils.OrcidStringUtils;
import org.orcid.persistence.jpa.entities.EmailDomainEntity;
import org.orcid.pojo.OrgDisambiguated;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
Expand All @@ -22,6 +26,9 @@ public class EmailDomainController {
@Resource
private EmailDomainManager emailDomainManager;

@Resource
private OrgDisambiguatedManager orgDisambiguatedManager;

@RequestMapping(value = "/find-category", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON)
public @ResponseBody ObjectNode findCategory(@RequestParam("domain") String domain) {
ObjectMapper mapper = new ObjectMapper();
Expand All @@ -42,4 +49,35 @@ public class EmailDomainController {
return response;
}
}

@RequestMapping(value = "/find-org", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON)
public @ResponseBody ObjectNode findOrgInfo(@RequestParam("domain") String domain) {
ObjectMapper mapper = new ObjectMapper();
ObjectNode response = mapper.createObjectNode();
if(domain == null || domain.isBlank() || domain.length() > 254) {
response.put("error", "Domain length too short, empty or invalid");
return response;
}
domain = OrcidStringUtils.stripHtml(domain);

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()) {
// 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());
}
}
}
return response;
}
}

0 comments on commit 6b49808

Please sign in to comment.