Skip to content
This repository was archived by the owner on May 5, 2021. It is now read-only.

Commit e05849a

Browse files
SORMAS-Foundation#3211: Add feature configuration for email/SMS notifications
1 parent 1000d53 commit e05849a

13 files changed

Lines changed: 74 additions & 61 deletions

File tree

sormas-api/src/main/java/de/symeda/sormas/api/feature/FeatureType.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ public enum FeatureType {
3333
CASE_SURVEILANCE,
3434
CONTACT_TRACING }),
3535
INFRASTRUCTURE_TYPE_AREA(true, false, null),
36-
CASE_FOLLOWUP(true, false, null);
36+
CASE_FOLLOWUP(true, false, null),
37+
TASK_NOTIFICATIONS(true, true, null),
38+
OTHER_NOTIFICATIONS(true, true, null);
3739

3840
/**
3941
* Server feature means that the feature only needs to be configured once per server since they define the way the system

sormas-api/src/main/java/de/symeda/sormas/api/i18n/Strings.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,37 +686,27 @@ public interface Strings {
686686
String none = "none";
687687
String notAnswered = "notAnswered";
688688
String notificationCaseClassificationChanged = "notificationCaseClassificationChanged";
689-
String notificationCaseClassificationChangedSubject = "notificationCaseClassificationChangedSubject";
690689
String notificationCaseInvestigationDone = "notificationCaseInvestigationDone";
691-
String notificationCaseInvestigationDoneSubject = "notificationCaseInvestigationDoneSubject";
692690
String notificationContactSymptomatic = "notificationContactSymptomatic";
693-
String notificationContactSymptomaticSubject = "notificationContactSymptomaticSubject";
694691
String notificationContactWithoutCaseSymptomatic = "notificationContactWithoutCaseSymptomatic";
695692
String notificationDiseaseChanged = "notificationDiseaseChanged";
696-
String notificationDiseaseChangedSubject = "notificationDiseaseChangedSubject";
697693
String notificationLabResultArrived = "notificationLabResultArrived";
698694
String notificationLabResultArrivedContact = "notificationLabResultArrivedContact";
699695
String notificationLabResultArrivedEventParticipant = "notificationLabResultArrivedEventParticipant";
700696
String notificationLabResultArrivedEventParticipantNoDisease = "notificationLabResultArrivedEventParticipantNoDisease";
701-
String notificationLabResultArrivedSubject = "notificationLabResultArrivedSubject";
702697
String notificationLabResultSpecified = "notificationLabResultSpecified";
703698
String notificationLabResultSpecifiedContact = "notificationLabResultSpecifiedContact";
704699
String notificationLabResultSpecifiedEventParticipant = "notificationLabResultSpecifiedEventParticipant";
705700
String notificationLabResultSpecifiedEventParticipantNoDisease = "notificationLabResultSpecifiedEventParticipantNoDisease";
706-
String notificationLabResultSpecifiedSubject = "notificationLabResultSpecifiedSubject";
707701
String notificationLabSampleShipped = "notificationLabSampleShipped";
708702
String notificationLabSampleShippedShort = "notificationLabSampleShippedShort";
709703
String notificationLabSampleShippedShortForContact = "notificationLabSampleShippedShortForContact";
710704
String notificationLabSampleShippedShortForEventParticipant = "notificationLabSampleShippedShortForEventParticipant";
711-
String notificationLabSampleShippedSubject = "notificationLabSampleShippedSubject";
712705
String notificationTaskDueGeneral = "notificationTaskDueGeneral";
713706
String notificationTaskDueSpecific = "notificationTaskDueSpecific";
714-
String notificationTaskDueSubject = "notificationTaskDueSubject";
715707
String notificationTaskStartGeneral = "notificationTaskStartGeneral";
716708
String notificationTaskStartSpecific = "notificationTaskStartSpecific";
717-
String notificationTaskStartSubject = "notificationTaskStartSubject";
718709
String notificationVisitCompleted = "notificationVisitCompleted";
719-
String notificationVisitCompletedSubject = "notificationVisitCompletedSubject";
720710
String notSpecified = "notSpecified";
721711
String number = "number";
722712
String numberEight = "numberEight";
299 Bytes
Binary file not shown.
20 Bytes
Binary file not shown.

sormas-api/src/main/resources/enum.properties

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,20 @@ MapPeriodType.DAILY = Daily
548548
MapPeriodType.WEEKLY = Weekly
549549
MapPeriodType.MONTHLY = Monthly
550550
MapPeriodType.YEARLY = Yearly
551-
551+
552+
# MessageSubject
553+
MessageSubject.CASE_CLASSIFICATION_CHANGED = Case classification changed
554+
MessageSubject.CASE_INVESTIGATION_DONE = Case investigation done
555+
MessageSubject.LAB_RESULT_ARRIVED = Lab result arrived
556+
MessageSubject.LAB_RESULT_SPECIFIED = Lab result specified
557+
MessageSubject.LAB_SAMPLE_SHIPPED = Lab sample shipped
558+
MessageSubject.CONTACT_SYMPTOMATIC = Contact has become symptomatic
559+
MessageSubject.TASK_START = Task to be started
560+
MessageSubject.TASK_DUE = Task overdue
561+
MessageSubject.VISIT_COMPLETED = Follow-up visit completed
562+
MessageSubject.DISEASE_CHANGED = Case disease changed
563+
564+
552565
# Month
553566
Month.JANUARY = January
554567
Month.FEBRUARY = February

sormas-api/src/main/resources/strings.properties

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -722,37 +722,27 @@ messageAllCampaignFormsValid = All campaign forms have been successfully validat
722722

723723
# Notifications
724724
notificationCaseClassificationChanged = The classification of case %s has changed to %s.
725-
notificationCaseClassificationChangedSubject = Case classification changed
726725
notificationCaseInvestigationDone = The investigation of case %s has been done.
727-
notificationCaseInvestigationDoneSubject = Case investigation done
728726
notificationContactSymptomatic = The contact %s of case %s has become symptomatic.
729727
notificationContactWithoutCaseSymptomatic = The contact %s has become symptomatic.
730-
notificationContactSymptomaticSubject = Contact has become symptomatic
731728
notificationDiseaseChanged = The disease of case %s has changed from %s to %s. Please review all related cases and see if their diseases need to be changed as well.
732-
notificationDiseaseChangedSubject = Case disease changed
733729
notificationLabResultArrived = %s pathogen test result has arrived for %s case %s. Test type: %s. Tested disease: %s.
734730
notificationLabResultArrivedContact = %s pathogen test result has arrived for %s contact %s. Test type: %s. Tested disease: %s.
735731
notificationLabResultArrivedEventParticipant = %s pathogen test result has arrived for %s event participant %s. Test type: %s. Tested disease: %s.
736732
notificationLabResultArrivedEventParticipantNoDisease = %s pathogen test result has arrived for %s event participant %s. Test type: %s.
737-
notificationLabResultArrivedSubject = Lab result arrived
738733
notificationLabResultSpecified = A pathogen test result for %s case %s has been specified to %s. Test type: %s. Tested disease: %s.
739734
notificationLabResultSpecifiedContact = A pathogen test result for %s contact %s has been specified to %s. Test type: %s. Tested disease: %s.
740735
notificationLabResultSpecifiedEventParticipant = A pathogen test result for %s event participant %s has been specified to %s. Test type: %s. Tested disease: %s.
741736
notificationLabResultSpecifiedEventParticipantNoDisease = A pathogen test result for %s event participant %s has been specified to %s. Test type: %s.
742-
notificationLabResultSpecifiedSubject = Lab result specified
743737
notificationLabSampleShipped = A new sample (sample code: %s) for case %s is being shipped to your laboratory.
744738
notificationLabSampleShippedShort = A new sample for case %s is being shipped to your laboratory.
745739
notificationLabSampleShippedShortForContact = A new sample for contact %s is being shipped to your laboratory.
746740
notificationLabSampleShippedShortForEventParticipant = A new sample for event participant %s is being shipped to your laboratory.
747-
notificationLabSampleShippedSubject = Lab sample shipped
748741
notificationTaskDueGeneral = Your %s task is overdue.
749742
notificationTaskDueSpecific = Your %s task for %s is overdue.
750-
notificationTaskDueSubject = Task overdue
751743
notificationTaskStartGeneral = Your %s task should be started today.
752744
notificationTaskStartSpecific = Your %s task for %s should be started today.
753-
notificationTaskStartSubject = Task to be started
754745
notificationVisitCompleted = A follow-up visit for contact %s assigned to user %s has been completed.
755-
notificationVisitCompletedSubject = Follow-up visit completed
756746

757747
#Labels
758748
labelNumberOfUsers = No. of users

sormas-backend/src/main/java/de/symeda/sormas/backend/caze/CaseFacadeEjb.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175
import de.symeda.sormas.backend.common.AbstractAdoService;
176176
import de.symeda.sormas.backend.common.AbstractDomainObject;
177177
import de.symeda.sormas.backend.common.ConfigFacadeEjb.ConfigFacadeEjbLocal;
178+
import de.symeda.sormas.backend.common.MessageSubject;
178179
import de.symeda.sormas.backend.common.MessageType;
179180
import de.symeda.sormas.backend.common.MessagingService;
180181
import de.symeda.sormas.backend.common.NotificationDeliveryFailedException;
@@ -1735,7 +1736,7 @@ public void onCaseChanged(CaseDataDto existingCase, Case newCase) {
17351736
try {
17361737
messagingService.sendMessage(
17371738
recipient,
1738-
I18nProperties.getString(MessagingService.SUBJECT_CASE_CLASSIFICATION_CHANGED),
1739+
MessageSubject.CASE_CLASSIFICATION_CHANGED,
17391740
String.format(
17401741
I18nProperties.getString(MessagingService.CONTENT_CASE_CLASSIFICATION_CHANGED),
17411742
DataHelper.getShortUuid(newCase.getUuid()),
@@ -1765,7 +1766,7 @@ public void onCaseChanged(CaseDataDto existingCase, Case newCase) {
17651766
try {
17661767
messagingService.sendMessage(
17671768
recipient,
1768-
I18nProperties.getString(MessagingService.SUBJECT_DISEASE_CHANGED),
1769+
MessageSubject.DISEASE_CHANGED,
17691770
String.format(
17701771
I18nProperties.getString(MessagingService.CONTENT_DISEASE_CHANGED),
17711772
DataHelper.getShortUuid(newCase.getUuid()),
@@ -2701,7 +2702,7 @@ private void sendInvestigationDoneNotifications(Case caze) {
27012702
try {
27022703
messagingService.sendMessage(
27032704
recipient,
2704-
I18nProperties.getString(MessagingService.SUBJECT_CASE_INVESTIGATION_DONE),
2705+
MessageSubject.CASE_INVESTIGATION_DONE,
27052706
String
27062707
.format(I18nProperties.getString(MessagingService.CONTENT_CASE_INVESTIGATION_DONE), DataHelper.getShortUuid(caze.getUuid())),
27072708
MessageType.EMAIL,
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package de.symeda.sormas.backend.common;
2+
3+
public enum MessageSubject {
4+
5+
CASE_CLASSIFICATION_CHANGED,
6+
CASE_INVESTIGATION_DONE,
7+
LAB_RESULT_ARRIVED,
8+
LAB_RESULT_SPECIFIED,
9+
LAB_SAMPLE_SHIPPED,
10+
CONTACT_SYMPTOMATIC,
11+
TASK_START,
12+
TASK_DUE,
13+
VISIT_COMPLETED,
14+
DISEASE_CHANGED;
15+
}

sormas-backend/src/main/java/de/symeda/sormas/backend/common/MessagingService.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929

3030
import com.nexmo.client.NexmoClientException;
3131

32+
import de.symeda.sormas.api.feature.FeatureType;
33+
import de.symeda.sormas.api.i18n.I18nProperties;
3234
import de.symeda.sormas.api.utils.DataHelper;
35+
import de.symeda.sormas.backend.feature.FeatureConfigurationFacadeEjb;
3336
import de.symeda.sormas.backend.user.User;
3437
import de.symeda.sormas.backend.user.UserService;
3538

@@ -42,18 +45,6 @@
4245
@LocalBean
4346
public class MessagingService {
4447

45-
// Message subjects
46-
public static final String SUBJECT_CASE_CLASSIFICATION_CHANGED = "notificationCaseClassificationChangedSubject";
47-
public static final String SUBJECT_CASE_INVESTIGATION_DONE = "notificationCaseInvestigationDoneSubject";
48-
public static final String SUBJECT_LAB_RESULT_ARRIVED = "notificationLabResultArrivedSubject";
49-
public static final String SUBJECT_LAB_RESULT_SPECIFIED = "notificationLabResultSpecifiedSubject";
50-
public static final String SUBJECT_LAB_SAMPLE_SHIPPED = "notificationLabSampleShippedSubject";
51-
public static final String SUBJECT_CONTACT_SYMPTOMATIC = "notificationContactSymptomaticSubject";
52-
public static final String SUBJECT_TASK_START = "notificationTaskStartSubject";
53-
public static final String SUBJECT_TASK_DUE = "notificationTtaskDueSubject";
54-
public static final String SUBJECT_VISIT_COMPLETED = "notificationVisitCompletedSubject";
55-
public static final String SUBJECT_DISEASE_CHANGED = "notificationDiseaseChangedSubject";
56-
5748
// Message contents (via properties file)
5849
public static final String CONTENT_CASE_CLASSIFICATION_CHANGED = "notificationCaseClassificationChanged";
5950
public static final String CONTENT_CASE_INVESTIGATION_DONE = "notificationCaseInvestigationDone";
@@ -86,18 +77,28 @@ public class MessagingService {
8677
private EmailService emailService;
8778
@EJB
8879
private SmsService smsService;
80+
@EJB
81+
private FeatureConfigurationFacadeEjb.FeatureConfigurationFacadeEjbLocal featureConfigurationFacade;
8982

9083
/**
9184
* Sends the message specified by the messageContent via mail and/or SMS, according to the messageTypes, to the specified recipient's
9285
* email address and/or phone number. Logs an error if the email address or phone number is not set.
9386
*/
94-
public void sendMessage(User recipient, String subject, String messageContent, MessageType... messageTypes)
87+
public void sendMessage(User recipient, MessageSubject subject, String messageContent, MessageType... messageTypes)
9588
throws NotificationDeliveryFailedException {
9689

9790
// Don't send notifications to users that initiated an action
9891
if (recipient.equals(userService.getCurrentUser())) {
9992
return;
10093
}
94+
// Don't send notifications if the feature is disabled for the current MessageSubject
95+
if ((MessageSubject.TASK_DUE.equals(subject) || MessageSubject.TASK_START.equals(subject))
96+
&& !featureConfigurationFacade.isFeatureEnabled(FeatureType.TASK_NOTIFICATIONS)
97+
|| !MessageSubject.TASK_DUE.equals(subject)
98+
&& !MessageSubject.TASK_START.equals(subject)
99+
&& !featureConfigurationFacade.isFeatureEnabled(FeatureType.OTHER_NOTIFICATIONS)) {
100+
return;
101+
}
101102

102103
String emailAddress = recipient.getUserEmail();
103104
String phoneNumber = recipient.getPhone();
@@ -110,9 +111,9 @@ public void sendMessage(User recipient, String subject, String messageContent, M
110111
} else {
111112
try {
112113
if (messageType == MessageType.EMAIL) {
113-
emailService.sendEmail(emailAddress, subject, messageContent);
114+
emailService.sendEmail(emailAddress, I18nProperties.getEnumCaption(subject), messageContent);
114115
} else if (messageType == MessageType.SMS) {
115-
smsService.sendSms(phoneNumber, subject, messageContent);
116+
smsService.sendSms(phoneNumber, I18nProperties.getEnumCaption(subject), messageContent);
116117
}
117118
} catch (MessagingException e) {
118119
throw new NotificationDeliveryFailedException("Email could not be sent due to an unexpected error.", MessageType.EMAIL, e);

sormas-backend/src/main/java/de/symeda/sormas/backend/sample/PathogenTestFacadeEjb.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
import de.symeda.sormas.api.utils.ValidationRuntimeException;
5454
import de.symeda.sormas.backend.caze.Case;
5555
import de.symeda.sormas.backend.caze.CaseFacadeEjb.CaseFacadeEjbLocal;
56+
import de.symeda.sormas.backend.common.MessageSubject;
5657
import de.symeda.sormas.backend.common.MessageType;
5758
import de.symeda.sormas.backend.common.MessagingService;
5859
import de.symeda.sormas.backend.common.NotificationDeliveryFailedException;
@@ -431,7 +432,7 @@ private void sendMessageOnPathogenTestChanged(
431432
try {
432433
messagingService.sendMessage(
433434
recipient,
434-
I18nProperties.getString(MessagingService.SUBJECT_LAB_RESULT_ARRIVED),
435+
MessageSubject.LAB_RESULT_ARRIVED,
435436
String.format(
436437
I18nProperties.getString(contentLabResultArrived),
437438
newPathogenTest.getTestResult().toString(),
@@ -456,7 +457,7 @@ private void sendMessageOnPathogenTestChanged(
456457
try {
457458
messagingService.sendMessage(
458459
recipient,
459-
I18nProperties.getString(MessagingService.SUBJECT_LAB_RESULT_SPECIFIED),
460+
MessageSubject.LAB_RESULT_SPECIFIED,
460461
String.format(
461462
I18nProperties.getString(contentLabResultSpecified),
462463
disease,

0 commit comments

Comments
 (0)