Search in sources :

Example 26 with Submission

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

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

the class DatabaseUtilService method createCoursesWithExercisesAndLectures.

public List<Course> createCoursesWithExercisesAndLectures(boolean withParticipations) throws Exception {
    ZonedDateTime pastTimestamp = ZonedDateTime.now().minusDays(5);
    ZonedDateTime futureTimestamp = ZonedDateTime.now().plusDays(5);
    ZonedDateTime futureFutureTimestamp = ZonedDateTime.now().plusDays(8);
    Course course1 = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    Course course2 = ModelFactory.generateCourse(null, ZonedDateTime.now().minusDays(8), pastTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course1);
    modelingExercise.setGradingInstructions("some grading instructions");
    modelingExercise.setExampleSolutionModel("Example solution model");
    modelingExercise.setExampleSolutionExplanation("Example Solution");
    addGradingInstructionsToExercise(modelingExercise);
    modelingExercise.getCategories().add("Modeling");
    modelingExercise.setKnowledge(modelAssessmentKnowledgeService.createNewKnowledge());
    course1.addExercises(modelingExercise);
    TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course1);
    textExercise.setGradingInstructions("some grading instructions");
    textExercise.setExampleSolution("Example Solution");
    addGradingInstructionsToExercise(textExercise);
    textExercise.getCategories().add("Text");
    textExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
    course1.addExercises(textExercise);
    FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course1);
    fileUploadExercise.setGradingInstructions("some grading instructions");
    fileUploadExercise.setExampleSolution("Example Solution");
    addGradingInstructionsToExercise(fileUploadExercise);
    fileUploadExercise.getCategories().add("File");
    course1.addExercises(fileUploadExercise);
    ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course1);
    programmingExercise.setGradingInstructions("some grading instructions");
    addGradingInstructionsToExercise(programmingExercise);
    programmingExercise.getCategories().add("Programming");
    course1.addExercises(programmingExercise);
    QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course1);
    programmingExercise.getCategories().add("Quiz");
    course1.addExercises(quizExercise);
    Lecture lecture1 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
    Attachment attachment1 = ModelFactory.generateAttachment(pastTimestamp, lecture1);
    lecture1.addAttachments(attachment1);
    course1.addLectures(lecture1);
    Lecture lecture2 = ModelFactory.generateLecture(pastTimestamp, futureFutureTimestamp, course1);
    Attachment attachment2 = ModelFactory.generateAttachment(pastTimestamp, lecture2);
    lecture2.addAttachments(attachment2);
    course1.addLectures(lecture2);
    course1 = courseRepo.save(course1);
    course2 = courseRepo.save(course2);
    lectureRepo.save(lecture1);
    lectureRepo.save(lecture2);
    attachmentRepo.save(attachment1);
    attachmentRepo.save(attachment2);
    modelingExercise = exerciseRepo.save(modelingExercise);
    textExercise = exerciseRepo.save(textExercise);
    exerciseRepo.save(fileUploadExercise);
    exerciseRepo.save(programmingExercise);
    exerciseRepo.save(quizExercise);
    if (withParticipations) {
        // create 5 tutor participations and 5 example submissions and connect all of them (to test the many-to-many relationship)
        var tutorParticipations = new ArrayList<TutorParticipation>();
        for (int i = 1; i < 6; i++) {
            var tutorParticipation = new TutorParticipation().tutor(getUserByLogin("tutor" + i));
            tutorParticipationRepo.save(tutorParticipation);
            tutorParticipations.add(tutorParticipation);
        }
        for (int i = 0; i < 5; i++) {
            String validModel = FileUtils.loadFileFromResources("test-data/model-submission/model.54727.json");
            var exampleSubmission = addExampleSubmission(generateExampleSubmission(validModel, modelingExercise, true));
            exampleSubmission.assessmentExplanation("exp");
            for (var tutorParticipation : tutorParticipations) {
                exampleSubmission.addTutorParticipations(tutorParticipation);
            }
            exampleSubmissionRepo.save(exampleSubmission);
        }
        User user = (userRepo.findOneByLogin("student1")).get();
        StudentParticipation participation1 = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, modelingExercise, user);
        StudentParticipation participation2 = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
        StudentParticipation participation3 = ModelFactory.generateStudentParticipation(InitializationState.UNINITIALIZED, modelingExercise, user);
        Submission modelingSubmission1 = ModelFactory.generateModelingSubmission("model1", true);
        Submission modelingSubmission2 = ModelFactory.generateModelingSubmission("model2", true);
        Submission textSubmission = ModelFactory.generateTextSubmission("text", Language.ENGLISH, true);
        Result result1 = ModelFactory.generateResult(true, 10D);
        Result result2 = ModelFactory.generateResult(true, 12D);
        Result result3 = ModelFactory.generateResult(false, 0D);
        participation1 = studentParticipationRepo.save(participation1);
        participation2 = studentParticipationRepo.save(participation2);
        participation3 = studentParticipationRepo.save(participation3);
        submissionRepository.save(modelingSubmission1);
        submissionRepository.save(modelingSubmission2);
        submissionRepository.save(textSubmission);
        modelingSubmission1.setParticipation(participation1);
        textSubmission.setParticipation(participation2);
        modelingSubmission2.setParticipation(participation3);
        result1.setParticipation(participation1);
        result2.setParticipation(participation3);
        result3.setParticipation(participation2);
        result1 = resultRepo.save(result1);
        result2 = resultRepo.save(result2);
        result3 = resultRepo.save(result3);
        result1.setSubmission(modelingSubmission1);
        result2.setSubmission(modelingSubmission2);
        result3.setSubmission(textSubmission);
        modelingSubmission1.addResult(result1);
        modelingSubmission2.addResult(result2);
        textSubmission.addResult(result3);
        submissionRepository.save(modelingSubmission1);
        submissionRepository.save(modelingSubmission2);
        submissionRepository.save(textSubmission);
    }
    return Arrays.asList(course1, course2);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) JsonParser.parseString(com.google.gson.JsonParser.parseString) 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) ZonedDateTime(java.time.ZonedDateTime)

Example 28 with Submission

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

the class DatabaseUtilService method addComplaintToSubmission.

public void addComplaintToSubmission(Submission submission, String userLogin, ComplaintType type) {
    Result result = submission.getLatestResult();
    if (result != null) {
        result.hasComplaint(true);
        resultRepo.save(result);
    }
    Complaint complaint = new Complaint().participant(getUserByLogin(userLogin)).result(result).complaintType(type);
    complaintRepo.save(complaint);
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 29 with Submission

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

the class DatabaseUtilService method generateResult.

public Result generateResult(Submission submission, User assessor) {
    Result result = new Result();
    result = resultRepo.save(result);
    result.setSubmission(submission);
    result.completionDate(pastTimestamp);
    result.resultString("3 of 10 points");
    result.setAssessmentType(AssessmentType.SEMI_AUTOMATIC);
    result.setAssessor(assessor);
    result.setRated(true);
    return result;
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 30 with Submission

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

the class DatabaseUtilService method addProgrammingSubmissionWithResult.

/**
 * Add a submission with a result to the given programming exercise. The submission will be assigned to the corresponding participation of the given login (if exists or create a new participation).
 * The method will make sure that all necessary entities are connected.
 *
 * @param exercise   for which to create the submission/participation/result combination.
 * @param submission to use for adding to the exercise/participation/result.
 * @param login      of the user to identify the corresponding student participation.
 */
public void addProgrammingSubmissionWithResult(ProgrammingExercise exercise, ProgrammingSubmission submission, String login) {
    StudentParticipation participation = addStudentParticipationForProgrammingExercise(exercise, login);
    submission = programmingSubmissionRepo.save(submission);
    Result result = resultRepo.save(new Result().participation(participation));
    participation.addSubmission(submission);
    submission.setParticipation(participation);
    submission.addResult(result);
    submission = programmingSubmissionRepo.save(submission);
    result.setSubmission(submission);
    result = resultRepo.save(result);
    participation.addResult(result);
    studentParticipationRepo.save(participation);
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Aggregations

Test (org.junit.jupiter.api.Test)226 WithMockUser (org.springframework.security.test.context.support.WithMockUser)216 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)178 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)153 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)72 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)56 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)52 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)48 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)44 Collectors (java.util.stream.Collectors)42 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)40 ZonedDateTime (java.time.ZonedDateTime)40 java.util (java.util)40 HttpHeaders (org.springframework.http.HttpHeaders)40 LinkedMultiValueMap (org.springframework.util.LinkedMultiValueMap)40 Participation (de.tum.in.www1.artemis.domain.participation.Participation)38 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)34 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)34 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)32 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)30