Search in sources :

Example 11 with TextExercise

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

the class DatabaseUtilService method addCourseExamWithReviewDatesExerciseGroupWithOneTextExercise.

public TextExercise addCourseExamWithReviewDatesExerciseGroupWithOneTextExercise() {
    ExerciseGroup exerciseGroup = addExerciseGroupWithExamWithReviewDatesAndCourse(true);
    TextExercise textExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup);
    final var exercisesNrBefore = exerciseRepo.count();
    exerciseRepo.save(textExercise);
    assertThat(exercisesNrBefore + 1).as("one exercise got stored").isEqualTo(exerciseRepo.count());
    return textExercise;
}
Also used : ExerciseGroup(de.tum.in.www1.artemis.domain.exam.ExerciseGroup)

Example 12 with TextExercise

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

the class DatabaseUtilService method addCourseWithModelingAndTextExercise.

public Course addCourseWithModelingAndTextExercise() {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
    modelingExercise.setTitle("Modeling");
    course.addExercises(modelingExercise);
    TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
    textExercise.setTitle("Text");
    course.addExercises(textExercise);
    course = courseRepo.save(course);
    exerciseRepo.save(modelingExercise);
    exerciseRepo.save(textExercise);
    return course;
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 13 with TextExercise

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

the class DatabaseUtilService method createSubmissionAndResult.

public Result createSubmissionAndResult(StudentParticipation studentParticipation, long scoreAwarded, boolean rated) {
    Exercise exercise = studentParticipation.getExercise();
    Submission submission;
    if (exercise instanceof ProgrammingExercise) {
        submission = new ProgrammingSubmission();
    } else if (exercise instanceof ModelingExercise) {
        submission = new ModelingSubmission();
    } else if (exercise instanceof TextExercise) {
        submission = new TextSubmission();
    } else if (exercise instanceof FileUploadExercise) {
        submission = new FileUploadSubmission();
    } else if (exercise instanceof QuizExercise) {
        submission = new QuizSubmission();
    } else {
        throw new RuntimeException("Unsupported exercise type: " + exercise);
    }
    submission.setType(SubmissionType.MANUAL);
    submission.setParticipation(studentParticipation);
    submission = submissionRepository.saveAndFlush(submission);
    Result result = ModelFactory.generateResult(rated, scoreAwarded);
    result.setParticipation(studentParticipation);
    result.setSubmission(submission);
    result.completionDate(ZonedDateTime.now());
    submission.addResult(result);
    submission = submissionRepository.saveAndFlush(submission);
    return submission.getResults().get(0);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise)

Example 14 with TextExercise

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

the class DatabaseUtilService method addCourseWithOneExerciseAndSubmissions.

/**
 * Generates a course with one specific exercise, and an arbitrare amount of submissions.
 *
 * @param exerciseType             - the type of exercise which should be generated: modeling, programming, file-pload or text
 * @param numberOfSubmissions      - the amount of submissions which should be generated for an exercise
 * @param modelForModelingExercise - the model string for a modeling exercise
 * @return a course with an exercise with submissions
 */
public Course addCourseWithOneExerciseAndSubmissions(String exerciseType, int numberOfSubmissions, Optional<String> modelForModelingExercise) {
    Course course;
    Exercise exercise;
    switch(exerciseType) {
        case "modeling":
            course = addCourseWithOneModelingExercise();
            exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
            for (int j = 1; j <= numberOfSubmissions; j++) {
                StudentParticipation participation = createAndSaveParticipationForExercise(exercise, "student" + j);
                assertThat(modelForModelingExercise).isNotEmpty();
                ModelingSubmission submission = ModelFactory.generateModelingSubmission(modelForModelingExercise.get(), true);
                modelSubmissionService.save(submission, (ModelingExercise) exercise, "student" + j);
                studentParticipationRepo.save(participation);
            }
            return course;
        case "programming":
            course = addCourseWithOneProgrammingExercise();
            exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
            for (int j = 1; j <= numberOfSubmissions; j++) {
                ProgrammingSubmission submission = new ProgrammingSubmission();
                addProgrammingSubmission((ProgrammingExercise) exercise, submission, "student" + j);
            }
            return course;
        case "text":
            course = addCourseWithOneFinishedTextExercise();
            exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
            for (int j = 1; j <= numberOfSubmissions; j++) {
                TextSubmission textSubmission = ModelFactory.generateTextSubmission("Text" + j + j, null, true);
                saveTextSubmission((TextExercise) exercise, textSubmission, "student" + j);
            }
            return course;
        case "file-upload":
            course = addCourseWithFileUploadExercise();
            exercise = exerciseRepo.findAllExercisesByCourseId(course.getId()).iterator().next();
            for (int j = 1; j <= numberOfSubmissions; j++) {
                FileUploadSubmission submission = ModelFactory.generateFileUploadSubmissionWithFile(true, "path/to/file.pdf");
                saveFileUploadSubmission((FileUploadExercise) exercise, submission, "student" + j);
            }
            return course;
        default:
            return null;
    }
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint)

Example 15 with TextExercise

use of de.tum.in.www1.artemis.domain.TextExercise 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)

Aggregations

WithMockUser (org.springframework.security.test.context.support.WithMockUser)109 Test (org.junit.jupiter.api.Test)105 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)58 TextExercise (de.tum.in.www1.artemis.domain.TextExercise)51 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)50 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)44 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)41 Course (de.tum.in.www1.artemis.domain.Course)31 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)30 BeforeEach (org.junit.jupiter.api.BeforeEach)26 TextSubmissionElement (de.tum.in.www1.artemis.domain.plagiarism.text.TextSubmissionElement)25 PlagiarismComparison (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismComparison)23 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)22 PlagiarismSubmission (de.tum.in.www1.artemis.domain.plagiarism.PlagiarismSubmission)22 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)22 Participation (de.tum.in.www1.artemis.domain.participation.Participation)16 TextAssessmentDTO (de.tum.in.www1.artemis.web.rest.dto.TextAssessmentDTO)16 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14