From 7bc60d543c0bb7c53a627ca5e8b703801f65a2e0 Mon Sep 17 00:00:00 2001 From: Elliot Otchet Date: Tue, 5 Nov 2024 16:27:48 -0500 Subject: [PATCH] Supports renaming a draft; adds draft type to entries returned in summary listing; updates swagger docs. --- .../consent/http/db/DraftDAO.java | 2 +- .../http/db/mapper/DraftSummaryMapper.java | 4 ++- .../consent/http/models/DraftSummary.java | 9 ++++++- .../consent/http/resources/DraftResource.java | 17 ++++++++++++ .../assets/paths/draftDocumentIndex.yaml | 27 +++++++++++++++++++ .../resources/assets/paths/draftIndex.yaml | 4 +-- .../assets/schemas/DraftSummary.yaml | 3 +++ .../consent/http/db/DraftDAOTest.java | 1 + .../http/resources/DraftResourceTest.java | 4 ++- 9 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/main/java/org/broadinstitute/consent/http/db/DraftDAO.java b/src/main/java/org/broadinstitute/consent/http/db/DraftDAO.java index b5d1967056..7df4c412e7 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/DraftDAO.java +++ b/src/main/java/org/broadinstitute/consent/http/db/DraftDAO.java @@ -27,7 +27,7 @@ public interface DraftDAO extends Transactional { String DRAFT_SUMMARY = """ - SELECT ds.name, ds.create_date, ds.uuid, ds.update_date + SELECT ds.name, ds.create_date, ds.uuid, ds.update_date, ds.draft_type FROM draft ds WHERE ds.create_user_id = :createdUserId ORDER BY ds.update_date DESC diff --git a/src/main/java/org/broadinstitute/consent/http/db/mapper/DraftSummaryMapper.java b/src/main/java/org/broadinstitute/consent/http/db/mapper/DraftSummaryMapper.java index 98640e9def..4fa22ae45c 100644 --- a/src/main/java/org/broadinstitute/consent/http/db/mapper/DraftSummaryMapper.java +++ b/src/main/java/org/broadinstitute/consent/http/db/mapper/DraftSummaryMapper.java @@ -5,6 +5,7 @@ import java.sql.SQLException; import java.util.Date; import java.util.UUID; +import org.broadinstitute.consent.http.enumeration.DraftType; import org.broadinstitute.consent.http.models.DraftSummary; import org.jdbi.v3.core.mapper.RowMapper; import org.jdbi.v3.core.statement.StatementContext; @@ -18,7 +19,8 @@ public DraftSummary map(ResultSet rs, StatementContext ctx) throws SQLException UUID uuid = UUID.fromString(rs.getString("uuid")); Date createDate = rs.getTimestamp("create_date"); Date updateDate = hasColumn(rs, "update_date") ? rs.getTimestamp("update_date") : null; + DraftType draftType = DraftType.fromValue(rs.getString("draft_type")); - return new DraftSummary(uuid, name, createDate, updateDate); + return new DraftSummary(uuid, name, createDate, updateDate, draftType); } } diff --git a/src/main/java/org/broadinstitute/consent/http/models/DraftSummary.java b/src/main/java/org/broadinstitute/consent/http/models/DraftSummary.java index ad2cff72c6..494f78b94f 100644 --- a/src/main/java/org/broadinstitute/consent/http/models/DraftSummary.java +++ b/src/main/java/org/broadinstitute/consent/http/models/DraftSummary.java @@ -2,6 +2,7 @@ import java.util.Date; import java.util.UUID; +import org.broadinstitute.consent.http.enumeration.DraftType; public class DraftSummary { @@ -9,12 +10,14 @@ public class DraftSummary { private String name; private Date createDate; private Date updateDate; + private DraftType draftType; - public DraftSummary(UUID id, String name, Date createDate, Date updateDate) { + public DraftSummary(UUID id, String name, Date createDate, Date updateDate, DraftType draftType) { this.setId(id); this.setName(name); this.setCreateDate(createDate); this.setUpdateDate(updateDate); + this.setDraftType(draftType); } public UUID getId() { @@ -48,4 +51,8 @@ public Date getUpdateDate() { public void setUpdateDate(Date updateDate) { this.updateDate = updateDate; } + + public DraftType getDraftType() { return draftType; } + + public void setDraftType(DraftType draftType) { this.draftType = draftType; } } diff --git a/src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java b/src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java index a8d7d17f97..2599013ca3 100644 --- a/src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java +++ b/src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java @@ -9,6 +9,7 @@ import jakarta.ws.rs.GET; import jakarta.ws.rs.InternalServerErrorException; import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.PATCH; import jakarta.ws.rs.POST; import jakarta.ws.rs.PUT; import jakarta.ws.rs.Path; @@ -119,6 +120,22 @@ public Response updateDraft(@Auth AuthUser authUser, @PathParam("draftUUID") Str } } + @PATCH + @Produces({MediaType.APPLICATION_JSON}) + @Consumes({MediaType.TEXT_PLAIN}) + @Path("/v1/{draftUUID}") + public Response patchDraftName(@Auth AuthUser authUser, @PathParam("draftUUID") String draftUUID, String name) { + try { + User user = userService.findUserByEmail(authUser.getEmail()); + DraftInterface draft = draftService.getAuthorizedDraft(validateUUID(draftUUID), user); + draft.setName(name); + DraftInterface responseDraft = draftService.updateDraft(draft, user); + return Response.ok().entity(draftService.draftAsJson(responseDraft)).build(); + } catch (Exception e) { + return createExceptionResponse(e); + } + } + @DELETE @Produces(MediaType.APPLICATION_JSON) @Path("/v1/{draftUUID}") diff --git a/src/main/resources/assets/paths/draftDocumentIndex.yaml b/src/main/resources/assets/paths/draftDocumentIndex.yaml index 5609bb6c16..f7da5e31b8 100644 --- a/src/main/resources/assets/paths/draftDocumentIndex.yaml +++ b/src/main/resources/assets/paths/draftDocumentIndex.yaml @@ -74,3 +74,30 @@ delete: description: User not authorized to delete draft 404: description: The draft cannot be found. +patch: + summary: Renames a draft + description: Updates the name of a draft to the supplied value. + tags: + - Draft + parameters: + - name: draftUUID + in: path + description: The UUID identifying the draft. + required: true + schema: + type: string + format: uuid + requestBody: + description: | + The name of the draft. + content: + text/plain: + schema: + type: string + responses: + 200: + description: The delete succeeded. + 401: + description: User not authorized to delete draft + 404: + description: The draft cannot be found. diff --git a/src/main/resources/assets/paths/draftIndex.yaml b/src/main/resources/assets/paths/draftIndex.yaml index 96c8a13042..333041dee9 100644 --- a/src/main/resources/assets/paths/draftIndex.yaml +++ b/src/main/resources/assets/paths/draftIndex.yaml @@ -13,7 +13,7 @@ get: items: $ref: '../schemas/DraftSummary.yaml' 401: - description: Not authorized. Did you remember to authenticate? You must be a data submitter to use this endpoint. + description: User not authorized to get draft summaries. 500: description: Internal server error. Something went wrong with the valid input provided. post: @@ -38,6 +38,6 @@ post: 400: description: Bad Request (invalid input) 401: - description: Not authorized. Did you remember to authenticate? You must be a data submitter to use this endpoint. + description: User not authorized to create draft 500: description: Internal Error (something went wrong processing valid input) diff --git a/src/main/resources/assets/schemas/DraftSummary.yaml b/src/main/resources/assets/schemas/DraftSummary.yaml index 7538de1965..f34ce6eb64 100644 --- a/src/main/resources/assets/schemas/DraftSummary.yaml +++ b/src/main/resources/assets/schemas/DraftSummary.yaml @@ -15,3 +15,6 @@ properties: type: string format: date description: Describes the date the draft was last modified. + draftType: + type: string + enum: [StudyDatasetSubmissionV1] diff --git a/src/test/java/org/broadinstitute/consent/http/db/DraftDAOTest.java b/src/test/java/org/broadinstitute/consent/http/db/DraftDAOTest.java index 7b608b6011..047e5be344 100644 --- a/src/test/java/org/broadinstitute/consent/http/db/DraftDAOTest.java +++ b/src/test/java/org/broadinstitute/consent/http/db/DraftDAOTest.java @@ -222,5 +222,6 @@ private void summaryMatchesDetails(DraftSummary draftSummary, assertEquals(draftSummary.getName(), draftInterface.getName()); assertEquals(draftSummary.getCreateDate(), draftInterface.getCreateDate()); assertEquals(draftSummary.getUpdateDate(), draftInterface.getUpdateDate()); + assertEquals(draftSummary.getDraftType(), draftInterface.getType()); } } diff --git a/src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java b/src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java index 00df92d20d..4d8f077581 100644 --- a/src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java +++ b/src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java @@ -25,6 +25,7 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import org.broadinstitute.consent.http.enumeration.DraftType; import org.broadinstitute.consent.http.models.AuthUser; import org.broadinstitute.consent.http.models.DraftStudyDataset; import org.broadinstitute.consent.http.models.DraftInterface; @@ -84,7 +85,8 @@ void testGetDraftWhenNoneExistForUser() { void testGetDraftsWhenOneExistForUser() { Set draftSummaries = new HashSet<>(); draftSummaries.add( - new DraftSummary(UUID.randomUUID(), "test", new Date(), new Date())); + new DraftSummary(UUID.randomUUID(), "test", new Date(), new Date(), + DraftType.STUDY_DATASET_SUBMISSION_V1)); when(userService.findUserByEmail(any())).thenReturn(user); when(draftService.findDraftSummariesForUser(any())).thenReturn(draftSummaries); initResource();