diff --git a/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/PackageShowMapper.java b/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/PackageShowMapper.java index a6bb54a..37ad586 100644 --- a/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/PackageShowMapper.java +++ b/src/main/java/io/github/genomicdatainfrastructure/discovery/utils/PackageShowMapper.java @@ -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; @@ -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(List values) { + return ofNullable(values) + .orElseGet(List::of) + .stream() + .filter(Objects::nonNull) + .map(PackageShowMapper::contactPointEntry) + .toList(); + } + + private List relations(List values) { + return ofNullable(values) + .orElseGet(List::of) + .stream() + .filter(Objects::nonNull) + .map(PackageShowMapper::relation) + .toList(); + } + + private List dictionary(List 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(); } @@ -65,7 +113,6 @@ private List values(List values) { private ValueLabel value(String value) { return ofNullable(value) - .filter(Objects::nonNull) .filter(not(String::isBlank)) .map(it -> ValueLabel.builder() .value(it) @@ -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) { diff --git a/src/main/openapi/ckan.yaml b/src/main/openapi/ckan.yaml index 28e77e9..061ca12 100644 --- a/src/main/openapi/ckan.yaml +++ b/src/main/openapi/ckan.yaml @@ -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: @@ -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: @@ -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: diff --git a/src/main/openapi/discovery.yaml b/src/main/openapi/discovery.yaml index 0396540..41f7ca8 100644 --- a/src/main/openapi/discovery.yaml +++ b/src/main/openapi/discovery.yaml @@ -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 @@ -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: @@ -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: 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 a9b1d74..9cb61ad 100644 --- a/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java +++ b/src/test/java/io/github/genomicdatainfrastructure/discovery/services/PackageShowMapperTest.java @@ -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; @@ -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) @@ -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") @@ -104,6 +105,24 @@ void can_parse() { .lastModified("2024-03-19T13:37:05.472970") .build() )) + .contacts(List.of( + CkanContactPoint.builder().name("Contact 1").email("contact1@example.com") + .build(), + CkanContactPoint.builder().name("Contact 2").email("contact2@example.com") + .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); @@ -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") @@ -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("contact1@example.com") + .build(), + ContactPoint.builder().name("Contact 2").email("contact2@example.com") + .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)