Skip to content

Commit

Permalink
chore: retrieve organization metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopacheco1 committed Aug 5, 2024
1 parent 9aa714b commit 5e6ef38
Show file tree
Hide file tree
Showing 10 changed files with 197 additions and 46 deletions.
3 changes: 3 additions & 0 deletions _http/ckan.http
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,15 @@
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 {

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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,8 @@
@ApplicationScoped
public class CkanOrganizationsRepository {

private static final Boolean SHOW_ALL_FIELDS = true;

private final CkanQueryApi ckanQueryApi;

@Inject
Expand All @@ -23,7 +26,9 @@ public CkanOrganizationsRepository(
this.ckanQueryApi = ckanQueryApi;
}

public List<String> retrieveOrganizations() {
return ckanQueryApi.organizationList().getResult();
public List<CkanOrganization> retrieveOrganizations(Integer limit) {
return ckanQueryApi
.organizationList(SHOW_ALL_FIELDS, limit)
.getResult();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,7 +18,11 @@ public class RetrieveOrganizationsService {
@Inject
CkanOrganizationsRepository organizationsRepository;

public List<String> get() {
return organizationsRepository.retrieveOrganizations();
public List<DatasetOrganization> retrieve(Integer limit) {
var ckanOrganizations = organizationsRepository.retrieveOrganizations(limit);

return ckanOrganizations.stream()
.map(DatasetOrganizationMapper::from)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
18 changes: 16 additions & 2 deletions src/main/openapi/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -336,7 +351,6 @@ components:
required:
- id
- name
- title
CkanOrganizationsResponse:
type: object
properties:
Expand All @@ -347,7 +361,7 @@ components:
result:
type: array
items:
type: string
$ref: "#/components/schemas/CkanOrganization"
CkanResource:
type: object
properties:
Expand Down
14 changes: 14 additions & 0 deletions src/main/openapi/discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -424,6 +432,9 @@ components:
- relation
DatasetOrganization:
properties:
id:
type: string
title: ID of organization
name:
type: string
title: Name of organization
Expand All @@ -436,6 +447,9 @@ components:
image_url:
type: string
title: Image url of organization
required:
- id
- name
DatasetDictionaryEntry:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,39 @@
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 {

@Test
void can_retrieve_organizations() {
given()
.when()
.get("/api/v1/organizations")
.then()
.statusCode(200);
}

@Test
void can_retrieve_correct_organizations_data() {
var response = given()
.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"
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
122 changes: 113 additions & 9 deletions src/test/resources/mappings/organization_list.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
]
}
}
Expand Down

0 comments on commit 5e6ef38

Please sign in to comment.