Skip to content

Commit

Permalink
chore: (ART-10814) update beacon api
Browse files Browse the repository at this point in the history
  • Loading branch information
jadz94 committed Dec 12, 2024
1 parent f3eac40 commit fe7e3ca
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

package io.github.genomicdatainfrastructure.discovery.datasets.infrastructure.beacon.persistence;

import static io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.IncludeResultsetResponsesEnum.HIT;
import static io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.RequestedGranularityEnum.RECORD;
import static java.util.Optional.ofNullable;
import static java.util.function.Predicate.not;
import static java.util.stream.Collectors.toMap;
Expand All @@ -13,7 +15,10 @@
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequest;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestMeta;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.IncludeResultsetResponsesEnum;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.RequestedGranularityEnum;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQueryFilter;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQueryFilter.OperatorEnum;
import io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQueryPagination;
import lombok.experimental.UtilityClass;
import java.util.List;
Expand All @@ -26,8 +31,8 @@ public class BeaconIndividualsRequestMapper {

private static final String BEACON_FACET_GROUP = "beacon";
private static final String SCOPE = "individual";
private static final String INCLUDE_RESULT_SET_RESPONSES = "HIT";
private static final String REQUESTED_GRANULARITY = "record";
private static final IncludeResultsetResponsesEnum INCLUDE_RESULT_SET_RESPONSES = HIT;
private static final RequestedGranularityEnum REQUESTED_GRANULARITY = RECORD;

public BeaconIndividualsRequest from(
DatasetSearchQuery query
Expand Down Expand Up @@ -104,7 +109,7 @@ private BeaconIndividualsRequestQueryFilter buildFreeTextBeaconFacet(
return BeaconIndividualsRequestQueryFilter
.builder()
.id(key)
.operator(operator)
.operator(OperatorEnum.fromString(operator))
.value(value)
.scope(SCOPE)
.build();
Expand Down
137 changes: 118 additions & 19 deletions src/main/openapi/beacon.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,51 +95,153 @@ components:
title: Filters
items:
$ref: "#/components/schemas/BeaconIndividualsRequestQueryFilter"
default: []
requestParameters:
type: array
items:
additionalProperties:
type: string
default: [ ]
includeResultsetResponses:
type: string
title: Include Resultset Responses
default: "HIT"
enum:
- ALL
- HIT
- MISS
- NONE
default: HIT
pagination:
type: object
properties:
skip:
type: integer
title: Skip
minimum: 0
default: 0
example: 0
limit:
type: integer
title: Limit
minimum: 0
default: 1
example: 10
currentPage:
type: string
example: ab0sc&fe1dd
nextPage:
type: string
example: ab0sc&fe1dd
previousPage:
type: string
example: ab0sc&fe1dd
requestParameters:
properties:
"$schema":
description: Added here to allow proper validation of the documents w/o providing specific values.
type: string
type: array
items:
additionalProperties:
description: The schema below is a placeholder for a dictionary 'key':'object'. The individual
definitions depend on the model (e.g. beacon-v2-default-model) and entity (e.g. `genomicVariant`).
type: string
requestedGranularity:
type: string
title: Requested Granularity
enum:
- boolean
- count
- record
default: boolean
testMode:
description: >-
Used for indicating that a request or response is done in a test context e.g. for compliance testing
i.e. to evaluate the acceptance/understanding of a request and the structure of the returned response by
the Beacon instance. A TRUE `testMode` parameter DOES NOT require that the Beacon instance is a test
instance, but that this specific request-response cycle is a testing one. When `true` the Beacon instance
MUST respond the request but it SHOULD use virtual or non-sensitive data. Here, what is being evaluated
is the acceptance/understanding of a request and the structure of the returned response by the Beacon
instance.
type: boolean
title: Test Mode
default: false
requestedGranularity:
type: string
title: Requested Granularity
default: "record"
BeaconIndividualsRequestQueryFilter:
anyOf:
- "$ref": "#/components/schemas/OntologyFilter"
- "$ref": "#/components/schemas/AlphanumericFilter"
- "$ref": "#/components/schemas/CustomFilter"

AlphanumericFilter:
type: object
description: Filter results based on operators and values applied to alphanumeric fields.
required:
- id
- operator
- value
properties:
id:
description: Field identifier to be queried.
example: ageOfOnset
type: string
title: Term ID
operator:
default: "="
description: Defines how the value relates to the field `id`.
enum:
- "="
- "<"
- ">"
- "!"
- ">="
- "<="
example: ">"
type: string
scope:
description: The entry type to which the filter applies
example: individuals
type: string
title: Operator
value:
description: Alphanumeric search term to be used within the query which can contain wildcard characters (%)
to denote any number of unknown characters. Values can be associated with units if applicable.
example: P70Y
type: string
CustomFilter:
type: object
description: Filter results to include records that contain a custom term defined by this Beacon.
required:
- id
properties:
id:
description: Custom filter terms should contain a unique identifier.
example: demographic.ethnicity:asian
type: string
scope:
description: The entry type to which the filter applies
example: individuals
type: string
title: Value
OntologyFilter:
type: object
description: Filter results to include records that contain a specific ontology term.
required:
- id
properties:
id:
description: Term ID to be queried, using CURIE syntax where possible.
example: HP:0002664
type: string
includeDescendantTerms:
default: true
description: Define if the Beacon should implement the ontology hierarchy, thus query the descendant terms of `id`.
type: boolean
scope:
description: The entry type to which the filter applies
example: biosamples
type: string
similarity:
default: exact
description: Allow the Beacon to return results which do not match the filter exactly, but do match to a certain
degree of similarity. The Beacon defines the semantic similarity model implemented and how to apply
the thresholds of 'high', 'medium' and 'low' similarity.
enum:
- exact
- high
- medium
- low
type: string
title: Scope
default: "individual"
BeaconIndividualsResponse:
type: object
properties:
Expand All @@ -153,9 +255,6 @@ components:
title: Result Sets
items:
$ref: "#/components/schemas/BeaconResultSet"
required:
- individuals
- resources
BeaconResultSet:
type: object
properties:
Expand Down
18 changes: 8 additions & 10 deletions src/main/openapi/discovery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -239,19 +239,17 @@ components:
- ENTRIES
title: Filter type
Operator:
type: string
default: "="
description: Defines how the value relates to the field `id`.
enum:
- "="
- ">"
- "<"
- "!="
- "%"
x-enum-varnames:
- EQUALS
- GREATER_THAN
- LESS_THAN
- DIFFERENT
- CONTAINS
- ">"
- "!"
- ">="
- "<="
example: ">"
type: string
QueryEntry:
properties:
key:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import java.util.List;
import java.util.Map;

import static io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.IncludeResultsetResponsesEnum.HIT;
import static io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQuery.RequestedGranularityEnum.RECORD;
import static io.github.genomicdatainfrastructure.discovery.remote.beacon.model.BeaconIndividualsRequestQueryFilter.OperatorEnum.GREATER_THAN_SYMBOL;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy;

Expand All @@ -37,8 +40,8 @@ void shouldAcceptNullQuery() {
.apiVersion("2.0")
.build())
.query(BeaconIndividualsRequestQuery.builder()
.includeResultsetResponses("HIT")
.requestedGranularity("record")
.includeResultsetResponses(HIT)
.requestedGranularity(RECORD)
.testMode(false)
.pagination(BeaconIndividualsRequestQueryPagination.builder()
.limit(1)
Expand All @@ -63,8 +66,8 @@ void shouldAcceptEmptyQuery() {
.apiVersion("2.0")
.build())
.query(BeaconIndividualsRequestQuery.builder()
.includeResultsetResponses("HIT")
.requestedGranularity("record")
.includeResultsetResponses(HIT)
.requestedGranularity(RECORD)
.testMode(false)
.pagination(BeaconIndividualsRequestQueryPagination.builder()
.limit(1)
Expand All @@ -89,8 +92,8 @@ void shouldAcceptEmptyFacets() {
.apiVersion("2.0")
.build())
.query(BeaconIndividualsRequestQuery.builder()
.includeResultsetResponses("HIT")
.requestedGranularity("record")
.includeResultsetResponses(HIT)
.requestedGranularity(RECORD)
.testMode(false)
.pagination(BeaconIndividualsRequestQueryPagination.builder()
.limit(1)
Expand Down Expand Up @@ -118,7 +121,7 @@ void canParse() {
.type(FilterType.FREE_TEXT)
.key("dummy_key_2")
.value("dummy_value_2")
.operator(Operator.GREATER_THAN)
.operator(Operator.GREATER_THAN_SYMBOL)
.entries(List.of())
.build(),
DatasetSearchQueryFacet.builder()
Expand All @@ -139,8 +142,8 @@ void canParse() {
.apiVersion("2.0")
.build())
.query(BeaconIndividualsRequestQuery.builder()
.includeResultsetResponses("HIT")
.requestedGranularity("record")
.includeResultsetResponses(HIT)
.requestedGranularity(RECORD)
.testMode(false)
.pagination(BeaconIndividualsRequestQueryPagination.builder()
.limit(1)
Expand All @@ -153,7 +156,7 @@ void canParse() {
.build(),
BeaconIndividualsRequestQueryFilter.builder()
.id("dummy_key_2")
.operator(">")
.operator(GREATER_THAN_SYMBOL)
.value("dummy_value_2")
.scope("individual")
.build()
Expand Down

0 comments on commit fe7e3ca

Please sign in to comment.