Search in sources :

Example 16 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, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) {
    Exam exam = ModelFactory.generateExam(course);
    exam.setVisibleDate(visibleDate);
    exam.setStartDate(startDate);
    exam.setEndDate(endDate);
    exam.setGracePeriod(180);
    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 17 with Exam

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

the class DatabaseUtilService method generateTestRunForInstructor.

public StudentExam generateTestRunForInstructor(Exam exam, User instructor, List<Exercise> exercises) {
    var testRun = ModelFactory.generateExamTestRun(exam);
    testRun.setUser(instructor);
    examRepository.findWithExerciseGroupsAndExercisesById(exam.getId()).get();
    for (final var exercise : exercises) {
        testRun.addExercise(exercise);
        assertThat(exercise.isExamExercise()).isTrue();
        Submission submission;
        if (exercise instanceof ModelingExercise) {
            submission = addModelingSubmission((ModelingExercise) exercise, ModelFactory.generateModelingSubmission("", false), instructor.getLogin());
        } else if (exercise instanceof TextExercise) {
            submission = saveTextSubmission((TextExercise) exercise, ModelFactory.generateTextSubmission("", null, false), instructor.getLogin());
        } else {
            submission = new ProgrammingSubmission().submitted(true);
            addProgrammingSubmission((ProgrammingExercise) exercise, (ProgrammingSubmission) submission, instructor.getLogin());
            submission = submissionRepository.save(submission);
        }
        var studentParticipation = (StudentParticipation) submission.getParticipation();
        studentParticipation.setTestRun(true);
        studentParticipationRepo.save(studentParticipation);
    }
    return testRun;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 18 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 19 with Exam

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

the class DatabaseUtilService method addActiveExamWithRegisteredUser.

public Exam addActiveExamWithRegisteredUser(Course course, User user) {
    Exam exam = ModelFactory.generateExam(course);
    exam.setStartDate(ZonedDateTime.now().minusHours(1));
    exam.setEndDate(ZonedDateTime.now().plusHours(1));
    exam.addRegisteredUser(user);
    examRepository.save(exam);
    var studentExam = new StudentExam();
    studentExam.setExam(exam);
    studentExam.setTestRun(false);
    studentExam.setUser(user);
    studentExam.setWorkingTime((int) Duration.between(exam.getStartDate(), exam.getEndDate()).toSeconds());
    studentExamRepository.save(studentExam);
    return exam;
}
Also used : 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)

Example 20 with Exam

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

the class ResultService method getFeedbacksForResult.

/**
 * Returns a list of feedbacks that is filtered for students depending on the settings and the time.
 *
 * @param result    the result for which the feedback elements should be returned
 * @return the list of filtered feedbacks
 */
public List<Feedback> getFeedbacksForResult(Result result) {
    Exercise exercise = result.getParticipation().getExercise();
    boolean filterForStudent = !authCheckService.isAtLeastTeachingAssistantForExercise(exercise);
    List<Feedback> feedbacks = result.getFeedbacks();
    if (filterForStudent) {
        if (exercise.isExamExercise()) {
            Exam exam = exercise.getExerciseGroup().getExam();
            result.filterSensitiveFeedbacks(!exam.resultsPublished());
        } else {
            boolean applyFilter = exerciseDateService.isBeforeDueDate(result.getParticipation()) || (AssessmentType.AUTOMATIC.equals(result.getAssessmentType()) && exerciseDateService.isBeforeLatestDueDate(exercise));
            result.filterSensitiveFeedbacks(applyFilter);
        }
        feedbacks = result.getFeedbacks();
        boolean resultSetAndNonAutomatic = result.getAssessmentType() != null && result.getAssessmentType() != AssessmentType.AUTOMATIC;
        boolean dueDateNotSetOrNotOver = exercise.getAssessmentDueDate() != null && ZonedDateTime.now().isBefore(exercise.getAssessmentDueDate());
        // A tutor is allowed to access all feedback, but filter for a student the manual feedback if the assessment due date is not over yet
        if (!exercise.isExamExercise() && resultSetAndNonAutomatic && dueDateNotSetOrNotOver) {
            // filter all non-automatic feedbacks
            feedbacks = feedbacks.stream().filter(feedback -> feedback.getType() != null && feedback.getType() == FeedbackType.AUTOMATIC).toList();
        }
    }
    // remove unnecessary data to keep the json payload smaller
    for (Feedback feedback : feedbacks) {
        if (feedback.getResult() != null) {
            feedback.getResult().setSubmission(null);
            feedback.getResult().setParticipation(null);
        }
    }
    return feedbacks;
}
Also used : Exam(de.tum.in.www1.artemis.domain.exam.Exam)

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