28
28
import java .util .HashMap ;
29
29
import java .util .List ;
30
30
import java .util .Map ;
31
+ import java .util .Properties ;
31
32
import java .util .Set ;
32
33
import java .util .stream .Collectors ;
33
34
38
39
import javax .mail .MessagingException ;
39
40
import javax .validation .Valid ;
40
41
42
+ import de .symeda .sormas .api .survey .SurveyTokenCriteria ;
41
43
import org .apache .commons .collections4 .CollectionUtils ;
42
44
import org .apache .commons .io .FileUtils ;
43
45
import org .apache .commons .lang3 .StringUtils ;
102
104
import de .symeda .sormas .backend .manualmessagelog .ManualMessageLogService ;
103
105
import de .symeda .sormas .backend .person .Person ;
104
106
import de .symeda .sormas .backend .person .PersonService ;
107
+ import de .symeda .sormas .backend .survey .SurveyToken ;
108
+ import de .symeda .sormas .backend .survey .SurveyTokenService ;
105
109
import de .symeda .sormas .backend .travelentry .services .TravelEntryService ;
106
110
import de .symeda .sormas .backend .user .User ;
107
111
import de .symeda .sormas .backend .user .UserService ;
@@ -111,6 +115,7 @@ public class ExternalEmailFacadeEjb implements ExternalEmailFacade {
111
115
112
116
private static final Logger logger = LoggerFactory .getLogger (ExternalEmailFacadeEjb .class );
113
117
public static final int ATTACHMENT_PASSWORD_LENGTH = 10 ;
118
+ private static final String SURVEY_TOKEN_DOCUMENT_PLACEHOLDER = "surveyToken" ;
114
119
// @formatter:off
115
120
private static final Map <DocumentWorkflow , DocumentRelatedEntityType > DOCUMENT_WORKFLOW_DOCUMENT_RELATION_MAPPING = Map .of (
116
121
DocumentWorkflow .CASE_EMAIL , DocumentRelatedEntityType .CASE ,
@@ -158,6 +163,8 @@ public class ExternalEmailFacadeEjb implements ExternalEmailFacade {
158
163
private ManualMessageLogService manualMessageLogService ;
159
164
@ EJB
160
165
private DocGenerationHelper docGenerationHelper ;
166
+ @ EJB
167
+ private SurveyTokenService surveyTokenService ;
161
168
162
169
@ Override
163
170
public List <DocumentTemplateDto > getTemplates (DocumentWorkflow documentWorkflow ) {
@@ -235,7 +242,22 @@ private void sendEmail(@Valid ExternalEmailOptionsDto options, boolean onlyLinke
235
242
emailAttachments = attachmentService .createEncryptedPdfs (filesToBeEncryped , password );
236
243
}
237
244
238
- String generatedText = documentTemplateFacade .generateDocumentTxtFromEntities (options .getTemplate (), documentEntities , null );
245
+ SurveyTokenCriteria surveyTokenCriteria = new SurveyTokenCriteria ();
246
+ if (options .getRootEntityReference () instanceof CaseReferenceDto ){
247
+ surveyTokenCriteria .caseAssignedTo ((CaseReferenceDto ) options .getRootEntityReference ());
248
+ if (options .getAttachedDocuments () != null && options .getAttachedDocuments ().size () > 0 ) {
249
+ DocumentReferenceDto documentRef = options .getAttachedDocuments ().iterator ().next ();
250
+ surveyTokenCriteria .document (documentRef );
251
+ }
252
+ }
253
+
254
+ Properties externalEmailProperties = new Properties ();
255
+ SurveyToken surveyToken = surveyTokenService .getToken (surveyTokenCriteria );
256
+ if (surveyToken != null ) {
257
+ externalEmailProperties .setProperty (SURVEY_TOKEN_DOCUMENT_PLACEHOLDER , surveyToken .getToken ());
258
+ }
259
+
260
+ String generatedText = documentTemplateFacade .generateDocumentTxtFromEntities (options .getTemplate (), documentEntities , externalEmailProperties );
239
261
EmailTemplateTexts emailTexts = splitTemplateContent (generatedText );
240
262
241
263
try {
0 commit comments