Skip to content

Commit

Permalink
Merge branch 'dev' into CSCEXAM-1163-2
Browse files Browse the repository at this point in the history
  • Loading branch information
VirmasaloA authored Sep 9, 2024
2 parents 601b55b + 42cad31 commit 7c8a970
Show file tree
Hide file tree
Showing 55 changed files with 1,127 additions and 1,019 deletions.
3 changes: 2 additions & 1 deletion app/controllers/AccessibilityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public Result removeAccessibility(Long id) {
if (accessibility == null) {
return notFound();
}
DB.find(ExamRoom.class)
DB
.find(ExamRoom.class)
.where()
.in("accessibilities", accessibility)
.findList()
Expand Down
43 changes: 23 additions & 20 deletions app/controllers/AttachmentController.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public CompletionStage<Result> addAttachmentToQuestionAnswer(Http.Request reques
long qid = Long.parseLong(mf.getForm().get("questionId")[0]);

// first check if answer already exists
ExamSectionQuestion question = DB.find(ExamSectionQuestion.class)
ExamSectionQuestion question = DB
.find(ExamSectionQuestion.class)
.fetch("essayAnswer")
.where()
.idEq(qid)
Expand All @@ -82,13 +83,14 @@ public CompletionStage<Result> addAttachmentToQuestionAnswer(Http.Request reques

String newFilePath;
try {
newFilePath = copyFile(
filePart.getRef(),
"question",
Long.toString(qid),
"answer",
question.getEssayAnswer().getId().toString()
);
newFilePath =
copyFile(
filePart.getRef(),
"question",
Long.toString(qid),
"answer",
question.getEssayAnswer().getId().toString()
);
} catch (IOException e) {
return wrapAsPromise(internalServerError("i18n_error_creating_attachment"));
}
Expand Down Expand Up @@ -123,7 +125,8 @@ private CompletionStage<Result> replaceAndFinish(
public CompletionStage<Result> addAttachmentToQuestion(Http.Request request) {
MultipartForm mf = getForm(request);
long qid = Long.parseLong(mf.getForm().get("questionId")[0]);
Question question = DB.find(Question.class)
Question question = DB
.find(Question.class)
.fetch("examSectionQuestions.examSection.exam.parent")
.where()
.idEq(qid)
Expand Down Expand Up @@ -159,11 +162,8 @@ public CompletionStage<Result> deleteQuestionAnswerAttachment(Long qid, Http.Req
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
ExamSectionQuestion question;
if (user.hasRole(Role.Name.STUDENT)) {
question = DB.find(ExamSectionQuestion.class)
.where()
.idEq(qid)
.eq("examSection.exam.creator", user)
.findOne();
question =
DB.find(ExamSectionQuestion.class).where().idEq(qid).eq("examSection.exam.creator", user).findOne();
} else {
question = DB.find(ExamSectionQuestion.class, qid);
}
Expand Down Expand Up @@ -306,11 +306,13 @@ public CompletionStage<Result> downloadQuestionAttachment(Long id, Http.Request
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
Question question;
if (user.hasRole(Role.Name.STUDENT)) {
question = DB.find(Question.class)
.where()
.idEq(id)
.eq("examSectionQuestions.examSection.exam.creator", user)
.findOne();
question =
DB
.find(Question.class)
.where()
.idEq(id)
.eq("examSectionQuestions.examSection.exam.creator", user)
.findOne();
} else {
question = DB.find(Question.class, id);
}
Expand Down Expand Up @@ -367,7 +369,8 @@ public CompletionStage<Result> downloadFeedbackAttachment(Long id, Http.Request
@Override
public CompletionStage<Result> downloadStatementAttachment(Long id, Http.Request request) {
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
ExpressionList<Exam> query = DB.find(Exam.class)
ExpressionList<Exam> query = DB
.find(Exam.class)
.where()
.idEq(id)
.isNotNull("languageInspection.statement.attachment");
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/AvailabilityController.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public Result getAvailability(Long roomId, String day) {
}
DateTime searchStart = parseSearchStartDate(day);
DateTime searchEnd = getSearchEndDate(searchStart);
List<Reservation> reservations = DB.find(Reservation.class)
List<Reservation> reservations = DB
.find(Reservation.class)
.where()
.eq("machine.room.id", roomId)
.between("startAt", searchStart.toDate(), searchEnd.toDate())
Expand All @@ -98,12 +99,11 @@ public Result getAvailability(Long roomId, String day) {
List<Interval> slotsForDate = dateTimeHandler
.getWorkingHoursForDate(window, room)
.stream()
.map(
oh ->
new Interval(
oh.getHours().getStart().minusMillis(oh.getTimezoneOffset()),
oh.getHours().getEnd().minusMillis(oh.getTimezoneOffset())
)
.map(oh ->
new Interval(
oh.getHours().getStart().minusMillis(oh.getTimezoneOffset()),
oh.getHours().getEnd().minusMillis(oh.getTimezoneOffset())
)
)
.map(this::round)
.flatMap(i -> toOneHourChunks(i).stream())
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/ExamAnswerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ private boolean canReleaseAnswers(Exam exam) {
@Authenticated
@Restrict(@Group({ "STUDENT" }))
public Result getAnswers(Long eid, Http.Request request) {
Optional<Exam> oe = DB.find(Exam.class)
Optional<Exam> oe = DB
.find(Exam.class)
.fetch("course", "name, code, credits")
.fetch("grade", "name")
.fetch("examFeedback")
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/ExamInspectionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,9 @@ public Result addInspection(Long eid, Long uid, Http.Request request) {
exam
.getChildren()
.stream()
.filter(
c ->
c.hasState(Exam.State.REVIEW, Exam.State.STUDENT_STARTED, Exam.State.REVIEW_STARTED) &&
!isInspectorOf(recipient, c)
.filter(c ->
c.hasState(Exam.State.REVIEW, Exam.State.STUDENT_STARTED, Exam.State.REVIEW_STARTED) &&
!isInspectorOf(recipient, c)
)
.forEach(c -> {
ExamInspection i = new ExamInspection();
Expand All @@ -114,7 +113,8 @@ private static boolean isInspectorOf(User user, Exam exam) {

@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result getExamInspections(Long id) {
Set<ExamInspection> inspections = DB.find(ExamInspection.class)
Set<ExamInspection> inspections = DB
.find(ExamInspection.class)
.fetch("user", "id, email, firstName, lastName")
.where()
.eq("exam.id", id)
Expand Down Expand Up @@ -148,8 +148,8 @@ public Result deleteInspection(Long id) {
.getChildren()
.stream()
.filter(c -> c.hasState(Exam.State.REVIEW, Exam.State.STUDENT_STARTED, Exam.State.REVIEW_STARTED))
.forEach(
c -> c.getExamInspections().stream().filter(ei -> ei.getUser().equals(inspector)).forEach(Model::delete)
.forEach(c ->
c.getExamInspections().stream().filter(ei -> ei.getUser().equals(inspector)).forEach(Model::delete)
);
inspection.delete();
return ok();
Expand Down
45 changes: 24 additions & 21 deletions app/controllers/ExamMaterialController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ public Result createMaterial(Http.Request request) {
@Authenticated
@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result listMaterials(Http.Request request) {
Set<ExamMaterial> materials = DB.find(ExamMaterial.class)
Set<ExamMaterial> materials = DB
.find(ExamMaterial.class)
.where()
.eq("creator", request.attrs().get(Attrs.AUTHENTICATED_USER))
.findSet();
Expand Down Expand Up @@ -101,32 +102,34 @@ private Optional<Result> getOwnershipError(ExamMaterial em, User user) {
public Result addMaterialForSection(Long sectionId, Long materialId, Http.Request request) {
ExamMaterial em = DB.find(ExamMaterial.class, materialId);
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
return getOwnershipError(em, user).orElseGet(() -> {
Optional<ExamSection> oes = getSection(sectionId, user);
if (oes.isPresent()) {
ExamSection es = oes.get();
es.getExamMaterials().add(em);
es.update();
return ok();
}
return notFound();
});
return getOwnershipError(em, user)
.orElseGet(() -> {
Optional<ExamSection> oes = getSection(sectionId, user);
if (oes.isPresent()) {
ExamSection es = oes.get();
es.getExamMaterials().add(em);
es.update();
return ok();
}
return notFound();
});
}

@Authenticated
@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result removeMaterialFromSection(Long sectionId, Long materialId, Http.Request request) {
ExamMaterial em = DB.find(ExamMaterial.class, materialId);
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
return getOwnershipError(em, user).orElseGet(() -> {
Optional<ExamSection> oes = getSection(sectionId, user);
if (oes.isPresent()) {
ExamSection es = oes.get();
es.getExamMaterials().remove(em);
es.update();
return ok();
}
return notFound();
});
return getOwnershipError(em, user)
.orElseGet(() -> {
Optional<ExamSection> oes = getSection(sectionId, user);
if (oes.isPresent()) {
ExamSection es = oes.get();
es.getExamMaterials().remove(em);
es.update();
return ok();
}
return notFound();
});
}
}
79 changes: 42 additions & 37 deletions app/controllers/ExamRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ public ExamRecordController(
@Transactional
public Result addExamRecord(Http.Request request) {
DynamicForm df = formFactory.form().bindFromRequest(request);
final Optional<Exam> optionalExam = DB.find(Exam.class)
final Optional<Exam> optionalExam = DB
.find(Exam.class)
.fetch("parent")
.fetch("parent.creator")
.fetch("examSections.sectionQuestions.question")
Expand All @@ -106,42 +107,45 @@ public Result addExamRecord(Http.Request request) {
}
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
Exam exam = optionalExam.get();
return validateExamState(exam, true, user).orElseGet(() -> {
exam.setState(Exam.State.GRADED_LOGGED);
exam.update();
ExamParticipation participation = DB.find(ExamParticipation.class)
.fetch("user")
.where()
.eq("exam.id", exam.getId())
.findOne();
if (participation == null) {
return notFound();
}
return validateExamState(exam, true, user)
.orElseGet(() -> {
exam.setState(Exam.State.GRADED_LOGGED);
exam.update();
ExamParticipation participation = DB
.find(ExamParticipation.class)
.fetch("user")
.where()
.eq("exam.id", exam.getId())
.findOne();
if (participation == null) {
return notFound();
}

ExamRecord record = createRecord(exam, participation);
ExamScore score = createScore(record, participation.getEnded());
score.save();
record.setExamScore(score);
record.save();
actor
.scheduler()
.scheduleOnce(
Duration.create(1, TimeUnit.SECONDS),
() -> {
emailComposer.composeInspectionReady(exam.getCreator(), user, exam);
logger.info("Inspection ready notification email sent to {}", user.getEmail());
},
actor.dispatcher()
);
return ok();
});
ExamRecord record = createRecord(exam, participation);
ExamScore score = createScore(record, participation.getEnded());
score.save();
record.setExamScore(score);
record.save();
actor
.scheduler()
.scheduleOnce(
Duration.create(1, TimeUnit.SECONDS),
() -> {
emailComposer.composeInspectionReady(exam.getCreator(), user, exam);
logger.info("Inspection ready notification email sent to {}", user.getEmail());
},
actor.dispatcher()
);
return ok();
});
}

@Authenticated
@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result registerExamWithoutRecord(Http.Request request) {
DynamicForm df = formFactory.form().bindFromRequest(request);
final Optional<Exam> optionalExam = DB.find(Exam.class)
final Optional<Exam> optionalExam = DB
.find(Exam.class)
.fetch("languageInspection")
.fetch("parent")
.fetch("parent.creator")
Expand All @@ -153,13 +157,14 @@ public Result registerExamWithoutRecord(Http.Request request) {
}
Exam exam = optionalExam.get();
User user = request.attrs().get(Attrs.AUTHENTICATED_USER);
return validateExamState(exam, false, user).orElseGet(() -> {
exam.setState(Exam.State.GRADED_LOGGED);
exam.setGrade(null);
exam.setGradeless(true);
exam.update();
return ok();
});
return validateExamState(exam, false, user)
.orElseGet(() -> {
exam.setState(Exam.State.GRADED_LOGGED);
exam.setGrade(null);
exam.setGradeless(true);
exam.update();
return ok();
});
}

@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
Expand Down
18 changes: 12 additions & 6 deletions app/controllers/ExaminationEventController.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ private int getParticipantUpperBound(DateTime start, DateTime end, Long id) {
}

private boolean isWithinMaintenancePeriod(Interval interval) {
return DB.find(MaintenancePeriod.class)
return DB
.find(MaintenancePeriod.class)
.findSet()
.stream()
.map(p -> new Interval(p.getStartsAt(), p.getEndsAt()))
Expand Down Expand Up @@ -166,7 +167,8 @@ public Result insertExaminationEvent(Long eid, Http.Request request) {
@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result updateExaminationEvent(Long eid, Long eecid, Http.Request request) {
Exam exam = DB.find(Exam.class, eid);
Optional<ExaminationEventConfiguration> oeec = DB.find(ExaminationEventConfiguration.class)
Optional<ExaminationEventConfiguration> oeec = DB
.find(ExaminationEventConfiguration.class)
.where()
.idEq(eecid)
.eq("exam.id", eid)
Expand Down Expand Up @@ -232,7 +234,8 @@ public Result updateExaminationEvent(Long eid, Long eecid, Http.Request request)

@Restrict({ @Group("TEACHER"), @Group("ADMIN") })
public Result removeExaminationEvent(Long eid, Long eeid) {
Optional<ExaminationEventConfiguration> oeec = DB.find(ExaminationEventConfiguration.class)
Optional<ExaminationEventConfiguration> oeec = DB
.find(ExaminationEventConfiguration.class)
.where()
.idEq(eeid)
.eq("exam.id", eid)
Expand All @@ -247,7 +250,8 @@ public Result removeExaminationEvent(Long eid, Long eeid) {
}
eec.delete();
// Check if we can delete the event altogether (in case no configs are using it)
Set<ExaminationEventConfiguration> configs = DB.find(ExaminationEventConfiguration.class)
Set<ExaminationEventConfiguration> configs = DB
.find(ExaminationEventConfiguration.class)
.where()
.eq("examinationEvent", eec.getExaminationEvent())
.findSet();
Expand Down Expand Up @@ -303,7 +307,8 @@ public Result listExaminationEvents(Optional<String> start, Optional<String> end
PathProperties pp = PathProperties.parse(
"(*, exam(*, course(*), examOwners(*)), examinationEvent(*), examEnrolments(*))"
);
ExpressionList<ExaminationEventConfiguration> query = DB.find(ExaminationEventConfiguration.class)
ExpressionList<ExaminationEventConfiguration> query = DB
.find(ExaminationEventConfiguration.class)
.apply(pp)
.where();
if (start.isPresent()) {
Expand All @@ -323,7 +328,8 @@ public Result listOverlappingExaminationEvents(String start, Integer duration) {
PathProperties pp = PathProperties.parse("(*, examinationEventConfiguration(exam(id, duration)))");
DateTime startDate = DateTime.parse(start, ISODateTimeFormat.dateTimeParser());
DateTime endDate = startDate.plusMinutes(duration);
Set<ExaminationEvent> events = DB.find(ExaminationEvent.class)
Set<ExaminationEvent> events = DB
.find(ExaminationEvent.class)
.where()
.le("start", endDate)
.findSet()
Expand Down
Loading

0 comments on commit 7c8a970

Please sign in to comment.