diff --git a/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java b/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java index 5cd6813a7c1d871deeb6b95645a1c3a8c631a040..4db76cab6e04a70441b592c2d5a6754c187bb033 100644 --- a/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java +++ b/src/main/java/org/nrg/xapi/rest/notifications/NotificationsApi.java @@ -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"; diff --git a/src/main/java/org/nrg/xnat/event/listeners/AutoRunEmailHandler.java b/src/main/java/org/nrg/xnat/event/listeners/AutoRunEmailHandler.java index d853c63aee711bc7f7db12da812fa565dc8cf13d..838f5a495360a89161983cfb674a300f59a02ec1 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/AutoRunEmailHandler.java +++ b/src/main/java/org/nrg/xnat/event/listeners/AutoRunEmailHandler.java @@ -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; } diff --git a/src/main/java/org/nrg/xnat/event/listeners/DicomToNiftiEmailHandler.java b/src/main/java/org/nrg/xnat/event/listeners/DicomToNiftiEmailHandler.java index 1e9de916a099572dfc4c38d2e0b1af9969576ff0..ed5dbdee71a0dd568c6e00884b08ebfa8e00a85a 100644 --- a/src/main/java/org/nrg/xnat/event/listeners/DicomToNiftiEmailHandler.java +++ b/src/main/java/org/nrg/xnat/event/listeners/DicomToNiftiEmailHandler.java @@ -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)) { diff --git a/src/main/java/org/nrg/xnat/turbine/modules/actions/PipelineActions.java b/src/main/java/org/nrg/xnat/turbine/modules/actions/PipelineActions.java index 3898a4d2a015cbdbd9a5a065d9da12b76b55e084..e417d4cbf8b82ae183c481a05296bb9a252007c9 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/actions/PipelineActions.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/actions/PipelineActions.java @@ -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"); } } diff --git a/src/main/java/org/nrg/xnat/turbine/modules/actions/QDECAction.java b/src/main/java/org/nrg/xnat/turbine/modules/actions/QDECAction.java index f24a55688bddc56b0aa568fb840e464c4c8de72a..7a94dbf24df46eea7ee32e6d0f6271f49a6ae1cd 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/actions/QDECAction.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/actions/QDECAction.java @@ -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"); } } diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/BuildPipelineParameters.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/BuildPipelineParameters.java index 709dd0bb80be4d4597947e4952251f33d857ca4b..3545025970211ad5f25c5f123dd9d0f657812ae9 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/BuildPipelineParameters.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/BuildPipelineParameters.java @@ -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"); diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen.java index 73ecbe0b7c4df1f27f4ce8a09b835b715f62835f..d99ec235e545802ac3f2885a7906400f4a11cb8f 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen.java @@ -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; } diff --git a/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen_set_site_parameters.java b/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen_set_site_parameters.java index d53b11b3be94338bf511d9c202e74377c72fb6ca..681cbd404891eebab4afacecde2657fef5c45ae9 100644 --- a/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen_set_site_parameters.java +++ b/src/main/java/org/nrg/xnat/turbine/modules/screens/PipelineScreen_set_site_parameters.java @@ -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"); } } diff --git a/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml b/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml index ee225a43b4003ec4f69ffb1a2e134ae19e8ac572..a1b3272f1d6e5d2bff6efba3475db91e296485f8 100644 --- a/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml +++ b/src/main/resources/META-INF/xnat/spawner/site-admin-elements.yaml @@ -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: diff --git a/src/main/webapp/xdat-templates/screens/email/WelcomeNewUser.vm b/src/main/webapp/xdat-templates/screens/email/WelcomeNewUser.vm index 8bdae25d894962eb298cf8eeb37d60cfed0f3073..d019bfab692ac8b471feb2890929e1c1490f348f 100644 --- a/src/main/webapp/xdat-templates/screens/email/WelcomeNewUser.vm +++ b/src/main/webapp/xdat-templates/screens/email/WelcomeNewUser.vm @@ -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 diff --git a/src/main/webapp/xnat-templates/screens/PipelineEmail_failure.vm b/src/main/webapp/xnat-templates/screens/PipelineEmail_failure.vm index 04cd5cea9c7065113cd5558ebc78ca97a0e1c7ab..7119c4a2f8675ae948a8fb8fb883beb1630d0f71 100644 --- a/src/main/webapp/xnat-templates/screens/PipelineEmail_failure.vm +++ b/src/main/webapp/xnat-templates/screens/PipelineEmail_failure.vm @@ -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())