Skip to content

Commit 7bc60d5

Browse files
committed
Supports renaming a draft; adds draft type to entries returned in summary listing; updates swagger docs.
1 parent 0dafb88 commit 7bc60d5

File tree

9 files changed

+65
-6
lines changed

9 files changed

+65
-6
lines changed

src/main/java/org/broadinstitute/consent/http/db/DraftDAO.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
public interface DraftDAO extends Transactional<DraftDAO> {
2828

2929
String DRAFT_SUMMARY = """
30-
SELECT ds.name, ds.create_date, ds.uuid, ds.update_date
30+
SELECT ds.name, ds.create_date, ds.uuid, ds.update_date, ds.draft_type
3131
FROM draft ds
3232
WHERE ds.create_user_id = :createdUserId
3333
ORDER BY ds.update_date DESC

src/main/java/org/broadinstitute/consent/http/db/mapper/DraftSummaryMapper.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import java.sql.SQLException;
66
import java.util.Date;
77
import java.util.UUID;
8+
import org.broadinstitute.consent.http.enumeration.DraftType;
89
import org.broadinstitute.consent.http.models.DraftSummary;
910
import org.jdbi.v3.core.mapper.RowMapper;
1011
import org.jdbi.v3.core.statement.StatementContext;
@@ -18,7 +19,8 @@ public DraftSummary map(ResultSet rs, StatementContext ctx) throws SQLException
1819
UUID uuid = UUID.fromString(rs.getString("uuid"));
1920
Date createDate = rs.getTimestamp("create_date");
2021
Date updateDate = hasColumn(rs, "update_date") ? rs.getTimestamp("update_date") : null;
22+
DraftType draftType = DraftType.fromValue(rs.getString("draft_type"));
2123

22-
return new DraftSummary(uuid, name, createDate, updateDate);
24+
return new DraftSummary(uuid, name, createDate, updateDate, draftType);
2325
}
2426
}

src/main/java/org/broadinstitute/consent/http/models/DraftSummary.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,22 @@
22

33
import java.util.Date;
44
import java.util.UUID;
5+
import org.broadinstitute.consent.http.enumeration.DraftType;
56

67
public class DraftSummary {
78

89
private UUID id;
910
private String name;
1011
private Date createDate;
1112
private Date updateDate;
13+
private DraftType draftType;
1214

13-
public DraftSummary(UUID id, String name, Date createDate, Date updateDate) {
15+
public DraftSummary(UUID id, String name, Date createDate, Date updateDate, DraftType draftType) {
1416
this.setId(id);
1517
this.setName(name);
1618
this.setCreateDate(createDate);
1719
this.setUpdateDate(updateDate);
20+
this.setDraftType(draftType);
1821
}
1922

2023
public UUID getId() {
@@ -48,4 +51,8 @@ public Date getUpdateDate() {
4851
public void setUpdateDate(Date updateDate) {
4952
this.updateDate = updateDate;
5053
}
54+
55+
public DraftType getDraftType() { return draftType; }
56+
57+
public void setDraftType(DraftType draftType) { this.draftType = draftType; }
5158
}

src/main/java/org/broadinstitute/consent/http/resources/DraftResource.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import jakarta.ws.rs.GET;
1010
import jakarta.ws.rs.InternalServerErrorException;
1111
import jakarta.ws.rs.NotFoundException;
12+
import jakarta.ws.rs.PATCH;
1213
import jakarta.ws.rs.POST;
1314
import jakarta.ws.rs.PUT;
1415
import jakarta.ws.rs.Path;
@@ -119,6 +120,22 @@ public Response updateDraft(@Auth AuthUser authUser, @PathParam("draftUUID") Str
119120
}
120121
}
121122

123+
@PATCH
124+
@Produces({MediaType.APPLICATION_JSON})
125+
@Consumes({MediaType.TEXT_PLAIN})
126+
@Path("/v1/{draftUUID}")
127+
public Response patchDraftName(@Auth AuthUser authUser, @PathParam("draftUUID") String draftUUID, String name) {
128+
try {
129+
User user = userService.findUserByEmail(authUser.getEmail());
130+
DraftInterface draft = draftService.getAuthorizedDraft(validateUUID(draftUUID), user);
131+
draft.setName(name);
132+
DraftInterface responseDraft = draftService.updateDraft(draft, user);
133+
return Response.ok().entity(draftService.draftAsJson(responseDraft)).build();
134+
} catch (Exception e) {
135+
return createExceptionResponse(e);
136+
}
137+
}
138+
122139
@DELETE
123140
@Produces(MediaType.APPLICATION_JSON)
124141
@Path("/v1/{draftUUID}")

src/main/resources/assets/paths/draftDocumentIndex.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,30 @@ delete:
7474
description: User not authorized to delete draft
7575
404:
7676
description: The draft cannot be found.
77+
patch:
78+
summary: Renames a draft
79+
description: Updates the name of a draft to the supplied value.
80+
tags:
81+
- Draft
82+
parameters:
83+
- name: draftUUID
84+
in: path
85+
description: The UUID identifying the draft.
86+
required: true
87+
schema:
88+
type: string
89+
format: uuid
90+
requestBody:
91+
description: |
92+
The name of the draft.
93+
content:
94+
text/plain:
95+
schema:
96+
type: string
97+
responses:
98+
200:
99+
description: The delete succeeded.
100+
401:
101+
description: User not authorized to delete draft
102+
404:
103+
description: The draft cannot be found.

src/main/resources/assets/paths/draftIndex.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ get:
1313
items:
1414
$ref: '../schemas/DraftSummary.yaml'
1515
401:
16-
description: Not authorized. Did you remember to authenticate? You must be a data submitter to use this endpoint.
16+
description: User not authorized to get draft summaries.
1717
500:
1818
description: Internal server error. Something went wrong with the valid input provided.
1919
post:
@@ -38,6 +38,6 @@ post:
3838
400:
3939
description: Bad Request (invalid input)
4040
401:
41-
description: Not authorized. Did you remember to authenticate? You must be a data submitter to use this endpoint.
41+
description: User not authorized to create draft
4242
500:
4343
description: Internal Error (something went wrong processing valid input)

src/main/resources/assets/schemas/DraftSummary.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ properties:
1515
type: string
1616
format: date
1717
description: Describes the date the draft was last modified.
18+
draftType:
19+
type: string
20+
enum: [StudyDatasetSubmissionV1]

src/test/java/org/broadinstitute/consent/http/db/DraftDAOTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,6 @@ private void summaryMatchesDetails(DraftSummary draftSummary,
222222
assertEquals(draftSummary.getName(), draftInterface.getName());
223223
assertEquals(draftSummary.getCreateDate(), draftInterface.getCreateDate());
224224
assertEquals(draftSummary.getUpdateDate(), draftInterface.getUpdateDate());
225+
assertEquals(draftSummary.getDraftType(), draftInterface.getType());
225226
}
226227
}

src/test/java/org/broadinstitute/consent/http/resources/DraftResourceTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.util.HashSet;
2626
import java.util.Set;
2727
import java.util.UUID;
28+
import org.broadinstitute.consent.http.enumeration.DraftType;
2829
import org.broadinstitute.consent.http.models.AuthUser;
2930
import org.broadinstitute.consent.http.models.DraftStudyDataset;
3031
import org.broadinstitute.consent.http.models.DraftInterface;
@@ -84,7 +85,8 @@ void testGetDraftWhenNoneExistForUser() {
8485
void testGetDraftsWhenOneExistForUser() {
8586
Set<DraftSummary> draftSummaries = new HashSet<>();
8687
draftSummaries.add(
87-
new DraftSummary(UUID.randomUUID(), "test", new Date(), new Date()));
88+
new DraftSummary(UUID.randomUUID(), "test", new Date(), new Date(),
89+
DraftType.STUDY_DATASET_SUBMISSION_V1));
8890
when(userService.findUserByEmail(any())).thenReturn(user);
8991
when(draftService.findDraftSummariesForUser(any())).thenReturn(draftSummaries);
9092
initResource();

0 commit comments

Comments
 (0)