Skip to content

Commit

Permalink
persist curator's review comments to database #3943
Browse files Browse the repository at this point in the history
  • Loading branch information
pdurbin committed Jun 27, 2017
1 parent 55bf5ba commit 78de1cb
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 3 deletions.
1 change: 1 addition & 0 deletions scripts/database/upgrades/upgrade_v4.7_to_v4.7.1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE usernotification ADD COLUMN text TEXT default NULL;
13 changes: 12 additions & 1 deletion src/main/java/edu/harvard/iq/dataverse/UserNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public enum Type {

@Transient
String roleString;


@Column(columnDefinition = "TEXT", nullable = true)
private String text;

private boolean emailed;

public Long getId() {
Expand Down Expand Up @@ -121,6 +124,14 @@ public void setDisplayAsRead(boolean displayAsRead) {
this.displayAsRead = displayAsRead;
}

public String getText() {
return text;
}

public void setText(String text) {
this.text = text;
}

public boolean isEmailed() {
return emailed;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,20 @@ public UserNotification save(UserNotification userNotification) {
public void delete(UserNotification userNotification) {
em.remove(em.merge(userNotification));
}

public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId) {
String noExtraTextOrComments = null;
sendNotification(dataverseUser, sendDate, type, objectId, noExtraTextOrComments);
}

public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId, String text) {

UserNotification userNotification = new UserNotification();
userNotification.setUser(dataverseUser);
userNotification.setSendDate(sendDate);
userNotification.setType(type);
userNotification.setObjectId(objectId);
userNotification.setText(text);
if (mailService.sendNotificationEmail(userNotification)) {
logger.fine("email was sent");
userNotification.setEmailed(true);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/edu/harvard/iq/dataverse/api/Datasets.java
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ public Response returnToAuthor(@PathParam("id") String idSupplied, String jsonBo
editUsers.remove(au);
}
for (AuthenticatedUser au : editUsers) {
userNotificationSvc.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.RETURNEDDS, dataset.getLatestVersion().getId());
userNotificationSvc.sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.RETURNEDDS, dataset.getLatestVersion().getId(), json.getString("comments"));
}
JsonObjectBuilder result = Json.createObjectBuilder();
result.add("inReview", inReview);
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/api/Notifications.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public Response getAllNotificationsForUser() {
for (UserNotification notification : notifications) {
JsonObjectBuilder notificationObjectBuilder = Json.createObjectBuilder();
notificationObjectBuilder.add("type", notification.getType().toString());
String comments = notification.getText();
if (comments != null) {
notificationObjectBuilder.add("comments", comments);
}
jsonArrayBuilder.add(notificationObjectBuilder);
}
JsonObjectBuilder result = Json.createObjectBuilder().add("notifications", jsonArrayBuilder);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,14 @@ public void testCuratorSendsCommentsToAuthor() {
authorsChecksForCommentsAgain.prettyPrint();
authorsChecksForCommentsAgain.then().assertThat()
.body("data.notifications[0].type", equalTo("RETURNEDDS"))
// The author thinks, "This why we have curators!"
.body("data.notifications[0].comments", equalTo("You forgot to upload your files."))
.body("data.notifications[1].type", equalTo("CREATEACC"))
.body("data.notifications[1].comments", equalTo(null))
.statusCode(OK.getStatusCode());

// Author then makes corrections (uploads files, in this case), etc.
// These println's are here in case you want to log into the GUI to see what notifications look like.
System.out.println("Curator username/password: " + curatorUsername);
System.out.println("Author username/password: " + authorUsername);

Expand Down

0 comments on commit 78de1cb

Please sign in to comment.