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 6, 2024
1 parent 9aa714b commit 0608184
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 54 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,18 @@
import io.github.genomicdatainfrastructure.discovery.services.RetrieveOrganizationsService;
import jakarta.ws.rs.core.Response;
import lombok.RequiredArgsConstructor;
import java.util.List;

import static java.util.Optional.ofNullable;

@RequiredArgsConstructor
public class OrganizationQueryApiImpl implements OrganizationQueryApi {

private final RetrieveOrganizationsService retrieveOrganizationsService;

@Override
public Response retrieveOrganizations() {
var content = retrieveOrganizationsService.get();
public Response retrieveOrganizations(Integer limit) {
var nonNullLimit = ofNullable(limit).orElse(100);
var content = retrieveOrganizationsService.retrieve(nonNullLimit);
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,19 +4,25 @@

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;
import lombok.RequiredArgsConstructor;

import java.util.List;

@ApplicationScoped
@RequiredArgsConstructor
public class RetrieveOrganizationsService {

@Inject
CkanOrganizationsRepository organizationsRepository;
private final 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,30 @@
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()))
.numberOfDatasets(organization.getPackageCount())
.build();
}

private String nullableString(String value) {
return Optional.ofNullable(value)
.filter(Predicate.not(String::isBlank))
.orElse(null);
}
}
21 changes: 19 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 @@ -333,10 +348,12 @@ components:
type: string
description:
type: string
package_count:
type: integer
required:
- id
- name
- title
- package_count
CkanOrganizationsResponse:
type: object
properties:
Expand All @@ -347,7 +364,7 @@ components:
result:
type: array
items:
type: string
$ref: "#/components/schemas/CkanOrganization"
CkanResource:
type: object
properties:
Expand Down
22 changes: 20 additions & 2 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 All @@ -89,7 +97,7 @@ paths:
schema:
type: array
items:
type: string
$ref: "#/components/schemas/DatasetOrganization"
/api/v1/datasets/{id}.{format}:
get:
summary: Retrieves a dataset by its ID, in the requested format
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 @@ -433,9 +444,16 @@ components:
description:
type: string
title: Description of organization
image_url:
imageUrl:
type: string
title: Image url of organization
numberOfDatasets:
type: integer
title: Number of datasets
required:
- id
- name
- numberOfDatasets
DatasetDictionaryEntry:
properties:
name:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,78 @@
package io.github.genomicdatainfrastructure.discovery.api;

import io.github.genomicdatainfrastructure.discovery.BaseTest;
import io.github.genomicdatainfrastructure.discovery.model.DatasetOrganization;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.common.mapper.TypeRef;
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 actual = response.getBody()
.as(new TypeRef<List<DatasetOrganization>>() {
});

assertThat(actual)
.usingRecursiveFieldByFieldElementComparator()
.containsExactlyInAnyOrder(
DatasetOrganization.builder()
.id("3e0a548c-eef4-404b-96ec-dd95b549643c")
.name("instituto-superior-tecnico")
.title("Instituto Superior Técnico")
.numberOfDatasets(1)
.build(),
DatasetOrganization.builder()
.id("d9133f3e-8747-4764-a3c6-27f93a37c38d")
.title("CSC FI")
.name("csc-fi")
.description(
"The tools CSC provides for scientific computing and data management create a stepping stone for breakthroughs.")
.imageUrl(
"https://csc.fi/app/uploads/2023/09/CSC_logo_no_tagline.svg")
.numberOfDatasets(1)
.build(),
DatasetOrganization.builder()
.id("da348a59-8632-4c28-af3e-786e72448b8c")
.name("ega")
.title("EGA")
.numberOfDatasets(4)
.build(),
DatasetOrganization.builder()
.id("1acb508d-371c-4a43-b143-65ec2e0f1f82")
.name("lnds")
.title("LNDS")
.numberOfDatasets(1)
.build(),
DatasetOrganization.builder()
.id("d4f783b7-64e9-4552-9667-c81a56259bbb")
.name("nbis")
.title("NBIS")
.numberOfDatasets(3)
.build(),
DatasetOrganization.builder()
.id("c24f44ff-a0e0-4171-bf33-a9b6e2ea9298")
.name("umcg")
.title("UMCG")
.numberOfDatasets(5)
.build(),
DatasetOrganization.builder()
.id("5e48036d-4e38-40d8-ba8e-8cce6faeb3be")
.name("university-of-oslo")
.title("University of Oslo")
.numberOfDatasets(1)
.build()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ void doesnt_call_beacon_if_access_token_is_null() {
SearchedDataset.builder()
.id("id")
.title("title")
.organization(DatasetOrganization.builder().build())
.themes(List.of())
.build()
))
Expand Down Expand Up @@ -140,7 +139,6 @@ void doesnt_call_beacon_if_keycloak_throws_expected_4xx_errors(Integer statusCod
SearchedDataset.builder()
.id("id")
.title("title")
.organization(DatasetOrganization.builder().build())
.themes(List.of())
.build()
))
Expand Down Expand Up @@ -199,7 +197,6 @@ void doesnt_call_beacon_if_there_are_no_beacon_filters() {
SearchedDataset.builder()
.id("id")
.title("title")
.organization(DatasetOrganization.builder().build())
.themes(List.of())
.build()
))
Expand Down Expand Up @@ -424,7 +421,6 @@ void calls_ckan_and_beacon() {
SearchedDataset.builder()
.id("id")
.title("title")
.organization(DatasetOrganization.builder().build())
.themes(List.of())
.build()
))
Expand Down
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
Loading

0 comments on commit 0608184

Please sign in to comment.