Skip to content

Commit

Permalink
CSCEXAM-000 Upgrade to Angular 188
Browse files Browse the repository at this point in the history
  • Loading branch information
lupari committed Aug 13, 2024
1 parent afdc916 commit dcf5406
Show file tree
Hide file tree
Showing 96 changed files with 10,934 additions and 10,103 deletions.
23 changes: 10 additions & 13 deletions app/controllers/admin/ReportController.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ private <T> ExpressionList<T> applyFilters(

@Restrict({ @Group("ADMIN") })
public Result getExamParticipations(Optional<String> dept, Optional<String> start, Optional<String> end) {
List<ExamEnrolment> enrolments = DB
.find(ExamEnrolment.class)
List<ExamEnrolment> enrolments = DB.find(ExamEnrolment.class)
.fetch("exam", "id, created")
.fetch("externalExam", "id, started")
.where()
Expand Down Expand Up @@ -184,8 +183,7 @@ private boolean applyEnrolmentFilter(

@Restrict({ @Group("ADMIN") })
public Result getPublishedExams(Optional<String> dept, Optional<String> start, Optional<String> end) {
ExpressionList<Exam> query = DB
.find(Exam.class)
ExpressionList<Exam> query = DB.find(Exam.class)
.fetch("course", "code")
.where()
.isNull("parent")
Expand All @@ -210,15 +208,14 @@ public Result getPublishedExams(Optional<String> dept, Optional<String> start, O
@Restrict({ @Group("ADMIN") })
public Result getReservations(Optional<String> dept, Optional<String> start, Optional<String> end) {
ExpressionList<Reservation> query = DB.find(Reservation.class).where();
query =
applyFilters(
query,
"enrolment.exam.course",
"startAt",
dept.orElse(null),
start.orElse(null),
end.orElse(null)
);
query = applyFilters(
query,
"enrolment.exam.course",
"startAt",
dept.orElse(null),
start.orElse(null),
end.orElse(null)
);
return ok(query.findList());
}

Expand Down
9 changes: 4 additions & 5 deletions app/controllers/admin/SettingsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,7 @@ public CompletionStage<Result> getMaturityInstructions(String lang, Optional<Str
return wrapAsPromise(badRequest("Language not supported"));
}
if (hash.isPresent()) {
ExamEnrolment enrolment = DB
.find(ExamEnrolment.class)
ExamEnrolment enrolment = DB.find(ExamEnrolment.class)
.where()
.eq("externalExam.hash", hash.get())
.findOne();
Expand Down Expand Up @@ -323,8 +322,8 @@ public Result getByodMaxParticipants() {
}

private URL parseExternalUrl(String reservationRef) throws MalformedURLException {
return URI
.create(configReader.getIopHost() + String.format("/api/enrolments/%s/instructions", reservationRef))
.toURL();
return URI.create(
configReader.getIopHost() + String.format("/api/enrolments/%s/instructions", reservationRef)
).toURL();
}
}
87 changes: 37 additions & 50 deletions app/controllers/admin/StatisticsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ public class StatisticsController extends BaseController {

@Restrict({ @Group("ADMIN") })
public Result getStudents() {
List<User> students = DB
.find(User.class)
List<User> students = DB.find(User.class)
.select("id, firstName, lastName")
.where()
.eq("roles.name", "STUDENT")
Expand All @@ -54,8 +53,7 @@ public Result getStudents() {

@Restrict({ @Group("ADMIN") })
public Result getExamNames() {
List<Exam> exams = DB
.find(Exam.class)
List<Exam> exams = DB.find(Exam.class)
.select("id, name")
.fetch("course", "id, name, code")
.where()
Expand Down Expand Up @@ -138,8 +136,7 @@ public Result getExam(Long id, String reportType) throws IOException {
public Result getTeacherExamsByDate(Long uid, String from, String to) throws IOException {
final DateTime start = DateTime.parse(from, DTF);
final DateTime end = DateTime.parse(to, DTF);
List<Exam> exams = DB
.find(Exam.class)
List<Exam> exams = DB.find(Exam.class)
.fetch("creator")
.fetch("examType")
.fetch("course")
Expand Down Expand Up @@ -184,12 +181,11 @@ public Result getTeacherExamsByDate(Long uid, String from, String to) throws IOE
data[1] = ISODateTimeFormat.date().print(new DateTime(parent.getCreated()));
data[2] = parent.getState().toString();
data[3] = parent.getCourse().getCode();
data[4] =
String.format(
"%s - %s",
ISODateTimeFormat.date().print(new DateTime(parent.getPeriodStart())),
ISODateTimeFormat.date().print(new DateTime(parent.getPeriodEnd()))
);
data[4] = String.format(
"%s - %s",
ISODateTimeFormat.date().print(new DateTime(parent.getPeriodStart())),
ISODateTimeFormat.date().print(new DateTime(parent.getPeriodEnd()))
);
data[5] = parent.getCourse().getCredits() == null ? "" : Double.toString(parent.getCourse().getCredits());
data[6] = parent.getExamType().getType();
data[7] = Integer.toString(inReview);
Expand All @@ -206,8 +202,7 @@ public Result getTeacherExamsByDate(Long uid, String from, String to) throws IOE

@Restrict({ @Group("ADMIN") })
public Result getExamEnrollments(Long id) throws IOException {
Exam proto = DB
.find(Exam.class)
Exam proto = DB.find(Exam.class)
.fetch("examEnrolments")
.fetch("examEnrolments.user")
.fetch("examEnrolments.reservation")
Expand All @@ -228,10 +223,9 @@ public Result getExamEnrollments(Long id) throws IOException {
data[0] = String.format("%s %s", e.getUser().getFirstName(), e.getUser().getLastName());
data[1] = forceNotNull(e.getUser().getIdentifier());
data[2] = e.getUser().getEppn();
data[3] =
e.getReservation() == null
? ""
: ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(e.getReservation().getStartAt()));
data[3] = e.getReservation() == null
? ""
: ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(e.getReservation().getStartAt()));
data[4] = ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(e.getEnrolledOn()));
Row dataRow = sheet.createRow(proto.getExamEnrolments().indexOf(e) + 1);
for (int i = 0; i < data.length; ++i) {
Expand All @@ -257,8 +251,7 @@ private String parse(Supplier<String> supplier) {
public Result getReviewsByDate(String from, String to) throws IOException {
final DateTime start = DateTime.parse(from, DTF);
final DateTime end = DateTime.parse(to, DTF);
List<Exam> exams = DB
.find(Exam.class)
List<Exam> exams = DB.find(Exam.class)
.fetch("course")
.where()
.between("gradedTime", start, end)
Expand Down Expand Up @@ -292,10 +285,9 @@ public Result getReviewsByDate(String from, String to) throws IOException {
data[2] = e.getCourse().getCode();
data[3] = ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(e.getCreated()));
data[4] = ISODateTimeFormat.dateTimeNoMillis().print(new DateTime(e.getGradedTime()));
data[5] =
parse(() ->
String.format("%s %s", e.getGradedByUser().getFirstName(), e.getGradedByUser().getLastName())
);
data[5] = parse(() ->
String.format("%s %s", e.getGradedByUser().getFirstName(), e.getGradedByUser().getLastName())
);

data[6] = e.getCourse().getCredits() == null ? "" : Double.toString(e.getCourse().getCredits()); // custom credits?
data[7] = parse(() -> e.getGrade().getName());
Expand All @@ -313,8 +305,7 @@ public Result getReservationsForRoomByDate(Long roomId, String from, String to)
final DateTime start = DateTime.parse(from, DTF);
final DateTime end = DateTime.parse(to, DTF);

List<ExamEnrolment> enrolments = DB
.find(ExamEnrolment.class)
List<ExamEnrolment> enrolments = DB.find(ExamEnrolment.class)
.fetch("user")
.fetch("exam")
.where()
Expand Down Expand Up @@ -348,26 +339,24 @@ public Result getReservationsForRoomByDate(Long roomId, String from, String to)
addHeader(sheet, headers);

for (ExamEnrolment e : enrolments) {
String[] data = Arrays
.asList(
Long.toString(e.getId()),
ISODateTimeFormat.date().print(new DateTime(e.getEnrolledOn())),
Long.toString(e.getUser().getId()),
e.getUser().getFirstName(),
e.getUser().getLastName(),
Long.toString(e.getExam().getId()),
e.getExam().getName(),
Long.toString(e.getReservation().getId()),
ISODateTimeFormat.dateTime().print(new DateTime(e.getReservation().getStartAt())),
ISODateTimeFormat.dateTime().print(new DateTime(e.getReservation().getEndAt())),
Long.toString(e.getReservation().getMachine().getId()),
e.getReservation().getMachine().getName(),
e.getReservation().getMachine().getIpAddress(),
Long.toString(e.getReservation().getMachine().getRoom().getId()),
e.getReservation().getMachine().getRoom().getName(),
e.getReservation().getMachine().getRoom().getRoomCode()
)
.toArray(new String[0]);
String[] data = Arrays.asList(
Long.toString(e.getId()),
ISODateTimeFormat.date().print(new DateTime(e.getEnrolledOn())),
Long.toString(e.getUser().getId()),
e.getUser().getFirstName(),
e.getUser().getLastName(),
Long.toString(e.getExam().getId()),
e.getExam().getName(),
Long.toString(e.getReservation().getId()),
ISODateTimeFormat.dateTime().print(new DateTime(e.getReservation().getStartAt())),
ISODateTimeFormat.dateTime().print(new DateTime(e.getReservation().getEndAt())),
Long.toString(e.getReservation().getMachine().getId()),
e.getReservation().getMachine().getName(),
e.getReservation().getMachine().getIpAddress(),
Long.toString(e.getReservation().getMachine().getRoom().getId()),
e.getReservation().getMachine().getRoom().getName(),
e.getReservation().getMachine().getRoom().getRoomCode()
).toArray(new String[0]);
createRow(sheet, data, enrolments, e);
}
IntStream.range(0, headers.length + 1).forEach(i -> sheet.autoSizeColumn(i, true));
Expand All @@ -381,8 +370,7 @@ public Result reportAllExams(String from, String to) throws IOException {
final DateTime start = DateTime.parse(from, DTF);
final DateTime end = DateTime.parse(to, DTF);

List<ExamParticipation> participations = DB
.find(ExamParticipation.class)
List<ExamParticipation> participations = DB.find(ExamParticipation.class)
.fetch("exam")
.where()
.gt("started", start)
Expand Down Expand Up @@ -422,8 +410,7 @@ public Result reportStudentActivity(Long studentId, String from, String to) thro
dataRow.createCell(index++).setCellValue(student.getEmail());
dataRow.createCell(index).setCellValue(student.getLanguage().getCode());

List<ExamParticipation> participations = DB
.find(ExamParticipation.class)
List<ExamParticipation> participations = DB.find(ExamParticipation.class)
.fetch("exam")
.fetch("reservation")
.fetch("reservation.externalReservation")
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/assessment/ExamAnswerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ 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
10 changes: 5 additions & 5 deletions app/controllers/assessment/ExamInspectionController.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,10 @@ 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 @@ -102,8 +103,7 @@ 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
79 changes: 37 additions & 42 deletions app/controllers/assessment/ExamRecordController.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ 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 @@ -96,45 +95,42 @@ 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 @@ -146,14 +142,13 @@ 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
Loading

0 comments on commit dcf5406

Please sign in to comment.