Skip to content

Commit 0d073f1

Browse files
author
Levente Gal
committed
#13193 Send a survey request email to a case person's email - don't allow send if the person has no national healyh id or phone number
1 parent 7b5ac33 commit 0d073f1

File tree

1 file changed

+44
-25
lines changed

1 file changed

+44
-25
lines changed

sormas-ui/src/main/java/de/symeda/sormas/ui/survey/SurveyDocumentController.java

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@
2626
import org.apache.commons.lang3.StringUtils;
2727
import org.slf4j.LoggerFactory;
2828

29+
import com.vaadin.icons.VaadinIcons;
2930
import com.vaadin.server.Page;
3031
import com.vaadin.server.Sizeable;
32+
import com.vaadin.shared.ui.ContentMode;
3133
import com.vaadin.shared.ui.MarginInfo;
3234
import com.vaadin.ui.Component;
3335
import com.vaadin.ui.Label;
@@ -56,6 +58,7 @@
5658
import de.symeda.sormas.ui.utils.CssStyles;
5759
import de.symeda.sormas.ui.utils.FieldHelper;
5860
import de.symeda.sormas.ui.utils.VaadinUiUtil;
61+
import de.symeda.sormas.ui.utils.components.MultilineLabel;
5962

6063
public class SurveyDocumentController {
6164

@@ -65,7 +68,8 @@ public void sendSurveyDocument(
6568
Disease disease,
6669
PersonDto person,
6770
Runnable callback) {
68-
SurveyDocumentOptionsForm form = new SurveyDocumentOptionsForm(disease, true, person);
71+
boolean attachmentAvailable = FacadeProvider.getExternalEmailFacade().isAttachmentAvailable(person.toReference());
72+
SurveyDocumentOptionsForm form = new SurveyDocumentOptionsForm(disease, true, person, attachmentAvailable);
6973
form.setWidth(600, Sizeable.Unit.PIXELS);
7074
SurveyDocumentOptionsDto options = new SurveyDocumentOptionsDto(rootEntityType, rootEntityReference);
7175
options.setRecipientEmail(person.getEmailAddress(true));
@@ -74,25 +78,29 @@ public void sendSurveyDocument(
7478
CommitDiscardWrapperComponent<SurveyDocumentOptionsForm> editView = new CommitDiscardWrapperComponent<>(form, form.getFieldGroup());
7579
editView.getCommitButton().setCaption(I18nProperties.getCaption(Captions.surveySend));
7680

77-
editView.addCommitListener(() -> {
78-
SurveyDocumentOptionsDto surveyOptions = form.getValue();
79-
try {
80-
FacadeProvider.getSurveyFacade().sendDocument(surveyOptions);
81-
callback.run();
82-
} catch (DocumentTemplateException | ValidationException e) {
83-
new Notification(
84-
String.format(I18nProperties.getString(Strings.errorDocumentGeneration), surveyOptions.getSurvey().getCaption()),
85-
e.getMessage(),
86-
Notification.Type.ERROR_MESSAGE,
87-
false).show(Page.getCurrent());
88-
} catch (AttachmentException | IOException | ExternalEmailException e) {
89-
new Notification(
90-
I18nProperties.getString(Strings.headingErrorSendingExternalEmail),
91-
e.getMessage(),
92-
Notification.Type.ERROR_MESSAGE,
93-
false).show(Page.getCurrent());
94-
}
95-
});
81+
if (attachmentAvailable) {
82+
editView.addCommitListener(() -> {
83+
SurveyDocumentOptionsDto surveyOptions = form.getValue();
84+
try {
85+
FacadeProvider.getSurveyFacade().sendDocument(surveyOptions);
86+
callback.run();
87+
} catch (DocumentTemplateException | ValidationException e) {
88+
new Notification(
89+
String.format(I18nProperties.getString(Strings.errorDocumentGeneration), surveyOptions.getSurvey().getCaption()),
90+
e.getMessage(),
91+
Notification.Type.ERROR_MESSAGE,
92+
false).show(Page.getCurrent());
93+
} catch (AttachmentException | IOException | ExternalEmailException e) {
94+
new Notification(
95+
I18nProperties.getString(Strings.headingErrorSendingExternalEmail),
96+
e.getMessage(),
97+
Notification.Type.ERROR_MESSAGE,
98+
false).show(Page.getCurrent());
99+
}
100+
});
101+
} else {
102+
editView.getCommitButton().setEnabled(false);
103+
}
96104
form.setSurveyErrorCallback(inError -> {
97105
editView.getCommitButton().setEnabled(!inError);
98106
});
@@ -101,7 +109,7 @@ public void sendSurveyDocument(
101109
}
102110

103111
public void generateSurveyDocument(RootEntityType rootEntityType, ReferenceDto rootEntityReference, Disease disease, Runnable callback) {
104-
SurveyDocumentOptionsForm form = new SurveyDocumentOptionsForm(disease, false, null);
112+
SurveyDocumentOptionsForm form = new SurveyDocumentOptionsForm(disease, false, null, true);
105113
form.setWidth(600, Sizeable.Unit.PIXELS);
106114
form.setValue(new SurveyDocumentOptionsDto(rootEntityType, rootEntityReference));
107115

@@ -136,24 +144,28 @@ private static class SurveyDocumentOptionsForm extends AbstractEditForm<SurveyDo
136144

137145
private static final String SURVEY_WARNING_LOC = "surveyWarningLoc";
138146
private static final String TEMPLATE_ADDITIONAL_VARIABLES_LOC = "templateAdditionalVariablesLoc";
147+
private static final String ATTACHMENT_NOT_AVAILABLE_INFO_LOC = "attachmentNotAvailableInfoLoc";
139148

140149
private static final String HTML_LAYOUT = fluidRowLocs(SurveyDocumentOptionsDto.RECIPIENT_EMAIL)
141150
+ fluidRowLocs(SurveyDocumentOptionsDto.SURVEY)
142151
+ fluidRowLocs(SURVEY_WARNING_LOC)
143-
+ fluidRowLocs(TEMPLATE_ADDITIONAL_VARIABLES_LOC);
152+
+ fluidRowLocs(TEMPLATE_ADDITIONAL_VARIABLES_LOC)
153+
+ fluidRowLocs(ATTACHMENT_NOT_AVAILABLE_INFO_LOC);
144154

145155
private final Disease disease;
146156
private final boolean forEmail;
147157
private final PersonDto person;
158+
private final boolean attachmentAvailable;
148159

149160
private VerticalLayout additionalVariablesComponent;
150161
private Consumer<Boolean> surveyErrorCallback;
151162

152-
protected SurveyDocumentOptionsForm(Disease disease, boolean forEmail, PersonDto person) {
163+
protected SurveyDocumentOptionsForm(Disease disease, boolean forEmail, PersonDto person, boolean attachmentAvailable) {
153164
super(SurveyDocumentOptionsDto.class, SurveyDocumentOptionsDto.I18N_PREFIX, false);
154165
this.disease = disease;
155166
this.forEmail = forEmail;
156167
this.person = person;
168+
this.attachmentAvailable = attachmentAvailable;
157169
this.surveyErrorCallback = e -> {
158170
};
159171

@@ -228,8 +240,7 @@ protected void addFields() {
228240
}
229241

230242
try {
231-
DocumentVariables documentVariables =
232-
FacadeProvider.getSurveyFacade().getDocumentVariables(survey.toReference());
243+
DocumentVariables documentVariables = FacadeProvider.getSurveyFacade().getDocumentVariables(survey.toReference());
233244
List<String> additionalVariables = documentVariables.getAdditionalVariables();
234245
if (additionalVariables != null && !additionalVariables.isEmpty()) {
235246
for (String variable : additionalVariables) {
@@ -244,6 +255,14 @@ protected void addFields() {
244255
.show(Page.getCurrent());
245256
}
246257
});
258+
259+
if (!attachmentAvailable) {
260+
MultilineLabel attachmentUnavailableInfo = new MultilineLabel(
261+
VaadinIcons.INFO_CIRCLE.getHtml() + " " + I18nProperties.getString(Strings.messageExternalEmailAttachmentNotAvailableInfo),
262+
ContentMode.HTML);
263+
attachmentUnavailableInfo.addStyleNames(CssStyles.VSPACE_2, CssStyles.VSPACE_TOP_4);
264+
getContent().addComponent(attachmentUnavailableInfo, ATTACHMENT_NOT_AVAILABLE_INFO_LOC);
265+
}
247266
}
248267

249268
protected Properties readAdditionalVariables() {

0 commit comments

Comments
 (0)