-
Notifications
You must be signed in to change notification settings - Fork 2
[DT-1520] DAR Expiration. #2491
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
Conversation
…mpute DAR status based on database field submission_date; don't consider DARs approved after one year; demonstrate how to find expiring DARs.
src/main/java/org/broadinstitute/consent/http/db/DataAccessRequestDAO.java
Outdated
Show resolved
Hide resolved
| dd.dataset_id | ||
| FROM data_access_request dar | ||
| LEFT JOIN dar_dataset dd ON dd.reference_id = dar.reference_id | ||
| WHERE dar.submission_date BETWEEN SYMMETRIC to_timestamp(:begin) AND to_timestamp(:end) |
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.
Now we can support time range queries for submitted DARs.
src/main/java/org/broadinstitute/consent/http/db/DarCollectionSummaryDAO.java
Outdated
Show resolved
Hide resolved
src/main/java/org/broadinstitute/consent/http/db/DataAccessRequestDAO.java
Outdated
Show resolved
Hide resolved
rushtong
left a comment
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.
Love the removal of draft. It would be interesting (not for this PR) to see if we could do something similar for the status field in data.
src/main/java/org/broadinstitute/consent/http/db/DataAccessRequestDAO.java
Outdated
Show resolved
Hide resolved
src/main/java/org/broadinstitute/consent/http/db/DataAccessRequestDAO.java
Outdated
Show resolved
Hide resolved
s-rubenstein
left a comment
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.
Where possible, could you drop comments where the SQL text blocks are logically the same? It looks like a bunch of this is solely formatting changes but I am not sure which is functional and which is format
src/main/java/org/broadinstitute/consent/http/models/DataAccessRequest.java
Outdated
Show resolved
Hide resolved
| SELECT dd.dataset_id, dar.id, dar.reference_id, dar.collection_id, dar.parent_id, dar.user_id, dar.create_date, dar.sort_date, dar.submission_date, dar.update_date, | ||
| (regexp_replace(dar.data #>> '{}', '\\\\u0000', '', 'g'))::jsonb AS data FROM data_access_request dar | ||
| LEFT JOIN dar_dataset dd on dd.reference_id = dar.reference_id | ||
| WHERE dar.submission_date is not null |
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.
switching from draft to submission date
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.
Thanks for these comments, they were very helpful!
| AND dar.submission_date > now() - interval '1 year' | ||
| """) | ||
| @SqlQuery( | ||
| """ |
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.
remove dar.draft + formatting
| + " WHERE dar.draft = true " | ||
| + " AND (LOWER(dar.data->>'status') != 'archived' OR dar.data->>'status' IS NULL) " | ||
| + " ORDER BY dar.update_date DESC") | ||
| """ |
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.
Remove dar.draft + formatting
| + " AND (LOWER(dar.data->>'status') != 'archived' OR dar.data->>'status' IS NULL) " | ||
| + " AND dar.user_id = :userId " | ||
| + " ORDER BY dar.sort_date DESC") | ||
| """ |
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.
remove dar.draft + Formatting.
| + " AND dar.user_id = :userId " | ||
| + " AND (LOWER(dar.data->>'status') != 'archived' OR dar.data->>'status' IS NULL) " | ||
| + " ORDER BY dar.sort_date DESC") | ||
| """ |
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.
Remove dar.draft + formatting
| + "SET data = to_jsonb(regexp_replace(:data, '\\\\u0000', '', 'g')), user_id = :userId, sort_date = :sortDate, " | ||
| + "submission_date = :submissionDate, update_date = :updateDate " | ||
| + "WHERE reference_id = :referenceId") | ||
| """ |
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.
formatting.
| * @param referenceId String | ||
| */ | ||
| @SqlUpdate("DELETE FROM data_access_request WHERE reference_id = :referenceId") | ||
| @SqlUpdate( |
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.
Formatting
| "UPDATE data_access_request dar " | ||
| + "SET data=jsonb_set((regexp_replace(dar.data #>> '{}', '\\\\u0000', '', 'g'))::jsonb, '{status}', '\"Canceled\"') " | ||
| + "WHERE reference_id IN (<referenceIds>)") | ||
| """ |
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.
Formatting.
| * @param collectionId Integer | ||
| */ | ||
| @SqlUpdate("DELETE FROM data_access_request WHERE collection_id = :collectionId") | ||
| @SqlUpdate( |
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.
Formatting.
| + "VALUES (:referenceId, :userId, :createDate, :sortDate, " | ||
| + ":submissionDate, :updateDate, to_jsonb(:data), true)") | ||
| """ | ||
| INSERT INTO data_access_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.
remove draft.
src/main/java/org/broadinstitute/consent/http/models/DataAccessRequest.java
Outdated
Show resolved
Hide resolved
src/main/java/org/broadinstitute/consent/http/models/DataAccessRequest.java
Outdated
Show resolved
Hide resolved
| + "(collection_id, reference_id, user_id, create_date, sort_date, submission_date, update_date, data) " | ||
| + "VALUES (:collectionId, :referenceId, :userId, :createDate, :sortDate, " + | ||
| ":submissionDate, :updateDate, to_jsonb(:data))") | ||
| """ |
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.
Formatting.
| void updateDraftForCollection(@Bind("collectionId") Integer collectionId, | ||
| """ | ||
| UPDATE data_access_request | ||
| SET submission_date = now(), collection_id = :collectionId |
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.
remove the use of draft
src/main/java/org/broadinstitute/consent/http/db/DataAccessRequestDAO.java
Show resolved
Hide resolved
| LEFT JOIN dar_dataset dd ON dd.reference_id = dar.reference_id | ||
| WHERE dar.submission_date BETWEEN SYMMETRIC :begin AND :end | ||
| """) | ||
| List<DataAccessRequest> findSubmittedDarsByTimeRange(@Bind("begin") Timestamp begin, |
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.
Why is this API being added? I don't see it used anywhere in this PR other than tests.
Before when I asked about SYMMETRIC, my question was really about how do we know that this needs to support out-of-order queries? Without an example of how it will be used in code, it's hard to tell.
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.
The ticket includes an AC of "Mechanism to find expired DARs"
This is an example of a "Mechanism to find expired DARs"
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.
If the only need is to find expired, could it be done with a query that has a single bound? Adding the service method that uses this API (e.g. DataAccessRequestService.findExpiredDars()) would help me understand how this API works to meet the AC.
Is the idea that, instead of keeping track of which DARs we've notified users of, we instead find only those that expired in a specific time range? That could work but we'd need to be very precise about when the check is done, to avoid missing some DARs or notifying twice for others.
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.
Exactly. As discussed at standup this morning, we have a ticket to notify DAR submitters when their DAR will expire in 30 days (from today). We'll know the starting time and ending time of the query range. That's the use case I was specifically thinking about.
Do others exist? Sure.
Are they in other tickets? Yes.
Do I expect this to change? Maybe. It's just an example.
| + "FROM data_access_request " | ||
| + "WHERE (LOWER(data->>'status') != 'archived' " | ||
| + "OR data->>'status' IS NULL)") | ||
| """ |
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.
formatting
| + " SET data = jsonb_set ((data #>> '{}')::jsonb, '{status}', '\"Archived\"', true) " | ||
| + " WHERE reference_id IN (<referenceIds>)") | ||
| """ | ||
| UPDATE data_access_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.
Formatting
| + "VALUES (:referenceId, :datasetId) " | ||
| + "ON CONFLICT DO NOTHING") | ||
| """ | ||
| INSERT INTO dar_dataset (reference_id, dataset_id) |
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.
Formatting.
| + "VALUES (:referenceId, :datasetId) " | ||
| + "ON CONFLICT DO NOTHING") | ||
| """ | ||
| INSERT INTO dar_dataset (reference_id, dataset_id) |
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.
Formatting
| @SqlUpdate("DELETE FROM dar_dataset WHERE reference_id = :referenceId") | ||
| @SqlUpdate( | ||
| """ | ||
| DELETE FROM dar_dataset WHERE reference_id = :referenceId |
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.
Formatting.
| "dar.id AS dar_id, dar.reference_id AS dar_reference_id, dar.collection_id AS dar_collection_id, " | ||
| + | ||
| "dar.parent_id AS dar_parent_id, dar.draft AS dar_draft, dar.user_id AS dar_userId, " + | ||
| "dar.parent_id AS dar_parent_id, dar.user_id AS dar_userId, " + |
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.
remove draft
| return datasets; | ||
| } | ||
|
|
||
| public void setDatasets(Set<Dataset> datasets) { |
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.
Formatting.
pshapiro4broad
left a comment
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.
Some possible changes; also I would like to avoid storing computed values if that's possible here. But looks OK overall.
src/main/java/org/broadinstitute/consent/http/models/DataAccessRequest.java
Show resolved
Hide resolved
src/main/java/org/broadinstitute/consent/http/models/DarCollectionSummary.java
Show resolved
Hide resolved
src/test/java/org/broadinstitute/consent/http/db/DataAccessRequestDAOTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/broadinstitute/consent/http/db/DataAccessRequestDAOTest.java
Outdated
Show resolved
Hide resolved
src/test/java/org/broadinstitute/consent/http/db/DataAccessRequestDAOTest.java
Outdated
Show resolved
Hide resolved
…ests; updated swagger based on this change.
Addresses
https://broadworkbench.atlassian.net/browse/DT-1520
Summary
Consent had two state machines for determining if a Data Access Request was in draft form or submitted for a Data Access Committee to consider for approval. This PR aligns the code so that only one state machine exists. It is now centered on submission_date.
When submission_date is non-null, the DAR has been submitted by a RESEARCHER to a DATA ACCESS COMMITTEE for consideration. When the submission_date is null, it is considered a draft. This was the behavior in the existing code paths except for some tests that leveraged methods to short circuit that requirement.
The DataAccessRequest class now computes the fields
draft,expired, andexpiredAtfields when the submissionDate is set. These three values are now returned to the UI for enrichment.Of critical importance is the update to<- This was already completed in #2487DataAccessRequestDAO.findApprovedDARsByDatasetIdthat now requires DARs to be submitted within the last year in order to be considered "approved."Also added in
DataAccessRequestDAOisfindSubmittedDarsByTimeRange. This method is intended to be used by a to-be-built notification component that can alert users to expiring DARs. It allows the caller to specify the date range of approved DARs so that notifications can be sent. For example, give me the list of DARs that will expire 30 days from today. Those DARs would have a submission_date during the time of 1745193600.000 to 1745279999.999To simplify our codebase, other test only methods that were impacting draft state were removed.
Have you read CONTRIBUTING.md lately? If not, do that first.