use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ProgrammingExerciseScheduleService method scheduleBuildAndTestAfterDueDateForParticipation.
private void scheduleBuildAndTestAfterDueDateForParticipation(ProgrammingExerciseStudentParticipation participation) {
scheduleService.scheduleParticipationTask(participation, ParticipationLifecycle.BUILD_AND_TEST_AFTER_DUE_DATE, () -> {
final ProgrammingExercise exercise = participation.getProgrammingExercise();
SecurityUtils.setAuthorizationObject();
try {
log.info("Invoking scheduled task for participation {} in programming exercise with id {}.", participation.getId(), exercise.getId());
programmingSubmissionService.triggerBuildForParticipations(List.of(participation));
} catch (EntityNotFoundException ex) {
log.error("Programming participation with id {} in exercise {} is no longer available in database for use in scheduled task.", participation.getId(), exercise.getId());
}
});
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ProgrammingExerciseScheduleService method invokeOperationOnAllParticipationsThatSatisfy.
/**
* Invokes the given <code>operation</code> on all student participations that satisfy the <code>condition</code>-{@link Predicate}.
* <p>
*
* @param programmingExerciseId the programming exercise whose participations should be processed
* @param operation the operation to perform
* @param condition the condition that tests whether to invoke the operation on a participation
* @param operationName the name of the operation, this is only used for logging
* @return a list containing all participations for which the operation has failed with an exception
* @throws EntityNotFoundException if the programming exercise can't be found.
*/
private List<ProgrammingExerciseStudentParticipation> invokeOperationOnAllParticipationsThatSatisfy(Long programmingExerciseId, BiConsumer<ProgrammingExercise, ProgrammingExerciseStudentParticipation> operation, Predicate<ProgrammingExerciseStudentParticipation> condition, String operationName) {
log.info("Invoking (scheduled) task '{}' for programming exercise with id {}.", operationName, programmingExerciseId);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithEagerStudentParticipationsById(programmingExerciseId).orElseThrow(() -> new EntityNotFoundException("ProgrammingExercise", programmingExerciseId));
List<ProgrammingExerciseStudentParticipation> failedOperations = new ArrayList<>();
for (StudentParticipation studentParticipation : programmingExercise.getStudentParticipations()) {
ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
try {
if (condition.test(programmingExerciseStudentParticipation)) {
operation.accept(programmingExercise, programmingExerciseStudentParticipation);
}
} catch (Exception e) {
log.error(String.format("'%s' failed for programming exercise with id %d for student repository with participation id %d", operationName, programmingExercise.getId(), studentParticipation.getId()), e);
failedOperations.add(programmingExerciseStudentParticipation);
}
}
return failedOperations;
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class TextUnitResource method getTextUnit.
/**
* GET lectures/:lectureId/text-units/:textUnitId : gets the text unit with the specified id
*
* @param textUnitId the id of the textUnit to retrieve
* @param lectureId the id of the lecture to which the unit belongs
* @return the ResponseEntity with status 200 (OK) and with body the text unit, or with status 404 (Not Found)
*/
@GetMapping("lectures/{lectureId}/text-units/{textUnitId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<TextUnit> getTextUnit(@PathVariable Long textUnitId, @PathVariable Long lectureId) {
log.debug("REST request to get TextUnit : {}", textUnitId);
Optional<TextUnit> optionalTextUnit = textUnitRepository.findById(textUnitId);
if (optionalTextUnit.isEmpty()) {
throw new EntityNotFoundException("TextUnit");
}
TextUnit textUnit = optionalTextUnit.get();
if (textUnit.getLecture() == null || textUnit.getLecture().getCourse() == null || !textUnit.getLecture().getId().equals(lectureId)) {
throw new ConflictException("Input data not valid", ENTITY_NAME, "inputInvalid");
}
authorizationCheckService.checkHasAtLeastRoleForLectureElseThrow(Role.EDITOR, textUnit.getLecture(), null);
return ResponseEntity.ok().body(textUnit);
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class VideoUnitResource method getVideoUnit.
/**
* GET lectures/:lectureId/video-units/:videoUnitId: gets the video unit with the specified id
*
* @param videoUnitId the id of the videoUnit to retrieve
* @param lectureId the id of the lecture to which the unit belongs
* @return the ResponseEntity with status 200 (OK) and with body the video unit, or with status 404 (Not Found)
*/
@GetMapping("lectures/{lectureId}/video-units/{videoUnitId}")
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<VideoUnit> getVideoUnit(@PathVariable Long videoUnitId, @PathVariable Long lectureId) {
log.debug("REST request to get VideoUnit : {}", videoUnitId);
var videoUnit = videoUnitRepository.findById(videoUnitId).orElseThrow(() -> new EntityNotFoundException("VideoUnit", videoUnitId));
if (videoUnit.getLecture() == null || videoUnit.getLecture().getCourse() == null) {
throw new ConflictException("Lecture unit must be associated to a lecture of a course", "VideoUnit", "lectureOrCourseMissing");
}
if (!videoUnit.getLecture().getId().equals(lectureId)) {
throw new ConflictException("Requested lecture unit is not part of the specified lecture", "VideoUnit", "lectureIdMismatch");
}
authorizationCheckService.checkHasAtLeastRoleInCourseElseThrow(Role.EDITOR, videoUnit.getLecture().getCourse(), null);
return ResponseEntity.ok().body(videoUnit);
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ExamRegistrationService method unregisterAllStudentFromExam.
/**
* Unregisters all students from the exam
*
* @param examId the exam for which a student should be unregistered
* @param deleteParticipationsAndSubmission whether the participations and submissions of the student should be deleted
*/
public void unregisterAllStudentFromExam(Long examId, boolean deleteParticipationsAndSubmission) {
var exam = examRepository.findWithRegisteredUsersById(examId).orElseThrow(() -> new EntityNotFoundException("Exam", examId));
// remove all registered students
List<Long> userIds = new ArrayList<>();
exam.getRegisteredUsers().forEach(user -> userIds.add(user.getId()));
List<User> registeredStudentsList = userRepository.findAllById(userIds);
registeredStudentsList.forEach(exam::removeRegisteredUser);
examRepository.save(exam);
// remove all students exams
Set<StudentExam> studentExams = studentExamRepository.findAllWithExercisesByExamId(examId);
studentExams.forEach(studentExam -> removeStudentExam(studentExam, deleteParticipationsAndSubmission));
User currentUser = userRepository.getUserWithGroupsAndAuthorities();
AuditEvent auditEvent = new AuditEvent(currentUser.getLogin(), Constants.REMOVE_ALL_USERS_FROM_EXAM, "exam=" + exam.getTitle());
auditEventRepository.add(auditEvent);
log.info("User {} has removed all users from the exam {} with id {}. This also deleted potentially existing student exams with all its participations and submissions.", currentUser.getLogin(), exam.getTitle(), exam.getId());
}
Aggregations