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 authored and lupari committed Dec 21, 2023
1 parent b4cba4b commit ea937df
Show file tree
Hide file tree
Showing 329 changed files with 6,137 additions and 6,170 deletions.
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
32 changes: 16 additions & 16 deletions app/controllers/EnrolmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public Result listEnrolledExams(String code) {
.eq("course.code", code)
.eq("executionType.type", ExamExecutionType.Type.PUBLIC.toString())
.eq("state", Exam.State.PUBLISHED)
.ge("examActiveEndDate", new Date())
.ge("periodEnd", new Date())
.findList();

return ok(exams);
Expand Down Expand Up @@ -159,7 +159,7 @@ public Result getEnrolledExamInfo(String code, Long id) {
.findOne();

if (exam == null) {
return notFound("sitnet_error_exam_not_found");
return notFound("i18n_error_exam_not_found");
}
return ok(exam);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ public Result checkIfEnrolled(Long id, Http.Request request) {
.where()
.eq("user", user)
.eq("exam.id", id)
.gt("exam.examActiveEndDate", now.toDate())
.gt("exam.periodEnd", now.toDate())
.disjunction()
.eq("exam.state", Exam.State.PUBLISHED)
.eq("exam.state", Exam.State.STUDENT_STARTED)
Expand All @@ -203,7 +203,7 @@ public Result checkIfEnrolled(Long id, Http.Request request) {
.collect(Collectors.toList());
return ok(enrolments);
}
return unauthorized("sitnet_no_trials_left");
return unauthorized("i18n_no_trials_left");
}

private boolean isActive(ExamEnrolment enrolment) {
Expand Down Expand Up @@ -238,7 +238,7 @@ public Result removeEnrolment(Long id, Http.Request request) {
return forbidden();
}
if (enrolment.getReservation() != null || enrolment.getExaminationEventConfiguration() != null) {
return forbidden("sitnet_cancel_reservation_first");
return forbidden("i18n_cancel_reservation_first");
}
enrolment.delete();
return ok();
Expand Down Expand Up @@ -280,7 +280,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
DB.find(User.class).forUpdate().where().eq("id", user.getId()).findOne();
Optional<Exam> possibleExam = getExam(eid, type);
if (possibleExam.isEmpty()) {
return wrapAsPromise(notFound("sitnet_error_exam_not_found"));
return wrapAsPromise(notFound("i18n_error_exam_not_found"));
}
Exam exam = possibleExam.get();

Expand Down Expand Up @@ -312,7 +312,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
e.getExam().getImplementation() == Exam.Implementation.AQUARIUM && e.getReservation() == null
)
) {
return wrapAsPromise(forbidden("sitnet_error_enrolment_exists"));
return wrapAsPromise(forbidden("i18n_error_enrolment_exists"));
}
// already enrolled (BYOD examination)
if (
Expand All @@ -323,7 +323,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
e.getExaminationEventConfiguration() == null
)
) {
return wrapAsPromise(forbidden("sitnet_error_enrolment_exists"));
return wrapAsPromise(forbidden("i18n_error_enrolment_exists"));
}
// reservation in effect
if (
Expand All @@ -332,7 +332,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
.map(ExamEnrolment::getReservation)
.anyMatch(r -> r != null && r.toInterval().contains(dateTimeHandler.adjustDST(DateTime.now(), r)))
) {
return wrapAsPromise(forbidden("sitnet_reservation_in_effect"));
return wrapAsPromise(forbidden("i18n_reservation_in_effect"));
}
// examination event in effect
if (
Expand All @@ -347,7 +347,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
.contains(dateTimeHandler.adjustDST(DateTime.now()))
)
) {
return wrapAsPromise(forbidden("sitnet_reservation_in_effect"));
return wrapAsPromise(forbidden("i18n_reservation_in_effect"));
}
List<ExamEnrolment> enrolmentsWithFutureReservations = enrolments
.stream()
Expand Down Expand Up @@ -409,7 +409,7 @@ private CompletionStage<Result> doCreateEnrolment(Long eid, ExamExecutionType.Ty
enrolment.getExam().getState().equals(Exam.State.PUBLISHED)
) {
// External reservation, assessment not returned yet. We must wait for it to arrive first
return wrapAsPromise(forbidden("sitnet_enrolment_assessment_not_received"));
return wrapAsPromise(forbidden("i18n_enrolment_assessment_not_received"));
}
}
ExamEnrolment newEnrolment = makeEnrolment(exam, user);
Expand All @@ -423,7 +423,7 @@ private CompletionStage<Result> checkPermission(Long id, Collection<String> code
return doCreateEnrolment(id, ExamExecutionType.Type.PUBLIC, user);
} else {
logger.warn("Attempt to enroll for a course without permission from {}", user.toString());
return wrapAsPromise(forbidden("sitnet_error_access_forbidden"));
return wrapAsPromise(forbidden("i18n_error_access_forbidden"));
}
}

Expand Down Expand Up @@ -451,7 +451,7 @@ public CompletionStage<Result> createStudentEnrolment(Long eid, Http.Request req
Optional<String> email = request.attrs().getOptional(Attrs.EMAIL);
Exam exam = DB.find(Exam.class, eid);
if (exam == null) {
return wrapAsPromise(notFound("sitnet_error_exam_not_found"));
return wrapAsPromise(notFound("i18n_error_exam_not_found"));
}
ExamExecutionType.Type executionType = ExamExecutionType.Type.valueOf(exam.getExecutionType().getType());

Expand Down Expand Up @@ -539,7 +539,7 @@ public Result removeStudentEnrolment(Long id, Http.Request request) {
.endJunction()
.findOne();
if (enrolment == null) {
return forbidden("sitnet_not_possible_to_remove_participant");
return forbidden("i18n_not_possible_to_remove_participant");
}
enrolment.delete();
return ok();
Expand Down Expand Up @@ -586,7 +586,7 @@ public Result addExaminationEventConfig(Long enrolmentId, Long configId, Http.Re
ExaminationEventConfiguration config = optionalConfig.get();
ExaminationEvent event = config.getExaminationEvent();
if (config.getExamEnrolments().size() + 1 > event.getCapacity()) {
return forbidden("sitnet_error_max_enrolments_reached");
return forbidden("i18n_error_max_enrolments_reached");
}
enrolment.setExaminationEventConfiguration(config);
enrolment.update();
Expand Down Expand Up @@ -683,7 +683,7 @@ public Result removeExaminationEvent(Long configId) {
public Result permitRetrial(Long id) {
ExamEnrolment enrolment = DB.find(ExamEnrolment.class, id);
if (enrolment == null) {
return notFound("sitnet_not_found");
return notFound("i18n_not_found");
}
enrolment.setRetrialPermitted(true);
enrolment.update();
Expand Down
Loading

0 comments on commit ea937df

Please sign in to comment.