Skip to content

Commit

Permalink
Merge pull request #15 from GenomicDataInfrastructure/152-add-missing…
Browse files Browse the repository at this point in the history
…-fields

feat: extend api with fields needed for ui
  • Loading branch information
brunopacheco1 authored Apr 15, 2024
2 parents f7f48d3 + 307b1c8 commit e5aeba3
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanOrganization;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanPackage;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanResource;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanTag;
import lombok.experimental.UtilityClass;

import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -52,6 +53,7 @@ public RetrievedDataset from(CkanPackage ckanPackage) {
.provenance(ckanPackage.getProvenance())
.spatial(value(ckanPackage.getSpatialUri()))
.distributions(distributions(ckanPackage))
.keywords(keywords(ckanPackage))
.build();
}

Expand Down Expand Up @@ -89,6 +91,14 @@ private List<RetrievedDistribution> distributions(CkanPackage ckanPackage) {
.toList();
}

private List<ValueLabel> keywords(CkanPackage ckanPackage) {
return ofNullable(ckanPackage.getTags())
.orElseGet(List::of)
.stream()
.map(PackageShowMapper::keyword)
.toList();
}

private RetrievedDistribution distribution(CkanResource ckanResource) {
return RetrievedDistribution.builder()
.id(ckanResource.getId())
Expand All @@ -100,4 +110,11 @@ private RetrievedDistribution distribution(CkanResource ckanResource) {
.modifiedAt(parse(ckanResource.getLastModified()))
.build();
}

private ValueLabel keyword(CkanTag ckanTag) {
return ValueLabel.builder()
.label(ckanTag.getDisplayName())
.value(ckanTag.getName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ private SearchedDataset result(CkanPackage dataset) {
.themes(values(dataset.getTheme()))
.catalogue(catalogue)
.modifiedAt(parse(dataset.getMetadataModified()))
.createdAt(parse(dataset.getMetadataCreated()))
.build();
}

Expand Down
20 changes: 20 additions & 0 deletions src/main/openapi/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ components:
type: array
items:
type: string
tags:
type: array
items:
$ref: "#/components/schemas/CkanTag"
publisher_name:
type: string
organization:
Expand Down Expand Up @@ -247,6 +251,22 @@ components:
type: boolean
result:
$ref: "#/components/schemas/CkanPackage"
CkanTag:
type: object
properties:
id:
type: string
state:
type: string
display_name:
type: string
name:
type: string
required:
- id
- display_name
- name
- state
CkanErrorResponse:
type: object
properties:
Expand Down
9 changes: 9 additions & 0 deletions src/main/openapi/discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ components:
type: string
format: date-time
title: Dataset modified at
createdAt:
type: string
format: date-time
title: Metadata for dataset created at
recordsCount:
type: integer
title: Records count
Expand Down Expand Up @@ -237,6 +241,11 @@ components:
items:
$ref: "#/components/schemas/ValueLabel"
title: Conforms to
keywords:
type: array
items:
$ref: "#/components/schemas/ValueLabel"
title: Keywords
provenance:
type: string
title: Contact URI
Expand Down
4 changes: 4 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,7 @@ quarkus.rest-client.beacon_yaml.url=http://localhost:4000
%dev.quarkus.rest-client.logging.body-limit=10000
%dev.quarkus.rest-client.logging.scope=request-response
%dev.quarkus.log.category."org.jboss.resteasy.reactive.client.logging".level=DEBUG
quarkus.http.cors=true
quarkus.http.cors.origins=http://localhost:3000
quarkus.http.cors.headers=accept, authorization, content-type, x-requested-with
quarkus.http.cors.methods=POST, OPTIONS, GET
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.List;

import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanTag;
import org.junit.jupiter.api.Test;
import io.github.genomicdatainfrastructure.discovery.model.RetrievedDataset;
import io.github.genomicdatainfrastructure.discovery.model.RetrievedDistribution;
Expand All @@ -35,6 +36,7 @@ void accepts_empty_package() {
.hasVersions(List.of())
.languages(List.of())
.themes(List.of())
.keywords(List.of())
.build();

assertThat(actual)
Expand All @@ -56,6 +58,11 @@ void can_parse() {
.build())
.metadataCreated("2024-03-19T13:37:05.472970")
.metadataModified("2024-03-19T13:37:05.472970")
.tags(List.of(CkanTag.builder()
.displayName("key-tag")
.id("tag-id")
.name("key")
.build()))
.url("url")
.language(List.of("language"))
.contactUri("contactUri")
Expand Down Expand Up @@ -121,6 +128,10 @@ void can_parse() {
.build()
))
.provenance("provenance")
.keywords(List.of(ValueLabel.builder()
.label("key-tag")
.value("key")
.build()))
.spatial(ValueLabel.builder()
.value("spatialUri")
.label("spatialUri")
Expand Down

0 comments on commit e5aeba3

Please sign in to comment.