-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DUOS-2887][risk=no] New api to search for dataset summaries (#2234)
- Loading branch information
Showing
10 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/org/broadinstitute/consent/http/db/mapper/DatasetSummaryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.broadinstitute.consent.http.db.mapper; | ||
|
||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
import org.broadinstitute.consent.http.models.Dataset; | ||
import org.broadinstitute.consent.http.models.DatasetSummary; | ||
import org.jdbi.v3.core.mapper.RowMapper; | ||
import org.jdbi.v3.core.statement.StatementContext; | ||
|
||
public class DatasetSummaryMapper implements RowMapper<DatasetSummary>, RowMapperHelper { | ||
|
||
@Override | ||
public DatasetSummary map(ResultSet rs, StatementContext ctx) throws SQLException { | ||
if (hasColumn(rs, "dataset_id") && hasColumn(rs, "name") && hasColumn(rs, "alias")) { | ||
String identifier = Dataset.parseAliasToIdentifier(rs.getInt("alias")); | ||
return new DatasetSummary(rs.getInt("dataset_id"), identifier, rs.getString("name")); | ||
} | ||
return null; | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/org/broadinstitute/consent/http/models/DatasetSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
package org.broadinstitute.consent.http.models; | ||
|
||
public record DatasetSummary(Integer id, String identifier, String name) { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/resources/assets/paths/datasetSummaryAutocomplete.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
get: | ||
summary: Autocomplete Datasets | ||
description: Returns all DAC approved dataset summaries matching a search query. | ||
parameters: | ||
- name: query | ||
in: query | ||
description: Search Query | ||
required: true | ||
schema: | ||
type: string | ||
tags: | ||
- Dataset | ||
responses: | ||
200: | ||
description: A list of Dataset Summary objects | ||
content: | ||
application/json: | ||
schema: | ||
type: array | ||
items: | ||
$ref: '../schemas/DatasetSummary.yaml' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
type: object | ||
properties: | ||
id: | ||
type: integer | ||
description: The unique identifier for a dataset | ||
identifier: | ||
type: string | ||
description: The public DUOS identifier for a dataset | ||
name: | ||
type: string | ||
description: The dataset name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,7 @@ | |
import org.broadinstitute.consent.http.models.DataUseBuilder; | ||
import org.broadinstitute.consent.http.models.Dataset; | ||
import org.broadinstitute.consent.http.models.DatasetProperty; | ||
import org.broadinstitute.consent.http.models.DatasetSummary; | ||
import org.broadinstitute.consent.http.models.Error; | ||
import org.broadinstitute.consent.http.models.Study; | ||
import org.broadinstitute.consent.http.models.StudyProperty; | ||
|
@@ -586,6 +587,18 @@ void testSearchDatasetsOpenAccess() { | |
assertEquals(GsonUtil.buildGson().toJson(List.of(ds)), response.getEntity()); | ||
} | ||
|
||
@Test | ||
void testAutocompleteDatasets() { | ||
when(authUser.getEmail()).thenReturn("[email protected]"); | ||
when(userService.findUserByEmail("[email protected]")).thenReturn(user); | ||
when(datasetService.searchDatasetSummaries(any())).thenReturn(List.of(new DatasetSummary(1, "ID", "Name"))); | ||
|
||
initResource(); | ||
try (Response response = resource.autocompleteDatasets(authUser, "test")) { | ||
assertTrue(HttpStatusCodes.isSuccess(response.getStatus())); | ||
} | ||
} | ||
|
||
@Test | ||
void testSearchDatasetIndex() throws IOException { | ||
String query = "{ \"dataUse\": [\"HMB\"] }"; | ||
|