Skip to content

Commit

Permalink
CSCEXAM-000 Renaming
Browse files Browse the repository at this point in the history
- translation constants: changed prefix to i18n
- exam data model: examActiveStartDate and examActiveEndDate -> periodStart, periodEnd
- backend library upgrades
  • Loading branch information
Matti Lupari committed Dec 21, 2023
1 parent b4cba4b commit 6ef2927
Show file tree
Hide file tree
Showing 342 changed files with 6,334 additions and 6,425 deletions.
4 changes: 3 additions & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
align = more
version = "3.7.7"
runner.dialect = scala3
align.preset = more
maxColumn = 100
20 changes: 10 additions & 10 deletions app/controllers/AttachmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public CompletionStage<Result> addAttachmentToQuestionAnswer(Http.Request reques
question.getEssayAnswer().getId().toString()
);
} catch (IOException e) {
return wrapAsPromise(internalServerError("sitnet_error_creating_attachment"));
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
// Remove existing one if found
EssayAnswer answer = question.getEssayAnswer();
Expand Down Expand Up @@ -139,7 +139,7 @@ public CompletionStage<Result> addAttachmentToQuestion(Http.Request request) {
try {
newFilePath = copyFile(filePart.getRef(), "question", Long.toString(qid));
} catch (IOException e) {
return wrapAsPromise(internalServerError("sitnet_error_creating_attachment"));
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
return replaceAndFinish(question, filePart, newFilePath);
}
Expand Down Expand Up @@ -191,7 +191,7 @@ public CompletionStage<Result> deleteExamAttachment(Long id, Http.Request reques
return wrapAsPromise(notFound());
}
if (!user.hasRole(Role.Name.ADMIN) && !exam.isOwnedOrCreatedBy(user)) {
return wrapAsPromise(forbidden("sitnet_error_access_forbidden"));
return wrapAsPromise(forbidden("i18n_error_access_forbidden"));
}

fileHandler.removePrevious(exam);
Expand All @@ -203,7 +203,7 @@ public CompletionStage<Result> deleteExamAttachment(Long id, Http.Request reques
public CompletionStage<Result> deleteFeedbackAttachment(Long id, Http.Request request) {
Exam exam = DB.find(Exam.class, id);
if (exam == null) {
return wrapAsPromise(notFound("sitnet_exam_not_found"));
return wrapAsPromise(notFound("i18n_exam_not_found"));
}
Comment comment = exam.getExamFeedback();
fileHandler.removePrevious(comment);
Expand All @@ -216,7 +216,7 @@ public CompletionStage<Result> deleteFeedbackAttachment(Long id, Http.Request re
public CompletionStage<Result> deleteStatementAttachment(Long id, Http.Request request) {
LanguageInspection inspection = DB.find(LanguageInspection.class).where().eq("exam.id", id).findOne();
if (inspection == null || inspection.getStatement() == null) {
return wrapAsPromise(notFound("sitnet_exam_not_found"));
return wrapAsPromise(notFound("i18n_exam_not_found"));
}
Comment comment = inspection.getStatement();
fileHandler.removePrevious(comment);
Expand All @@ -235,14 +235,14 @@ public CompletionStage<Result> addAttachmentToExam(Http.Request request) {
}
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
if (!user.hasRole(Role.Name.ADMIN) && !exam.isOwnedOrCreatedBy(user)) {
return wrapAsPromise(forbidden("sitnet_error_access_forbidden"));
return wrapAsPromise(forbidden("i18n_error_access_forbidden"));
}
String newFilePath;
FilePart<Files.TemporaryFile> filePart = mf.getFilePart();
try {
newFilePath = copyFile(filePart.getRef(), "exam", Long.toString(eid));
} catch (IOException e) {
return wrapAsPromise(internalServerError("sitnet_error_creating_attachment"));
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
return replaceAndFinish(exam, filePart, newFilePath);
}
Expand All @@ -267,7 +267,7 @@ public CompletionStage<Result> addFeedbackAttachment(Long id, Http.Request reque
try {
newFilePath = copyFile(filePart.getRef(), "exam", id.toString(), "feedback");
} catch (IOException e) {
return wrapAsPromise(internalServerError("sitnet_error_creating_attachment"));
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
Comment comment = exam.getExamFeedback();
return replaceAndFinish(comment, filePart, newFilePath);
Expand All @@ -293,7 +293,7 @@ public CompletionStage<Result> addStatementAttachment(Long id, Http.Request requ
try {
newFilePath = copyFile(filePart.getRef(), "exam", id.toString(), "inspectionstatement");
} catch (IOException e) {
return wrapAsPromise(internalServerError("sitnet_error_creating_attachment"));
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
Comment comment = inspection.getStatement();
return replaceAndFinish(comment, filePart, newFilePath);
Expand Down Expand Up @@ -392,7 +392,7 @@ public ConfigReader getConfigReader() {
private CompletionStage<Result> serveAttachment(Attachment attachment) {
File file = new File(attachment.getFilePath());
if (!file.exists()) {
return wrapAsPromise(internalServerError("sitnet_file_not_found_but_referred_in_database"));
return wrapAsPromise(internalServerError("i18n_file_not_found_but_referred_in_database"));
}
final Source<ByteString, CompletionStage<IOResult>> source = FileIO.fromPath(file.toPath());
return serveAsBase64Stream(attachment, source);
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/BaseAttachmentInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ default MultipartForm getForm(Http.Request request) throws IllegalArgumentExcept
}
Optional<String> contentLength = request.header("Content-Length");
if (contentLength.isEmpty() || Long.parseLong(contentLength.get()) > getConfigReader().getMaxFileSize()) {
throw new IllegalArgumentException("sitnet_file_too_large");
throw new IllegalArgumentException("i18n_file_too_large");
}
return new MultipartForm(filePart, body.asFormUrlEncoded());
}
Expand Down
16 changes: 8 additions & 8 deletions app/controllers/CalendarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public Result removeReservation(long id, Http.Request request) throws NotFoundEx
final Reservation reservation = enrolment.getReservation();
DateTime now = dateTimeHandler.adjustDST(DateTime.now(), reservation);
if (reservation.toInterval().isBefore(now) || reservation.toInterval().contains(now)) {
return forbidden("sitnet_reservation_in_effect");
return forbidden("i18n_reservation_in_effect");
}
enrolment.setReservation(null);
enrolment.setReservationCanceled(true);
Expand Down Expand Up @@ -134,13 +134,13 @@ protected Optional<Result> checkEnrolment(ExamEnrolment enrolment, User user, Co
enrolment.getExam().getState() == Exam.State.STUDENT_STARTED ||
(oldReservation != null && oldReservation.toInterval().isBefore(DateTime.now()))
) {
return Optional.of(forbidden("sitnet_reservation_in_effect"));
return Optional.of(forbidden("i18n_reservation_in_effect"));
}
// No previous reservation or it's in the future
// If no previous reservation, check if allowed to participate. This check is skipped if user already
// has a reservation to this exam so that change of reservation is always possible.
if (oldReservation == null && !isAllowedToParticipate(enrolment.getExam(), user)) {
return Optional.of(forbidden("sitnet_no_trials_left"));
return Optional.of(forbidden("i18n_no_trials_left"));
}
// Check that at least one section will end up in the exam
Set<ExamSection> sections = enrolment.getExam().getExamSections();
Expand All @@ -157,7 +157,7 @@ protected Optional<Result> checkEnrolment(ExamEnrolment enrolment, User user, Co
enrolment.getExam().getState().equals(Exam.State.PUBLISHED)
) {
// External reservation, assessment not returned yet. We must wait for it to arrive first
return Optional.of(forbidden("sitnet_enrolment_assessment_not_received"));
return Optional.of(forbidden("i18n_enrolment_assessment_not_received"));
}

return Optional.empty();
Expand Down Expand Up @@ -214,7 +214,7 @@ public CompletionStage<Result> createReservation(Http.Request request) {
.endJunction()
.findOneOrEmpty();
if (optionalEnrolment.isEmpty()) {
return wrapAsPromise(forbidden("sitnet_error_enrolment_not_found"));
return wrapAsPromise(forbidden("i18n_error_enrolment_not_found"));
}
ExamEnrolment enrolment = optionalEnrolment.get();
Optional<Result> badEnrolment = checkEnrolment(enrolment, user, sectionIds);
Expand All @@ -230,7 +230,7 @@ public CompletionStage<Result> createReservation(Http.Request request) {
aids
);
if (machine.isEmpty()) {
return wrapAsPromise(forbidden("sitnet_no_machines_available"));
return wrapAsPromise(forbidden("i18n_no_machines_available"));
}

// Check that the proposed reservation is (still) doable
Expand All @@ -241,7 +241,7 @@ public CompletionStage<Result> createReservation(Http.Request request) {
proposedReservation.setUser(user);
proposedReservation.setEnrolment(enrolment);
if (!calendarHandler.isDoable(proposedReservation, aids)) {
return wrapAsPromise(forbidden("sitnet_no_machines_available"));
return wrapAsPromise(forbidden("i18n_no_machines_available"));
}

// We are good to go :)
Expand Down Expand Up @@ -321,7 +321,7 @@ public Result getSlots(Long examId, Long roomId, String day, Optional<List<Integ
ExamEnrolment ee = getEnrolment(examId, user);
// Sanity check so that we avoid accidentally getting reservations for SEB exams
if (ee == null || ee.getExam().getImplementation() != Exam.Implementation.AQUARIUM) {
return forbidden("sitnet_error_enrolment_not_found");
return forbidden("i18n_error_enrolment_not_found");
}
List<Integer> accessibilityIds = aids.orElse(Collections.emptyList());
return calendarHandler.getSlots(user, ee.getExam(), roomId, day, accessibilityIds);
Expand Down
65 changes: 31 additions & 34 deletions app/controllers/CourseController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,20 @@ import scala.concurrent.Future
import scala.jdk.CollectionConverters._
import scala.jdk.FutureConverters._

class CourseController @Inject()(externalApi: ExternalCourseHandler,
configReader: ConfigReader,
authenticated: AuthenticatedAction,
implicit val ec: AuthExecutionContext)
extends InjectedController
with JavaJsonResultProducer {
class CourseController @Inject() (
externalApi: ExternalCourseHandler,
configReader: ConfigReader,
authenticated: AuthenticatedAction,
implicit val ec: AuthExecutionContext
) extends InjectedController
with JavaJsonResultProducer:

def listCourses(filterType: Option[String],
criteria: Option[String],
user: User): Future[Result] = {
(filterType, criteria) match {
def listCourses(
filterType: Option[String],
criteria: Option[String],
user: User
): Future[Result] =
(filterType, criteria) match
case (Some("code"), Some(c)) =>
externalApi.getCoursesByCode(user, c).asScala.map(_.asScala.toResult(OK))
case (Some("name"), Some(x)) if x.length >= 2 =>
Expand All @@ -58,58 +61,52 @@ class CourseController @Inject()(externalApi: ExternalCourseHandler,
.filter(c =>
c.getStartDate == null || configReader
.getCourseValidityDate(new DateTime(c.getStartDate))
.isBeforeNow)
.isBeforeNow
)
}.map(_.toResult(OK))
case (Some("name"), Some(_)) =>
throw new IllegalArgumentException("Too short criteria")
case _ =>
Future {
DB.find(classOf[Course]).where.isNotNull("name").orderBy("code").findList
}.map(_.asScala.toResult(OK))
}
}

private def getUserCourses(user: User,
examIds: Option[List[Long]],
sectionIds: Option[List[Long]],
tagIds: Option[List[Long]]): Result = {
private def getUserCourses(
user: User,
examIds: Option[List[Long]],
sectionIds: Option[List[Long]],
tagIds: Option[List[Long]]
): Result =
var query = DB.find(classOf[Course]).where.isNotNull("name")
if (!user.hasRole(Role.Name.ADMIN)) {
if !user.hasRole(Role.Name.ADMIN) then
query = query
.eq("exams.examOwners", user)
}
if (examIds.getOrElse(Nil).nonEmpty) {
query = query.in("exams.id", examIds.get.asJava)
}
if (sectionIds.getOrElse(Nil).nonEmpty) {
if examIds.getOrElse(Nil).nonEmpty then query = query.in("exams.id", examIds.get.asJava)
if sectionIds.getOrElse(Nil).nonEmpty then
query = query.in("exams.examSections.id", sectionIds.get.asJava)
}
if (tagIds.getOrElse(Nil).nonEmpty) {
if tagIds.getOrElse(Nil).nonEmpty then
query =
query.in("exams.examSections.sectionQuestions.question.parent.tags.id", tagIds.get.asJava)
}
query.orderBy("name desc").findList.asScala.toResult(OK)
}

// Actions ->
def getCourses(filterType: Option[String], criteria: Option[String]): Action[AnyContent] = {
def getCourses(filterType: Option[String], criteria: Option[String]): Action[AnyContent] =
authenticated.andThen(authorized(Seq(Role.Name.ADMIN, Role.Name.TEACHER))).async { request =>
val user = request.attrs(Auth.ATTR_USER)
listCourses(filterType, criteria, user)
}
}

def getCourse(id: Long): Action[AnyContent] =
Action.andThen(authorized(Seq(Role.Name.TEACHER, Role.Name.ADMIN))) { _ =>
DB.find(classOf[Course], id).toResult(OK)
}

def listUsersCourses(examIds: Option[List[Long]],
sectionIds: Option[List[Long]],
tagIds: Option[List[Long]]): Action[AnyContent] =
def listUsersCourses(
examIds: Option[List[Long]],
sectionIds: Option[List[Long]],
tagIds: Option[List[Long]]
): Action[AnyContent] =
authenticated.andThen(authorized(Seq(Role.Name.TEACHER, Role.Name.ADMIN))) { request =>
val user = request.attrs(Auth.ATTR_USER)
getUserCourses(user, examIds, sectionIds, tagIds)
}

}
Loading

0 comments on commit 6ef2927

Please sign in to comment.