Skip to content

Commit

Permalink
VKT(Backend): Send confirmation email upon contact request to client …
Browse files Browse the repository at this point in the history
…[deploy]
  • Loading branch information
pkoivisto committed Dec 2, 2024
1 parent 214b116 commit 04fa675
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,37 @@ public class ContactEmailService extends AbstractEnrollmentEmailService {
private final TemplateRenderer templateRenderer;

@Transactional
public void sendEnrollmentAppointmentAuthLink(final EnrollmentAppointment enrollment)
public void sendReceiptNotificationForContactRequest(final EnrollmentAppointment enrollment)
throws IOException, InterruptedException {
final Map<String, Object> templateParams = new HashMap<>(Map.of());
final Examiner examiner = enrollment.getExaminer();
final String examinerName = examiner.getFirstName() + " " + examiner.getLastName();
templateParams.put("examinerName", examinerName);
templateParams.put("message", enrollment.getMessage());
final String recipientName = enrollment.getFirstName() + " " + enrollment.getLastName();
final String recipientAddress = enrollment.getEmail();
templateParams.put("name", recipientName);
templateParams.put("email", recipientAddress);

// TODO Translate to Swedish
final String subject = String.format(
"%s",
LocalisationUtil.translate(localeFI, "subject.contact-request.receipt-notification")
);
final String body = templateRenderer.renderContactRequestReceiptNotification(templateParams);
createEmail(
emailService,
recipientName,
recipientAddress,
subject,
body,
List.of(),
EmailType.ENROLLMENT_CONTACT_REQUEST
);
}

@Transactional
public void sendExaminerNotificationOfContactRequest(final EnrollmentAppointment enrollment)
throws IOException, InterruptedException {
final Map<String, Object> templateParams = new HashMap<>(Map.of());
final Examiner examiner = enrollment.getExaminer();
Expand All @@ -36,10 +66,10 @@ public void sendEnrollmentAppointmentAuthLink(final EnrollmentAppointment enroll
final String recipientAddress = examiner.getEmail();
final String subject = String.format(
"%s | %s",
LocalisationUtil.translate(localeFI, "subject.contact-request"),
LocalisationUtil.translate(localeSV, "subject.contact-request")
LocalisationUtil.translate(localeFI, "subject.contact-request.notice-for-examiner"),
LocalisationUtil.translate(localeSV, "subject.contact-request.notice-for-examiner")
);
final String body = templateRenderer.renderContactRequest(templateParams);
final String body = templateRenderer.renderContactRequestNoticeForExaminer(templateParams);

createEmail(
emailService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import fi.oph.vkt.api.dto.PublicEnrollmentDTO;
import fi.oph.vkt.api.dto.PublicEnrollmentInitialisationDTO;
import fi.oph.vkt.api.dto.PublicExamEventDTO;
import fi.oph.vkt.api.dto.PublicExaminerDTO;
import fi.oph.vkt.api.dto.PublicExaminerExamDateDTO;
import fi.oph.vkt.api.dto.PublicExaminerNameDTO;
import fi.oph.vkt.api.dto.PublicFreeEnrollmentBasisDTO;
import fi.oph.vkt.api.dto.PublicPersonDTO;
Expand Down Expand Up @@ -706,7 +704,8 @@ public void createEnrollmentContact(final PublicEnrollmentContactCreateDTO dto,
enrollmentAppointment.setExaminer(examiner);
copyDtoFieldsToEnrollment(enrollmentAppointment, dto);

contactEmailService.sendEnrollmentAppointmentAuthLink(enrollmentAppointment);
contactEmailService.sendReceiptNotificationForContactRequest(enrollmentAppointment);
contactEmailService.sendExaminerNotificationOfContactRequest(enrollmentAppointment);

enrollmentAppointmentRepository.saveAndFlush(enrollmentAppointment);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fi.oph.vkt.util;

import fi.oph.vkt.model.type.FreeEnrollmentSource;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
Expand All @@ -27,7 +26,11 @@ public String renderEnrollmentAppointmentConfirmationEmailBody(final Map<String,
return renderTemplate("enrollment-appointment-confirmation", params, Optional.empty());
}

public String renderContactRequest(final Map<String, Object> params) {
public String renderContactRequestReceiptNotification(final Map<String, Object> params) {
return renderTemplate("contact-request-receipt-notification.html", params, Optional.empty());
}

public String renderContactRequestNoticeForExaminer(final Map<String, Object> params) {
return renderTemplate("examiner-contact-request.html", params, Optional.empty());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="fi" xmlns:th="http://www.thymeleaf.org">
<body>
<p>
Hei,
</p>
<br/>
<p>
Olet lähettänyt viestin seuraavalle Valtionhallinnon kielitutkintojen hyvän ja tyydyttävän taidon tutkintojen tutkintosuoritusten vastaanottajalle:
<br />
<b th:text="${examinerName}"></b>
</p>
<p>
Lähettämäsi viesti ja yhteystietosi:
</p>
<p>
<b>Viesti:</b>
<br />
<span th:text="${message}"></span>
</p>
<p>
<b>Yhteystietosi:</b>
<br />
Nimi: <span th:text="${name}"></span>
<br />
Sähköpostiosoite: <span th:text="${email}"></span>
</p>
<p>
<b>Mitä seuraavaksi?</b>
<br />
Tutkintosuoritusten vastaanottaja ottaa sinuun yhteyttä sähköpostitse.
</p>
<p>
Älä vastaa tähän viestiin - viesti on lähetetty automaattisesti.
</p>
<p>
Ystävällisin terveisin<br />
Opetushallitus
</p>
</body>
</html>
3 changes: 2 additions & 1 deletion backend/vkt/src/main/resources/localisation_fi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ skill.mail.oral = Suullinen taito
subject.enrollment-confirmation = Vahvistus ilmoittautumisesta Valtionhallinnon kielitutkintoon (VKT)
subject.enrollment-to-queue-confirmation = Vahvistus ilmoittautumisesta jonotuspaikalle Valtionhallinnon kielitutkintoon (VKT)
subject.enrollment-appointment-confirmation = Vahvistus ilmoittautumisesta Valtionhallinnon kielitutkintoon (VKT)
subject.contact-request = Yhteydenotto Valtionhallinnon kielitutkintoon (VKT)
subject.contact-request.receipt-notification = Valtionhallinnon kielitutkinnot: Lähettämäsi viesti tutkintosuorituksen vastaanottajalle
subject.contact-request.notice-for-examiner = Yhteydenotto Valtionhallinnon kielitutkintoon (VKT)
3 changes: 2 additions & 1 deletion backend/vkt/src/main/resources/localisation_sv.properties
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ skill.mail.oral = Förmåga att använda språket i tal
subject.enrollment-confirmation = Bekräftelse av anmälan till Språkexamen för statsförvaltningen (VKT)
subject.enrollment-to-queue-confirmation = Bekräftelse av plats i kön för Språkexamen för statsförvaltningen (VKT)
subject.enrollment-appointment-confirmation = Bekräftelse av anmälan till Språkexamen för statsförvaltningen (VKT)
subject.contact-request = Yhteydenotto Valtionhallinnon kielitutkintoon (VKT)
subject.contact-request.receipt-notification = Valtionhallinnon kielitutkinnot: Lähettämäsi viesti tutkintosuorituksen vastaanottajalle
subject.contact-request.notice-for-examiner = Yhteydenotto Valtionhallinnon kielitutkintoon (VKT)
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import fi.oph.vkt.api.dto.PublicExamEventDTO;
import fi.oph.vkt.api.dto.PublicPersonDTO;
import fi.oph.vkt.model.Enrollment;
import fi.oph.vkt.model.EnrollmentAppointment;
import fi.oph.vkt.model.ExamEvent;
import fi.oph.vkt.model.FeatureFlag;
import fi.oph.vkt.model.Person;
Expand Down Expand Up @@ -102,7 +101,8 @@ public void setup() throws IOException, InterruptedException {
doNothing().when(publicEnrollmentEmailServiceMock).sendEnrollmentToQueueConfirmationEmail(any(), any());
doNothing().when(publicEnrollmentEmailServiceMock).sendEnrollmentConfirmationEmail(any());
doNothing().when(publicEnrollmentEmailServiceMock).sendEnrollmentAppointmentConfirmationEmail(any());
doNothing().when(contactEmailServiceMock).sendEnrollmentAppointmentAuthLink(any());
doNothing().when(contactEmailServiceMock).sendReceiptNotificationForContactRequest(any());
doNothing().when(contactEmailServiceMock).sendExaminerNotificationOfContactRequest(any());

final Environment environment = mock(Environment.class);
when(environment.getRequiredProperty("app.reservation.duration")).thenReturn(ONE_MINUTE.toString());
Expand Down

0 comments on commit 04fa675

Please sign in to comment.