Skip to content

Commit

Permalink
explicitly type unpacked optional api instead of using var-identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ole-ve committed Feb 16, 2025
1 parent 85aa983 commit a4543fa
Show file tree
Hide file tree
Showing 31 changed files with 52 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public boolean isAllowedToCreateOrOverrideResult(Result existingResult, Exercise
// Tutors can assess exam exercises only after the last student has finished the exam and before the publishing result date
if (isExamMode && !isAtLeastInstructor) {
final Exam exam = exercise.getExerciseGroup().getExam();
var api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
ExamDateApi api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
ZonedDateTime latestExamDueDate = api.getLatestIndividualExamEndDate(exam.getId());
if (latestExamDueDate.isAfter(ZonedDateTime.now()) || (exam.getPublishResultsDate() != null && exam.getPublishResultsDate().isBefore(ZonedDateTime.now()))) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public Complaint createComplaint(ComplaintRequestDTO complaintRequest, Optional<

// checking if it is allowed to create a complaint
if (examId.isPresent()) {
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
final Exam exam = api.findByIdElseThrow(examId.get());
final Set<User> instructors = userRepository.getInstructors(exam.getCourse());
boolean examTestRun = instructors.stream().anyMatch(instructor -> instructor.getLogin().equals(principal.getName()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private void filterSensitiveFeedbackInCourseExercise(Participation participation
}

private void filterSensitiveFeedbacksInExamExercise(Participation participation, Collection<Result> results, Exercise exercise) {
var api = studentExamApi.orElseThrow(() -> new ApiNotPresentException(StudentExamApi.class, PROFILE_CORE));
StudentExamApi api = studentExamApi.orElseThrow(() -> new ApiNotPresentException(StudentExamApi.class, PROFILE_CORE));
Exam exam = exercise.getExerciseGroup().getExam();
boolean shouldResultsBePublished = exam.resultsPublished();
if (!shouldResultsBePublished && exam.isTestExam() && participation instanceof StudentParticipation studentParticipation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public BonusResource(BonusService bonusService, BonusRepository bonusRepository,
@EnforceAtLeastStudent
public ResponseEntity<Bonus> getBonusForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestParam(required = false) boolean includeSourceGradeSteps) {
log.debug("REST request to get bonus for exam: {}", examId);
var api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
ExamAccessApi api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
api.checkCourseAndExamAccessForStudentElseThrow(courseId, examId);

var bonus = bonusRepository.findAllByBonusToExamId(examId).stream().findAny().orElseThrow(() -> new EntityNotFoundException("BonusToGradingScale exam", examId));
Expand Down Expand Up @@ -142,7 +142,7 @@ public ResponseEntity<BonusExampleDTO> calculateGradeWithBonus(@PathVariable Lon
@RequestParam Double calculationSign, @RequestParam Double bonusToPoints, @RequestParam Long sourceGradingScaleId, @RequestParam Double sourcePoints) {

// TODO: Add auth and validation and authorize to USER role. Currently enabled only to ADMINs for testing.
var api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
ExamAccessApi api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
api.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);

var bonusToGradingScale = gradingScaleRepository.findWithEagerBonusFromByExamId(examId).orElseThrow();
Expand Down Expand Up @@ -172,7 +172,7 @@ public ResponseEntity<Bonus> createBonusForExam(@PathVariable Long courseId, @Pa
throw new BadRequestAlertException("A new bonus cannot already have an ID", ENTITY_NAME, "idexists");
}

var api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
ExamAccessApi api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
api.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);

GradingScale sourceGradingScaleFromDb = gradingScaleRepository.findById(bonus.getSourceGradingScale().getId()).orElseThrow();
Expand Down Expand Up @@ -239,7 +239,7 @@ public ResponseEntity<Bonus> updateBonus(@PathVariable Long courseId, @PathVaria
throw new ConflictException("The updatedBonus id in the body and path do not match", ENTITY_NAME, "bonusIdMismatch");
}

var api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
ExamAccessApi api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
api.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);

Bonus oldBonus = bonusRepository.findByIdElseThrow(updatedBonus.getId());
Expand Down Expand Up @@ -289,7 +289,7 @@ private void checkBonusAppliesToExam(Bonus bonus, Long examId) {
@EnforceAtLeastInstructor
public ResponseEntity<Void> deleteBonus(@PathVariable Long courseId, @PathVariable Long examId, @PathVariable Long bonusId) {
log.debug("REST request to delete the bonus: {}", bonusId);
var api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
ExamAccessApi api = examAccessApi.orElseThrow(() -> new ApiNotPresentException(ExamAccessApi.class, PROFILE_CORE));
api.checkCourseAndExamAccessForInstructorElseThrow(courseId, examId);
Bonus bonus = bonusRepository.findByIdElseThrow(bonusId);
checkBonusAppliesToExam(bonus, examId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public ResponseEntity<GradeStepsDTO> getAllGradeStepsForCourse(@PathVariable Lon
@EnforceAtLeastStudent
public ResponseEntity<GradeStepsDTO> getAllGradeStepsForExam(@PathVariable Long courseId, @PathVariable Long examId) {
log.debug("REST request to get all grade steps for exam: {}", examId);
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

User user = userRepository.getUserWithGroupsAndAuthorities();
Course course = courseRepository.findByIdElseThrow(courseId);
Expand Down Expand Up @@ -216,7 +216,7 @@ else if (plagiarismCaseRepository.findByCourseIdAndStudentId(courseId, user.getI
@EnforceAtLeastStudent
public ResponseEntity<GradeDTO> getGradeStepByPercentageForExam(@PathVariable Long courseId, @PathVariable Long examId, @RequestParam Double gradePercentage) {
log.debug("REST request to get grade step for grade percentage {} for exam: {}", gradePercentage, examId);
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

User user = userRepository.getUserWithGroupsAndAuthorities();
Course course = courseRepository.findByIdElseThrow(courseId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ else if (gradingScale.getId() != null) {
public ResponseEntity<GradingScale> createGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId, @Valid @RequestBody GradingScale gradingScale)
throws URISyntaxException {
log.debug("REST request to create a grading scale for exam: {}", examId);
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

Course course = courseRepository.findByIdElseThrow(courseId);
Optional<GradingScale> existingGradingScale = gradingScaleRepository.findByExamId(examId);
Expand Down Expand Up @@ -230,7 +230,7 @@ public ResponseEntity<GradingScale> updateGradingScaleForCourse(@PathVariable Lo
@EnforceAtLeastInstructor
public ResponseEntity<GradingScale> updateGradingScaleForExam(@PathVariable Long courseId, @PathVariable Long examId, @Valid @RequestBody GradingScale gradingScale) {
log.debug("REST request to update a grading scale for exam: {}", examId);
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

Course course = courseRepository.findByIdElseThrow(courseId);
Exam exam = api.findByIdElseThrow(examId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ResponseEntity<List<ScoreDTO>> getScoresOfCourse(@PathVariable Long cours
public ResponseEntity<List<ScoreDTO>> getScoresOfExam(@PathVariable Long examId) {
long start = System.currentTimeMillis();
log.debug("REST request to get exam scores for exam : {}", examId);
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

Exam exam = api.findByIdWithExamUsersExerciseGroupsAndExercisesElseThrow(examId);
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.INSTRUCTOR, exam.getCourse(), null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public ResponseEntity<Result> createResultForExternalSubmission(@PathVariable Lo
}
else {
Exam exam = exercise.getExerciseGroup().getExam();
var api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
ExamDateApi api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
ZonedDateTime latestIndividualExamEndDate = api.getLatestIndividualExamEndDate(exam);
if (latestIndividualExamEndDate == null || ZonedDateTime.now().isBefore(latestIndividualExamEndDate)) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionBeforeDueDate",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ private void broadcastNewResultToParticipants(StudentParticipation studentPartic
final var exercise = studentParticipation.getExercise();
boolean isWorkingPeriodOver;
if (exercise.isExamExercise()) {
var api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
ExamDateApi api = examDateApi.orElseThrow(() -> new ApiNotPresentException(ExamDateApi.class, PROFILE_CORE));
isWorkingPeriodOver = api.isIndividualExerciseWorkingPeriodOver(exercise.getExam(), studentParticipation);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ public void recalculateMetrics() {
if (!scheduledMetricsEnabled) {
return;
}
var api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));
ExamMetricsApi api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));

var startDate = System.currentTimeMillis();

Expand Down Expand Up @@ -601,7 +601,7 @@ public void updatePublicArtemisMetrics() {
return;
}

var api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));
ExamMetricsApi api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));
final long startDate = System.currentTimeMillis();

// The authorization object has to be set because this method is not called by a user but by the scheduler
Expand Down Expand Up @@ -659,7 +659,7 @@ private void updateStudentsCourseMultiGauge(List<Course> activeCourses) {
}

private void updateStudentsExamMultiGauge(List<Exam> examsInActiveCourses, List<Course> courses) {
var api = studentExamApi.orElseThrow(() -> new ApiNotPresentException(StudentExamApi.class, PROFILE_CORE));
StudentExamApi api = studentExamApi.orElseThrow(() -> new ApiNotPresentException(StudentExamApi.class, PROFILE_CORE));
// A mutable list is required here because otherwise the values can not be updated correctly
final List<MultiGauge.Row<?>> gauges = examsInActiveCourses.stream().map(exam -> {
final Tags tags = getExamMetricTags(courses, exam);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private boolean allowSubscription(@Nullable Principal principal, String destinat

var examId = getExamIdFromExamRootDestination(destination);
if (examId.isPresent()) {
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
var exam = api.findByIdElseThrow(examId.get());
return authorizationCheckService.isAtLeastInstructorInCourse(login, exam.getCourse().getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ public Set<Course> findAllActiveForUser(User user) {
* @return an unmodifiable list of all courses including exercises for the user
*/
public Set<Course> findAllActiveWithExercisesForUser(User user) {
var api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamMetricsApi.class, PROFILE_CORE));
ExamMetricsApi api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamMetricsApi.class, PROFILE_CORE));

long start = System.nanoTime();

Expand Down Expand Up @@ -490,7 +490,7 @@ public Set<Course> findAllOnlineCoursesForPlatformForUser(String registrationId,
* @return the course deletion summary
*/
public CourseDeletionSummaryDTO getDeletionSummary(Course course) {
var api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamMetricsApi.class, PROFILE_CORE));
ExamMetricsApi api = examMetricsApi.orElseThrow(() -> new ApiNotPresentException(ExamMetricsApi.class, PROFILE_CORE));

Long courseId = course.getId();

Expand Down Expand Up @@ -573,7 +573,7 @@ private void deleteGradingScaleOfCourse(Course course) {

private void deleteExamsOfCourse(Course course) {
var deletionApi = examDeletionApi.orElseThrow(() -> new ApiNotPresentException(ExamDeletionApi.class, PROFILE_CORE));
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
// delete the Exams
List<Exam> exams = api.findByCourseId(course.getId());
for (Exam exam : exams) {
Expand Down Expand Up @@ -634,7 +634,7 @@ private void deleteFaqsOfCourse(Course course) {
public Course retrieveCourseOverExerciseGroupOrCourseId(Exercise exercise) {

if (exercise.isExamExercise()) {
var api = exerciseGroupApi.orElseThrow(() -> new ApiNotPresentException(ExerciseGroupApi.class, PROFILE_CORE));
ExerciseGroupApi api = exerciseGroupApi.orElseThrow(() -> new ApiNotPresentException(ExerciseGroupApi.class, PROFILE_CORE));
ExerciseGroup exerciseGroup = api.findByIdElseThrow(exercise.getExerciseGroup().getId());
exercise.setExerciseGroup(exerciseGroup);
return exerciseGroup.getExam().getCourse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ private Optional<Path> zipExportedExercises(Path outputDir, List<String> exportE
* @return Path to the zip file
*/
public Optional<Path> exportExam(Exam exam, Path outputDir, List<String> exportErrors) {
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

// Used for sending export progress notifications to instructors
var notificationTopic = "/topic/exams/" + exam.getId() + "/export";
Expand Down Expand Up @@ -235,7 +235,7 @@ public Optional<Path> exportExam(Exam exam, Path outputDir, List<String> exportE
* @return list of zip files
*/
private List<Path> exportCourseAndExamExercises(String notificationTopic, Course course, String outputDir, List<String> exportErrors, List<ArchivalReportEntry> reportData) {
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

notifyUserAboutExerciseExportState(notificationTopic, CourseExamExportState.RUNNING, List.of("Preparing to export course exercises and exams..."), null);

Expand Down Expand Up @@ -310,7 +310,7 @@ private List<Path> exportCourseExercises(String notificationTopic, Course course
*/
private List<Path> exportExams(String notificationTopic, List<Exam> exams, String outputDir, int progress, int totalExerciseCount, List<String> exportErrors,
List<ArchivalReportEntry> reportData) {
var api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));
ExamRepositoryApi api = examRepositoryApi.orElseThrow(() -> new ApiNotPresentException(ExamRepositoryApi.class, PROFILE_CORE));

Optional<Exam> firstExam = exams.stream().findFirst();
if (firstExam.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void createExportForExams(long userId, Path workingDirectory) throws IOEx
return;
}

var api = studentExamApi.get();
StudentExamApi api = studentExamApi.get();
Map<Course, List<StudentExam>> studentExamsPerCourse = api.findStudentExamsByCourseForUserId(userId);

for (var entry : studentExamsPerCourse.entrySet()) {
Expand Down Expand Up @@ -121,7 +121,7 @@ private void createStudentExamExport(StudentExam studentExam, Path examWorkingDi
* @param examWorkingDir the directory in which the results should be stored
*/
private void addExamScores(StudentExam studentExam, Path examWorkingDir) throws IOException {
var api = examApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));
ExamApi api = examApi.orElseThrow(() -> new ApiNotPresentException(ExamApi.class, PROFILE_CORE));
var studentExamGrade = api.getStudentExamGradeForDataExport(studentExam);
var studentResult = studentExamGrade.studentResult();
var gradingScale = gradingScaleRepository.findByExamId(studentExam.getExam().getId());
Expand Down
Loading

0 comments on commit a4543fa

Please sign in to comment.