Skip to content

Commit

Permalink
Supports renaming a draft; adds draft type to entries returned in sum…
Browse files Browse the repository at this point in the history
…mary listing; updates swagger docs.
  • Loading branch information
otchet-broad committed Nov 5, 2024
1 parent 0dafb88 commit 7bc60d5
Show file tree
Hide file tree
Showing 9 changed files with 65 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public interface DraftDAO extends Transactional<DraftDAO> {

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,22 @@

import java.util.Date;
import java.util.UUID;
import org.broadinstitute.consent.http.enumeration.DraftType;

public class DraftSummary {

private UUID id;
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() {
Expand Down Expand Up @@ -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; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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}")
Expand Down
27 changes: 27 additions & 0 deletions src/main/resources/assets/paths/draftDocumentIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
4 changes: 2 additions & 2 deletions src/main/resources/assets/paths/draftIndex.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
3 changes: 3 additions & 0 deletions src/main/resources/assets/schemas/DraftSummary.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ properties:
type: string
format: date
description: Describes the date the draft was last modified.
draftType:
type: string
enum: [StudyDatasetSubmissionV1]
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -84,7 +85,8 @@ void testGetDraftWhenNoneExistForUser() {
void testGetDraftsWhenOneExistForUser() {
Set<DraftSummary> 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();
Expand Down

0 comments on commit 7bc60d5

Please sign in to comment.