Skip to content

Commit

Permalink
Merge pull request #717 from Opetushallitus/feature/OPHKIOS-101
Browse files Browse the repository at this point in the history
VKT(Backend): OPHKIOS-101 Combine enrollment confirmation templates
  • Loading branch information
lket authored Sep 17, 2024
2 parents 6e7a639 + 0094eb0 commit 1fe0973
Show file tree
Hide file tree
Showing 12 changed files with 226 additions and 482 deletions.
12 changes: 11 additions & 1 deletion backend/vkt/src/main/java/fi/oph/vkt/service/PaymentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,13 +132,23 @@ public Payment finalizePayment(final Long paymentId, final Map<String, String> p
}

final Enrollment enrollment = payment.getEnrollment();
FreeEnrollmentDetails freeEnrollmentDetails = enrollmentRepository.countEnrollmentsByPerson(enrollment.getPerson());

setEnrollmentStatus(enrollment, newStatus);

payment.setPaymentStatus(newStatus);
paymentRepository.saveAndFlush(payment);

if (newStatus == PaymentStatus.OK) {
publicEnrollmentEmailService.sendEnrollmentConfirmationEmail(enrollment);
if (enrollment.getFreeEnrollment() != null) {
publicEnrollmentEmailService.sendPartiallyFreeEnrollmentConfirmationEmail(
enrollment,
enrollment.getPerson(),
freeEnrollmentDetails
);
} else {
publicEnrollmentEmailService.sendEnrollmentConfirmationEmail(enrollment);
}
}

return payment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.Person;
import fi.oph.vkt.model.type.ExamLanguage;
import fi.oph.vkt.model.type.FreeEnrollmentSource;
import fi.oph.vkt.service.email.EmailAttachmentData;
import fi.oph.vkt.service.email.EmailData;
import fi.oph.vkt.service.email.EmailService;
Expand Down Expand Up @@ -43,6 +44,7 @@ public class PublicEnrollmentEmailService {
public void sendEnrollmentConfirmationEmail(final Enrollment enrollment) throws IOException, InterruptedException {
final Person person = enrollment.getPerson();
final Map<String, Object> templateParams = getEmailParams(enrollment);
templateParams.put("type", "enrollment");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -66,6 +68,7 @@ public void sendEnrollmentConfirmationEmail(final Enrollment enrollment) throws
@Transactional
public void sendEnrollmentToQueueConfirmationEmail(final Enrollment enrollment, final Person person) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
templateParams.put("type", "queue");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -74,7 +77,8 @@ public void sendEnrollmentToQueueConfirmationEmail(final Enrollment enrollment,
LocalisationUtil.translate(localeFI, "subject.enrollment-to-queue-confirmation"),
LocalisationUtil.translate(localeSV, "subject.enrollment-to-queue-confirmation")
);
final String body = templateRenderer.renderEnrollmentToQueueConfirmationEmailBody(templateParams);

final String body = templateRenderer.renderEnrollmentConfirmationEmailBody(templateParams);

createEmail(recipientName, recipientAddress, subject, body, List.of(), EmailType.ENROLLMENT_TO_QUEUE_CONFIRMATION);
}
Expand Down Expand Up @@ -103,6 +107,9 @@ private Map<String, Object> getEmailParams(final Enrollment enrollment) {
params.put("partialExamsFI", getEmailParamPartialExams(enrollment, localeFI));
params.put("partialExamsSV", getEmailParamPartialExams(enrollment, localeSV));

params.put("type", "enrollment");
params.put("isFree", false);

return params;
}

Expand Down Expand Up @@ -176,8 +183,12 @@ public void sendFreeEnrollmentConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails);
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"enrollment"
);

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -186,10 +197,7 @@ public void sendFreeEnrollmentConfirmationEmail(
LocalisationUtil.translate(localeFI, "subject.enrollment-confirmation"),
LocalisationUtil.translate(localeSV, "subject.enrollment-confirmation")
);
final String body = templateRenderer.renderFreeEnrollmentConfirmationEmailBody(
templateParams,
enrollment.getFreeEnrollment().getSource()
);
final String body = templateRenderer.renderEnrollmentConfirmationEmailBody(templateParams);

createEmail(recipientName, recipientAddress, subject, body, List.of(), EmailType.ENROLLMENT_CONFIRMATION);
}
Expand All @@ -200,8 +208,12 @@ public void sendFreeEnrollmentToQueueConfirmationEmail(
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = getEmailParams(enrollment);
getFreeEmailParams(templateParams, freeEnrollmentDetails);
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"queue"
);

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
Expand All @@ -210,16 +222,81 @@ public void sendFreeEnrollmentToQueueConfirmationEmail(
LocalisationUtil.translate(localeFI, "subject.enrollment-to-queue-confirmation"),
LocalisationUtil.translate(localeSV, "subject.enrollment-to-queue-confirmation")
);
final String body = templateRenderer.renderFreeEnrollmentToQueueConfirmationEmailBody(
templateParams,
enrollment.getFreeEnrollment().getSource()
final String body = templateRenderer.renderEnrollmentConfirmationEmailBody(templateParams);

createEmail(recipientName, recipientAddress, subject, body, List.of(), EmailType.ENROLLMENT_TO_QUEUE_CONFIRMATION);
}

@Transactional
public void sendPartiallyFreeEnrollmentConfirmationEmail(
final Enrollment enrollment,
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) throws IOException, InterruptedException {
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"enrollment"
);
templateParams.put("isFree", "false");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
final String subject = String.format(
"%s | %s",
LocalisationUtil.translate(localeFI, "subject.enrollment-to-queue-confirmation"),
LocalisationUtil.translate(localeSV, "subject.enrollment-to-queue-confirmation")
);
final String body = templateRenderer.renderEnrollmentConfirmationEmailBody(templateParams);

final List<EmailAttachmentData> attachments = environment.getRequiredProperty(
"app.email.sending-enabled",
Boolean.class
)
? List.of(createReceiptAttachment(enrollment, localeFI), createReceiptAttachment(enrollment, localeSV))
: List.of(); // for local development

createEmail(recipientName, recipientAddress, subject, body, attachments, EmailType.ENROLLMENT_CONFIRMATION);
}

@Transactional
public void sendPartiallyFreeEnrollmentToQueueConfirmationEmail(
final Enrollment enrollment,
final Person person,
final FreeEnrollmentDetails freeEnrollmentDetails
) {
final Map<String, Object> templateParams = withFreeEmailParams(
getEmailParams(enrollment),
freeEnrollmentDetails,
enrollment.getFreeEnrollment().getSource(),
"queue"
);
templateParams.put("isFree", "false");

final String recipientName = person.getFirstName() + " " + person.getLastName();
final String recipientAddress = enrollment.getEmail();
final String subject = String.format(
"%s | %s",
LocalisationUtil.translate(localeFI, "subject.enrollment-to-queue-confirmation"),
LocalisationUtil.translate(localeSV, "subject.enrollment-to-queue-confirmation")
);
final String body = templateRenderer.renderEnrollmentConfirmationEmailBody(templateParams);

createEmail(recipientName, recipientAddress, subject, body, List.of(), EmailType.ENROLLMENT_TO_QUEUE_CONFIRMATION);
}

public void getFreeEmailParams(Map<String, Object> params, FreeEnrollmentDetails details) {
params.put(
public Map<String, Object> withFreeEmailParams(
Map<String, Object> params,
FreeEnrollmentDetails details,
FreeEnrollmentSource source,
String type
) {
Map<String, Object> freeParams = new HashMap<>(params);
freeParams.put("isFree", true);
freeParams.put("type", type);
freeParams.put("source", source.name());
freeParams.put(
"freeExamsLeftFI",
String.format(
"%s: %s/3. %s: %s/3",
Expand All @@ -229,7 +306,7 @@ public void getFreeEmailParams(Map<String, Object> params, FreeEnrollmentDetails
EnrollmentUtil.getFreeExamsLeft(details.oralSkillCount())
)
);
params.put(
freeParams.put(
"freeExamsLeftSV",
String.format(
"%s: %s/3. %s: %s/3",
Expand All @@ -239,5 +316,7 @@ public void getFreeEmailParams(Map<String, Object> params, FreeEnrollmentDetails
EnrollmentUtil.getFreeExamsLeft(details.oralSkillCount())
)
);

return freeParams;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -492,11 +492,19 @@ public PublicEnrollmentDTO createEnrollmentToQueue(
);

if (freeEnrollmentDetails != null && freeEnrollment != null) {
publicEnrollmentEmailService.sendFreeEnrollmentToQueueConfirmationEmail(
enrollment,
person,
freeEnrollmentDetails
);
if (freeEnrollmentDetails.textualSkillCount() == 0 || freeEnrollmentDetails.oralSkillCount() == 0) {
publicEnrollmentEmailService.sendPartiallyFreeEnrollmentToQueueConfirmationEmail(
enrollment,
person,
freeEnrollmentDetails
);
} else {
publicEnrollmentEmailService.sendFreeEnrollmentToQueueConfirmationEmail(
enrollment,
person,
freeEnrollmentDetails
);
}
} else {
publicEnrollmentEmailService.sendEnrollmentToQueueConfirmationEmail(enrollment, person);
}
Expand Down
26 changes: 0 additions & 26 deletions backend/vkt/src/main/java/fi/oph/vkt/util/TemplateRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,10 @@ public class TemplateRenderer {

private final TemplateEngine templateEngine;

public String renderFreeEnrollmentConfirmationEmailBody(
final Map<String, Object> params,
FreeEnrollmentSource source
) {
if (source.equals(FreeEnrollmentSource.KOSKI)) {
return renderTemplate("enrollment-free-koski-confirmation", params, Optional.empty());
} else {
return renderTemplate("enrollment-free-user-confirmation", params, Optional.empty());
}
}

public String renderEnrollmentConfirmationEmailBody(final Map<String, Object> params) {
return renderTemplate("enrollment-confirmation", params, Optional.empty());
}

public String renderEnrollmentToQueueConfirmationEmailBody(final Map<String, Object> params) {
return renderTemplate("enrollment-to-queue-confirmation", params, Optional.empty());
}

public String renderFreeEnrollmentToQueueConfirmationEmailBody(
final Map<String, Object> params,
FreeEnrollmentSource source
) {
if (source.equals(FreeEnrollmentSource.KOSKI)) {
return renderTemplate("enrollment-to-queue-free-koski-confirmation", params, Optional.empty());
} else {
return renderTemplate("enrollment-to-queue-free-user-confirmation", params, Optional.empty());
}
}

public String renderReceipt(final Locale locale, final Map<String, Object> params) {
return renderTemplate("receipt", params, Optional.of(locale));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,46 @@
<!DOCTYPE html>
<html lang="fi">
<html lang="fi" xmlns:th="http://www.thymeleaf.org">
<body>
<p>
Hei,
</p>
<p>
Olet ilmoittautunut Valtionhallinnon kielitutkintoon. Ohessa tiedot ilmoittautumisestasi. Liitteenä myös maksukuitti suomeksi ja ruotsiksi.
</p>
<th:block th:if="${!isFree and type == 'enrollment'}">
<p>Olet ilmoittautunut Valtionhallinnon kielitutkintoon. Ohessa tiedot ilmoittautumisestasi. Liitteenä myös maksukuitti suomeksi ja ruotsiksi.</p>
</th:block>
<th:block th:if="${!isFree and type == 'queue'}">
<p>Olet ilmoittautunut jonotuspaikalle Valtionhallinnon kielitutkintoon. Olemme sinuun yhteydessä, mikäli tutkintotilaisuuteen vapautuu paikkoja. Ohessa tiedot ilmoittautumisestasi.</p>
</th:block>
<th:block th:if="${isFree and source == 'KOSKI' and type == 'enrollment'}">
<p>Olet ilmoittautunut Valtionhallinnon kielitutkintoon. Tietojemme mukaan olet oikeutettu maksuttomaan tutkintoon. Ohessa tiedot ilmoittautumisestasi.</p>
</th:block>
<th:block th:if="${isFree and source == 'USER' and type == 'enrollment'}">
<p>Olet ilmoittautunut Valtionhallinnon kielitutkintoon. Olet ilmoittanut ilmoittautumislomakkeella, että olet oikeutettu maksuttomaan tutkintoon ja lisännyt todistusasiakirjoja.</p>
<p>Virkailija tarkastaa, täyttävätkö asiakirjat maksuttomuuden ehdot. Asiakirjat tarkastetaan mahdollisimman pian.</p>
<p>Jos ehdot täyttyvät, tutkinto on maksuton ja saat sähköpostilla vahvistuksen ilmoittautumisesta.</p>
<p>Jos ehdot eivät täyty, tutkinto on maksullinen ja saat sähköpostilla maksulinkin tutkintomaksun maksamista varten.</p>
<p>Ohessa tiedot ilmoittautumisestasi.</p>
</th:block>
<th:block th:if="${isFree and source == 'KOSKI' and type == 'queue'}">
<p>Olet ilmoittautunut jonotuspaikalle Valtionhallinnon kielitutkintoon. Olemme sinuun yhteydessä, mikäli tutkintotilaisuuteen vapautuu paikkoja.</p>
<p>Tietojemme mukaan olet oikeutettu maksuttomaan tutkintoon. Jos saat paikan tutkintoon, sinun ei tarvitse maksaa tutkintomaksua. Ohessa tiedot ilmoittautumisestasi.</p>
</th:block>
<th:block th:if="${isFree and source == 'USER' and type == 'queue'}">
<p>Olet ilmoittautunut jonotuspaikalle Valtionhallinnon kielitutkintoon. Olemme sinuun yhteydessä, mikäli tutkintotilaisuuteen vapautuu paikkoja.</p>
<p>Olet ilmoittanut ilmoittautumislomakkeella, että olet oikeutettu maksuttomaan tutkintoon ja lisännyt todistusasiakirjoja. Jos saat paikan tutkintoon, virkailija tarkastaa, täyttävätkö asiakirjat maksuttomuuden ehdot.</p>
<p>Jos ehdot täyttyvät, tutkinto on maksuton ja saat sähköpostilla vahvistuksen ilmoittautumisesta.</p>
<p>Jos ehdot eivät täyty, tutkinto on maksullinen ja saat sähköpostilla maksulinkin tutkintomaksun maksamista varten.</p>
<p>Ohessa tiedot ilmoittautumisestasi.</p>
</th:block>
<br/>

<p>
<b>Tutkinnon kieli:</b> <span th:text="${examLanguageFI}"></span><br/>
<b>Tutkinnon taso:</b> <span th:text="${examLevelFI}"></span><br/>
<b>Tutkintopäivä:</b> <span th:text="${examDate}"></span><br/>
<b>Oikeutettu maksuttomaan tutkintoon:</b> <span>Ei</span><br/>
<b>Oikeutettu maksuttomaan tutkintoon:</b> <span th:text="${isFree}? 'Kyllä' : 'Ei'">Ei</span><br/>
<b>Valitsemasi taidot:</b> <span th:text="${skillsFI}"></span><br/>
<b>Valitsemasi osakokeet:</b> <span th:text="${partialExamsFI}"></span><br/>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftFI)}"><b>Maksuttomia tutkintokertoja jäljellä:</b> <span th:text="${freeExamsLeftFI}"></span><br/></th:block>
</p>
<br/>

Expand All @@ -41,18 +66,43 @@
<p>
Hej,
</p>
<p>
Du har anmält dig till Språkexamen för statsförvaltningen (VKT). Uppgifter om din anmälan hittar du nedan. Bifogat finns även kvittot för din examensavgift på finska och på svenska.
</p>
<th:block th:if="${!isFree and type == 'enrollment'}">
<p>Du har anmält dig till Språkexamen för statsförvaltningen (VKT). Uppgifter om din anmälan hittar du nedan. Bifogat finns även kvittot för din examensavgift på finska och på svenska.</p>
</th:block>
<th:block th:if="${!isFree and type == 'queue'}">
<p>Du har en plats i kön för Språkexamen för statsförvaltningen (VKT). Vi kommer att kontakta dig om platser blir lediga. Uppgifter om din anmälan hittar du nedan.</p>
</th:block>
<th:block th:if="${isFree and source == 'KOSKI' and type == 'enrollment'}">
<p>Du har anmält dig till Språkexamen för statsförvaltningen (VKT). Enligt våra uppgifter har du rätt till avgiftsfri examen. Uppgifter om din anmälan hittar du nedan.</p>
</th:block>
<th:block th:if="${isFree and source == 'USER' and type == 'enrollment'}">
<p>Du har anmält dig till Språkexamen för statsförvaltningen (VKT).</p>
<p>Du har uppgett på anmälningsblanketten att du har rätt till avgiftsfri examen och bifogat intyg. Dina intyg granskas vid Utbildningsstyrelsen så fort som möjligt.</p>
<p>Om du har rätt till avgiftsfri examen får du en bekräftelse på din anmälan per e-post.</p>
<p>Om du inte har rätt till avgiftsfri examen, får du en länk för att betala examensavgiften.</p>
<p>Uppgifter om din anmälan hittar du nedan.</p>
</th:block>
<th:block th:if="${isFree and source == 'KOSKI' and type == 'queue'}">
<p>Du har en plats i kön för Språkexamen för statsförvaltningen (VKT). Vi kommer att kontakta dig om platser blir lediga.</p>
<p>Enligt våra uppgifter har du rätt till avgiftsfri examen. Ifall du får plats vid examenstillfället behöver du inte betala examensavgift. Uppgifter om din anmälan hittar du nedan.</p>
</th:block>
<th:block th:if="${isFree and source == 'USER' and type == 'queue'}">
<p>Du har en plats i kön för Språkexamen för statsförvaltningen (VKT). Vi kontaktar dig om platser blir lediga.</p>
<p>Du har uppgett på anmälningsblanketten att du har rätt till avgiftsfri examen och bifogat intyg. Om du får en plats vid examenstillfället granskas dina intyg vid Utbildningsstyrelsen.</p>
<p>Ifall du har rätt till avgiftsfri examen får du en bekräftelse på din anmälan per e-post.</p>
<p>Om du inte har rätt till avgiftsfri examen, får du en länk för att betala examensavgiften.</p>
<p>Uppgifter om din anmälan hittar du nedan.</p>
</th:block>
<br/>

<p>
<b>Examensspråk:</b> <span th:text="${examLanguageSV}"></span><br/>
<b>Examensnivå:</b> <span th:text="${examLevelSV}"></span><br/>
<b>Examensdatum:</b> <span th:text="${examDate}"></span><br/>
<b>Rätt till avgiftsfri examen:</b> <span>Nej</span><br/>
<b>Rätt till avgiftsfri examen:</b> <span th:text="${isFree} ? 'Ja' : 'Nej'">Nej</span><br/>
<b>Förmågor som du har valt:</b> <span th:text="${skillsSV}"></span><br/>
<b>Delprov som du har valt:</b> <span th:text="${partialExamsSV}"></span><br/>
<th:block th:if="${!#strings.isEmpty(freeExamsLeftSV)}"><b>Antal avgiftsfria examina kvar:</b> <span th:text="${freeExamsLeftSV}"></span><br/></th:block>
</p>
<br/>
<p><b>Information om examenstillfället</b></p>
Expand Down
Loading

0 comments on commit 1fe0973

Please sign in to comment.