From 6b49808e402f5e3a46f2eaa4178f7d573b566ad6 Mon Sep 17 00:00:00 2001 From: amontenegro Date: Fri, 20 Oct 2023 12:02:59 -0600 Subject: [PATCH] Endpoint to get org info --- .../controllers/EmailDomainController.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java index 39cd788af50..9a79e493f88 100644 --- a/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java +++ b/orcid-web/src/main/java/org/orcid/frontend/web/controllers/EmailDomainController.java @@ -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; @@ -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(); @@ -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 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; + } }