Skip to content

Commit

Permalink
Merge pull request #19 from GenomicDataInfrastructure/16-gdi-dataset-…
Browse files Browse the repository at this point in the history
…discovery-service-integrate-with-new-endpoints-to-retrieve-label-of-values

16 gdi dataset discovery service integrate with new endpoints to retrieve label of values
  • Loading branch information
brunopacheco1 authored Apr 17, 2024
2 parents 0d239f7 + 06aa887 commit a65fc9f
Show file tree
Hide file tree
Showing 10 changed files with 276 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,15 @@ public DatasetsSearchResponse search(DatasetSearchQuery query, String accessToke
return datasetsSearchService.search(query, accessToken);
}

var resultsets = queryOnBeaconIfThereAreBeaconFilters(beaconAuthorization, query);
var resultSets = queryOnBeaconIfThereAreBeaconFilters(beaconAuthorization, query);

var datasetsSearchResponse = queryOnCkanIfThereIsNoBeaconFilterOrResultsetsIsNotEmpty(
accessToken,
query,
resultsets
resultSets
);

return enhanceDatasetsResponse(beaconAuthorization, datasetsSearchResponse, resultsets);
return enhanceDatasetsResponse(beaconAuthorization, datasetsSearchResponse, resultSets);
}

private String retrieveBeaconAuthorization(String accessToken) {
Expand Down Expand Up @@ -174,38 +174,38 @@ private DatasetSearchQuery enhanceQueryFacets(

private DatasetsSearchResponse enhanceDatasetsResponse(
String beaconAuthorization,
DatasetsSearchResponse datasetsSearchReponse,
DatasetsSearchResponse datasetsSearchResponse,
List<BeaconResultSet> resultSets
) {
var facetGroupCount = new HashMap<String, Integer>();
facetGroupCount.put(BEACON_FACET_GROUP, resultSets.size());
if (isNotEmpty(datasetsSearchReponse.getFacetGroupCount())) {
facetGroupCount.putAll(datasetsSearchReponse.getFacetGroupCount());
if (isNotEmpty(datasetsSearchResponse.getFacetGroupCount())) {
facetGroupCount.putAll(datasetsSearchResponse.getFacetGroupCount());
}

var facetGroups = new ArrayList<FacetGroup>();
facetGroups.add(beaconFilteringTermsService.listFilteringTerms(beaconAuthorization));
if (isNotEmpty(datasetsSearchReponse.getFacetGroups())) {
facetGroups.addAll(datasetsSearchReponse.getFacetGroups());
if (isNotEmpty(datasetsSearchResponse.getFacetGroups())) {
facetGroups.addAll(datasetsSearchResponse.getFacetGroups());
}

var results = List.<SearchedDataset>of();
if (isNotEmpty(datasetsSearchReponse.getResults())) {
if (isNotEmpty(datasetsSearchResponse.getResults())) {
var recordCounts = resultSets.stream()
.collect(toMap(
BeaconResultSet::getId,
BeaconResultSet::getResultsCount
));

results = datasetsSearchReponse.getResults()
results = datasetsSearchResponse.getResults()
.stream()
.map(it -> it.toBuilder()
.recordsCount(recordCounts.get(it.getIdentifier()))
.build())
.toList();
}

return datasetsSearchReponse.toBuilder()
return datasetsSearchResponse.toBuilder()
.facetGroupCount(facetGroupCount)
.facetGroups(facetGroups)
.results(results)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
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.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.*;
import lombok.experimental.UtilityClass;

import static java.util.Optional.ofNullable;
Expand Down Expand Up @@ -57,7 +54,7 @@ public RetrievedDataset from(CkanPackage ckanPackage) {
.build();
}

private List<ValueLabel> values(List<String> values) {
private List<ValueLabel> values(List<CkanValueLabel> values) {
return ofNullable(values)
.orElseGet(List::of)
.stream()
Expand All @@ -77,6 +74,16 @@ private ValueLabel value(String value) {
.orElse(null);
}

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

private LocalDateTime parse(String date) {
return ofNullable(date)
.map(it -> LocalDateTime.parse(it, DATE_FORMATTER))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,7 @@
import io.github.genomicdatainfrastructure.discovery.model.FacetGroup;
import io.github.genomicdatainfrastructure.discovery.model.SearchedDataset;
import io.github.genomicdatainfrastructure.discovery.model.ValueLabel;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.CkanFacet;
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.PackagesSearchResponse;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.PackagesSearchResult;
import io.github.genomicdatainfrastructure.discovery.remote.ckan.model.*;
import lombok.experimental.UtilityClass;

import java.util.List;
Expand All @@ -26,7 +22,6 @@
import java.time.LocalDateTime;

import static java.util.Optional.ofNullable;
import static java.util.function.Predicate.not;

@UtilityClass
public class PackagesSearchResponseMapper {
Expand Down Expand Up @@ -130,7 +125,7 @@ private LocalDateTime parse(String date) {
.orElse(null);
}

private List<ValueLabel> values(List<String> values) {
private List<ValueLabel> values(List<CkanValueLabel> values) {
return ofNullable(values)
.orElseGet(List::of)
.stream()
Expand All @@ -139,13 +134,12 @@ private List<ValueLabel> values(List<String> values) {
.toList();
}

private ValueLabel value(String value) {
private ValueLabel value(CkanValueLabel value) {
return ofNullable(value)
.filter(Objects::nonNull)
.filter(not(String::isBlank))
.map(it -> ValueLabel.builder()
.value(it)
.label(it)
.value(it.getName())
.label(it.getDisplayName())
.build())
.orElse(null);
}
Expand Down
48 changes: 23 additions & 25 deletions src/main/openapi/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ info:
servers:
- url: /
paths:
/api/3/action/package_search:
/api/3/action/enhanced_package_search:
get:
summary: Searches for packages based on criteria
operationId: package_search
Expand Down Expand Up @@ -73,7 +73,7 @@ paths:
application/json:
schema:
$ref: "#/components/schemas/PackagesSearchResponse"
/api/3/action/package_show:
/api/3/action/enhanced_package_show:
get:
summary: Retrieves a package by ID
operationId: package_show
Expand Down Expand Up @@ -137,20 +137,7 @@ components:
items:
type: array
items:
$ref: "#/components/schemas/CkanFacetItem"
CkanFacetItem:
type: object
properties:
name:
type: string
display_name:
type: string
count:
type: integer
required:
- name
- display_name
- count
$ref: "#/components/schemas/CkanValueLabel"
CkanPackage:
type: object
properties:
Expand All @@ -165,7 +152,7 @@ components:
theme:
type: array
items:
type: string
$ref: "#/components/schemas/CkanValueLabel"
tags:
type: array
items:
Expand All @@ -183,23 +170,23 @@ components:
language:
type: array
items:
type: string
contact_uri: #TODO check if there are other attributes to form value/label
$ref: "#/components/schemas/CkanValueLabel"
contact_uri:
type: string
has_version:
type: array
items:
type: string
$ref: "#/components/schemas/CkanValueLabel"
access_rights:
type: string
$ref: "#/components/schemas/CkanValueLabel"
conforms_to:
type: array
items:
type: string
$ref: "#/components/schemas/CkanValueLabel"
provenance:
type: string
spatial_uri: #TODO check if there are other attributes to form value/label
type: string
spatial_uri:
$ref: "#/components/schemas/CkanValueLabel"
resources:
type: array
items:
Expand Down Expand Up @@ -230,7 +217,7 @@ components:
description:
type: string
format:
type: string
$ref: "#/components/schemas/CkanValueLabel"
uri:
type: string
created:
Expand Down Expand Up @@ -281,3 +268,14 @@ components:
type: string
message:
type: string
CkanValueLabel:
properties:
name:
type: string
display_name:
type: string
count:
type: integer
required:
- name
- display_name
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void can_search_datasets_with_beacon_filters() {
.post("/api/v1/datasets/search")
.then()
.statusCode(200)
.body("count", equalTo(1))
.body("count", equalTo(1167))
.body("results[0].recordsCount", equalTo(64));
}

Expand Down
Loading

0 comments on commit a65fc9f

Please sign in to comment.