Search in sources :

Example 51 with StudentParticipation

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

the class ComplaintResource method buildComplaintsListForAssessor.

private List<Complaint> buildComplaintsListForAssessor(List<Complaint> complaints, Principal principal, boolean assessorSameAsCaller, boolean isTestRun, boolean isAtLeastInstructor) {
    List<Complaint> responseComplaints = new ArrayList<>();
    if (complaints.isEmpty()) {
        return responseComplaints;
    }
    complaints.forEach(complaint -> {
        String submissorName = principal.getName();
        User assessor = complaint.getResult().getAssessor();
        User student = complaint.getStudent();
        if (assessor != null && (assessor.getLogin().equals(submissorName) == assessorSameAsCaller || isAtLeastInstructor) && (student != null && assessor.getLogin().equals(student.getLogin())) == isTestRun) {
            // Remove data about the student
            StudentParticipation studentParticipation = (StudentParticipation) complaint.getResult().getParticipation();
            studentParticipation.setParticipant(null);
            studentParticipation.setExercise(null);
            complaint.setParticipant(null);
            responseComplaints.add(complaint);
        }
    });
    return responseComplaints;
}
Also used : StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 52 with StudentParticipation

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

the class ProgrammingSubmissionResultSimulationResource method createNewProgrammingExerciseResult.

/**
 * This method is used to notify artemis that there is a new programming exercise build result.
 * This result is only a SIMULATION for the testing of programming exercises without a connection
 * to the VCS and CI server
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 * @param exerciseId id of the exercise
 * @return HTTP OK and Result
 */
@PostMapping(Endpoints.RESULTS_SIMULATION)
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Result> createNewProgrammingExerciseResult(@PathVariable Long exerciseId) {
    log.debug("Received result notify (NEW)");
    User user = userRepository.getUserWithGroupsAndAuthorities();
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
    var studentParticipation = participationService.findOneByExerciseAndParticipantAnyState(programmingExercise, user).orElseThrow(() -> new EntityNotFoundException("Participation for programming exercise " + programmingExercise.getId() + " and user " + user.getLogin() + " not found!"));
    var programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
    Result result = programmingSubmissionResultSimulationService.createResult(programmingExerciseStudentParticipation);
    messagingService.broadcastNewResult(programmingExerciseStudentParticipation, result);
    log.info("The new result for {} was saved successfully", programmingExerciseStudentParticipation.getBuildPlanId());
    try {
        return ResponseEntity.created(new URI("/api/results" + result.getId())).body(result);
    } catch (URISyntaxException e) {
        log.error("Error while simulating a result", e);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(HeaderUtil.createAlert(applicationName, "An error occurred while simulating a result: " + e.getMessage(), "errorResult")).body(null);
    }
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 53 with StudentParticipation

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

the class QuizSubmissionResource method submitForPractice.

/**
 * POST /exercises/:exerciseId/submissions/practice : Submit a new quizSubmission for practice mode.
 *
 * @param exerciseId     the id of the exercise for which to init a participation
 * @param quizSubmission the quizSubmission to submit
 * @return the ResponseEntity with status 200 (OK) and the Result as its body, or with status 4xx if the request is invalid
 */
@PostMapping("/exercises/{exerciseId}/submissions/practice")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Result> submitForPractice(@PathVariable Long exerciseId, @RequestBody QuizSubmission quizSubmission) {
    log.debug("REST request to submit QuizSubmission for practice : {}", quizSubmission);
    // recreate pointers back to submission in each submitted answer
    for (SubmittedAnswer submittedAnswer : quizSubmission.getSubmittedAnswers()) {
        submittedAnswer.setSubmission(quizSubmission);
    }
    if (quizSubmission.getId() != null) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, ENTITY_NAME, "idexists", "A new quizSubmission cannot already have an ID.")).body(null);
    }
    QuizExercise quizExercise = quizExerciseRepository.findByIdWithQuestionsElseThrow(exerciseId);
    User user = userRepository.getUserWithGroupsAndAuthorities();
    if (!authCheckService.isAllowedToSeeExercise(quizExercise, user)) {
        return ResponseEntity.status(403).headers(HeaderUtil.createFailureAlert(applicationName, true, "submission", "Forbidden", "You are not allowed to participate in this exercise.")).body(null);
    }
    // Note that exam quiz exercises do not have an end date, so we need to check in that order
    if (!Boolean.TRUE.equals(quizExercise.isIsOpenForPractice()) || !quizExercise.isQuizEnded()) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "submission", "exerciseNotOpenForPractice", "The exercise is not open for practice or hasn't ended yet.")).body(null);
    }
    // the following method either reuses an existing participation or creates a new one
    StudentParticipation participation = participationService.startExercise(quizExercise, user, false);
    // we set the exercise again to prevent issues with lazy loaded quiz questions
    participation.setExercise(quizExercise);
    // update and save submission
    Result result = quizSubmissionService.submitForPractice(quizSubmission, quizExercise, participation);
    // The quizScheduler is usually responsible for updating the participation to FINISHED in the database. If quizzes where the student did not participate are used for
    // practice, the QuizScheduler does not update the participation, that's why we update it manually here
    participation.setInitializationState(InitializationState.FINISHED);
    studentParticipationRepository.saveAndFlush(participation);
    // remove some redundant or unnecessary data that is not needed on client side
    for (SubmittedAnswer answer : quizSubmission.getSubmittedAnswers()) {
        answer.getQuizQuestion().setQuizQuestionStatistic(null);
    }
    quizExercise.setQuizPointStatistic(null);
    quizExercise.setCourse(null);
    messagingService.broadcastNewResult(result.getParticipation(), result);
    // return result with quizSubmission, participation and quiz exercise (including the solution)
    return ResponseEntity.ok(result);
}
Also used : SubmittedAnswer(de.tum.in.www1.artemis.domain.quiz.SubmittedAnswer) User(de.tum.in.www1.artemis.domain.User) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) QuizExercise(de.tum.in.www1.artemis.domain.quiz.QuizExercise) Result(de.tum.in.www1.artemis.domain.Result) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 54 with StudentParticipation

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

the class TeamIntegrationTest method getCourseWithExercisesAndParticipationsForTeam_AsTutor.

@Test
@WithMockUser(username = "tutor1", roles = "TA")
public void getCourseWithExercisesAndParticipationsForTeam_AsTutor() throws Exception {
    List<Course> courses = database.createCoursesWithExercisesAndLectures(false);
    Course course = courses.get(0);
    ProgrammingExercise programmingExercise = (ProgrammingExercise) course.getExercises().stream().filter(exercise -> exercise instanceof ProgrammingExercise).findAny().orElseThrow();
    TextExercise textExercise = (TextExercise) course.getExercises().stream().filter(exercise -> exercise instanceof TextExercise).findAny().orElseThrow();
    ModelingExercise modelingExercise = (ModelingExercise) course.getExercises().stream().filter(exercise -> exercise instanceof ModelingExercise).findAny().orElseThrow();
    // make exercises team-based
    Stream.of(programmingExercise, textExercise, modelingExercise).forEach(exercise -> {
        exercise.setMode(ExerciseMode.TEAM);
        exerciseRepo.save(exercise);
    });
    String shortNamePrefix1 = "team";
    String shortNamePrefix2 = "otherTeam";
    Team team1a = database.addTeamsForExercise(programmingExercise, shortNamePrefix1, "team1astudent", 1, tutor).get(0);
    Team team1b = database.addTeamsForExercise(textExercise, shortNamePrefix1, "team1bstudent", 1, tutor).get(0);
    Team team1c = database.addTeamsForExercise(modelingExercise, shortNamePrefix1, "team1cstudent", 1, tutor).get(0);
    Team team2a = database.addTeamsForExercise(programmingExercise, shortNamePrefix2, "team2astudent", 1, null).get(0);
    Team team2b = database.addTeamsForExercise(textExercise, shortNamePrefix2, "team2bstudent", 1, null).get(0);
    assertThat(Stream.of(team1a, team1b, team1c).map(Team::getShortName).distinct()).as("Teams 1 need the same short name for this test").hasSize(1);
    assertThat(Stream.of(team2a, team2b).map(Team::getShortName).distinct()).as("Teams 2 need the same short name for this test").hasSize(1);
    assertThat(Stream.of(team1a, team1b, team1c, team2a, team2b).map(Team::getShortName).distinct()).as("Teams 1 and Teams 2 need different short names").hasSize(2);
    database.addTeamParticipationForExercise(programmingExercise, team1a.getId());
    database.addTeamParticipationForExercise(textExercise, team1b.getId());
    database.addTeamParticipationForExercise(programmingExercise, team2a.getId());
    database.addTeamParticipationForExercise(textExercise, team2b.getId());
    Course course1 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team1a), HttpStatus.OK, Course.class);
    assertThat(course1.getExercises()).as("All exercises of team 1 in course were returned").hasSize(3);
    assertThat(course1.getExercises().stream().map(Exercise::getTeams).collect(Collectors.toSet())).as("All team instances of team 1 in course were returned").hasSize(3);
    assertThat(course1.getExercises().stream().flatMap(exercise -> exercise.getStudentParticipations().stream()).collect(Collectors.toSet())).as("All participations of team 1 in course were returned").hasSize(2);
    Course course2 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team2a), HttpStatus.OK, Course.class);
    assertThat(course2.getExercises()).as("All exercises of team 2 in course were returned").hasSize(2);
    StudentParticipation studentParticipation = course2.getExercises().iterator().next().getStudentParticipations().iterator().next();
    assertThat(studentParticipation.getSubmissionCount()).as("Participation includes submission count").isNotNull();
    // Submission and Result should be present for Team of which the user is the Team Owner
    final String submissionText = "Hello World";
    TextSubmission submission = ModelFactory.generateTextSubmission(submissionText, Language.ENGLISH, true);
    database.saveTextSubmissionWithResultAndAssessor(textExercise, submission, team1b.getId(), tutor.getLogin());
    Course course3 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team1a), HttpStatus.OK, Course.class);
    StudentParticipation participation = course3.getExercises().stream().filter(exercise -> exercise.equals(textExercise)).findAny().orElseThrow().getStudentParticipations().iterator().next();
    assertThat(participation.getSubmissions()).as("Latest submission is present").hasSize(1);
    assertThat(((TextSubmission) participation.getSubmissions().iterator().next()).getText()).as("Latest submission is present").isEqualTo(submissionText);
    assertThat(participation.getResults()).as("Latest result is present").hasSize(1);
    // Submission and Result should not be present for a Team of which the user is not (!) the Team Owner
    submission = ModelFactory.generateTextSubmission(submissionText, Language.ENGLISH, true);
    database.saveTextSubmissionWithResultAndAssessor(textExercise, submission, team2b.getId(), "tutor2");
    Course course4 = request.get(resourceUrlCourseWithExercisesAndParticipationsForTeam(course, team2a), HttpStatus.OK, Course.class);
    participation = course4.getExercises().stream().filter(exercise -> exercise.equals(textExercise)).findAny().orElseThrow().getStudentParticipations().iterator().next();
    assertThat(participation.getSubmissions()).as("Latest submission is not present").isEmpty();
    assertThat(participation.getResults()).as("Latest result is not present").isEmpty();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) java.util(java.util) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) Language(de.tum.in.www1.artemis.domain.enumeration.Language) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) ExerciseMode(de.tum.in.www1.artemis.domain.enumeration.ExerciseMode) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) AfterEach(org.junit.jupiter.api.AfterEach) Stream(java.util.stream.Stream) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) WithMockUser(org.springframework.security.test.context.support.WithMockUser) TeamSearchUserDTO(de.tum.in.www1.artemis.service.dto.TeamSearchUserDTO) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ModelFactory(de.tum.in.www1.artemis.util.ModelFactory) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Example 55 with StudentParticipation

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

the class TextAssessmentIntegrationTest method updateTextAssessmentAfterComplaint_withTextBlocks.

@Test
@WithMockUser(username = "tutor2", roles = "TA")
public void updateTextAssessmentAfterComplaint_withTextBlocks() throws Exception {
    // Setup
    TextSubmission textSubmission = ModelFactory.generateTextSubmission("This is Part 1, and this is Part 2. There is also Part 3.", Language.ENGLISH, true);
    textSubmission = database.saveTextSubmissionWithResultAndAssessor(textExercise, textSubmission, "student1", "tutor1");
    database.addAndSaveTextBlocksToTextSubmission(Set.of(new TextBlock().startIndex(0).endIndex(15).automatic(), new TextBlock().startIndex(16).endIndex(35).automatic(), new TextBlock().startIndex(36).endIndex(57).automatic()), textSubmission);
    Result textAssessment = textSubmission.getLatestResult();
    complaintRepo.save(new Complaint().result(textAssessment).complaintText("This is not fair"));
    // Get Text Submission and Complaint
    StudentParticipation participation = request.get("/api/participations/" + textSubmission.getParticipation().getId() + "/submissions/" + textSubmission.getId() + "/for-text-assessment", HttpStatus.OK, StudentParticipation.class);
    final Complaint complaint = request.get("/api/complaints/submissions/" + textSubmission.getId(), HttpStatus.OK, Complaint.class);
    // Accept Complaint and update Assessment
    ComplaintResponse complaintResponse = database.createInitialEmptyResponse("tutor2", complaint);
    complaintResponse.getComplaint().setAccepted(false);
    complaintResponse.setResponseText("rejected");
    TextAssessmentUpdateDTO assessmentUpdate = new TextAssessmentUpdateDTO();
    assessmentUpdate.feedbacks(new ArrayList<>()).complaintResponse(complaintResponse);
    assessmentUpdate.setTextBlocks(new HashSet<>());
    Result updatedResult = request.putWithResponseBody("/api/participations/" + textSubmission.getParticipation().getId() + "/submissions/" + textSubmission.getId() + "/text-assessment-after-complaint", assessmentUpdate, Result.class, HttpStatus.OK);
    assertThat(updatedResult).as("updated result found").isNotNull();
}
Also used : StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) TextAssessmentUpdateDTO(de.tum.in.www1.artemis.web.rest.dto.TextAssessmentUpdateDTO) WithMockUser(org.springframework.security.test.context.support.WithMockUser) Test(org.junit.jupiter.api.Test)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)219 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)44 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 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 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)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 Collectors (java.util.stream.Collectors)24