Skip to content

Commit

Permalink
email notification debug DAT-608
Browse files Browse the repository at this point in the history
  • Loading branch information
JayanthyChengan committed Jul 11, 2024
1 parent 01ee4ff commit 67a2787
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/main/java/edu/harvard/iq/dataverse/DatasetPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -4277,6 +4277,7 @@ public boolean isLockedForAnyReason() {
}

public void processPublishButton() {
logger.info(" JC TESTING process publish dataset = " );
if (dataset.isReleased()) {
PrimeFaces.current().executeScript("PF('publishDataset').show()");
}
Expand Down
16 changes: 12 additions & 4 deletions src/main/java/edu/harvard/iq/dataverse/MailServiceBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public boolean sendSystemEmail(String to, String subject, String messageText) {
* @return Status: true if sent successfully, false otherwise
*/
public boolean sendSystemEmail(String to, String subject, String messageText, boolean isHtmlContent) {
logger.info("JC Sending notifications 6.4 to address: " + to);

Optional<InternetAddress> optionalAddress = getSystemAddress();
if (optionalAddress.isEmpty()) {
logger.fine(() -> "Skipping sending mail to " + to + ", because no system address has been set.");
Expand All @@ -126,11 +128,13 @@ public boolean sendSystemEmail(String to, String subject, String messageText, bo
BundleUtil.getStringFromBundle(isHtmlContent ? "notification.email.closing.html" : "notification.email.closing",
List.of(BrandingUtil.getSupportTeamEmailAddress(systemAddress), BrandingUtil.getSupportTeamName(systemAddress)));

logger.fine(() -> "Sending email to %s. Subject: <<<%s>>>. Body: %s".formatted(to, subject, body));
logger.info("JC Sending notifications 6.4 body : " + body);

logger.info(() -> "Sending email to %s. Subject: <<<%s>>>. Body: %s".formatted(to, subject, body));
try {
// Since JavaMail 1.6, we have support for UTF-8 mail addresses and do not need to handle these ourselves.
InternetAddress[] recipients = InternetAddress.parse(to);

logger.info("JC Sending notifications 6.4 from address : " + systemAddress.getAddress().toString());
MimeMessage msg = new MimeMessage(session);
msg.setFrom(systemAddress);
msg.setSentDate(new Date());
Expand All @@ -141,13 +145,15 @@ public boolean sendSystemEmail(String to, String subject, String messageText, bo
} else {
msg.setText(body, charset);
}

logger.info("JC Sending notifications 6.5 tansport send - start : " );
Transport.send(msg, recipients);
logger.info("JC Sending notifications 6.5 tansport send - end : " );
return true;
} catch (MessagingException ae) {
logger.log(Level.WARNING, "Failed to send mail to %s: %s".formatted(to, ae.getMessage()), ae);
logger.info("When UTF-8 characters in recipients: make sure MTA supports it and JVM option " + JvmSettings.MAIL_MTA_SUPPORT_UTF8.getScopedKey() + "=true");
}
logger.info("JC Sending notifications 6.5 tansport send - failed : " );
return false;
}

Expand Down Expand Up @@ -278,14 +284,16 @@ public Boolean sendNotificationEmail(UserNotification notification, String comme
}

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

logger.info("JC Sending notifications 6.1: ");
boolean retval = false;
String emailAddress = getUserEmailAddress(notification);
if (emailAddress != null){
Object objectOfNotification = getObjectOfNotification(notification);
if (objectOfNotification != null){
String messageText = getMessageTextBasedOnNotification(notification, objectOfNotification, comment, requestor);
logger.info("JC Sending notifications 6.2: " + messageText);
String subjectText = MailUtil.getSubjectTextBasedOnNotification(notification, objectOfNotification);
logger.info("JC Sending notifications 6.3: " + subjectText);
if (!(messageText.isEmpty() || subjectText.isEmpty())){
retval = sendSystemEmail(emailAddress, subjectText, messageText, isHtmlContent);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public void delete(UserNotification userNotification) {

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void sendNotificationInNewTransaction(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId) {
logger.info("JC Sending notifications 2: ");
sendNotification(dataverseUser, sendDate, type, objectId, "");
}

Expand All @@ -102,6 +103,7 @@ public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate
}

public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId, String comment) {
logger.info("JC Sending notifications 3: ");
sendNotification(dataverseUser, sendDate, type, objectId, comment, null, false);
}

Expand All @@ -110,24 +112,30 @@ public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate
}

public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId, String comment, AuthenticatedUser requestor, boolean isHtmlContent) {
logger.info("JC Sending notifications 4: ");
sendNotification(dataverseUser, sendDate, type, objectId, comment, requestor, isHtmlContent, null);
}
public void sendNotification(AuthenticatedUser dataverseUser, Timestamp sendDate, Type type, Long objectId, String comment, AuthenticatedUser requestor, boolean isHtmlContent, String additionalInfo) {
logger.info("JC Sending notifications 5: ");
UserNotification userNotification = new UserNotification();
userNotification.setUser(dataverseUser);
userNotification.setSendDate(sendDate);
userNotification.setType(type);
userNotification.setObjectId(objectId);
userNotification.setRequestor(requestor);
userNotification.setAdditionalInfo(additionalInfo);
logger.info("JC Sending notifications 6: ");

if (!isEmailMuted(userNotification) && mailService.sendNotificationEmail(userNotification, comment, requestor, isHtmlContent)) {
logger.info("JC Sending notifications 7: ");
logger.fine("email was sent");
userNotification.setEmailed(true);
} else {
logger.info("JC Sending notifications 8: ");
logger.fine("email was not sent");
}
if (!isNotificationMuted(userNotification)) {
logger.info("JC Sending notifications 9: ");
save(userNotification);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public FinalizeDatasetPublicationCommand(Dataset aDataset, DataverseRequest aReq
@Override
public Dataset execute(CommandContext ctxt) throws CommandException {
Dataset theDataset = getDataset();


// JC 1
logger.info("Finalizing publication of the dataset "+theDataset.getGlobalId().asString());

// validate the physical files before we do anything else:
Expand Down Expand Up @@ -244,7 +245,7 @@ public Dataset execute(CommandContext ctxt) throws CommandException {
if (readyDataset.isLockedFor(DatasetLock.Reason.InReview) ) {
ctxt.datasets().removeDatasetLocks(readyDataset, DatasetLock.Reason.InReview);
}

//JC 2
logger.info("Successfully published the dataset "+readyDataset.getGlobalId().asString());
readyDataset = ctxt.em().merge(readyDataset);

Expand Down Expand Up @@ -495,6 +496,8 @@ private void notifyUsersDatasetPublishStatus(CommandContext ctxt, DvObject subje
}
}
*/

logger.info("JC Sending notifications : 1 ");
ctxt.roles().rolesAssignments(subject).stream()
.filter( ra -> ra.getRole().permissions().contains(Permission.ViewUnpublishedDataset) || ra.getRole().permissions().contains(Permission.DownloadFile))
.flatMap( ra -> ctxt.roleAssignees().getExplicitUsers(ctxt.roleAssignees().getRoleAssignee(ra.getAssigneeIdentifier())).stream() )
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/dataset.xhtml
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@
<!-- Publish BTN DROPDOWN-MENU OPTIONS -->
<ul class="dropdown-menu pull-right text-left">
<li jsf:rendered="#{showPublishLink}" class="#{!DatasetPage.hasValidTermsOfAccess or ( DatasetPage.locked and !DatasetPage.dataset.latestVersion.inReview) ? 'disabled' : ''}">
<!-- Publish LINK -->
<!-- JC Publish LINK -->
<p:commandLink styleClass="#{!DatasetPage.hasValidTermsOfAccess or (DatasetPage.locked and !DatasetPage.dataset.latestVersion.inReview) ? 'disabled' : ''}"
disabled="#{!DatasetPage.hasValidTermsOfAccess or (DatasetPage.locked and !DatasetPage.dataset.latestVersion.inReview)}"
action="#{DatasetPage.processPublishButton()}">
Expand Down

0 comments on commit 67a2787

Please sign in to comment.