Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.time.Duration;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.regex.MatchResult;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -41,17 +42,19 @@ public class CachedOrganisationRepository implements OrganisationRepository {
private static final String ROR_API_URL = "https://api.ror.org/v1/organizations/%s";
private static final String ROR_ID_PATTERN = "0[a-z|0-9]{6}[0-9]{2}$";
private final Map<String, String> iriToOrganisation = new HashMap<>();
private final String apiClientId;
private final int configuredCacheSize;

private boolean cacheUsedForLastRequest = false;



public CachedOrganisationRepository(int cacheSize) {
public CachedOrganisationRepository(String apiClientId, int cacheSize) {
this.apiClientId = Objects.requireNonNull(apiClientId);
this.configuredCacheSize = cacheSize;
}

public CachedOrganisationRepository() {
public CachedOrganisationRepository(String apiClientId) {
this.apiClientId = Objects.requireNonNull(apiClientId);
this.configuredCacheSize = DEFAULT_CACHE_SIZE;
}

Expand Down Expand Up @@ -85,6 +88,7 @@ private Organisation findOrganisationInROR(String rorId) {
.followRedirects(Redirect.NORMAL).connectTimeout(
Duration.ofSeconds(10)).build();
HttpRequest rorQuery = HttpRequest.newBuilder().uri(URI.create(ROR_API_URL.formatted(rorId)))
.header("Client-Id", apiClientId)
.header("Content-Type", "application/json").GET().build();
var result = client.send(rorQuery, BodyHandlers.ofString());
//If a valid RoRId was provided but the ID does not exist we fail
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ public IdentityService userRegistrationService(
}

@Bean
public OrganisationRepository organisationRepository() {
return new CachedOrganisationRepository();
public OrganisationRepository organisationRepository(
@Value("${qbic.external-service.organisation-search.ror.client-id}") String clientId) {
return new CachedOrganisationRepository(clientId);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@
"name": "qbic.external-service.person-search.orcid.issuer",
"type": "java.lang.String",
"description": "The URL of the orcid issuer. Most probably https://orcid.org"
},
{
"name": "qbic.external-service.organisation-search.ror.client-id",
"type": "java.lang.String",
"description": "The client id for the ROR API to allow for a rate limit of 2000 requests/5 minutes. See https://ror.readme.io/docs/client-id for more detail."
}
]
}
3 changes: 3 additions & 0 deletions user-interface/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ qbic.external-service.person-search.orcid.extended-search-uri=${qbic.external-se
qbic.external-service.person-search.orcid.scope=/read-public
qbic.external-service.person-search.orcid.grant-type=client_credentials
qbic.external-service.person-search.orcid.issuer=${ORCID_SEARCH_ISSUER_URL:https://orcid.org}
###############################################################################
################### ROR ID ####################################################
qbic.external-service.organisation-search.ror.client-id=${ROR_CLIENT_ID}

###############################################################################
################### ActiveMQ Artemis ##########################################
Expand Down
Loading