Skip to content
Snippets Groups Projects
Commit 8455af57 authored by Mike McKay's avatar Mike McKay
Browse files

Made help email be used by site. Got recipient lists to save and take effect.

parent 9577dce7
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 73 deletions
......@@ -4,18 +4,10 @@ import io.swagger.annotations.*;
import org.apache.commons.lang3.StringUtils;
import org.nrg.framework.annotations.XapiRestController;
import org.nrg.framework.exceptions.NrgServiceError;
import org.nrg.framework.exceptions.NrgServiceException;
import org.nrg.framework.exceptions.NrgServiceRuntimeException;
import org.nrg.mail.api.NotificationType;
import org.nrg.notify.api.CategoryScope;
import org.nrg.notify.api.SubscriberType;
import org.nrg.notify.entities.*;
import org.nrg.notify.exceptions.DuplicateDefinitionException;
import org.nrg.notify.exceptions.DuplicateSubscriberException;
import org.nrg.notify.services.NotificationService;
import org.nrg.prefs.exceptions.InvalidPreferenceName;
import org.nrg.xapi.exceptions.InitializationException;
import org.nrg.xdat.XDAT;
import org.nrg.xdat.preferences.NotificationsPreferences;
import org.nrg.xdat.rest.AbstractXnatRestApi;
import org.nrg.xnat.services.XnatAppInfo;
......@@ -38,6 +30,7 @@ import java.util.*;
@XapiRestController
@RequestMapping(value = "/notifications")
public class NotificationsApi extends AbstractXnatRestApi {
public static final String POST_PROPERTIES_NOTES = "Sets the mail service host, port, username, password, and protocol. You can set "
+ "extra properties on the mail sender (e.g. for configuring SSL or TLS transport) by "
+ "specifying the property name and value. Any parameters submitted that are not one "
......@@ -96,7 +89,21 @@ public class NotificationsApi extends AbstractXnatRestApi {
for (final String name : properties.keySet()) {
try {
_notificationsPrefs.set(properties.get(name), name);
if(StringUtils.equals(name, "notifications.emailRecipientErrorMessages")){
_notificationsPrefs.setEmailRecipientErrorMessages(properties.get(name));
}
else if(StringUtils.equals(name, "notifications.emailRecipientIssueReports")){
_notificationsPrefs.setEmailRecipientIssueReports(properties.get(name));
}
else if(StringUtils.equals(name, "notifications.emailRecipientNewUserAlert")){
_notificationsPrefs.setEmailRecipientNewUserAlert(properties.get(name));
}
else if(StringUtils.equals(name, "notifications.emailRecipientUpdate")){
_notificationsPrefs.setEmailRecipientUpdate(properties.get(name));
}
else {
_notificationsPrefs.set(properties.get(name), name);
}
if (_log.isInfoEnabled()) {
_log.info("Set property {} to value: {}", name, properties.get(name));
}
......@@ -519,7 +526,6 @@ public class NotificationsApi extends AbstractXnatRestApi {
@ApiResponses({@ApiResponse(code = 200, message = "Error subscribers successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the error subscribers."), @ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(value = {"subscribers/error"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST})
public ResponseEntity<Void> setErrorSubscribers(@ApiParam(value = "The values to set for email addresses for error notifications.", required = true) @RequestParam final String subscribers) {
setSubscribersForNotificationType(NotificationType.Error, subscribers);
_notificationsPrefs.setEmailRecipientErrorMessages(subscribers);
return new ResponseEntity<>(HttpStatus.OK);
}
......@@ -528,7 +534,6 @@ public class NotificationsApi extends AbstractXnatRestApi {
@ApiResponses({@ApiResponse(code = 200, message = "Issue subscribers successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the issue subscribers."), @ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(value = {"subscribers/issue"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST})
public ResponseEntity<Properties> setIssueSubscribers(@ApiParam(value = "The values to set for email addresses for issue notifications.", required = true) @RequestParam final String subscribers) {
setSubscribersForNotificationType(NotificationType.Issue, subscribers);
_notificationsPrefs.setEmailRecipientIssueReports(subscribers);
return new ResponseEntity<>(HttpStatus.OK);
}
......@@ -537,7 +542,6 @@ public class NotificationsApi extends AbstractXnatRestApi {
@ApiResponses({@ApiResponse(code = 200, message = "New user subscribers successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the new user subscribers."), @ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(value = {"subscribers/newuser"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST})
public ResponseEntity<Properties> setNewUserSubscribers(@ApiParam(value = "The values to set for email addresses for new user notifications.", required = true) @RequestParam final String subscribers) {
setSubscribersForNotificationType(NotificationType.NewUser, subscribers);
_notificationsPrefs.setEmailRecipientNewUserAlert(subscribers);
return new ResponseEntity<>(HttpStatus.OK);
}
......@@ -546,7 +550,6 @@ public class NotificationsApi extends AbstractXnatRestApi {
@ApiResponses({@ApiResponse(code = 200, message = "Update subscribers successfully set."), @ApiResponse(code = 401, message = "Must be authenticated to access the XNAT REST API."), @ApiResponse(code = 403, message = "Not authorized to set the update subscribers."), @ApiResponse(code = 500, message = "Unexpected error")})
@RequestMapping(value = {"subscribers/update"}, produces = {MediaType.APPLICATION_JSON_VALUE}, method = {RequestMethod.POST})
public ResponseEntity<Properties> setUpdateSubscribers(@ApiParam(value = "The values to set for email addresses for update notifications.", required = true) @RequestParam final String subscribers) {
setSubscribersForNotificationType(NotificationType.Update, subscribers);
_notificationsPrefs.setEmailRecipientUpdate(subscribers);
return new ResponseEntity<>(HttpStatus.OK);
}
......@@ -679,54 +682,6 @@ public class NotificationsApi extends AbstractXnatRestApi {
}
}
private void setSubscribersForNotificationType(NotificationType notificationType, final String subscribersString){
List<String> subscribers = Arrays.asList(subscribersString.split("\\s*,\\s*"));
Category category = _notificationService.getCategoryService().getCategoryByScopeAndEvent(CategoryScope.Site, notificationType.id());
if(category==null) {
category = _notificationService.getCategoryService().newEntity();
category.setScope(CategoryScope.Site);
category.setEvent(notificationType.id());
XDAT.getNotificationService().getCategoryService().create(category);
}
for(String subscriber : subscribers){
try {
Subscriber subscriberObject = _notificationService.getSubscriberService().getSubscriberByName(subscriber);
if(subscriberObject==null){
subscriberObject = _notificationService.getSubscriberService().createSubscriber(subscriber, subscriber);
XDAT.getNotificationService().getSubscriberService().create(subscriberObject);
}
Definition definition1 = _notificationService.getDefinitionService().getDefinitionForCategoryAndEntity(category,1L);
if(definition1==null) {
definition1 = _notificationService.createDefinition(CategoryScope.Site, notificationType.id(), 1L);
XDAT.getNotificationService().getDefinitionService().create(definition1);
}
Channel channel1 = _notificationService.getChannelService().getChannel("htmlMail");
if(channel1==null) {
_notificationService.getChannelService().createChannel("htmlMail", "text/html");
}
Map<Subscriber, Subscription> subscriberMapOfSubscriptions = _notificationService.getSubscriptionService().getSubscriberMapOfSubscriptionsForDefinition(definition1);
for (Map.Entry<Subscriber, Subscription> entry : subscriberMapOfSubscriptions.entrySet()) {
//Remove all existing subscriptions that match this definition since we are replacing the old list with the new one.
Subscriber tempSubscriber = entry.getKey();
Subscription tempSubscription = entry.getValue();
tempSubscriber.removeSubscription(tempSubscription);
}
Subscription subscription = _notificationService.subscribe(subscriberObject, SubscriberType.User, definition1, channel1);
} catch (DuplicateSubscriberException e) {
_log.error("You tried to subscribe someone who was already subscribed",e);
} catch (DuplicateDefinitionException e) {
_log.error("Multiple definitions for this scope, event, and entity exist.",e);
} catch (NrgServiceException e) {
_log.error("Error setting email addresses for error notifications.",e);
}
}
}
private static final Logger _log = LoggerFactory.getLogger(NotificationsApi.class);
private static final String NOT_SET = "NotSet";
......
......@@ -2,6 +2,7 @@ package org.nrg.xnat.event.listeners;
import com.google.common.collect.Maps;
import org.nrg.xdat.XDAT;
import reactor.bus.Event;
import reactor.bus.EventBus;
import reactor.fn.Consumer;
......@@ -58,6 +59,7 @@ public class AutoRunEmailHandler extends PipelineEmailHandlerAbst implements Con
public void handleEvent(WorkflowStatusEvent e) {
Map<String,Object> params = Maps.newHashMap();
params.put("pipelineName",PIPELINE_NAME_PRETTY);
params.put("contactEmail", XDAT.getNotificationsPreferences().getHelpContactInfo());
if (!(e.getWorkflow() instanceof WrkWorkflowdata)) {
return;
}
......
......@@ -2,6 +2,7 @@ package org.nrg.xnat.event.listeners;
import com.google.common.collect.Maps;
import org.nrg.xdat.XDAT;
import reactor.bus.Event;
import reactor.bus.EventBus;
import reactor.fn.Consumer;
......@@ -66,6 +67,7 @@ public class DicomToNiftiEmailHandler extends PipelineEmailHandlerAbst implement
WrkWorkflowdata wrk = (WrkWorkflowdata)e.getWorkflow();
Map<String,Object> params = Maps.newHashMap();
params.put("pipelineName",PIPELINE_NAME_PRETTY);
params.put("contactEmail", XDAT.getNotificationsPreferences().getHelpContactInfo());
if (completed(e)) {
standardPipelineEmailImpl(e, wrk, PIPELINE_NAME, DEFAULT_TEMPLATE_SUCCESS, DEFAULT_SUBJECT_SUCCESS, "processed.lst", params);
} else if (failed(e)) {
......
......@@ -186,7 +186,7 @@ public class PipelineActions extends SecureAction{
}
} catch (Exception e){
logger.error("",e);
data.setMessage("<p><img src=\"/fcon/images/error.gif\">The build process failed to launch. Please contact the <a href=\"mailto:" + XDAT.getSiteConfigPreferences().getAdminEmail() + "?subject=Failed to launch build \">NRG techdesk</a>");
data.setMessage("<p><img src=\"/fcon/images/error.gif\">The build process failed to launch. Please contact the <a href=\"mailto:" + XDAT.getNotificationsPreferences().getHelpContactInfo() + "?subject=Failed to launch build \">NRG techdesk</a>");
data.setScreenTemplate("Error.vm");
}
}
......
......@@ -123,7 +123,7 @@ public class QDECAction extends ListingAction{
data.setMessage( "<p><b>Your QDEC analysis was successfully launched. Status email will be sent to you upon its completion.</b></p>");
data.setScreenTemplate("ClosePage.vm");
}catch(Exception e) {
data.setMessage("<p><b>The QDEC Analysis process could not be launched. Please contact <A HREF=\"mailto:"+XDAT.getSiteConfigPreferences().getAdminEmail()+"?subject=Error: Performing QDEC Group Analysis" + "\">Report Error to" +TurbineUtils.GetSystemName() + " Techdesk</A></b></p>");
data.setMessage("<p><b>The QDEC Analysis process could not be launched. Please contact <A HREF=\"mailto:"+XDAT.getNotificationsPreferences().getHelpContactInfo()+"?subject=Error: Performing QDEC Group Analysis" + "\">Report Error to" +TurbineUtils.GetSystemName() + " Techdesk</A></b></p>");
data.setScreenTemplate("Error.vm");
}
}
......
......@@ -54,7 +54,7 @@ public class BuildPipelineParameters extends SecureReport {
return;
}catch(Exception e) {
String errorString = "<img src=\"/cnda1/images/error.gif\"> Error in the Build Spec file document for the pipeline " + context.get("pipelineName") ;
errorString += "<p>Please contact the <a href=\"mailto:"+XDAT.getSiteConfigPreferences().getAdminEmail()+"?subject=Error in Build Spec file for " + mr.getSessionType() + " pipeline " + pipelineName + "\">CNL techdesk</a> to resolve the error.</p>";
errorString += "<p>Please contact the <a href=\"mailto:"+XDAT.getNotificationsPreferences().getHelpContactInfo()+"?subject=Error in Build Spec file for " + mr.getSessionType() + " pipeline " + pipelineName + "\">CNL techdesk</a> to resolve the error.</p>";
data.setMessage(errorString);
data.getParameters().add("exception",e.getMessage());
data.setScreenTemplate("Error.vm");
......
......@@ -253,7 +253,7 @@ public abstract class PipelineScreen extends SecureReport {
}
}
if (rtn == null) {
message = "Pipeline with step id " + pipeline_step + " is not defined. Please contact your site administrator <a href=\"mailto:" + XDAT.getSiteConfigPreferences().getAdminEmail() + "?subject=Invalid Pipeline Step " + pipeline_step + " for " + item.getXSIType() + "\">Report problem</A>";
message = "Pipeline with step id " + pipeline_step + " is not defined. Please contact your site administrator <a href=\"mailto:" + XDAT.getNotificationsPreferences().getHelpContactInfo() + "?subject=Invalid Pipeline Step " + pipeline_step + " for " + item.getXSIType() + "\">Report problem</A>";
}
return rtn;
}
......
......@@ -81,14 +81,14 @@ public class PipelineScreen_set_site_parameters extends AdminEditScreenA{
data.setMessage("The pipeline has been added to the repository");
data.setScreenTemplate("ClosePage.vm");
} catch (Exception e) {
data.setMessage("The pipeline could not be added to the repository. Please contact " + XDAT.getSiteConfigPreferences().getAdminEmail() );
data.setMessage("The pipeline could not be added to the repository. Please contact " + XDAT.getNotificationsPreferences().getHelpContactInfo() );
data.setScreenTemplate("Error.vm");
}
}
}catch(Exception e) {
logger.error(e);
e.printStackTrace();
data.setMessage("The pipeline could not be added to the repository. Please contact " + XDAT.getSiteConfigPreferences().getAdminEmail());
data.setMessage("The pipeline could not be added to the repository. Please contact " + XDAT.getNotificationsPreferences().getHelpContactInfo());
data.setScreenTemplate("Error.vm");
}
}
......
......@@ -620,28 +620,28 @@ notifications:
id: emailRecipientErrorMessages
name: notifications.emailRecipientErrorMessages
label: "Error Messages"
description: "What email address should receive error emails"
description: "What email address(es) should receive error emails. Separate multiple email addresses with commas. If empty, emails will be sent to the site administrator email address."
value: "!? XNAT.data.notifications['notifications.emailRecipientErrorMessages'] || XNAT.data.siteConfig.adminEmail"
emailRecipientIssueReports:
kind: panel.input.email
id: emailRecipientIssueReports
name: notifications.emailRecipientIssueReports
label: "Issue Reports"
description: "What email address should receive issue reports"
description: "What email address(es) should receive issue reports. Separate multiple email addresses with commas. If empty, emails will be sent to the site administrator email address."
value: "!? XNAT.data.notifications['notifications.emailRecipientIssueReports'] || XNAT.data.siteConfig.adminEmail"
emailRecipientNewUserAlert:
kind: panel.input.email
id: emailRecipientNewUserAlert
name: notifications.emailRecipientNewUserAlert
label: "New User Alert"
description: "What email address should receive New User Registration emails"
description: "What email address(es) should receive New User Registration emails. Separate multiple email addresses with commas. If empty, emails will be sent to the site administrator email address."
value: "!? XNAT.data.notifications['notifications.emailRecipientNewUserAlert'] || XNAT.data.siteConfig.adminEmail"
emailRecipientUpdate:
kind: panel.input.email
id: emailRecipientUpdate
name: notifications.emailRecipientUpdate
label: "Updates"
description: "What email address should receive update emails"
description: "What email address(es) should receive update emails. Separate multiple email addresses with commas. If empty, emails will be sent to the site administrator email address."
value: "!? XNAT.data.notifications['notifications.emailRecipientUpdate'] || XNAT.data.siteConfig.adminEmail"
otherSubhead:
......
......@@ -2,4 +2,4 @@ Welcome to the $system Web Archive!
<br><br>You can now log on to the $system at:
<a href="$server">$server</a>
<br><br>Your username is: $username<br>
<br><br>For support, contact the <a href="mailto:$admin_email?subject=$system Assistance">$system Management </A>
\ No newline at end of file
<br><br>For support, contact the <a href="mailto:$contactEmail?subject=$system Assistance">$system Management </A>
\ No newline at end of file
......@@ -10,7 +10,7 @@
<p>
The $system technical team is aware of the issue and will notify you when it has been resolved.
<br/>
We appreciate your patience. Please contact <a href="$admin_email">$admin_email</a> with questions or concerns.
We appreciate your patience. Please contact <a href="$contactEmail">$contactEmail</a> with questions or concerns.
</p>
#if (!$attachments.isEmpty())
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment