Skip to content

Commit

Permalink
Merge pull request #74 from GenomicDataInfrastructure/ART-6899
Browse files Browse the repository at this point in the history
feat: add dataset relations and dictionary
  • Loading branch information
brunopacheco1 authored Jul 26, 2024
2 parents b1ebb3b + 10d94d0 commit 25ab2f1
Show file tree
Hide file tree
Showing 4 changed files with 205 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import java.util.List;
import java.util.Objects;

import io.github.genomicdatainfrastructure.discovery.model.RetrievedDataset;
import io.github.genomicdatainfrastructure.discovery.model.RetrievedDistribution;
import io.github.genomicdatainfrastructure.discovery.model.ValueLabel;
import io.github.genomicdatainfrastructure.discovery.model.*;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.*;
import lombok.experimental.UtilityClass;

Expand Down Expand Up @@ -44,13 +42,63 @@ public RetrievedDataset from(CkanPackage ckanPackage) {
.url(ckanPackage.getUrl())
.languages(values(ckanPackage.getLanguage()))
.contact(value(ckanPackage.getContactUri()))
.hasVersions(values(ckanPackage.getHasVersion()))
.accessRights(value(ckanPackage.getAccessRights()))
.conformsTo(values(ckanPackage.getConformsTo()))
.provenance(ckanPackage.getProvenance())
.spatial(value(ckanPackage.getSpatialUri()))
.distributions(distributions(ckanPackage))
.keywords(keywords(ckanPackage))
.contacts(contactPoint(ckanPackage.getContacts()))
.datasetRelationships(relations(ckanPackage.getDatasetRelationships()))
.dataDictionary(dictionary(ckanPackage.getDataDictionary()))
.build();
}

private List<ContactPoint> contactPoint(List<CkanContactPoint> values) {
return ofNullable(values)
.orElseGet(List::of)
.stream()
.filter(Objects::nonNull)
.map(PackageShowMapper::contactPointEntry)
.toList();
}

private List<DatasetRelationEntry> relations(List<CkanDatasetRelationEntry> values) {
return ofNullable(values)
.orElseGet(List::of)
.stream()
.filter(Objects::nonNull)
.map(PackageShowMapper::relation)
.toList();
}

private List<DatasetDictionaryEntry> dictionary(List<CkanDatasetDictionaryEntry> values) {
return ofNullable(values)
.orElseGet(List::of)
.stream()
.filter(Objects::nonNull)
.map(PackageShowMapper::dictionaryEntry)
.toList();
}

private ContactPoint contactPointEntry(CkanContactPoint value) {
return ContactPoint.builder()
.name(value.getName())
.email(value.getEmail())
.build();
}

private DatasetRelationEntry relation(CkanDatasetRelationEntry value) {
return DatasetRelationEntry.builder()
.relation(value.getRelation())
.target(value.getTarget())
.build();
}

private DatasetDictionaryEntry dictionaryEntry(CkanDatasetDictionaryEntry value) {
return DatasetDictionaryEntry.builder()
.name(value.getName())
.type(value.getType())
.description(value.getDescription())
.build();
}

Expand All @@ -65,7 +113,6 @@ private List<ValueLabel> values(List<CkanValueLabel> values) {

private ValueLabel value(String value) {
return ofNullable(value)
.filter(Objects::nonNull)
.filter(not(String::isBlank))
.map(it -> ValueLabel.builder()
.value(it)
Expand All @@ -76,12 +123,12 @@ private ValueLabel value(String value) {

private ValueLabel value(CkanValueLabel value) {
return ofNullable(value)
.filter(Objects::nonNull)
.map(it -> ValueLabel.builder()
.value(it.getName())
.label(it.getDisplayName())
.value(value.getName())
.label(value.getDisplayName())
.build())
.orElse(null);

}

private LocalDateTime parse(String date) {
Expand Down
55 changes: 47 additions & 8 deletions src/main/openapi/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ components:
type: array
items:
$ref: "#/components/schemas/CkanTag"
contacts:
type: array
items:
$ref: "#/components/schemas/CkanContactPoint"
title: Contacts
datasetRelationships:
type: array
items:
$ref: "#/components/schemas/CkanDatasetRelationEntry"
title: Dataset Relationships
dataDictionary:
type: array
items:
$ref: "#/components/schemas/CkanDatasetDictionaryEntry"
title: Data Dictionary
publisher_name:
type: string
organization:
Expand All @@ -175,16 +190,8 @@ components:
$ref: "#/components/schemas/CkanValueLabel"
contact_uri:
type: string
has_version:
type: array
items:
$ref: "#/components/schemas/CkanValueLabel"
access_rights:
$ref: "#/components/schemas/CkanValueLabel"
conforms_to:
type: array
items:
$ref: "#/components/schemas/CkanValueLabel"
provenance:
type: string
spatial_uri:
Expand All @@ -196,6 +203,38 @@ components:
required:
- id
- title
CkanContactPoint:
properties:
name:
type: string
title: name
email:
type: string
title: email
required:
- name
- email
CkanDatasetRelationEntry:
properties:
relation:
type: string
target:
type: string
required:
- target
- relation
CkanDatasetDictionaryEntry:
properties:
name:
type: string
type:
type: string
description:
type: string
required:
- name
- type
- description
CkanOrganization:
type: object
properties:
Expand Down
62 changes: 52 additions & 10 deletions src/main/openapi/discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,21 @@ components:
items:
$ref: "#/components/schemas/ValueLabel"
title: Themes
contacts:
type: array
items:
$ref: "#/components/schemas/ContactPoint"
title: Contacts
datasetRelationships:
type: array
items:
$ref: "#/components/schemas/DatasetRelationEntry"
title: Dataset Relationships
dataDictionary:
type: array
items:
$ref: "#/components/schemas/DatasetDictionaryEntry"
title: Data Dictionary
publisherName:
type: string
title: Publisher Name
Expand All @@ -235,19 +250,9 @@ components:
contact:
$ref: "#/components/schemas/ValueLabel"
title: Contact
hasVersions:
type: array
items:
$ref: "#/components/schemas/ValueLabel"
title: Has Versions
accessRights:
$ref: "#/components/schemas/ValueLabel"
title: Access Rights
conformsTo:
type: array
items:
$ref: "#/components/schemas/ValueLabel"
title: Conforms to
keywords:
type: array
items:
Expand Down Expand Up @@ -312,6 +317,43 @@ components:
required:
- value
- label
ContactPoint:
properties:
name:
type: string
title: name
email:
type: string
title: email
required:
- name
- email
DatasetRelationEntry:
properties:
relation:
type: string
title: relation
target:
type: string
title: target
required:
- target
- relation
DatasetDictionaryEntry:
properties:
name:
type: string
title: name
type:
type: string
title: type
description:
type: string
title: description
required:
- name
- type
- description
FacetGroup:
properties:
key:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,20 @@

package io.github.genomicdatainfrastructure.discovery.services;

import io.github.genomicdatainfrastructure.discovery.model.ContactPoint;
import io.github.genomicdatainfrastructure.discovery.model.DatasetDictionaryEntry;
import io.github.genomicdatainfrastructure.discovery.model.DatasetRelationEntry;
import io.github.genomicdatainfrastructure.discovery.model.RetrievedDataset;
import io.github.genomicdatainfrastructure.discovery.model.RetrievedDistribution;
import io.github.genomicdatainfrastructure.discovery.model.ValueLabel;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.*;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanContactPoint;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanDatasetDictionaryEntry;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanDatasetRelationEntry;
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 io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanValueLabel;
import io.github.genomicdatainfrastructure.discovery.utils.PackageShowMapper;
import org.junit.jupiter.api.Test;

Expand All @@ -29,12 +39,13 @@ void accepts_empty_package() {

var actual = PackageShowMapper.from(ckanPackage);
var expected = RetrievedDataset.builder()
.conformsTo(List.of())
.distributions(List.of())
.hasVersions(List.of())
.languages(List.of())
.themes(List.of())
.keywords(List.of())
.contacts(List.of())
.datasetRelationships(List.of())
.dataDictionary(List.of())
.build();

assertThat(actual)
Expand Down Expand Up @@ -71,20 +82,10 @@ void can_parse() {
.name("en")
.build()))
.contactUri("contactUri")
.hasVersion(List.of(
CkanValueLabel.builder()
.displayName("version")
.name("1")
.build()))
.accessRights(CkanValueLabel.builder()
.displayName("accessRights")
.name("public")
.build())
.conformsTo(List.of(
CkanValueLabel.builder()
.displayName("conformsTo")
.name("conforms")
.build()))
.provenance("provenance")
.spatialUri(CkanValueLabel.builder()
.displayName("spatial")
Expand All @@ -104,6 +105,24 @@ void can_parse() {
.lastModified("2024-03-19T13:37:05.472970")
.build()
))
.contacts(List.of(
CkanContactPoint.builder().name("Contact 1").email("[email protected]")
.build(),
CkanContactPoint.builder().name("Contact 2").email("[email protected]")
.build()
))
.datasetRelationships(List.of(
CkanDatasetRelationEntry.builder().target("Dataset 1").relation(
"Relation 1").build(),
CkanDatasetRelationEntry.builder().target("Dataset 2").relation(
"Relation 2").build()
))
.dataDictionary(List.of(
CkanDatasetDictionaryEntry.builder().name("Entry 1").type("Type 1")
.description("Description 1").build(),
CkanDatasetDictionaryEntry.builder().name("Entry 2").type("Type 2")
.description("Description 2").build()
))
.build();

var actual = PackageShowMapper.from(ckanPackage);
Expand Down Expand Up @@ -133,22 +152,10 @@ void can_parse() {
.value("contactUri")
.label("contactUri")
.build())
.hasVersions(List.of(
ValueLabel.builder()
.value("1")
.label("version")
.build()
))
.accessRights(ValueLabel.builder()
.value("public")
.label("accessRights")
.build())
.conformsTo(List.of(
ValueLabel.builder()
.value("conforms")
.label("conformsTo")
.build()
))
.provenance("provenance")
.keywords(List.of(ValueLabel.builder()
.label("key-tag")
Expand All @@ -172,6 +179,24 @@ void can_parse() {
.modifiedAt(parse("2024-03-19T13:37:05.472970", DATE_FORMATTER))
.build()
))
.contacts(List.of(
ContactPoint.builder().name("Contact 1").email("[email protected]")
.build(),
ContactPoint.builder().name("Contact 2").email("[email protected]")
.build()
))
.datasetRelationships(List.of(
DatasetRelationEntry.builder().relation("Relation 1").target("Dataset 1")
.build(),
DatasetRelationEntry.builder().relation("Relation 2").target("Dataset 2")
.build()
))
.dataDictionary(List.of(
DatasetDictionaryEntry.builder().name("Entry 1").type("Type 1").description(
"Description 1").build(),
DatasetDictionaryEntry.builder().name("Entry 2").type("Type 2").description(
"Description 2").build()
))
.build();

assertThat(actual)
Expand Down

0 comments on commit 25ab2f1

Please sign in to comment.