use of de.tum.in.www1.artemis.domain.participation.StudentParticipation 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.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testRemovingAllStudents.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testRemovingAllStudents() throws Exception {
Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
// Generate student exams
List<StudentExam> studentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
assertThat(studentExams).hasSize(4);
assertThat(exam.getRegisteredUsers()).hasSize(4);
// /courses/{courseId}/exams/{examId}/student-exams/start-exercises
Integer numberOfGeneratedParticipations = request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
assertThat(numberOfGeneratedParticipations).isEqualTo(16);
// Fetch student exams
List<StudentExam> studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).hasSize(4);
List<StudentParticipation> participationList = new ArrayList<>();
Exercise[] exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
for (Exercise value : exercises) {
participationList.addAll(studentParticipationRepository.findByExerciseId(value.getId()));
}
assertThat(participationList).hasSize(16);
// TODO there should be some participation but no submissions unfortunately
// remove all students
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students", HttpStatus.OK);
// Get the exam with all registered users
var params = new LinkedMultiValueMap<String, String>();
params.add("withStudents", "true");
Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
assertThat(storedExam.getRegisteredUsers()).isEmpty();
// Fetch student exams
studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).isEmpty();
// Fetch participations
exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
participationList = new ArrayList<>();
for (Exercise exercise : exercises) {
participationList.addAll(studentParticipationRepository.findByExerciseId(exercise.getId()));
}
assertThat(participationList).hasSize(16);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testDeleteStudent.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testDeleteStudent() throws Exception {
// Create an exam with registered students
Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
var student1 = database.getUserByLogin("student1");
var student2 = database.getUserByLogin("student2");
// Remove student1 from the exam
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student1", HttpStatus.OK);
// Get the exam with all registered users
var params = new LinkedMultiValueMap<String, String>();
params.add("withStudents", "true");
Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
// Ensure that student1 was removed from the exam
assertThat(storedExam.getRegisteredUsers()).doesNotContain(student1);
assertThat(storedExam.getRegisteredUsers()).hasSize(3);
// Create individual student exams
List<StudentExam> generatedStudentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
assertThat(generatedStudentExams).hasSize(storedExam.getRegisteredUsers().size());
// Start the exam to create participations
request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
// Get the student exam of student2
Optional<StudentExam> optionalStudent1Exam = generatedStudentExams.stream().filter(studentExam -> studentExam.getUser().equals(student2)).findFirst();
assertThat(optionalStudent1Exam.get()).isNotNull();
var studentExam2 = optionalStudent1Exam.get();
// explicitly set the user again to prevent issues in the following server call due to the use of SecurityUtils.setAuthorizationObject();
database.changeUser("instructor1");
// Remove student2 from the exam
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student2", HttpStatus.OK);
// Get the exam with all registered users
params = new LinkedMultiValueMap<>();
params.add("withStudents", "true");
storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
// Ensure that student2 was removed from the exam
assertThat(storedExam.getRegisteredUsers()).doesNotContain(student2);
assertThat(storedExam.getRegisteredUsers()).hasSize(2);
// Ensure that the student exam of student2 was deleted
List<StudentExam> studentExams = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExams).hasSameSizeAs(storedExam.getRegisteredUsers()).doesNotContain(studentExam2);
// Ensure that the participations were not deleted
List<StudentParticipation> participationsStudent2 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student2.getId(), studentExam2.getExercises());
assertThat(participationsStudent2).hasSize(studentExam2.getExercises().size());
// Make sure delete also works if so many objects have been created before
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testDeleteStudentWithParticipationsAndSubmissions.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void testDeleteStudentWithParticipationsAndSubmissions() throws Exception {
// Create an exam with registered students
Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
var student1 = database.getUserByLogin("student1");
// Create individual student exams
List<StudentExam> generatedStudentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
// Get the student exam of student1
Optional<StudentExam> optionalStudent1Exam = generatedStudentExams.stream().filter(studentExam -> studentExam.getUser().equals(student1)).findFirst();
assertThat(optionalStudent1Exam.get()).isNotNull();
var studentExam1 = optionalStudent1Exam.get();
// Start the exam to create participations
request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
List<StudentParticipation> participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
assertThat(participationsStudent1).hasSize(studentExam1.getExercises().size());
// explicitly set the user again to prevent issues in the following server call due to the use of SecurityUtils.setAuthorizationObject();
database.changeUser("instructor1");
// Remove student1 from the exam and his participations
var params = new LinkedMultiValueMap<String, String>();
params.add("withParticipationsAndSubmission", "true");
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students/student1", HttpStatus.OK, params);
// Get the exam with all registered users
params = new LinkedMultiValueMap<>();
params.add("withStudents", "true");
Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
// Ensure that student1 was removed from the exam
assertThat(storedExam.getRegisteredUsers()).doesNotContain(student1);
assertThat(storedExam.getRegisteredUsers()).hasSize(3);
// Ensure that the student exam of student1 was deleted
List<StudentExam> studentExams = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExams).hasSameSizeAs(storedExam.getRegisteredUsers()).doesNotContain(studentExam1);
// Ensure that the participations of student1 were deleted
participationsStudent1 = studentParticipationRepository.findByStudentIdAndIndividualExercisesWithEagerSubmissionsResultIgnoreTestRuns(student1.getId(), studentExam1.getExercises());
assertThat(participationsStudent1).isEmpty();
// Make sure delete also works if so many objects have been created before
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ExamIntegrationTest method testRemovingAllStudentsAndParticipations.
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
public void testRemovingAllStudentsAndParticipations() throws Exception {
Exam exam = database.setupExamWithExerciseGroupsExercisesRegisteredStudents(course1);
// Generate student exams
List<StudentExam> studentExams = request.postListWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/generate-student-exams", Optional.empty(), StudentExam.class, HttpStatus.OK);
assertThat(studentExams).hasSize(4);
assertThat(exam.getRegisteredUsers()).hasSize(4);
// /courses/{courseId}/exams/{examId}/student-exams/start-exercises
Integer numberOfGeneratedParticipations = request.postWithResponseBody("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams/start-exercises", Optional.empty(), Integer.class, HttpStatus.OK);
assertThat(numberOfGeneratedParticipations).isEqualTo(16);
// Fetch student exams
List<StudentExam> studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).hasSize(4);
List<StudentParticipation> participationList = new ArrayList<>();
Exercise[] exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
for (Exercise value : exercises) {
participationList.addAll(studentParticipationRepository.findByExerciseId(value.getId()));
}
assertThat(participationList).hasSize(16);
// TODO there should be some participation but no submissions unfortunately
// remove all students
var paramsParticipations = new LinkedMultiValueMap<String, String>();
paramsParticipations.add("withParticipationsAndSubmission", "true");
request.delete("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/students", HttpStatus.OK, paramsParticipations);
// Get the exam with all registered users
var params = new LinkedMultiValueMap<String, String>();
params.add("withStudents", "true");
Exam storedExam = request.get("/api/courses/" + course1.getId() + "/exams/" + exam.getId(), HttpStatus.OK, Exam.class, params);
assertThat(storedExam.getRegisteredUsers()).isEmpty();
// Fetch student exams
studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
assertThat(studentExamsDB).isEmpty();
// Fetch participations
exercises = examRepository.findAllExercisesByExamId(exam.getId()).toArray(new Exercise[0]);
participationList = new ArrayList<>();
for (Exercise exercise : exercises) {
participationList.addAll(studentParticipationRepository.findByExerciseId(exercise.getId()));
}
assertThat(participationList).isEmpty();
}
Aggregations