Search in sources :

Example 11 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project Artemis by ls1intum.

the class DatabaseUtilService method addExerciseGroupsAndExercisesToExam.

public Exam addExerciseGroupsAndExercisesToExam(Exam exam, boolean withProgrammingExercise) {
    // text
    ModelFactory.generateExerciseGroup(true, exam);
    // quiz
    ModelFactory.generateExerciseGroup(true, exam);
    // file upload
    ModelFactory.generateExerciseGroup(true, exam);
    // modeling
    ModelFactory.generateExerciseGroup(true, exam);
    // bonus text
    ModelFactory.generateExerciseGroup(true, exam);
    // not included text
    ModelFactory.generateExerciseGroup(true, exam);
    exam.setNumberOfExercisesInExam(6);
    exam.setMaxPoints(24);
    exam = examRepository.save(exam);
    // NOTE: we have to reassign, otherwise we get problems, because the objects have changed
    var exerciseGroup0 = exam.getExerciseGroups().get(0);
    var exerciseGroup1 = exam.getExerciseGroups().get(1);
    var exerciseGroup2 = exam.getExerciseGroups().get(2);
    var exerciseGroup3 = exam.getExerciseGroups().get(3);
    var exerciseGroup4 = exam.getExerciseGroups().get(4);
    var exerciseGroup5 = exam.getExerciseGroups().get(5);
    TextExercise textExercise1 = ModelFactory.generateTextExerciseForExam(exerciseGroup0);
    TextExercise textExercise2 = ModelFactory.generateTextExerciseForExam(exerciseGroup0);
    textExercise1.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    textExercise2.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup0.setExercises(Set.of(textExercise1, textExercise2));
    exerciseRepo.save(textExercise1);
    exerciseRepo.save(textExercise2);
    QuizExercise quizExercise1 = createQuizForExam(exerciseGroup1);
    QuizExercise quizExercise2 = createQuizForExam(exerciseGroup1);
    exerciseGroup1.setExercises(Set.of(quizExercise1, quizExercise2));
    exerciseRepo.save(quizExercise1);
    exerciseRepo.save(quizExercise2);
    FileUploadExercise fileUploadExercise1 = ModelFactory.generateFileUploadExerciseForExam("pdf", exerciseGroup2);
    FileUploadExercise fileUploadExercise2 = ModelFactory.generateFileUploadExerciseForExam("pdf", exerciseGroup2);
    exerciseGroup2.setExercises(Set.of(fileUploadExercise1, fileUploadExercise2));
    exerciseRepo.save(fileUploadExercise1);
    exerciseRepo.save(fileUploadExercise2);
    ModelingExercise modelingExercise1 = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup3);
    ModelingExercise modelingExercise2 = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup3);
    modelingExercise1.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    modelingExercise2.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup3.setExercises(Set.of(modelingExercise1, modelingExercise2));
    exerciseRepo.save(modelingExercise1);
    exerciseRepo.save(modelingExercise2);
    TextExercise bonusTextExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup4);
    bonusTextExercise.setIncludedInOverallScore(IncludedInOverallScore.INCLUDED_AS_BONUS);
    bonusTextExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup4.setExercises(Set.of(bonusTextExercise));
    exerciseRepo.save(bonusTextExercise);
    TextExercise notIncludedTextExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup5);
    notIncludedTextExercise.setIncludedInOverallScore(IncludedInOverallScore.NOT_INCLUDED);
    notIncludedTextExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    exerciseGroup5.setExercises(Set.of(notIncludedTextExercise));
    exerciseRepo.save(notIncludedTextExercise);
    if (withProgrammingExercise) {
        // programming
        ModelFactory.generateExerciseGroup(true, exam);
        exam.setNumberOfExercisesInExam(7);
        exam.setMaxPoints(29);
        exam = examRepository.save(exam);
        var exerciseGroup6 = exam.getExerciseGroups().get(6);
        // Programming exercises need a proper setup for 'prepare exam start' to work
        ProgrammingExercise programmingExercise1 = ModelFactory.generateProgrammingExerciseForExam(exerciseGroup6);
        exerciseRepo.save(programmingExercise1);
        addTemplateParticipationForProgrammingExercise(programmingExercise1);
        addSolutionParticipationForProgrammingExercise(programmingExercise1);
        exerciseGroup6.setExercises(Set.of(programmingExercise1));
    }
    return exam;
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 12 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project Artemis by ls1intum.

the class DatabaseUtilService method createCourseWithExamAndExerciseGroupAndExercises.

public Course createCourseWithExamAndExerciseGroupAndExercises(User user, ZonedDateTime visible, ZonedDateTime start, ZonedDateTime end) {
    Course course = createCourse();
    Exam exam = addExam(course, user, visible, start, end);
    course.addExam(exam);
    addExerciseGroupsAndExercisesToExam(exam, false);
    return courseRepo.save(course);
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 13 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project Artemis by ls1intum.

the class DatabaseUtilService method addExam.

public Exam addExam(Course course) {
    Exam exam = ModelFactory.generateExam(course);
    examRepository.save(exam);
    return exam;
}
Also used : StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 14 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project Artemis by ls1intum.

the class DatabaseUtilService method saveFileUploadSubmissionWithResultAndAssessorFeedback.

public FileUploadSubmission saveFileUploadSubmissionWithResultAndAssessorFeedback(FileUploadExercise exercise, FileUploadSubmission fileUploadSubmission, String login, String assessorLogin, List<Feedback> feedbacks) {
    StudentParticipation participation = createAndSaveParticipationForExercise(exercise, login);
    submissionRepository.save(fileUploadSubmission);
    participation.addSubmission(fileUploadSubmission);
    Result result = new Result();
    result.setAssessor(getUserByLogin(assessorLogin));
    result.setScore(100D);
    result.setParticipation(participation);
    result.setResultString(exercise.getMaxPoints(), exercise.getMaxPoints());
    if (exercise.getReleaseDate() != null) {
        result.setCompletionDate(exercise.getReleaseDate());
    } else {
        // exam exercises do not have a release date
        result.setCompletionDate(ZonedDateTime.now());
    }
    result.setFeedbacks(feedbacks);
    result = resultRepo.save(result);
    for (Feedback feedback : feedbacks) {
        feedback.setResult(result);
    }
    result = resultRepo.save(result);
    result.setSubmission(fileUploadSubmission);
    fileUploadSubmission.setParticipation(participation);
    fileUploadSubmission.addResult(result);
    fileUploadSubmission.getParticipation().addResult(result);
    fileUploadSubmission = fileUploadSubmissionRepo.save(fileUploadSubmission);
    studentParticipationRepo.save(participation);
    return fileUploadSubmission;
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 15 with Exam

use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.

the class GitLabUserManagementService method removeOrUpdateUserFromGroups.

/**
 * Removes or updates the user to or from the groups.
 *
 * @param gitlabUserId the Gitlab user id
 * @param userGroups groups that the user belongs to
 * @param groupsToRemove groups where the user should be removed from
 */
private void removeOrUpdateUserFromGroups(int gitlabUserId, Set<String> userGroups, Set<String> groupsToRemove) throws GitLabApiException {
    if (groupsToRemove == null || groupsToRemove.isEmpty()) {
        return;
    }
    // Gitlab groups are identified by the project key of the programming exercise
    var exercises = programmingExerciseRepository.findAllByInstructorOrEditorOrTAGroupNameIn(groupsToRemove);
    log.info("Update Gitlab permissions for programming exercises: " + exercises.stream().map(ProgrammingExercise::getProjectKey).toList());
    for (var exercise : exercises) {
        // TODO: in case we update a tutor group / role here, the tutor should NOT get access to exam exercises before the exam has finished
        Course course = exercise.getCourseViaExerciseGroupOrCourseMember();
        Optional<AccessLevel> accessLevel = getAccessLevelFromUserGroups(userGroups, course);
        // Do not remove the user from the group and only update it's access level
        var shouldUpdateGroupAccess = accessLevel.isPresent();
        if (shouldUpdateGroupAccess) {
            gitlabApi.getGroupApi().updateMember(exercise.getProjectKey(), gitlabUserId, accessLevel.get());
        } else {
            removeUserFromGroup(gitlabUserId, exercise.getProjectKey());
        }
    }
}
Also used : Course(de.tum.in.www1.artemis.domain.Course) AccessLevel(org.gitlab4j.api.models.AccessLevel)

Aggregations

Exam (de.tum.in.www1.artemis.domain.exam.Exam)228 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)180 WithMockUser (org.springframework.security.test.context.support.WithMockUser)164 Test (org.junit.jupiter.api.Test)158 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)92 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)75 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)52 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)48 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)46 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)46 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 ZonedDateTime (java.time.ZonedDateTime)40 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)38 Course (de.tum.in.www1.artemis.domain.Course)36 GradingScale (de.tum.in.www1.artemis.domain.GradingScale)34 BeforeEach (org.junit.jupiter.api.BeforeEach)30 User (de.tum.in.www1.artemis.domain.User)27 Collectors (java.util.stream.Collectors)26 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)24 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)24