Skip to content

Commit

Permalink
Merge pull request #5134 from IQSS/5013-add-requestor-to-submit-ds-no…
Browse files Browse the repository at this point in the history
…tification

5013 add requestor to submit dataset for review notification and email to curator
  • Loading branch information
kcondon authored Oct 10, 2018
2 parents 8c01a38 + 192686f commit 0a12572
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 9 deletions.
4 changes: 4 additions & 0 deletions scripts/database/upgrades/upgrade_v4.9.4_to_v4.10.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE usernotification
ADD requestor_id BIGINT;


5 changes: 3 additions & 2 deletions src/main/java/Bundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ notification.createDataverse={0} was created in {1} . To learn more about what y
notification.dataverse.management.title=Dataverse Management - Dataverse User Guide
notification.createDataset={0} was created in {1}. To learn more about what you can do with a dataset, check out the {2}.
notification.dataset.management.title=Dataset Management - Dataset User Guide
notification.wasSubmittedForReview={0} was submitted for review to be published in {1}. Don''t forget to publish it or send it back to the contributor\!
notification.wasSubmittedForReview={0} was submitted for review to be published in {1}. Don''t forget to publish it or send it back to the contributor ({2} at {3})\!
notification.wasReturnedByReviewer={0} was returned by the curator of {1}.
notification.wasPublished={0} was published in {1}.
notification.worldMap.added={0}, dataset had WorldMap layer data added to it.
Expand Down Expand Up @@ -593,7 +593,7 @@ notification.email.rejectFileAccess=Your request for access was rejected for the
notification.email.createDataverse=Your new dataverse named {0} (view at {1} ) was created in {2} (view at {3} ). To learn more about what you can do with your dataverse, check out the Dataverse Management - User Guide at {4}/{5}/user/dataverse-management.html .
# Bundle file editors, please note that "notification.email.createDataset" is used in a unit test
notification.email.createDataset=Your new dataset named {0} (view at {1} ) was created in {2} (view at {3} ). To learn more about what you can do with a dataset, check out the Dataset Management - User Guide at {4}/{5}/user/dataset-management.html .
notification.email.wasSubmittedForReview={0} (view at {1}) was submitted for review to be published in {2} (view at {3}). Don''t forget to publish it or send it back to the contributor\!
notification.email.wasSubmittedForReview={0} (view at {1}) was submitted for review to be published in {2} (view at {3}). Don''t forget to publish it or send it back to the contributor({4} at {5})\!
notification.email.wasReturnedByReviewer={0} (view at {1}) was returned by the curator of {2} (view at {3}).
notification.email.wasPublished={0} (view at {1}) was published in {2} (view at {3}).
notification.email.worldMap.added={0} (view at {1}) had WorldMap layer data added to it.
Expand All @@ -609,6 +609,7 @@ notification.email.checksumfail.subject={0}: Your upload failed checksum validat
notification.email.import.filesystem.subject=Dataset {0} has been successfully uploaded and verified
notification.email.import.checksum.subject={0}: Your file checksum job has completed
contact.delegation={0} on behalf of {1}
notification.email.info.unavailable=Unavailable

# passwordreset.xhtml
pageTitle.passwdReset.pre=Account Password Reset
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,19 @@ public Boolean sendNotificationEmail(UserNotification notification){
}


public Boolean sendNotificationEmail(UserNotification notification, String comment){
public Boolean sendNotificationEmail(UserNotification notification, String comment) {
return sendNotificationEmail(notification, comment, null);
}


public Boolean sendNotificationEmail(UserNotification notification, String comment, AuthenticatedUser requestor){

boolean retval = false;
String emailAddress = getUserEmailAddress(notification);
if (emailAddress != null){
Object objectOfNotification = getObjectOfNotification(notification);
if (objectOfNotification != null){
String messageText = getMessageTextBasedOnNotification(notification, objectOfNotification);
String messageText = getMessageTextBasedOnNotification(notification, objectOfNotification, comment, requestor);
String rootDataverseName = dataverseService.findRootDataverse().getName();
String subjectText = MailUtil.getSubjectTextBasedOnNotification(notification, rootDataverseName, objectOfNotification);
if (!(messageText.isEmpty() || subjectText.isEmpty())){
Expand Down Expand Up @@ -318,7 +323,12 @@ public String getMessageTextBasedOnNotification(UserNotification userNotificatio

}

public String getMessageTextBasedOnNotification(UserNotification userNotification, Object targetObject, String comment){
public String getMessageTextBasedOnNotification(UserNotification userNotification, Object targetObject, String comment) {
return getMessageTextBasedOnNotification(userNotification, targetObject, comment, null);

}

public String getMessageTextBasedOnNotification(UserNotification userNotification, Object targetObject, String comment, AuthenticatedUser requestor) {

String messageText = BundleUtil.getStringFromBundle("notification.email.greeting");
DatasetVersion version;
Expand Down Expand Up @@ -437,10 +447,14 @@ public String getMessageTextBasedOnNotification(UserNotification userNotificatio
if (comment != null && !comment.isEmpty()) {
mightHaveSubmissionComment = ".\n\n" + BundleUtil.getStringFromBundle("submissionComment") + "\n\n" + comment;
}
*/
*/
String requestorName = (requestor.getLastName() != null && requestor.getLastName() != null) ? requestor.getFirstName() + " " + requestor.getLastName() : BundleUtil.getStringFromBundle("notification.email.info.unavailable");
String requestorEmail = requestor.getEmail() != null ? requestor.getEmail() : BundleUtil.getStringFromBundle("notification.email.info.unavailable");
pattern = BundleUtil.getStringFromBundle("notification.email.wasSubmittedForReview");

String[] paramArraySubmittedDataset = {version.getDataset().getDisplayName(), getDatasetDraftLink(version.getDataset()),
version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()), mightHaveSubmissionComment};
version.getDataset().getOwner().getDisplayName(), getDataverseLink(version.getDataset().getOwner()),
requestorName, requestorEmail };
messageText += MessageFormat.format(pattern, paramArraySubmittedDataset);
return messageText;
case PUBLISHEDDS:
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/edu/harvard/iq/dataverse/UserNotification.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ public enum Type {
@ManyToOne
@JoinColumn( nullable = false )
private AuthenticatedUser user;
@ManyToOne
@JoinColumn( nullable = true )
private AuthenticatedUser requestor;
private Timestamp sendDate;
private boolean readNotification;

Expand Down Expand Up @@ -68,6 +71,14 @@ public AuthenticatedUser getUser() {
public void setUser(AuthenticatedUser user) {
this.user = user;
}

public AuthenticatedUser getRequestor() {
return requestor;
}

public void setRequestor(AuthenticatedUser requestor) {
this.requestor = requestor;
}

public String getSendDate() {
return new SimpleDateFormat("MMMM d, yyyy h:mm a z").format(sendDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,18 @@ public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate
}

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

public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId, String comment, AuthenticatedUser requestor) {
UserNotification userNotification = new UserNotification();
userNotification.setUser(dataverseUser);
userNotification.setSendDate(sendDate);
userNotification.setType(type);
userNotification.setObjectId(objectId);
if (mailService.sendNotificationEmail(userNotification)) {
userNotification.setRequestor(requestor);

if (mailService.sendNotificationEmail(userNotification, comment, requestor)) {
logger.fine("email was sent");
userNotification.setEmailed(true);
save(userNotification);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -680,4 +680,16 @@ public String getReasonForReturn(DatasetVersion datasetVersion) {
public String getPasswordRequirements() {
return passwordValidatorService.getGoodPasswordDescription(passwordErrors);
}

public String getRequestorName(UserNotification notification) {
if(notification == null) return BundleUtil.getStringFromBundle("notification.email.info.unavailable");
if(notification.getRequestor() == null) return BundleUtil.getStringFromBundle("notification.email.info.unavailable");;
return (notification.getRequestor().getLastName() != null && notification.getRequestor().getLastName() != null) ? notification.getRequestor().getFirstName() + " " + notification.getRequestor().getLastName() : BundleUtil.getStringFromBundle("notification.email.info.unavailable");
}

public String getRequestorEmail(UserNotification notification) {
if(notification == null) return BundleUtil.getStringFromBundle("notification.email.info.unavailable");;
if(notification.getRequestor() == null) return BundleUtil.getStringFromBundle("notification.email.info.unavailable");;
return notification.getRequestor().getEmail() != null ? notification.getRequestor().getEmail() : BundleUtil.getStringFromBundle("notification.email.info.unavailable");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ public Dataset save(CommandContext ctxt) throws CommandException {
ctxt.em().flush();

updateDatasetUser(ctxt);

AuthenticatedUser requestor = getUser().isAuthenticated() ? (AuthenticatedUser) getUser() : null;

List<AuthenticatedUser> authUsers = ctxt.permissions().getUsersWithPermissionOn(Permission.PublishDataset, savedDataset);
for (AuthenticatedUser au : authUsers) {
ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.SUBMITTEDDS, savedDataset.getLatestVersion().getId());
ctxt.notifications().sendNotification(au, new Timestamp(new Date().getTime()), UserNotification.Type.SUBMITTEDDS, savedDataset.getLatestVersion().getId(), "", requestor);
}

// TODO: What should we do with the indexing result? Print it to the log?
Expand Down
6 changes: 6 additions & 0 deletions src/main/webapp/dataverseuser.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
<o:param>
<a href="/dataverse/#{item.theObject.getDataset().getOwner().getAlias()}" title="#{item.theObject.getDataset().getOwner().getDisplayName()}">#{item.theObject.getDataset().getOwner().getDisplayName()}</a>
</o:param>
<o:param>
#{DataverseUserPage.getRequestorName(item)}
</o:param>
<o:param>
#{DataverseUserPage.getRequestorEmail(item)}
</o:param>
<o:param>
#{DataverseUserPage.getReasonForReturn(item.theObject)}
</o:param>
Expand Down

0 comments on commit 0a12572

Please sign in to comment.