-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fix PostgREST URL bug and clean up
- Loading branch information
1 parent
5e5c584
commit e75b370
Showing
2 changed files
with
28 additions
and
54 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,25 +1,24 @@ | ||
// SPDX-FileCopyrightText: 2023 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2023 - 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2023 - 2024 Netherlands eScience Center | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package nl.esciencecenter.rsd.scraper.ror; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonParser; | ||
|
||
import nl.esciencecenter.rsd.scraper.Config; | ||
import nl.esciencecenter.rsd.scraper.Utils; | ||
|
||
import java.time.format.DateTimeFormatter; | ||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.UUID; | ||
|
||
public class RorPostgrestConnector { | ||
private final String backendUrl; | ||
|
||
|
@@ -28,7 +27,7 @@ public RorPostgrestConnector() { | |
} | ||
|
||
public Collection<BasicOrganisationData> organisationsWithoutLocation(int limit) { | ||
String filter = "organisation?ror_id=isdistinct.null&or=(country.is.null,city.is.null)&limit=" + limit; | ||
String filter = "organisation?ror_id=not.is.null&or=(country.is.null,city.is.null)&limit=" + limit; | ||
String data = Utils.getAsAdmin(backendUrl + "/" + filter); | ||
return parseBasicJsonData(data); | ||
} | ||
|
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 |
---|---|---|
@@ -1,18 +1,23 @@ | ||
// SPDX-FileCopyrightText: 2024 Christian Meeßen (GFZ) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Ewan Cahen (Netherlands eScience Center) <[email protected]> | ||
// SPDX-FileCopyrightText: 2024 Helmholtz Centre Potsdam - GFZ German Research Centre for Geosciences | ||
// SPDX-FileCopyrightText: 2024 Netherlands eScience Center | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package nl.esciencecenter.rsd.scraper.ror; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockTest; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.*; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
|
||
@WireMockTest(proxyMode = true) | ||
|
@@ -42,55 +47,25 @@ void testLocations() throws Exception { | |
|
||
} | ||
|
||
@Test | ||
void testNullLocations() throws Exception { | ||
stubFor( | ||
get(apiPath) | ||
.withHost(WireMock.equalTo(apiDomain)) | ||
.willReturn( | ||
aResponse() | ||
.withStatus(200) | ||
.withBody("{\"addresses\": [{\"city\": null}], \"country\": {\"country_name\": null}}") | ||
)); | ||
|
||
rorScraper = new RorScraper("http://" + apiDomain + apiPath); | ||
|
||
assertEquals(null, rorScraper.city()); | ||
assertEquals(null, rorScraper.country()); | ||
} | ||
|
||
@Test | ||
void testEmpyLocations() throws Exception { | ||
stubFor( | ||
get(apiPath) | ||
.withHost(WireMock.equalTo(apiDomain)) | ||
.willReturn( | ||
aResponse() | ||
.withStatus(200) | ||
.withBody("{\"addresses\": [],\"country\": {}}") | ||
) | ||
); | ||
|
||
rorScraper = new RorScraper("http://" + apiDomain + apiPath); | ||
|
||
assertEquals(null, rorScraper.city()); | ||
assertEquals(null, rorScraper.country()); | ||
} | ||
|
||
@Test | ||
void testEmptyResponse() throws Exception { | ||
@ParameterizedTest | ||
@ValueSource(strings = { | ||
"{\"addresses\": [{\"city\": null}], \"country\": {\"country_name\": null}}", | ||
"{\"addresses\": [],\"country\": {}}", | ||
"{}", | ||
}) | ||
void testNullLocationsOrEmptyLocationOrEmptyResponse(String jsonBody) throws Exception { | ||
stubFor( | ||
get(apiPath) | ||
.withHost(WireMock.equalTo(apiDomain)) | ||
.willReturn( | ||
aResponse() | ||
.withStatus(200) | ||
.withBody("{}") | ||
.withBody(jsonBody) | ||
)); | ||
|
||
rorScraper = new RorScraper("http://" + apiDomain + apiPath); | ||
|
||
assertEquals(null, rorScraper.city()); | ||
assertEquals(null, rorScraper.country()); | ||
assertNull(rorScraper.city()); | ||
assertNull(rorScraper.country()); | ||
} | ||
} |