-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DC-781] Create service endpoint stub for creating a Snapshot Request #1537
Conversation
src/main/java/bio/terra/service/snapshotbuilder/SnapshotBuilderService.java
Outdated
Show resolved
Hide resolved
src/test/java/bio/terra/app/controller/DatasetsApiControllerTest.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure the oneOf yaml will work; adding a test that specifies a complete snapshot request would be a way to help validate this.
src/main/java/bio/terra/service/snapshotbuilder/SnapshotBuilderService.java
Outdated
Show resolved
Hide resolved
description: Criteria Group specifying a Cohort. | ||
|
||
SnapshotBuilderAnyCriteria: | ||
oneOf: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, it will be great if oneOf
really works now. I've been avoiding it for a while because the java codegen wasn't usable.
Looking at the code this generates, I'm not sure it's working yet. This generates a type SnapshotBuilderAnyCriteria
which is what SnapshotBuilderCriteriaGroup
uses for its criteria
field. However the oneOf subtypes SnapshotBuilderDomainOption
and SnapshotBuilderProgramDataOption
are not subtypes of SnapshotBuilderAnyCriteria
. They are subtypes of OneOfSnapshotBuilderAnyCriteria
(which make them sibling types of SnapshotBuilderAnyCriteria
).
Long story short, I don't see how in Java we can get from SnapshotBuilderCriteriaGroup.criteria
to a subtype class like SnapshotBuilderDomainOption
. I'd like to see an example of that before merging this change in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah okay I see I will look into this. Instead of defining AnyCriteria as its own component, I could define SnapshotBuilderCriteriaGroup.criteria as a list of type SnapshotBuilderDomainOption or SnapshotBuilderProgramDataOption maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay removing the explicit definition of AnyCriteria seems to get rid of the extra class definition. So now there is OneOfSnapshotBuilderCriteriaGroupCriteriaItems which has two subtypes SnapshotBuilderDomainOption or SnapshotBuilderProgramDataOption. The name is not ideal, but I wonder what you think of this approach.
new SnapshotBuilderAccessRequest() | ||
.name("name") | ||
.researchPurposeStatement("purpose") | ||
.datasetRequest(new SnapshotBuilderRequest()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit messy but I think we need to test the entire API as specified in the yaml, so the request needs to include cohorts, concept sets and value set.
post: | ||
tags: | ||
- datasets | ||
description: Create a new snapshot request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if a user journey type description would be helpful here. Something like "As a researcher, create a snapshot request for a dataset, given a set of criteria and required concept sets and values."?
type: array | ||
items: | ||
oneOf: | ||
- $ref: '#/components/schemas/SnapshotBuilderDomainOption' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you may need a new type for this. The Option
versions of these types are like "prototype" or "source" versions. For a selected domain option, the only value needed is the option's concept code. The Domain root (which I think the UI calls category
) may also be helpful to include for non-OMOP cases. For OMOP data the code is unique across all categories so it's sufficient by itself.
Note that a future version of the cohort builder will support other constraints on the codes, like occurrence count and occurrence times.
items: | ||
oneOf: | ||
- $ref: '#/components/schemas/SnapshotBuilderDomainOption' | ||
- $ref: '#/components/schemas/SnapshotBuilderProgramDataOption' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ProgramDataOption
might work fine for both cases, even though it is representing a different thing. It may be that the same data is needed for both.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I could also do SnapshotBuilderConcept (which is the root of DomainOption) and ProgramDataOption, just to keep them separate.
void testCreateSnapshotRequest() throws Exception { | ||
mockValidators(); | ||
SnapshotBuilderAccessRequest expected = | ||
new SnapshotBuilderAccessRequest() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another approach here would be to write the object as JSON. If it's less code I would do it that way instead.
@@ -24,6 +25,12 @@ public SnapshotBuilderSettings updateSnapshotBuilderSettings( | |||
return snapshotBuilderSettingsDao.upsertSnapshotBuilderSettingsByDataset(id, settings); | |||
} | |||
|
|||
public SnapshotBuilderAccessRequest createSnapshotRequest( | |||
// TODO: add given request to the database, return real JobModel with the id of the new entry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: This comment is no longer accurate wrt the JobModel
. Also, could you reference the specific ticket number?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a few minor comments left
conceptSets: | ||
type: array | ||
items: | ||
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSets' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this type should be called SnapshotBuilderDatasetConceptSet
since it's a single concept set. It's an existing type but it'd be good to rename it now if it's not a lot of extra work.
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSets' | |
$ref: '#/components/schemas/SnapshotBuilderDatasetConceptSet' |
discriminator: | ||
propertyName: kind | ||
mapping: | ||
list: '#/components/schemas/SnapshotBuilderProgramDataListCriteria' | ||
range: '#/components/schemas/SnapshotBuilderProgramDataRangeCriteria' | ||
domain: '#/components/schemas/SnapshotBuilderCriteria' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉
@@ -239,6 +245,61 @@ void testUpdateSnapshotBuilderSettings() throws Exception { | |||
verify(snapshotBuilderService).updateSnapshotBuilderSettings(DATASET_ID, SETTINGS); | |||
} | |||
|
|||
@Test | |||
void testCreateCriteriaData() throws Exception { | |||
TestUtils.mapFromJson( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realize the point here is that the json conversion doesn't throw, but I think a test should have at least one assert per conversion. Something like
var criteria = TestUtils.mapFromJson(...);
assertThat(critera.name(), is("name"));
.addCohortsItem( | ||
new SnapshotBuilderCohort() | ||
.name("cohort") | ||
.addCriteriaGroupsItem(new SnapshotBuilderCriteriaGroup())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add at least one criteria to the group? It'd be good to have another check for round-trip operations on the oneOf
objects.
Kudos, SonarCloud Quality Gate passed! |
Create stub service endpoint for requesting access to a snapshot (creating a request)