Skip to content

Commit

Permalink
CSCEXAM-000 Email composer in Scala
Browse files Browse the repository at this point in the history
  • Loading branch information
lupari committed May 23, 2024
1 parent d17b6b6 commit 25e76cd
Show file tree
Hide file tree
Showing 37 changed files with 1,043 additions and 1,516 deletions.
2 changes: 1 addition & 1 deletion app/controllers/assessment/ExamInspectionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import be.objectify.deadbolt.java.actions.Group;
import be.objectify.deadbolt.java.actions.Restrict;
import controllers.base.BaseController;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.Model;
import java.util.Optional;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assessment/ExamRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import be.objectify.deadbolt.java.actions.Group;
import be.objectify.deadbolt.java.actions.Restrict;
import controllers.base.BaseController;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import be.objectify.deadbolt.java.actions.Pattern;
import be.objectify.deadbolt.java.actions.Restrict;
import controllers.base.BaseController;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.ExpressionList;
import io.ebean.FetchConfig;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/assessment/ReviewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import be.objectify.deadbolt.java.actions.Restrict;
import com.fasterxml.jackson.databind.JsonNode;
import controllers.base.BaseController;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.ExpressionList;
import io.ebean.FetchConfig;
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/calendar/CalendarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import controllers.iop.transfer.api.ExternalReservationHandler;
import exceptions.NotFoundException;
import impl.CalendarHandler;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.Transaction;
import java.util.Collection;
Expand Down Expand Up @@ -40,6 +40,7 @@
import sanitizers.Attrs;
import sanitizers.CalendarReservationSanitizer;
import scala.concurrent.duration.Duration;
import scala.jdk.javaapi.OptionConverters;
import security.Authenticated;

public class CalendarController extends BaseController {
Expand Down Expand Up @@ -101,7 +102,7 @@ public Result removeReservation(long id, Http.Request request) throws NotFoundEx
emailComposer.composeReservationCancellationNotification(
enrolment.getUser(),
reservation,
"",
OptionConverters.toScala(Optional.empty()),
isStudentUser,
enrolment
);
Expand Down
5 changes: 3 additions & 2 deletions app/controllers/enrolment/EnrolmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
import be.objectify.deadbolt.java.actions.Restrict;
import controllers.base.BaseController;
import controllers.iop.transfer.api.ExternalReservationHandler;
import impl.EmailComposer;
import impl.ExternalCourseHandler;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.Transaction;
import java.io.IOException;
Expand Down Expand Up @@ -644,13 +644,14 @@ public Result removeExaminationEvent(Long configId) {
});
config.delete();
event.delete();
var users = enrolments.stream().map(ExamEnrolment::getUser).collect(Collectors.toSet());
actor
.scheduler()
.scheduleOnce(
Duration.create(1, TimeUnit.SECONDS),
() -> {
emailComposer.composeExaminationEventCancellationNotification(
enrolments.stream().map(ExamEnrolment::getUser).collect(Collectors.toSet()),
CollectionConverters.asScala(users).toSet(),
exam,
event
);
Expand Down
11 changes: 9 additions & 2 deletions app/controllers/enrolment/ReservationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import controllers.iop.collaboration.api.CollaborativeExamLoader;
import controllers.iop.transfer.api.ExternalReservationHandler;
import exceptions.NotFoundException;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.FetchConfig;
import io.ebean.text.PathProperties;
Expand All @@ -39,6 +39,7 @@
import play.mvc.Http;
import play.mvc.Result;
import sanitizers.Attrs;
import scala.jdk.javaapi.OptionConverters;
import security.Authenticated;
import system.interceptors.Anonymous;

Expand Down Expand Up @@ -147,7 +148,13 @@ public CompletionStage<Result> removeReservation(long id, Http.Request request)
// Let's not send emails about historical reservations
if (reservation.getEndAt().isAfter(DateTime.now())) {
var student = enrolment.getUser();
emailComposer.composeReservationCancellationNotification(student, reservation, msg, false, enrolment);
emailComposer.composeReservationCancellationNotification(
student,
reservation,
OptionConverters.toScala(Optional.of(msg)),
false,
enrolment
);
}

if (reservation.getExternalReservation() != null) {
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/exam/ExamController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import be.objectify.deadbolt.java.actions.Restrict;
import com.fasterxml.jackson.databind.node.ObjectNode;
import controllers.base.BaseController;
import impl.EmailComposer;
import impl.ExamUpdater;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.ExpressionList;
import io.ebean.FetchConfig;
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/examination/ExaminationController.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import controllers.base.BaseController;
import controllers.iop.transfer.api.ExternalAttachmentLoader;
import impl.AutoEvaluationHandler;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.text.PathProperties;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import be.objectify.deadbolt.java.actions.Group;
import be.objectify.deadbolt.java.actions.Restrict;
import impl.CalendarHandler;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.Transaction;
import io.ebean.text.PathProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import be.objectify.deadbolt.java.actions.Group;
import be.objectify.deadbolt.java.actions.Restrict;
import com.fasterxml.jackson.databind.JsonNode;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import java.net.URL;
import java.util.List;
Expand Down Expand Up @@ -41,6 +41,7 @@
import sanitizers.EmailSanitizer;
import sanitizers.ExamUpdateSanitizer;
import scala.concurrent.duration.Duration;
import scala.jdk.javaapi.CollectionConverters;
import security.Authenticated;

public class CollaborativeExamController extends CollaborationController {
Expand Down Expand Up @@ -237,7 +238,12 @@ public CompletionStage<Result> updateExam(Long id, Http.Request request) {
.scheduler()
.scheduleOnce(
Duration.create(1, TimeUnit.SECONDS),
() -> composer.composeCollaborativeExamAnnouncement(receivers, user, exam),
() ->
composer.composeCollaborativeExamAnnouncement(
CollectionConverters.asScala(receivers).toSet(),
user,
exam
),
as.dispatcher()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.vavr.control.Either;
import java.io.File;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import play.mvc.With;
import sanitizers.Attrs;
import sanitizers.ExternalCalendarReservationSanitizer;
import scala.jdk.javaapi.OptionConverters;
import security.Authenticated;

public class ExternalCalendarController extends CalendarController {
Expand Down Expand Up @@ -370,7 +371,10 @@ public CompletionStage<Result> requestReservationRevocation(String ref, Http.Req
return internalServerError(root.get("message").asText("Connection refused"));
}
String msg = request.body().asJson().path("msg").asText("");
emailComposer.composeExternalReservationCancellationNotification(reservation, msg);
emailComposer.composeExternalReservationCancellationNotification(
reservation,
OptionConverters.toScala(Optional.of(msg))
);
reservation.delete();
return ok();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import controllers.iop.transfer.api.ExternalAttachmentLoader;
import controllers.iop.transfer.api.ExternalExamAPI;
import impl.AutoEvaluationHandler;
import impl.EmailComposer;
import impl.NoShowHandler;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.Query;
import io.ebean.text.PathProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import controllers.examination.ExaminationController;
import controllers.iop.transfer.api.ExternalAttachmentLoader;
import impl.AutoEvaluationHandler;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import io.ebean.text.PathProperties;
import io.vavr.Tuple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import com.fasterxml.jackson.databind.JsonNode;
import controllers.iop.transfer.api.ExternalReservationHandler;
import impl.EmailComposer;
import impl.mail.EmailComposer;
import io.ebean.DB;
import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -36,6 +36,7 @@
import play.mvc.Result;
import play.mvc.Results;
import scala.concurrent.duration.Duration;
import scala.jdk.javaapi.OptionConverters;

public class ExternalReservationHandlerImpl implements ExternalReservationHandler {

Expand Down Expand Up @@ -128,7 +129,7 @@ private CompletionStage<Result> requestRemoval(String ref, User user, String msg
emailComposer.composeReservationCancellationNotification(
enrolment.getUser(),
reservation,
msg,
OptionConverters.toScala(Optional.of(msg)),
isStudentUser,
enrolment
);
Expand Down
7 changes: 4 additions & 3 deletions app/impl/AutoEvaluationHandlerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@

package impl

import models.assessment.{AutoEvaluationConfig, GradeEvaluation}
import models.exam.{Exam, Grade, GradeScale}
import impl.mail.EmailComposer
import models.assessment.AutoEvaluationConfig
import models.exam.{Exam, GradeScale}
import org.apache.pekko.actor.ActorSystem
import org.joda.time.DateTime
import play.api.Logging
Expand All @@ -14,7 +15,7 @@ import java.util.concurrent.TimeUnit
import javax.inject.Inject
import scala.concurrent.ExecutionContext
import scala.concurrent.duration.Duration
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

class AutoEvaluationHandlerImpl @Inject (
private val composer: EmailComposer,
Expand Down
2 changes: 1 addition & 1 deletion app/impl/CalendarHandlerImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// SPDX-FileCopyrightText: 2024 The members of the EXAM Consortium
// SPDX-FileCopyrightText: 2024. The members of the EXAM Consortium
//
// SPDX-License-Identifier: EUPL-1.2

Expand All @@ -10,6 +9,7 @@
import controllers.admin.SettingsController;
import controllers.iop.transfer.api.ExternalReservationHandler;
import exceptions.NotFoundException;
import impl.mail.EmailComposer;
import io.ebean.DB;
import java.util.ArrayList;
import java.util.Collection;
Expand Down
Loading

0 comments on commit 25e76cd

Please sign in to comment.