26
26
import org .apache .commons .lang3 .StringUtils ;
27
27
import org .slf4j .LoggerFactory ;
28
28
29
+ import com .vaadin .icons .VaadinIcons ;
29
30
import com .vaadin .server .Page ;
30
31
import com .vaadin .server .Sizeable ;
32
+ import com .vaadin .shared .ui .ContentMode ;
31
33
import com .vaadin .shared .ui .MarginInfo ;
32
34
import com .vaadin .ui .Component ;
33
35
import com .vaadin .ui .Label ;
56
58
import de .symeda .sormas .ui .utils .CssStyles ;
57
59
import de .symeda .sormas .ui .utils .FieldHelper ;
58
60
import de .symeda .sormas .ui .utils .VaadinUiUtil ;
61
+ import de .symeda .sormas .ui .utils .components .MultilineLabel ;
59
62
60
63
public class SurveyDocumentController {
61
64
@@ -65,7 +68,8 @@ public void sendSurveyDocument(
65
68
Disease disease ,
66
69
PersonDto person ,
67
70
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 );
69
73
form .setWidth (600 , Sizeable .Unit .PIXELS );
70
74
SurveyDocumentOptionsDto options = new SurveyDocumentOptionsDto (rootEntityType , rootEntityReference );
71
75
options .setRecipientEmail (person .getEmailAddress (true ));
@@ -74,25 +78,29 @@ public void sendSurveyDocument(
74
78
CommitDiscardWrapperComponent <SurveyDocumentOptionsForm > editView = new CommitDiscardWrapperComponent <>(form , form .getFieldGroup ());
75
79
editView .getCommitButton ().setCaption (I18nProperties .getCaption (Captions .surveySend ));
76
80
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
+ }
96
104
form .setSurveyErrorCallback (inError -> {
97
105
editView .getCommitButton ().setEnabled (!inError );
98
106
});
@@ -101,7 +109,7 @@ public void sendSurveyDocument(
101
109
}
102
110
103
111
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 );
105
113
form .setWidth (600 , Sizeable .Unit .PIXELS );
106
114
form .setValue (new SurveyDocumentOptionsDto (rootEntityType , rootEntityReference ));
107
115
@@ -136,24 +144,28 @@ private static class SurveyDocumentOptionsForm extends AbstractEditForm<SurveyDo
136
144
137
145
private static final String SURVEY_WARNING_LOC = "surveyWarningLoc" ;
138
146
private static final String TEMPLATE_ADDITIONAL_VARIABLES_LOC = "templateAdditionalVariablesLoc" ;
147
+ private static final String ATTACHMENT_NOT_AVAILABLE_INFO_LOC = "attachmentNotAvailableInfoLoc" ;
139
148
140
149
private static final String HTML_LAYOUT = fluidRowLocs (SurveyDocumentOptionsDto .RECIPIENT_EMAIL )
141
150
+ fluidRowLocs (SurveyDocumentOptionsDto .SURVEY )
142
151
+ fluidRowLocs (SURVEY_WARNING_LOC )
143
- + fluidRowLocs (TEMPLATE_ADDITIONAL_VARIABLES_LOC );
152
+ + fluidRowLocs (TEMPLATE_ADDITIONAL_VARIABLES_LOC )
153
+ + fluidRowLocs (ATTACHMENT_NOT_AVAILABLE_INFO_LOC );
144
154
145
155
private final Disease disease ;
146
156
private final boolean forEmail ;
147
157
private final PersonDto person ;
158
+ private final boolean attachmentAvailable ;
148
159
149
160
private VerticalLayout additionalVariablesComponent ;
150
161
private Consumer <Boolean > surveyErrorCallback ;
151
162
152
- protected SurveyDocumentOptionsForm (Disease disease , boolean forEmail , PersonDto person ) {
163
+ protected SurveyDocumentOptionsForm (Disease disease , boolean forEmail , PersonDto person , boolean attachmentAvailable ) {
153
164
super (SurveyDocumentOptionsDto .class , SurveyDocumentOptionsDto .I18N_PREFIX , false );
154
165
this .disease = disease ;
155
166
this .forEmail = forEmail ;
156
167
this .person = person ;
168
+ this .attachmentAvailable = attachmentAvailable ;
157
169
this .surveyErrorCallback = e -> {
158
170
};
159
171
@@ -228,8 +240,7 @@ protected void addFields() {
228
240
}
229
241
230
242
try {
231
- DocumentVariables documentVariables =
232
- FacadeProvider .getSurveyFacade ().getDocumentVariables (survey .toReference ());
243
+ DocumentVariables documentVariables = FacadeProvider .getSurveyFacade ().getDocumentVariables (survey .toReference ());
233
244
List <String > additionalVariables = documentVariables .getAdditionalVariables ();
234
245
if (additionalVariables != null && !additionalVariables .isEmpty ()) {
235
246
for (String variable : additionalVariables ) {
@@ -244,6 +255,14 @@ protected void addFields() {
244
255
.show (Page .getCurrent ());
245
256
}
246
257
});
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
+ }
247
266
}
248
267
249
268
protected Properties readAdditionalVariables () {
0 commit comments