Skip to content

Commit

Permalink
Merge branch 'dev' into CSCEXAM-1389
Browse files Browse the repository at this point in the history
  • Loading branch information
VirmasaloA authored Jan 9, 2025
2 parents 02e90f6 + 8d35deb commit 59b3438
Showing 21 changed files with 382 additions and 155 deletions.
47 changes: 36 additions & 11 deletions app/controllers/admin/ReportController.java
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
import javax.inject.Inject;
import miscellaneous.excel.ExcelBuilder;
import models.enrolment.ExamEnrolment;
import models.enrolment.Reservation;
import models.exam.Course;
import models.exam.Exam;
import models.facility.ExamRoom;
@@ -228,21 +229,46 @@ 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<ExamEnrolment> query = DB.find(ExamEnrolment.class).where();
query =
applyFilters(
query,
"exam.course",
"reservation.startAt",
dept.orElse(null),
start.orElse(null),
end.orElse(null)
);
query = applyFilters(
query,
"exam.course",
"reservation.startAt",
dept.orElse(null),
start.orElse(null),
end.orElse(null)
);
Set<ExamEnrolment> enrolments = query.findSet();
long noShows = enrolments.stream().filter(ExamEnrolment::isNoShow).count();
long appearances = enrolments.size() - noShows;
return ok(Json.newObject().put("noShows", noShows).put("appearances", appearances));
}

@Restrict({ @Group("ADMIN") })
public Result getIopReservations(Optional<String> dept, Optional<String> start, Optional<String> end) {
ExpressionList<Reservation> query = DB.find(Reservation.class)
.fetch("externalReservation")
.fetch("enrolment")
.where()
.or()
.isNotNull("externalRef")
.isNotNull("externalReservation.orgName")
.endOr();
query = applyFilters(
query,
"examEnrolment.exam.course",
"startAt",
dept.orElse(null),
start.orElse(null),
end.orElse(null)
);
Set<Reservation> reservations = query
.findSet()
.stream()
.filter(r -> r.getExternalOrgName() != null || (r.getExternalReservation() != null))
.collect(Collectors.toSet());
return ok(reservations);
}

@Restrict({ @Group("ADMIN") })
public Result getResponses(Optional<String> dept, Optional<String> start, Optional<String> end) {
ExpressionList<Exam> query = DB.find(Exam.class).where().isNotNull("parent").isNotNull("course");
@@ -272,8 +298,7 @@ public Result getResponses(Optional<String> dept, Optional<String> start, Option
)
)
.count();
JsonNode node = Json
.newObject()
JsonNode node = Json.newObject()
.put("aborted", aborted)
.put("assessed", assessed)
.put("unAssessed", unAssessed);
Original file line number Diff line number Diff line change
@@ -109,6 +109,8 @@ public Result provideReservation(Http.Request request) {
DateTime start = ISODateTimeFormat.dateTimeParser().parseDateTime(node.get("start").asText());
DateTime end = ISODateTimeFormat.dateTimeParser().parseDateTime(node.get("end").asText());
String userEppn = node.get("user").asText();
String orgRef = node.get("orgRef").asText();
String orgName = node.get("orgName").asText();
if (start.isBeforeNow() || end.isBefore(start)) {
return badRequest("invalid dates");
}
@@ -133,6 +135,8 @@ public Result provideReservation(Http.Request request) {
reservation.setStartAt(start);
reservation.setMachine(machine.get());
reservation.setExternalUserRef(userEppn);
reservation.setExternalOrgRef(orgRef);
reservation.setExternalOrgName(orgName);
reservation.save();
PathProperties pp = PathProperties.parse("(*, machine(*, room(*, mailAddress(*))))");

10 changes: 5 additions & 5 deletions app/impl/ExternalCourseHandlerImpl.scala
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@ package impl
import io.ebean.DB
import miscellaneous.config.ConfigReader
import miscellaneous.scala.DbApiHelper
import models._
import models.*
import models.exam.{Course, Grade, GradeScale}
import models.facility.Organisation
import models.user.User
@@ -18,15 +18,15 @@ import play.api.Logging
import play.api.libs.json.{JsValue, Json}
import play.api.libs.ws.{WSClient, WSResponse}
import play.mvc.Http
import validators.ExternalCourseValidator.{CourseUnitInfo, GradeScale => ExtGradeScale}
import validators.ExternalCourseValidator.{CourseUnitInfo, GradeScale as ExtGradeScale}

import java.net._
import java.net.*
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import javax.inject.Inject
import scala.collection.immutable.TreeSet
import scala.concurrent.{ExecutionContext, Future}
import scala.jdk.CollectionConverters._
import scala.jdk.CollectionConverters.*

class ExternalCourseHandlerImpl @Inject (
private val wsClient: WSClient,
@@ -229,7 +229,7 @@ class ExternalCourseHandlerImpl @Inject (
val path = configReader.getString(configPath.getOrElse(""))
if (!path.contains(COURSE_CODE_PLACEHOLDER))
throw new RuntimeException("exam.integration.courseUnitInfo.url is malformed")
val url = path.replace(COURSE_CODE_PLACEHOLDER, courseCode)
val url = path.replace(COURSE_CODE_PLACEHOLDER, URLEncoder.encode(courseCode, StandardCharsets.UTF_8))
URI.create(url).toURL

private def parseUrl(user: User) =
26 changes: 22 additions & 4 deletions app/models/enrolment/Reservation.java
Original file line number Diff line number Diff line change
@@ -55,6 +55,8 @@ public class Reservation extends GeneratedIdentityModel implements Comparable<Re
private String externalRef;

private String externalUserRef;
private String externalOrgRef;
private String externalOrgName;

@OneToOne(cascade = CascadeType.ALL)
private ExternalReservation externalReservation;
@@ -123,10 +125,6 @@ public void setExternalRef(String externalRef) {
this.externalRef = externalRef;
}

public String getExternalUserRef() {
return externalUserRef;
}

public ExternalReservation getExternalReservation() {
return externalReservation;
}
@@ -135,10 +133,30 @@ public void setExternalReservation(ExternalReservation externalReservation) {
this.externalReservation = externalReservation;
}

public String getExternalUserRef() {
return externalUserRef;
}

public void setExternalUserRef(String externalUserRef) {
this.externalUserRef = externalUserRef;
}

public String getExternalOrgRef() {
return externalOrgRef;
}

public void setExternalOrgRef(String externalOrgRef) {
this.externalOrgRef = externalOrgRef;
}

public String getExternalOrgName() {
return externalOrgName;
}

public void setExternalOrgName(String externalOrgName) {
this.externalOrgName = externalOrgName;
}

public Interval toInterval() {
return new Interval(startAt, endAt);
}
11 changes: 11 additions & 0 deletions conf/evolutions/default/135.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- SPDX-FileCopyrightText: 2024 The members of the EXAM Consortium
--
-- SPDX-License-Identifier: EUPL-1.2

# --- !Ups
ALTER TABLE reservation ADD external_org_ref character varying(32);
ALTER TABLE reservation ADD external_org_name character varying(255);

# --- !Downs
ALTER TABLE reservation DROP external_org_ref;
ALTER TABLE reservation DROP external_org_name;
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
@@ -462,6 +462,7 @@ GET /app/reports/participations
GET /app/reports/departments controllers.admin.ReportController.listDepartments
GET /app/reports/exams controllers.admin.ReportController.getPublishedExams(dept: java.util.Optional[String], start: java.util.Optional[String], end: java.util.Optional[String])
GET /app/reports/reservations controllers.admin.ReportController.getReservations(dept: java.util.Optional[String], start: java.util.Optional[String], end: java.util.Optional[String])
GET /app/reports/reservations/iop controllers.admin.ReportController.getIopReservations(dept: java.util.Optional[String], start: java.util.Optional[String], end: java.util.Optional[String])
GET /app/reports/responses controllers.admin.ReportController.getResponses(dept: java.util.Optional[String], start: java.util.Optional[String], end: java.util.Optional[String])
POST /app/reports/questionreport/:id controllers.admin.ReportController.exportExamQuestionScoresAsExcel(id: Long, request: Request)

88 changes: 44 additions & 44 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@
"eslint-plugin-deprecation": "^3.0.0",
"eslint-plugin-no-relative-import-paths": "^1.5.5",
"karma": "^6.4.4",
"lefthook": "^1.6.1",
"lefthook": "^1.8.4",
"prettier": "^3.3.3",
"prettier-plugin-java": "^2.6.4",
"prettier-plugin-organize-imports": "^4.0.0",
2 changes: 2 additions & 0 deletions test/controllers/iop/ExternalCalendarInterfaceTest.java
Original file line number Diff line number Diff line change
@@ -343,6 +343,8 @@ public void testProvideReservation() {
.put("start", ISODateTimeFormat.dateTime().print(start))
.put("end", ISODateTimeFormat.dateTime().print(end))
.put("user", "[email protected]")
.put("orgRef", "1234")
.put("orgName", "1234")
);
assertThat(result.status()).isEqualTo(201);
Reservation reservation = DB.find(Reservation.class).where().eq("externalRef", RESERVATION_REF).findOne();
Loading

0 comments on commit 59b3438

Please sign in to comment.