From 0bdb71732d5944ab64a9243e3c7137646915ba99 Mon Sep 17 00:00:00 2001 From: Bruno Pacheco Date: Mon, 5 Aug 2024 18:17:56 +0200 Subject: [PATCH] chore: retrieve organization metadata --- _http/ckan.http | 3 + .../api/OrganizationQueryApiImpl.java | 5 +- .../CkanOrganizationsRepository.java | 9 +- .../RetrieveOrganizationsService.java | 10 +- .../utils/DatasetOrganizationMapper.java | 18 ++- src/main/openapi/ckan.yaml | 18 ++- src/main/openapi/discovery.yaml | 14 ++ .../api/RetrieveOrganizationsTest.java | 34 +++-- .../services/PackageShowMapperTest.java | 1 - .../resources/mappings/organization_list.json | 124 ++++++++++++++++-- 10 files changed, 198 insertions(+), 38 deletions(-) diff --git a/_http/ckan.http b/_http/ckan.http index f3ae4a1..e4c787a 100644 --- a/_http/ckan.http +++ b/_http/ckan.http @@ -15,3 +15,6 @@ GET https://catalogue.portal.dev.gdi.lu/api/3/action/enhanced_package_show?id=du ### GET https://catalogue.portal.dev.gdi.lu/dataset/vcf-and-phenotypic-data-of-stage-ii-and-iii-colorectal-cancer-patients-from-a-portuguese-use-ca.rdf + +### +GET https://catalogue.portal.dev.gdi.lu/api/3/action/organization_list?all_fields=true&limit=100 \ No newline at end of file diff --git a/src/main/java/io/github/genomicdatainfrastructure/discovery/api/OrganizationQueryApiImpl.java b/src/main/java/io/github/genomicdatainfrastructure/discovery/api/OrganizationQueryApiImpl.java index cb82a07..836edbe 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/discovery/api/OrganizationQueryApiImpl.java +++ b/src/main/java/io/github/genomicdatainfrastructure/discovery/api/OrganizationQueryApiImpl.java @@ -7,7 +7,6 @@ import io.github.genomicdatainfrastructure.discovery.services.RetrieveOrganizationsService; import jakarta.ws.rs.core.Response; import lombok.RequiredArgsConstructor; -import java.util.List; @RequiredArgsConstructor public class OrganizationQueryApiImpl implements OrganizationQueryApi { @@ -15,8 +14,8 @@ public class OrganizationQueryApiImpl implements OrganizationQueryApi { private final RetrieveOrganizationsService retrieveOrganizationsService; @Override - public Response retrieveOrganizations() { - var content = retrieveOrganizationsService.get(); + public Response retrieveOrganizations(Integer limit) { + var content = retrieveOrganizationsService.retrieve(limit); return Response.ok(content).build(); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/discovery/repositories/CkanOrganizationsRepository.java b/src/main/java/io/github/genomicdatainfrastructure/discovery/repositories/CkanOrganizationsRepository.java index 087ef0f..5ea03b1 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/discovery/repositories/CkanOrganizationsRepository.java +++ b/src/main/java/io/github/genomicdatainfrastructure/discovery/repositories/CkanOrganizationsRepository.java @@ -5,6 +5,7 @@ package io.github.genomicdatainfrastructure.discovery.repositories; import io.github.genomicdatainfrastructure.discovery.remote.ckan.api.CkanQueryApi; +import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanOrganization; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; import org.eclipse.microprofile.rest.client.inject.RestClient; @@ -14,6 +15,8 @@ @ApplicationScoped public class CkanOrganizationsRepository { + private static final Boolean SHOW_ALL_FIELDS = true; + private final CkanQueryApi ckanQueryApi; @Inject @@ -23,7 +26,9 @@ public CkanOrganizationsRepository( this.ckanQueryApi = ckanQueryApi; } - public List retrieveOrganizations() { - return ckanQueryApi.organizationList().getResult(); + public List retrieveOrganizations(Integer limit) { + return ckanQueryApi + .organizationList(SHOW_ALL_FIELDS, limit) + .getResult(); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/discovery/services/RetrieveOrganizationsService.java b/src/main/java/io/github/genomicdatainfrastructure/discovery/services/RetrieveOrganizationsService.java index 5776c54..33fa8be 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/discovery/services/RetrieveOrganizationsService.java +++ b/src/main/java/io/github/genomicdatainfrastructure/discovery/services/RetrieveOrganizationsService.java @@ -4,7 +4,9 @@ package io.github.genomicdatainfrastructure.discovery.services; +import io.github.genomicdatainfrastructure.discovery.model.DatasetOrganization; import io.github.genomicdatainfrastructure.discovery.repositories.CkanOrganizationsRepository; +import io.github.genomicdatainfrastructure.discovery.utils.DatasetOrganizationMapper; import jakarta.enterprise.context.ApplicationScoped; import jakarta.inject.Inject; @@ -16,7 +18,11 @@ public class RetrieveOrganizationsService { @Inject CkanOrganizationsRepository organizationsRepository; - public List get() { - return organizationsRepository.retrieveOrganizations(); + public List retrieve(Integer limit) { + var ckanOrganizations = organizationsRepository.retrieveOrganizations(limit); + + return ckanOrganizations.stream() + .map(DatasetOrganizationMapper::from) + .toList(); } } diff --git a/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/DatasetOrganizationMapper.java b/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/DatasetOrganizationMapper.java index 32de814..dc58f1a 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/DatasetOrganizationMapper.java +++ b/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/DatasetOrganizationMapper.java @@ -8,19 +8,29 @@ import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.*; import lombok.experimental.UtilityClass; +import java.util.Optional; +import java.util.function.Predicate; + @UtilityClass public class DatasetOrganizationMapper { public DatasetOrganization from(CkanOrganization organization) { if (organization == null) { - return DatasetOrganization.builder().build(); + return null; } return DatasetOrganization.builder() - .title(organization.getTitle()) + .id(organization.getId()) .name(organization.getName()) - .description(organization.getDescription()) - .imageUrl(organization.getImageUrl()) + .title(nullableString(organization.getTitle())) + .description(nullableString(organization.getDescription())) + .imageUrl(nullableString(organization.getImageUrl())) .build(); } + + private String nullableString(String value) { + return Optional.ofNullable(value) + .filter(Predicate.not(String::isBlank)) + .orElse(null); + } } diff --git a/src/main/openapi/ckan.yaml b/src/main/openapi/ckan.yaml index d36f5e9..3708730 100644 --- a/src/main/openapi/ckan.yaml +++ b/src/main/openapi/ckan.yaml @@ -109,6 +109,21 @@ paths: get: summary: Retrieves a list of organizations operationId: organization_list + parameters: + - name: all_fields + in: query + description: if all metadata of organization is required + required: true + schema: + type: boolean + default: true + - name: limit + in: query + description: maximum number of organizations per query + required: true + schema: + type: integer + default: 100 tags: - "ckan-query" responses: @@ -336,7 +351,6 @@ components: required: - id - name - - title CkanOrganizationsResponse: type: object properties: @@ -347,7 +361,7 @@ components: result: type: array items: - type: string + $ref: "#/components/schemas/CkanOrganization" CkanResource: type: object properties: diff --git a/src/main/openapi/discovery.yaml b/src/main/openapi/discovery.yaml index fb87e30..611175a 100644 --- a/src/main/openapi/discovery.yaml +++ b/src/main/openapi/discovery.yaml @@ -79,6 +79,14 @@ paths: get: summary: Retrieves a list of organizations operationId: retrieve_organizations + parameters: + - name: limit + in: query + description: maximum number of organizations per query + required: true + schema: + type: integer + default: 100 tags: - "organization-query" responses: @@ -424,6 +432,9 @@ components: - relation DatasetOrganization: properties: + id: + type: string + title: ID of organization name: type: string title: Name of organization @@ -436,6 +447,9 @@ components: image_url: type: string title: Image url of organization + required: + - id + - name DatasetDictionaryEntry: properties: name: diff --git a/src/test/java/io/github/genomicdatainfrastructure/discovery/api/RetrieveOrganizationsTest.java b/src/test/java/io/github/genomicdatainfrastructure/discovery/api/RetrieveOrganizationsTest.java index d16bc6c..a9a8b8d 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/discovery/api/RetrieveOrganizationsTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/discovery/api/RetrieveOrganizationsTest.java @@ -5,13 +5,13 @@ package io.github.genomicdatainfrastructure.discovery.api; import io.github.genomicdatainfrastructure.discovery.BaseTest; +import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanOrganization; +import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanOrganizationsResponse; import io.quarkus.test.junit.QuarkusTest; import org.junit.jupiter.api.Test; -import java.util.List; - import static io.restassured.RestAssured.given; -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; +import static org.assertj.core.api.Assertions.assertThat; @QuarkusTest class RetrieveOrganizationsTest extends BaseTest { @@ -31,16 +31,22 @@ void can_retrieve_correct_organizations_data() { .when() .get("/api/v1/organizations"); - var body = response.getBody().as(List.class); - assertThat(body).isEqualTo(List.of( - "cscfi", - "ega", - "instituto-superior-tecnico", - "lnds", - "nbis", - "radboud", - "umcg", - "university-of-oslo" - )); + var body = response.getBody().as(CkanOrganizationsResponse.class); + + var actual = body.getResult().stream() + .map(CkanOrganization::getName) + .toList(); + + assertThat(actual) + .containsExactlyInAnyOrder( + "cscfi", + "ega", + "instituto-superior-tecnico", + "lnds", + "nbis", + "radboud", + "umcg", + "university-of-oslo" + ); } } diff --git a/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java b/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java index 5fc3120..e4f969f 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java @@ -43,7 +43,6 @@ void accepts_empty_package() { .keywords(List.of()) .contacts(List.of()) .creators(List.of()) - .organization(DatasetOrganization.builder().build()) .datasetRelationships(List.of()) .dataDictionary(List.of()) .build(); diff --git a/src/test/resources/mappings/organization_list.json b/src/test/resources/mappings/organization_list.json index 30b5e3b..1accc2e 100644 --- a/src/test/resources/mappings/organization_list.json +++ b/src/test/resources/mappings/organization_list.json @@ -1,7 +1,7 @@ { "request": { "method": "GET", - "url": "/api/3/action/organization_list" + "url": "/api/3/action/organization_list?all_fields=true&limit=100" }, "response": { "status": 200, @@ -9,17 +9,121 @@ "Content-Type": "application/json" }, "jsonBody": { - "help": "https://ckan-test.healthdata.nl/api/3/action/help_show?name=organization_list", + "help": "https://catalogue.portal.dev.gdi.lu/api/3/action/help_show?name=organization_list", "success": true, "result": [ - "cscfi", - "ega", - "instituto-superior-tecnico", - "lnds", - "nbis", - "radboud", - "umcg", - "university-of-oslo" + { + "approval_status": "approved", + "created": "2024-04-25T12:01:57.722274", + "description": "", + "display_name": " Instituto Superior Técnico", + "id": "3e0a548c-eef4-404b-96ec-dd95b549643c", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "instituto-superior-tecnico", + "num_followers": 0, + "package_count": 1, + "state": "active", + "title": " Instituto Superior Técnico", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-19T12:55:51.635047", + "description": "The tools CSC provides for scientific computing and data management create a stepping stone for breakthroughs. We support Finland’s unique educative system. We connect Finnish higher education institutions, researchers, and students to each other and to the whole world. In 1988 we connected Finland to the Internet.\r\n\r\nWith our special expertise, for instance education, and health care can be managed by knowledge. This promotes innovations and creates new competence. When data is sensitive, we keep it secure.", + "display_name": "CSC FI", + "id": "d9133f3e-8747-4764-a3c6-27f93a37c38d", + "image_display_url": "https://csc.fi/app/uploads/2023/09/CSC_logo_no_tagline.svg", + "image_url": "https://csc.fi/app/uploads/2023/09/CSC_logo_no_tagline.svg", + "is_organization": true, + "name": "csc-fi", + "num_followers": 0, + "package_count": 1, + "state": "active", + "title": "CSC FI", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-19T13:09:30.488193", + "description": "", + "display_name": "EGA", + "id": "da348a59-8632-4c28-af3e-786e72448b8c", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "ega", + "num_followers": 0, + "package_count": 4, + "state": "active", + "title": "EGA", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-16T11:04:15.333600", + "description": "", + "display_name": "LNDS", + "id": "1acb508d-371c-4a43-b143-65ec2e0f1f82", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "lnds", + "num_followers": 0, + "package_count": 1, + "state": "active", + "title": "LNDS", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-19T13:46:17.885858", + "description": "", + "display_name": "NBIS", + "id": "d4f783b7-64e9-4552-9667-c81a56259bbb", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "nbis", + "num_followers": 0, + "package_count": 3, + "state": "active", + "title": "NBIS", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-16T18:43:42.174385", + "description": "", + "display_name": "UMCG", + "id": "c24f44ff-a0e0-4171-bf33-a9b6e2ea9298", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "umcg", + "num_followers": 0, + "package_count": 5, + "state": "active", + "title": "UMCG", + "type": "organization" + }, + { + "approval_status": "approved", + "created": "2024-04-19T12:55:38.657883", + "description": "", + "display_name": "University of Oslo", + "id": "5e48036d-4e38-40d8-ba8e-8cce6faeb3be", + "image_display_url": "", + "image_url": "", + "is_organization": true, + "name": "university-of-oslo", + "num_followers": 0, + "package_count": 1, + "state": "active", + "title": "University of Oslo", + "type": "organization" + } ] } }