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 Aug 12, 2024
1 parent b4350d0 commit e6dfb98
Show file tree
Hide file tree
Showing 51 changed files with 1,136 additions and 1,576 deletions.
2 changes: 1 addition & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

rules = [DisableSyntax, OrganizeImports, RedundantSyntax]
OrganizeImports {
removeUnused = false
removeUnused = true
groupedImports = Keep
coalesceToWildcardImportThreshold = 3
}
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
10 changes: 5 additions & 5 deletions app/controllers/assessment/ReviewDocumentsController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@
package controllers

import io.ebean.DB
import miscellaneous.csv.CsvBuilder
import miscellaneous.file.FileHandler
import miscellaneous.scala.{DbApiHelper, JavaApiHelper}
import models.exam.Exam
import models.questions.Question
import models.user.Role
import org.apache.commons.compress.archivers.ArchiveOutputStream
import org.apache.commons.compress.archivers.tar.{TarArchiveEntry, TarArchiveOutputStream}
import org.apache.commons.compress.utils.IOUtils
Expand All @@ -18,11 +23,6 @@ import play.api.libs.Files
import play.api.mvc._
import security.scala.Auth.{AuthenticatedAction, authorized}
import security.scala.{Auth, AuthExecutionContext}
import miscellaneous.csv.CsvBuilder
import miscellaneous.file.FileHandler
import miscellaneous.scala.{DbApiHelper, JavaApiHelper}
import models.exam.Exam
import models.user.Role

import java.io._
import java.text.SimpleDateFormat
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 Down Expand Up @@ -40,6 +40,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 @@ -144,7 +145,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) {
return externalReservationHandler.removeReservation(reservation, enrolment.getUser(), msg);
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/exam/CourseController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ package controllers.exam

import impl.ExternalCourseHandler
import io.ebean.DB
import org.joda.time.DateTime
import play.api.mvc._
import security.scala.Auth.{AuthenticatedAction, authorized}
import security.scala.{Auth, AuthExecutionContext}
import miscellaneous.config.ConfigReader
import miscellaneous.scala.{DbApiHelper, JavaApiHelper}
import models.exam.Course
import models.user.{Role, User}
import org.joda.time.DateTime
import play.api.mvc._
import security.scala.Auth.{AuthenticatedAction, authorized}
import security.scala.{Auth, AuthExecutionContext}

import javax.inject.Inject
import scala.concurrent.Future
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 @@ -8,8 +8,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
4 changes: 2 additions & 2 deletions app/controllers/facility/MaintenancePeriodController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@
package controllers

import io.ebean.DB
import miscellaneous.scala.{DbApiHelper, JavaApiHelper}
import models.calendar.MaintenancePeriod
import models.user.Role
import org.joda.time.DateTime
import org.joda.time.format.ISODateTimeFormat
import play.api.libs.json.JsValue
import play.api.mvc._
import security.scala.Auth.authorized
import security.scala.AuthExecutionContext
import system.AuditedAction
import miscellaneous.scala.{DbApiHelper, JavaApiHelper}
import models.user.Role

import javax.inject.Inject

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 @@ -232,7 +233,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
11 changes: 7 additions & 4 deletions app/impl/AutoEvaluationHandlerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

package impl

import models.assessment.{AutoEvaluationConfig, GradeEvaluation}
import models.exam.{Exam, Grade, GradeScale}
import impl.mail.EmailComposer
import miscellaneous.scala.DbApiHelper
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 @@ -21,6 +23,7 @@ class AutoEvaluationHandlerImpl @Inject (
private val actor: ActorSystem,
implicit val executionContext: ExecutionContext
) extends AutoEvaluationHandler
with DbApiHelper
with Logging:

override def autoEvaluate(exam: Exam): Unit =
Expand Down Expand Up @@ -76,6 +79,6 @@ class AutoEvaluationHandlerImpl @Inject (
private def resolveScale(exam: Exam): Option[GradeScale] = Option(exam.getGradeScale) match
case scale @ Some(_) => scale
case _ =>
Option(exam.getCourse).map(_.getGradeScale) match
Option(exam.getCourse).map(_.getGradeScale).nonNull match
case scale @ Some(_) => scale
case _ => Option(exam.getParent).map(_.getCourse).map(_.getGradeScale)
case _ => Option(exam.getParent).map(_.getCourse).nonNull.map(_.getGradeScale).nonNull
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 e6dfb98

Please sign in to comment.