Search in sources :

Example 1 with TextSubmission

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

the class DatabaseUtilService method addCourseWithExercisesAndSubmissions.

/**
 * With this method we can generate a course. We can specify the number of exercises. To not only test one type, this method generates modeling, file-upload and text
 * exercises in a cyclic manner.
 *
 * @param numberOfExercises             number of generated exercises. E.g. if you set it to 4, 2 modeling exercises, one text and one file-upload exercise will be generated.
 *                                      (thats why there is the %3 check)
 * @param numberOfSubmissionPerExercise for each exercise this number of submissions will be generated. E.g. if you have 2 exercises, and set this to 4, in total 8
 *                                      submissions will be created.
 * @param numberOfAssessments           generates the assessments for a submission of an exercise. Example from abobe, 2 exrecises, 4 submissions each. If you set
 *                                      numberOfAssessments to 2, for each exercise 2 assessmetns will be created. In total there will be 4 assessments then. (by two
 *                                      different tutors, as each exercise is assessed by an individual tutor. There are 4 tutors that create assessments)
 * @param numberOfComplaints            generates the complaints for assessments, in the same way as results are created.
 * @param typeComplaint                 true: complaintType==COMPLAINT | false: complaintType==MORE_FEEDBACK
 * @param numberComplaintResponses      generates responses for the complaint/feedback request (as above)
 * @param validModel                    model for the modeling submission
 * @return - the generated course
 */
public Course addCourseWithExercisesAndSubmissions(int numberOfExercises, int numberOfSubmissionPerExercise, int numberOfAssessments, int numberOfComplaints, boolean typeComplaint, int numberComplaintResponses, String validModel) {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureFutureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    var tutors = userRepo.getTutors(course);
    for (int i = 0; i < numberOfExercises; i++) {
        var currentUser = tutors.get(i % 4);
        if ((i % 3) == 0) {
            ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, DiagramType.ClassDiagram, course);
            modelingExercise.setTitle("Modeling" + i);
            course.addExercises(modelingExercise);
            course = courseRepo.save(course);
            exerciseRepo.save(modelingExercise);
            for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
                StudentParticipation participation = createAndSaveParticipationForExercise(modelingExercise, "student" + j);
                ModelingSubmission submission = ModelFactory.generateModelingSubmission(validModel, true);
                modelSubmissionService.save(submission, modelingExercise, "student" + j);
                studentParticipationRepo.save(participation);
                if (numberOfAssessments >= j) {
                    Result result = generateResult(submission, currentUser);
                    submission.addResult(result);
                    participation.addResult(result);
                    studentParticipationRepo.save(participation);
                    modelingSubmissionRepo.save(submission);
                    generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
                }
            }
        } else if ((i % 3) == 1) {
            TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, course);
            textExercise.setTitle("Text" + i);
            course.addExercises(textExercise);
            course = courseRepo.save(course);
            exerciseRepo.save(textExercise);
            for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
                TextSubmission submission = ModelFactory.generateTextSubmission("submissionText", Language.ENGLISH, true);
                submission = saveTextSubmission(textExercise, submission, "student" + j);
                if (numberOfAssessments >= j) {
                    Result result = generateResult(submission, currentUser);
                    submission.addResult(result);
                    saveResultInParticipation(submission, result);
                    textSubmissionRepo.save(submission);
                    generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
                }
            }
        } else if ((i % 3) == 2) {
            FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, pastTimestamp.plusHours(1), futureTimestamp, "png,pdf", course);
            fileUploadExercise.setTitle("FileUpload" + i);
            course.addExercises(fileUploadExercise);
            course = courseRepo.save(course);
            exerciseRepo.save(fileUploadExercise);
            for (int j = 1; j <= numberOfSubmissionPerExercise; j++) {
                FileUploadSubmission submission = ModelFactory.generateFileUploadSubmissionWithFile(true, "path/to/file.pdf");
                saveFileUploadSubmission(fileUploadExercise, submission, "student" + j);
                if (numberOfAssessments >= j) {
                    Result result = generateResult(submission, currentUser);
                    saveResultInParticipation(submission, result);
                    fileUploadSubmissionRepo.save(submission);
                    generateComplaintAndResponses(j, numberOfComplaints, numberComplaintResponses, typeComplaint, result, currentUser);
                }
            }
        }
    }
    course = courseRepo.save(course);
    return course;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) ExerciseHint(de.tum.in.www1.artemis.domain.hestia.ExerciseHint) TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 2 with TextSubmission

use of de.tum.in.www1.artemis.domain.TextSubmission 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 3 with TextSubmission

use of de.tum.in.www1.artemis.domain.TextSubmission 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 4 with TextSubmission

use of de.tum.in.www1.artemis.domain.TextSubmission 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 5 with TextSubmission

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

the class DatabaseUtilService method createCourseWithTestModelingAndFileUploadExercisesAndSubmissions.

public Course createCourseWithTestModelingAndFileUploadExercisesAndSubmissions() throws Exception {
    Course course = addCourseWithModelingAndTextAndFileUploadExercise();
    course.setEndDate(ZonedDateTime.now().minusMinutes(5));
    course = courseRepo.save(course);
    var fileUploadExercise = findFileUploadExerciseWithTitle(course.getExercises(), "FileUpload");
    createFileUploadSubmissionWithFile(fileUploadExercise, "uploaded-file.png");
    var textExercise = findTextExerciseWithTitle(course.getExercises(), "Text");
    var textSubmission = ModelFactory.generateTextSubmission("example text", Language.ENGLISH, true);
    saveTextSubmission(textExercise, textSubmission, "student1");
    var modelingExercise = findModelingExerciseWithTitle(course.getExercises(), "Modeling");
    createAndSaveParticipationForExercise(modelingExercise, "student1");
    String emptyActivityModel = FileUtils.loadFileFromResources("test-data/model-submission/empty-activity-diagram.json");
    ModelingSubmission submission = ModelFactory.generateModelingSubmission(emptyActivityModel, true);
    addSubmission(modelingExercise, submission, "student1");
    return course;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) JsonParser.parseString(com.google.gson.JsonParser.parseString)

Aggregations

Test (org.junit.jupiter.api.Test)86 WithMockUser (org.springframework.security.test.context.support.WithMockUser)84 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)62 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)44 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)28 TextAssessmentDTO (de.tum.in.www1.artemis.web.rest.dto.TextAssessmentDTO)28 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)28 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)22 ZonedDateTime (java.time.ZonedDateTime)16 BeforeEach (org.junit.jupiter.api.BeforeEach)16 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)14 TextSubmission (de.tum.in.www1.artemis.domain.TextSubmission)14 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)14 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)14 java.util (java.util)14 Exam (de.tum.in.www1.artemis.domain.exam.Exam)12 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)12 Collectors (java.util.stream.Collectors)12 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)10