Search in sources :

Example 6 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) {
    Course course = createCourse();
    Exam exam = addExam(course, user, ZonedDateTime.now().minusMinutes(1), ZonedDateTime.now(), ZonedDateTime.now().plusMinutes(1));
    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 7 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, User user, ZonedDateTime visibleDate, ZonedDateTime startDate, ZonedDateTime endDate) {
    Exam exam = ModelFactory.generateExam(course);
    exam.addRegisteredUser(user);
    exam.setVisibleDate(visibleDate);
    exam.setStartDate(startDate);
    exam.setEndDate(endDate);
    exam.setNumberOfCorrectionRoundsInExam(1);
    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 8 with Exam

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

the class DatabaseUtilService method saveTextSubmissionWithResultAndAssessor.

private TextSubmission saveTextSubmissionWithResultAndAssessor(TextExercise exercise, TextSubmission submission, String studentLogin, Long teamId, String assessorLogin) {
    StudentParticipation participation = Optional.ofNullable(studentLogin).map(login -> createAndSaveParticipationForExercise(exercise, login)).orElseGet(() -> addTeamParticipationForExercise(exercise, teamId));
    submissionRepository.save(submission);
    participation.addSubmission(submission);
    Result result = new Result();
    result.setAssessor(getUserByLogin(assessorLogin));
    result.setScore(100D);
    if (exercise.getReleaseDate() != null) {
        result.setCompletionDate(exercise.getReleaseDate());
    } else {
        // exam exercises do not have a release date
        result.setCompletionDate(ZonedDateTime.now());
    }
    result = resultRepo.save(result);
    result.setSubmission(submission);
    submission.setParticipation(participation);
    submission.addResult(result);
    submission.getParticipation().addResult(result);
    submission = textSubmissionRepo.save(submission);
    resultRepo.save(result);
    studentParticipationRepo.save(participation);
    submission = textSubmissionRepo.save(submission);
    return submission;
}
Also used : JsonObject(com.google.gson.JsonObject) TypeToken(com.google.gson.reflect.TypeToken) de.tum.in.www1.artemis.repository(de.tum.in.www1.artemis.repository) URL(java.net.URL) AnswerPost(de.tum.in.www1.artemis.domain.metis.AnswerPost) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ZonedDateTime(java.time.ZonedDateTime) ExerciseHintRepository(de.tum.in.www1.artemis.repository.hestia.ExerciseHintRepository) Autowired(org.springframework.beans.factory.annotation.Autowired) TextAssessmentEvent(de.tum.in.www1.artemis.domain.analytics.TextAssessmentEvent) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) PageableSearchDTO(de.tum.in.www1.artemis.web.rest.dto.PageableSearchDTO) PostRepository(de.tum.in.www1.artemis.repository.metis.PostRepository) TestSecurityContextHolder(org.springframework.security.test.context.TestSecurityContextHolder) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) Gson(com.google.gson.Gson) Duration(java.time.Duration) CourseWideContext(de.tum.in.www1.artemis.domain.metis.CourseWideContext) Post(de.tum.in.www1.artemis.domain.metis.Post) SecurityContextHolder(org.springframework.security.core.context.SecurityContextHolder) Path(java.nio.file.Path) SubmissionPolicy(de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy) NotNull(javax.validation.constraints.NotNull) Role(de.tum.in.www1.artemis.security.Role) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) ZoneId(java.time.ZoneId) de.tum.in.www1.artemis.domain.participation(de.tum.in.www1.artemis.domain.participation) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Assertions.fail(org.assertj.core.api.Assertions.fail) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) SecurityContext(org.springframework.security.core.context.SecurityContext) UsernamePasswordAuthenticationToken(org.springframework.security.authentication.UsernamePasswordAuthenticationToken) Authentication(org.springframework.security.core.Authentication) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) java.util(java.util) PasswordService(de.tum.in.www1.artemis.service.user.PasswordService) AnswerPostRepository(de.tum.in.www1.artemis.repository.metis.AnswerPostRepository) CSVReader(com.opencsv.CSVReader) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) Value(org.springframework.beans.factory.annotation.Value) de.tum.in.www1.artemis.domain.lecture(de.tum.in.www1.artemis.domain.lecture) Service(org.springframework.stereotype.Service) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) Exam(de.tum.in.www1.artemis.domain.exam.Exam) de.tum.in.www1.artemis.service(de.tum.in.www1.artemis.service) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult) JsonParser.parseString(com.google.gson.JsonParser.parseString) Files(java.nio.file.Files) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) de.tum.in.www1.artemis.domain.quiz(de.tum.in.www1.artemis.domain.quiz) ResourceUtils(org.springframework.util.ResourceUtils) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) FileReader(java.io.FileReader) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) de.tum.in.www1.artemis.domain.enumeration(de.tum.in.www1.artemis.domain.enumeration) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 9 with Exam

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

the class DatabaseUtilService method addExerciseGroupWithExamWithReviewDatesAndCourse.

public ExerciseGroup addExerciseGroupWithExamWithReviewDatesAndCourse(boolean mandatory) {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    Exam exam = ModelFactory.generateExamWithStudentReviewDates(course);
    ExerciseGroup exerciseGroup = ModelFactory.generateExerciseGroup(mandatory, exam);
    final var courseNrBefore = courseRepo.count();
    final var examNrBefore = examRepository.count();
    final var exerciseGroupNrBefore = exerciseGroupRepository.count();
    courseRepo.save(course);
    examRepository.save(exam);
    assertThat(courseNrBefore + 1).as("a course got stored").isEqualTo(courseRepo.count());
    assertThat(examNrBefore + 1).as("an exam got stored").isEqualTo(examRepository.count());
    assertThat(exerciseGroupNrBefore + 1).as("an exerciseGroup got stored").isEqualTo(exerciseGroupRepository.count());
    Optional<Course> optionalCourse = courseRepo.findById(course.getId());
    assertThat(optionalCourse).as("course can be retrieved").isPresent();
    Course courseDB = optionalCourse.get();
    Optional<Exam> optionalExam = examRepository.findById(exam.getId());
    assertThat(optionalCourse).as("exam can be retrieved").isPresent();
    Exam examDB = optionalExam.get();
    Optional<ExerciseGroup> optionalExerciseGroup = exerciseGroupRepository.findById(exerciseGroup.getId());
    assertThat(optionalExerciseGroup).as("exerciseGroup can be retrieved").isPresent();
    ExerciseGroup exerciseGroupDB = optionalExerciseGroup.get();
    assertThat(examDB.getCourse().getId()).as("exam and course are linked correctly").isEqualTo(courseDB.getId());
    assertThat(exerciseGroupDB.getExam().getId()).as("exerciseGroup and exam are linked correctly").isEqualTo(examDB.getId());
    return exerciseGroup;
}
Also used : ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) Exam(de.tum.in.www1.artemis.domain.exam.Exam)

Example 10 with Exam

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

the class DatabaseUtilService method createCourseWithExamAndExercises.

public Course createCourseWithExamAndExercises() throws IOException {
    Course course = courseRepo.save(addEmptyCourse());
    // Create a file upload exercise with a dummy submission file
    var exerciseGroup1 = exerciseGroupRepository.save(new ExerciseGroup());
    var fileUploadExercise = ModelFactory.generateFileUploadExerciseForExam(".png", exerciseGroup1);
    fileUploadExercise = exerciseRepo.save(fileUploadExercise);
    createFileUploadSubmissionWithFile(fileUploadExercise, "uploaded-file.png");
    exerciseGroup1.addExercise(fileUploadExercise);
    exerciseGroup1 = exerciseGroupRepository.save(exerciseGroup1);
    // Create a text exercise with a dummy submission file
    var exerciseGroup2 = exerciseGroupRepository.save(new ExerciseGroup());
    var textExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup2);
    textExercise = exerciseRepo.save(textExercise);
    var textSubmission = ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true);
    saveTextSubmission(textExercise, textSubmission, "student1");
    exerciseGroup2.addExercise(textExercise);
    exerciseGroup2 = exerciseGroupRepository.save(exerciseGroup2);
    // Create a modeling exercise with a dummy submission file
    var exerciseGroup3 = exerciseGroupRepository.save(new ExerciseGroup());
    var modelingExercise = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup2);
    modelingExercise = exerciseRepo.save(modelingExercise);
    String emptyActivityModel = FileUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json");
    var modelingSubmission = ModelFactory.generateModelingSubmission(emptyActivityModel, true);
    addSubmission(modelingExercise, modelingSubmission, "student1");
    exerciseGroup3.addExercise(modelingExercise);
    exerciseGroupRepository.save(exerciseGroup3);
    Exam exam = addExam(course);
    exam.setEndDate(ZonedDateTime.now().minusMinutes(5));
    exam.addExerciseGroup(exerciseGroup1);
    exam.addExerciseGroup(exerciseGroup2);
    examRepository.save(exam);
    return course;
}
Also used : JsonParser.parseString(com.google.gson.JsonParser.parseString) ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup) StudentExam(de.tum.in.www1.artemis.domain.exam.StudentExam) 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