Improved Performance For Invitations

Fixed Email Template To support dynamic domains
This commit is contained in:
Ioannis Kalyvas 2018-10-09 13:04:03 +03:00
parent b112748ba4
commit 66e66be4a1
5 changed files with 44 additions and 15 deletions

View File

@ -8,6 +8,7 @@ import eu.eudat.data.entities.Invitation;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface InvitationService { public interface InvitationService {
@ -17,5 +18,5 @@ public interface InvitationService {
void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, eu.eudat.data.entities.UserInfo creator) throws MessagingException; void createInvitations(InvitationDao invitationDao, MailService mailService, List<eu.eudat.data.entities.UserInfo> users, DMP dmp, eu.eudat.data.entities.UserInfo creator) throws MessagingException;
void sendInvitation(DMP dmp, Invitation invitation, String recipient, MailService mailService) throws MessagingException; CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService) throws MessagingException;
} }

View File

@ -1,19 +1,33 @@
package eu.eudat.logic.services.utilities; package eu.eudat.logic.services.utilities;
import eu.eudat.core.logger.Logger;
import eu.eudat.data.dao.entities.DMPDao; import eu.eudat.data.dao.entities.DMPDao;
import eu.eudat.data.dao.entities.InvitationDao; import eu.eudat.data.dao.entities.InvitationDao;
import eu.eudat.data.entities.DMP; import eu.eudat.data.entities.DMP;
import eu.eudat.data.entities.Invitation; import eu.eudat.data.entities.Invitation;
import eu.eudat.models.data.mail.SimpleMail; import eu.eudat.models.data.mail.SimpleMail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.CompletableFuture;
@Service("invitationService") @Service("invitationService")
public class InvitationServiceImpl implements InvitationService { public class InvitationServiceImpl implements InvitationService {
private Logger logger;
private Environment environment;
@Autowired
public InvitationServiceImpl(Logger logger, Environment environment) {
this.logger = logger;
this.environment = environment;
}
@Override @Override
public void assignToDmp(DMPDao dmpDao, List<eu.eudat.data.entities.UserInfo> users, DMP dmp) { public void assignToDmp(DMPDao dmpDao, List<eu.eudat.data.entities.UserInfo> users, DMP dmp) {
for (eu.eudat.data.entities.UserInfo user : users) { for (eu.eudat.data.entities.UserInfo user : users) {
@ -38,17 +52,23 @@ public class InvitationServiceImpl implements InvitationService {
invitation.setToken(UUID.randomUUID()); invitation.setToken(UUID.randomUUID());
invitation.setAcceptedInvitation(false); invitation.setAcceptedInvitation(false);
invitationDao.createOrUpdate(invitation); invitationDao.createOrUpdate(invitation);
sendInvitation(dmp, invitation, userInfo.getName(), mailService); sendInvitationAsync(dmp, invitation, userInfo.getName(), mailService);
} }
} }
@Override @Override
public void sendInvitation(DMP dmp, Invitation invitation, String recipient, MailService mailService) throws MessagingException { public CompletableFuture sendInvitationAsync(DMP dmp, Invitation invitation, String recipient, MailService mailService) {
return CompletableFuture.runAsync(() -> {
SimpleMail mail = new SimpleMail(); SimpleMail mail = new SimpleMail();
mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject())); mail.setSubject(createSubject(dmp, mailService.getMailTemplateSubject()));
mail.setContent(createContent(invitation.getId(), dmp, recipient, mailService.getMailTemplateContent())); mail.setContent(createContent(invitation.getId(), dmp, recipient, mailService.getMailTemplateContent()));
mail.setTo(invitation.getInvitationEmail()); mail.setTo(invitation.getInvitationEmail());
try {
mailService.sendSimpleMail(mail); mailService.sendSimpleMail(mail);
} catch (MessagingException e) {
this.logger.error(e, e.getMessage());
}
});
} }
private String createSubject(DMP dmp, String templateSubject) { private String createSubject(DMP dmp, String templateSubject) {
@ -60,6 +80,7 @@ public class InvitationServiceImpl implements InvitationService {
String content = templateContent.replace("{dmpname}", dmp.getLabel()); String content = templateContent.replace("{dmpname}", dmp.getLabel());
content = content.replace("{invitationID}", invitationID.toString()); content = content.replace("{invitationID}", invitationID.toString());
content = content.replace("{recipient}", recipient); content = content.replace("{recipient}", recipient);
content = content.replace("{host}", this.environment.getProperty("dmp.domain"));
return content; return content;
} }

View File

@ -271,7 +271,7 @@
<table border="0" cellpadding="0" cellspacing="0"> <table border="0" cellpadding="0" cellspacing="0">
<tbody> <tbody>
<tr> <tr>
<td> <a href="http://dl043.madgik.di.uoa.gr/dmps/invitation/{invitationID}" target="_blank">Join</a> </td> <td> <a href="{host}/dmps/invitation/{invitationID}" target="_blank">Join</a> </td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -1,5 +1,5 @@
<div class="dataset-wizard"> <div class="dataset-wizard">
<h3 *ngIf="isNew">New Dataset</h3> <h3 *ngIf="isNew">{{ 'DATASET-WIZARD.TITLE.NEW' | translate }}</h3>
<div class="flex-container"> <div class="flex-container">
<div fxLayout="row"> <div fxLayout="row">
<h3 *ngIf="!isNew">{{datasetWizardModel?.label}} {{ 'GENERAL.NAMES.DATASET' | translate }}</h3> <h3 *ngIf="!isNew">{{datasetWizardModel?.label}} {{ 'GENERAL.NAMES.DATASET' | translate }}</h3>
@ -10,14 +10,14 @@
<div class="flex-container"> <div class="flex-container">
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" <button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;"
(click)="save();" type="button">Save</button> (click)="save();" type="button">{{ 'DATASET-WIZARD.ACTIONS.SAVE' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" <button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status != 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;"
(click)="saveFinalize();" type="button">Save and Finalize</button> (click)="saveFinalize();" type="button">{{ 'DATASET-WIZARD.ACTIONS.SAVE-AND-FINALISE' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" <button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;"
(click)="downloadPDF();" type="button">Download PDF</button> (click)="downloadPDF();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-PDF' | translate }}</button>
<button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;" <button mat-raised-button color="primary" *ngIf="datasetWizardModel&&datasetWizardModel?.status == 1" style="margin-top: 15px;margin-bottom: 15px;margin-right: 15px;"
(click)="downloadXML();" type="button">Download XML</button> (click)="downloadXML();" type="button">{{ 'DATASET-WIZARD.ACTIONS.DOWNLOAD-XML' | translate }}</button>
<div class="fill-space"></div> <div class="fill-space"></div>
<!-- <button mat-button (click)="redirectToProject()"> <!-- <button mat-button (click)="redirectToProject()">
<mat-icon>arrow_right_alt</mat-icon>{{'DATASET-WIZARD.ACTIONS.GO-TO-PROJECT' | translate}}</button> <mat-icon>arrow_right_alt</mat-icon>{{'DATASET-WIZARD.ACTIONS.GO-TO-PROJECT' | translate}}</button>

View File

@ -75,6 +75,9 @@
} }
}, },
"DATASET-WIZARD": { "DATASET-WIZARD": {
"TITLE": {
"NEW": "New Dataset Description"
},
"EDITOR": { "EDITOR": {
"FIELDS": { "FIELDS": {
"EXTERNAL-DATASET-TYPE": "Type" "EXTERNAL-DATASET-TYPE": "Type"
@ -95,7 +98,11 @@
"NEXT": "Next", "NEXT": "Next",
"BACK": "Back", "BACK": "Back",
"GO-TO-PROJECT": "Go to Dataset Project", "GO-TO-PROJECT": "Go to Dataset Project",
"GO-TO-DMP": "Go to Dataset DMP" "GO-TO-DMP": "Go to Dataset DMP",
"SAVE": "Save",
"SAVE-AND-FINALISE": "Save and Finalise",
"DOWNLOAD-PDF": "Download PDF",
"DOWNLOAD-XML": "Download XML"
} }
}, },
"DATASET-LISTING": { "DATASET-LISTING": {