Search in sources :

Example 1 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project Artemis by ls1intum.

the class ComplaintResponseIntegrationTest method initTestCase.

@BeforeEach
public void initTestCase() throws Exception {
    // creating the users student1-student5, tutor1-tutor10 and instructors1-instructor10
    this.database.addUsers(5, 10, 0, 10);
    // Add users that are not in the course
    userRepository.save(ModelFactory.generateActivatedUser("student42"));
    userRepository.save(ModelFactory.generateActivatedUser("tutor42"));
    userRepository.save(ModelFactory.generateActivatedUser("instructor42"));
    userRepository.flush();
    // creating course
    // students: student1-student 5 | tutors: tutor1-tutor10 | instructors: instructor1 - instructor10
    Course course = this.database.createCourse();
    // creating text exercise
    TextExercise textExercise = ModelFactory.generateTextExercise(null, null, null, course);
    textExercise.setMaxPoints(10.0);
    textExercise.setBonusPoints(0.0);
    textExercise = exerciseRepository.saveAndFlush(textExercise);
    // creating participation of student1 by starting the exercise
    User student1 = userRepository.findOneByLogin("student1").get();
    StudentParticipation studentParticipation = participationService.startExercise(textExercise, student1, false);
    // creating submission of student1
    TextSubmission submission = new TextSubmission();
    submission.setType(SubmissionType.MANUAL);
    submission.setParticipation(studentParticipation);
    submission.setSubmitted(Boolean.TRUE);
    submission.setSubmissionDate(ZonedDateTime.now());
    submission.text("hello world");
    submission = submissionRepository.saveAndFlush(submission);
    // creating assessment by tutor1
    User tutor1 = userRepository.findOneByLogin("tutor1").get();
    Result result = ModelFactory.generateResult(true, 50D);
    result.setAssessor(tutor1);
    result.setHasComplaint(true);
    result.setHasFeedback(false);
    result.setParticipation(studentParticipation);
    result = resultRepository.saveAndFlush(result);
    submission.addResult(result);
    result.setSubmission(submission);
    submission = submissionRepository.saveAndFlush(submission);
    // creating complaint by student 1
    complaint = new Complaint();
    complaint.setComplaintType(ComplaintType.COMPLAINT);
    complaint.setComplaintText("Unfair");
    complaint.setResult(result);
    complaint.setAccepted(null);
    complaint.setSubmittedTime(null);
    complaint.setParticipant(student1);
    complaint = complaintRepository.saveAndFlush(complaint);
}
Also used : WithMockUser(org.springframework.security.test.context.support.WithMockUser) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with StudentParticipation

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().size()).isEqualTo(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().size()).isEqualTo(0);
    // Fetch student exams
    studentExamsDB = request.getList("/api/courses/" + course1.getId() + "/exams/" + exam.getId() + "/student-exams", HttpStatus.OK, StudentExam.class);
    assertThat(studentExamsDB).hasSize(0);
    // 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);
}
Also used : QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 3 with StudentParticipation

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).hasSize(storedExam.getRegisteredUsers().size());
    assertThat(studentExams).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);
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) PasswordService(de.tum.in.www1.artemis.service.user.PasswordService) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) Participation(de.tum.in.www1.artemis.domain.participation.Participation) Autowired(org.springframework.beans.factory.annotation.Autowired) TextAssessmentKnowledgeService(de.tum.in.www1.artemis.service.TextAssessmentKnowledgeService) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) ExamService(de.tum.in.www1.artemis.service.exam.ExamService) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) Path(java.nio.file.Path) IncludedInOverallScore(de.tum.in.www1.artemis.domain.enumeration.IncludedInOverallScore) Exam(de.tum.in.www1.artemis.domain.exam.Exam) DiagramType(de.tum.in.www1.artemis.domain.enumeration.DiagramType) ExamDateService(de.tum.in.www1.artemis.service.exam.ExamDateService) StudentDTO(de.tum.in.www1.artemis.service.dto.StudentDTO) Awaitility.await(org.awaitility.Awaitility.await) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) Files(java.nio.file.Files) ExamRegistrationService(de.tum.in.www1.artemis.service.exam.ExamRegistrationService) AssessmentType(de.tum.in.www1.artemis.domain.enumeration.AssessmentType) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) HttpStatus(org.springframework.http.HttpStatus) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) AfterEach(org.junit.jupiter.api.AfterEach) ChronoUnit(java.time.temporal.ChronoUnit) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) WithMockUser(org.springframework.security.test.context.support.WithMockUser) de.tum.in.www1.artemis.web.rest.dto(de.tum.in.www1.artemis.web.rest.dto) LdapUserDto(de.tum.in.www1.artemis.service.ldap.LdapUserDto) ZonedDateTime.now(java.time.ZonedDateTime.now) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ZipFileTestUtilService(de.tum.in.www1.artemis.util.ZipFileTestUtilService) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 4 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project Artemis by ls1intum.

the class ParticipationTeamWebsocketService method updateSubmission.

/**
 * Updates a modeling or text submission
 *
 * @param participationId id of participation
 * @param submission      updated modeling text submission
 * @param principal       principal of user who wants to update the submission
 * @param topicPath       path of websocket destination topic where to send the new submission
 */
private void updateSubmission(@DestinationVariable Long participationId, @Payload Submission submission, Principal principal, String topicPath) {
    // Without this, custom jpa repository methods don't work in websocket channel.
    SecurityUtils.setAuthorizationObject();
    final StudentParticipation participation = studentParticipationRepository.findByIdElseThrow(participationId);
    // user must belong to the team who owns the participation in order to update a submission
    if (!participation.isOwnedBy(principal.getName())) {
        return;
    }
    final User user = userRepository.getUserWithGroupsAndAuthorities(principal.getName());
    final Exercise exercise = exerciseRepository.findByIdElseThrow(participation.getExercise().getId());
    if (submission instanceof ModelingSubmission && exercise instanceof ModelingExercise) {
        submission = modelingSubmissionService.save((ModelingSubmission) submission, (ModelingExercise) exercise, principal.getName());
        modelingSubmissionService.hideDetails(submission, user);
    } else if (submission instanceof TextSubmission && exercise instanceof TextExercise) {
        submission = textSubmissionService.handleTextSubmission((TextSubmission) submission, (TextExercise) exercise, principal);
        textSubmissionService.hideDetails(submission, user);
    } else {
        throw new IllegalArgumentException("Submission type '" + submission.getType() + "' not allowed.");
    }
    // update the last action date for the user and send out list of team members
    updateValue(lastActionTracker, participationId, principal.getName());
    sendOnlineTeamStudents(participationId);
    SubmissionSyncPayload payload = new SubmissionSyncPayload(submission, user);
    messagingTemplate.convertAndSend(getDestination(participationId, topicPath), payload);
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) SubmissionSyncPayload(de.tum.in.www1.artemis.web.websocket.dto.SubmissionSyncPayload) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 5 with StudentParticipation

use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project Artemis by ls1intum.

the class TeamWebsocketService method sendTeamAssignmentUpdate.

/**
 * Sends out team assignment information for an exercise to students of a created/updated/deleted team
 *
 * Cases:
 * 1. Team was created: sendTeamAssignmentUpdate(exercise, null, createdTeam);
 * 2. Team was updated: sendTeamAssignmentUpdate(exercise, existingTeam, updatedTeam);
 * 3. Team was deleted: sendTeamAssignmentUpdate(exercise, deletedTeam, null);
 *
 * @param exercise                    Exercise for which the team assignment has been made
 * @param existingTeam                Team before the update (null when a team was created)
 * @param updatedTeam                 Team after the update (null when a team was deleted)
 * @param participationsOfUpdatedTeam Student participations of the updated team
 */
public void sendTeamAssignmentUpdate(Exercise exercise, @Nullable Team existingTeam, @Nullable Team updatedTeam, List<StudentParticipation> participationsOfUpdatedTeam) {
    // Users in the existing team that are no longer in the updated team were unassigned => inform them
    if (existingTeam != null) {
        TeamAssignmentPayload payload = new TeamAssignmentPayload(exercise, null);
        Set<User> unassignedUsers = new HashSet<>(existingTeam.getStudents());
        unassignedUsers.removeAll(Optional.ofNullable(updatedTeam).map(Team::getStudents).orElse(Set.of()));
        unassignedUsers.forEach(user -> messagingTemplate.convertAndSendToUser(user.getLogin(), assignmentTopic, payload));
    }
    // Users in the updated team that were not yet part of the existing team were newly assigned => inform them
    if (updatedTeam != null) {
        TeamAssignmentPayload payload = new TeamAssignmentPayload(exercise, updatedTeam, participationsOfUpdatedTeam);
        Set<User> assignedUsers = new HashSet<>(updatedTeam.getStudents());
        assignedUsers.removeAll(Optional.ofNullable(existingTeam).map(Team::getStudents).orElse(Set.of()));
        assignedUsers.forEach(user -> messagingTemplate.convertAndSendToUser(user.getLogin(), assignmentTopic, payload));
    }
}
Also used : User(de.tum.in.www1.artemis.domain.User) TeamAssignmentPayload(de.tum.in.www1.artemis.web.websocket.dto.TeamAssignmentPayload) Team(de.tum.in.www1.artemis.domain.Team)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)216 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)42 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)40 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)24