-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from DiSSCo/feature/add-wikidata
Support wikidata identifier + fix efg identifications
- Loading branch information
Showing
17 changed files
with
216 additions
and
113 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
src/main/java/eu/dissco/core/translator/component/InstitutionNameComponent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package eu.dissco.core.translator.component; | ||
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import eu.dissco.core.translator.exception.OrganisationException; | ||
import java.util.concurrent.ExecutionException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.cache.annotation.Cacheable; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.scheduler.Schedulers; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
public class InstitutionNameComponent { | ||
|
||
private final WebClient webClient; | ||
|
||
@Cacheable("ror") | ||
public String getRorName(String ror) throws OrganisationException { | ||
log.info("Requesting organisation details for organisation: {} with ror", ror); | ||
String url = "https://api.ror.org/organizations/" + ror; | ||
var response = webClient.get().uri(url).retrieve().bodyToMono(JsonNode.class) | ||
.publishOn(Schedulers.boundedElastic()); | ||
try { | ||
var json = response.toFuture().get(); | ||
if (json != null) { | ||
var name = json.get("name"); | ||
if (name != null) { | ||
return name.asText(); | ||
} | ||
} | ||
} catch (InterruptedException e) { | ||
log.error("Failed to make request to RoR service", e); | ||
Thread.currentThread().interrupt(); | ||
} catch (ExecutionException e) { | ||
log.error("Failed to make request to RoR service", e); | ||
} | ||
log.warn("Could not match name to a ROR id for: {}", url); | ||
throw new OrganisationException("Unable to retrieve organisationName"); | ||
} | ||
|
||
@Cacheable("wikidata") | ||
public String getWikiDataName(String wikidata) throws OrganisationException { | ||
log.info("Requesting organisation details for organisation: {} with wikidata", wikidata); | ||
String url = "https://www.wikidata.org/w/rest.php/wikibase/v0/entities/items/" + wikidata + "/labels/en"; | ||
var response = webClient.get().uri(url).retrieve().bodyToMono(JsonNode.class) | ||
.publishOn(Schedulers.boundedElastic()); | ||
try { | ||
var name = response.toFuture().get(); | ||
if (name != null && name.isTextual()) { | ||
return name.asText(); | ||
} | ||
} catch (InterruptedException e) { | ||
log.error("Failed to make request to wikidata service", e); | ||
Thread.currentThread().interrupt(); | ||
} catch (ExecutionException e) { | ||
log.error("Failed to make request to wikidata service", e); | ||
} | ||
log.warn("Could not match to an English (en) label to a wikidata id for: {}", url); | ||
throw new OrganisationException("Unable to retrieve organisationName"); | ||
} | ||
} |
42 changes: 0 additions & 42 deletions
42
src/main/java/eu/dissco/core/translator/component/RorComponent.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
src/main/java/eu/dissco/core/translator/exception/OrganisationException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package eu.dissco.core.translator.exception; | ||
|
||
public class OrganisationException extends DiSSCoDataException { | ||
|
||
public OrganisationException(String s) { | ||
super(s); | ||
} | ||
} |
8 changes: 0 additions & 8 deletions
8
src/main/java/eu/dissco/core/translator/exception/OrganisationNotRorId.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.