-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VKT(Frontend & Backend): Paytrail payment link and email sending fixe…
…s [deploy]
- Loading branch information
Showing
17 changed files
with
487 additions
and
221 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
backend/vkt/src/main/java/fi/oph/vkt/service/AbstractEnrollmentEmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import static fi.oph.vkt.util.LocalisationUtil.localeFI; | ||
import static fi.oph.vkt.util.LocalisationUtil.localeSV; | ||
|
||
import fi.oph.vkt.model.EmailType; | ||
import fi.oph.vkt.model.Enrollment; | ||
import fi.oph.vkt.model.EnrollmentAppointment; | ||
import fi.oph.vkt.model.EnrollmentCommon; | ||
import fi.oph.vkt.model.ExamEvent; | ||
import fi.oph.vkt.model.ExamEventCommon; | ||
import fi.oph.vkt.model.ExaminerExamEvent; | ||
import fi.oph.vkt.model.type.ExamLanguage; | ||
import fi.oph.vkt.service.email.EmailAttachmentData; | ||
import fi.oph.vkt.service.email.EmailData; | ||
import fi.oph.vkt.service.email.EmailService; | ||
import fi.oph.vkt.util.LocalisationUtil; | ||
import java.time.format.DateTimeFormatter; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Locale; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
public class AbstractEnrollmentEmailService { | ||
|
||
protected void createEmail( | ||
final EmailService emailService, | ||
final String recipientName, | ||
final String recipientAddress, | ||
final String subject, | ||
final String body, | ||
final List<EmailAttachmentData> attachments, | ||
final EmailType emailType | ||
) { | ||
final EmailData emailData = EmailData | ||
.builder() | ||
.recipientName(recipientName) | ||
.recipientAddress(recipientAddress) | ||
.subject(subject) | ||
.body(body) | ||
.attachments(attachments) | ||
.build(); | ||
|
||
emailService.saveEmail(emailType, emailData); | ||
} | ||
|
||
protected Map<String, Object> getEmailParams(final EnrollmentCommon enrollment, final ExamEventCommon examEvent) { | ||
final Map<String, Object> params = new HashMap<>(Map.of()); | ||
|
||
if (examEvent.getLanguage() == ExamLanguage.FI) { | ||
params.put("examLanguageFI", LocalisationUtil.translate(localeFI, "lang.finnish")); | ||
params.put("examLanguageSV", LocalisationUtil.translate(localeSV, "lang.finnish")); | ||
} else { | ||
params.put("examLanguageFI", LocalisationUtil.translate(localeFI, "lang.swedish")); | ||
params.put("examLanguageSV", LocalisationUtil.translate(localeSV, "lang.swedish")); | ||
} | ||
|
||
params.put("skillsFI", getEmailParamSkills(enrollment, localeFI, params.get("examLanguageFI"))); | ||
params.put("skillsSV", getEmailParamSkills(enrollment, localeSV, params.get("examLanguageSV"))); | ||
|
||
params.put("partialExamsFI", getEmailParamPartialExams(enrollment, localeFI)); | ||
params.put("partialExamsSV", getEmailParamPartialExams(enrollment, localeSV)); | ||
|
||
params.put("examLevelFI", LocalisationUtil.translate(localeFI, "examLevel.excellent")); | ||
params.put("examLevelSV", LocalisationUtil.translate(localeSV, "examLevel.excellent")); | ||
|
||
params.put("examDate", examEvent.getDate().format(DateTimeFormatter.ofPattern("dd.MM.yyyy"))); | ||
|
||
params.put("type", "enrollment"); | ||
params.put("isFree", false); | ||
|
||
return params; | ||
} | ||
|
||
private String getEmailParamSkills(final EnrollmentCommon enrollment, final Locale locale, final Object... args) { | ||
return joinNonEmptyStrings( | ||
Stream.of( | ||
enrollment.isTextualSkill() ? LocalisationUtil.translate(locale, "skill.textual", args) : "", | ||
enrollment.isOralSkill() ? LocalisationUtil.translate(locale, "skill.oral", args) : "", | ||
enrollment.isUnderstandingSkill() ? LocalisationUtil.translate(locale, "skill.understanding", args) : "" | ||
) | ||
); | ||
} | ||
|
||
private String getEmailParamPartialExams(final EnrollmentCommon enrollment, final Locale locale) { | ||
return joinNonEmptyStrings( | ||
Stream.of( | ||
enrollment.isWritingPartialExam() ? LocalisationUtil.translate(locale, "partialExam.writing") : "", | ||
enrollment.isReadingComprehensionPartialExam() | ||
? LocalisationUtil.translate(locale, "partialExam.readingComprehension") | ||
: "", | ||
enrollment.isSpeakingPartialExam() ? LocalisationUtil.translate(locale, "partialExam.speaking") : "", | ||
enrollment.isSpeechComprehensionPartialExam() | ||
? LocalisationUtil.translate(locale, "partialExam.speechComprehension") | ||
: "" | ||
) | ||
); | ||
} | ||
|
||
private String joinNonEmptyStrings(final Stream<String> stream) { | ||
return stream.filter(s -> !s.isEmpty()).collect(Collectors.joining(", ")); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
backend/vkt/src/main/java/fi/oph/vkt/service/ExaminerEnrollmentEmailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package fi.oph.vkt.service; | ||
|
||
import static fi.oph.vkt.util.LocalisationUtil.localeFI; | ||
import static fi.oph.vkt.util.LocalisationUtil.localeSV; | ||
|
||
import fi.oph.vkt.model.EmailType; | ||
import fi.oph.vkt.model.Enrollment; | ||
import fi.oph.vkt.model.EnrollmentAppointment; | ||
import fi.oph.vkt.model.Person; | ||
import fi.oph.vkt.service.email.EmailAttachmentData; | ||
import fi.oph.vkt.service.email.EmailService; | ||
import fi.oph.vkt.service.receipt.ReceiptRenderer; | ||
import fi.oph.vkt.util.ClerkEnrollmentUtil; | ||
import fi.oph.vkt.util.LocalisationUtil; | ||
import fi.oph.vkt.util.TemplateRenderer; | ||
import java.io.IOException; | ||
import java.util.List; | ||
import java.util.Map; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ExaminerEnrollmentEmailService extends AbstractEnrollmentEmailService { | ||
|
||
private final EmailService emailService; | ||
private final Environment environment; | ||
private final TemplateRenderer templateRenderer; | ||
|
||
@Transactional | ||
public void sendEnrollmentAppointmentAuthLink(final EnrollmentAppointment enrollment) | ||
throws IOException, InterruptedException { | ||
final String baseUrlAPI = environment.getRequiredProperty("app.base-url.api"); | ||
final Map<String, Object> templateParams = getEmailParams(enrollment, enrollment.getExaminerExamEvent()); | ||
final String authUrl = ClerkEnrollmentUtil.getAuthUrl(baseUrlAPI, enrollment.getId(), enrollment.getAuthHash()); | ||
|
||
templateParams.put("type", "enrollment"); | ||
templateParams.put("enrollmentAuthLink", authUrl); | ||
|
||
final String recipientName = enrollment.getFirstName() + " " + enrollment.getLastName(); | ||
final String recipientAddress = enrollment.getEmail(); | ||
final String subject = String.format( | ||
"%s | %s", | ||
LocalisationUtil.translate(localeFI, "subject.enrollment-confirmation"), | ||
LocalisationUtil.translate(localeSV, "subject.enrollment-confirmation") | ||
); | ||
final String body = templateRenderer.renderEnrollmentAppointmentAuthLink(templateParams); | ||
|
||
createEmail( | ||
emailService, | ||
recipientName, | ||
recipientAddress, | ||
subject, | ||
body, | ||
List.of(), | ||
EmailType.ENROLLMENT_APPOINTMENT_AUTH_LINK | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.