Skip to content

Commit

Permalink
refactor: create ckan config class and add fl parameter to ckan api
Browse files Browse the repository at this point in the history
  • Loading branch information
admy7 committed Aug 22, 2024
1 parent 86a32eb commit cfa843f
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
public interface DatasetsRepository {

List<SearchedDataset> search(List<String> datasetIds,
String returnFields,
String sort,
Integer rows,
Integer start,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.github.genomicdatainfrastructure.discovery.datasets.infra.ckan.config;

public class CkanConfiguration {
public static final String CKAN_IDENTIFIER_FIELD = "identifier";
public static final String CKAN_FACET_GROUP = "ckan";
public static final String CKAN_FACET_LABEL = "DCAT-AP";
public static final String SELECTED_FACETS = "[\"access_rights\",\"theme\",\"tags\",\"spatial_uri\",\"organization\",\"publisher_name\",\"res_format\"]";
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

import java.util.List;

import static io.github.genomicdatainfrastructure.discovery.datasets.infra.ckan.config.CkanConfiguration.CKAN_IDENTIFIER_FIELD;

@ApplicationScoped
public class CkanDatasetIdsCollector implements DatasetIdsCollector {

Expand All @@ -34,10 +36,11 @@ public List<String> collect(DatasetSearchQuery query, String accessToken) {
var response = ckanQueryApi.packageSearch(
query.getQuery(),
facetsQuery,
null,
null,
null,
null,
CKAN_IDENTIFIER_FIELD,
"",
1000,
0,
"",
accessToken
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
import java.util.List;
import java.util.Objects;

import static io.github.genomicdatainfrastructure.discovery.datasets.infra.ckan.config.CkanConfiguration.CKAN_FACET_GROUP;
import static io.github.genomicdatainfrastructure.discovery.datasets.infra.ckan.config.CkanConfiguration.CKAN_IDENTIFIER_FIELD;
import static java.util.Optional.ofNullable;

@ApplicationScoped
public class CkanDatasetsRepository implements DatasetsRepository {

private static final String CKAN_IDENTIFIER_FIELD = "identifier";
private static final String CKAN_FACET_GROUP = "ckan";
private static final DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern(
"yyyy-MM-dd'T'HH:mm:ss.SSSSSS"
);
Expand All @@ -45,6 +45,7 @@ public CkanDatasetsRepository(

@Override
public List<SearchedDataset> search(List<String> datasetIds,
String returnFields,
String sort,
Integer rows,
Integer start,
Expand Down Expand Up @@ -72,10 +73,11 @@ public List<SearchedDataset> search(List<String> datasetIds,
var response = ckanQueryApi.packageSearch(
"",
facetsQuery,
returnFields,
sort,
rows,
start,
null,
"",
accessToken
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,12 @@
import java.util.List;
import java.util.Map;

import static io.github.genomicdatainfrastructure.discovery.datasets.infra.ckan.config.CkanConfiguration.*;
import static java.util.Optional.ofNullable;

@ApplicationScoped
public class CkanFacetsBuilder implements FacetsBuilder {

private static final String CKAN_FACET_GROUP = "ckan";
private static final String SELECTED_FACETS = "[\"access_rights\",\"theme\",\"tags\",\"spatial_uri\",\"organization\",\"publisher_name\",\"res_format\"]";

private final CkanQueryApi ckanQueryApi;

Expand All @@ -36,9 +35,10 @@ public FacetGroup build(DatasetSearchQuery query, String accessToken) {
var response = ckanQueryApi.packageSearch(
query.getQuery(),
facetsQuery,
query.getFl(),
query.getSort(),
0,
0,
query.getStart(),
SELECTED_FACETS,
accessToken
);
Expand All @@ -53,7 +53,7 @@ public FacetGroup build(DatasetSearchQuery query, String accessToken) {
private FacetGroup facetGroup(Map<String, CkanFacet> facets) {
return FacetGroup.builder()
.key(CKAN_FACET_GROUP)
.label("DCAT-AP")
.label(CKAN_FACET_LABEL)
.facets(facets.entrySet().stream()
.map(this::facet)
.toList())
Expand Down
6 changes: 6 additions & 0 deletions src/main/openapi/ckan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ paths:
required: false
schema:
type: string
- name: fl
in: query
description: dataset fields to be returned
required: false
schema:
type: string
- name: sort
in: query
description: Sorting of search results
Expand Down
4 changes: 4 additions & 0 deletions src/main/openapi/discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ components:
title: Facets
items:
$ref: "#/components/schemas/DatasetSearchQueryFacet"
returnFields:
type: string
title: dataset fields to return
default: "*"
sort:
type: string
title: Sorting of search results
Expand Down

0 comments on commit cfa843f

Please sign in to comment.