Search in sources :

Example 16 with Submission

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

Example 17 with Submission

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

the class DatabaseUtilService method createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults.

public Course createCourseWithAllExerciseTypesAndParticipationsAndSubmissionsAndResults(boolean hasAssessmentDueDatePassed) {
    Course course = ModelFactory.generateCourse(null, pastTimestamp, futureTimestamp, new HashSet<>(), "tumuser", "tutor", "editor", "instructor");
    ModelingExercise modelingExercise = ModelFactory.generateModelingExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, DiagramType.ClassDiagram, course);
    TextExercise textExercise = ModelFactory.generateTextExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, course);
    FileUploadExercise fileUploadExercise = ModelFactory.generateFileUploadExercise(pastTimestamp, futureTimestamp, futureFutureTimestamp, "png", course);
    ProgrammingExercise programmingExercise = ModelFactory.generateProgrammingExercise(pastTimestamp, futureTimestamp, course);
    QuizExercise quizExercise = ModelFactory.generateQuizExercise(pastTimestamp, futureTimestamp, course);
    // Set assessment due dates
    if (hasAssessmentDueDatePassed) {
        modelingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        textExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        programmingExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
        quizExercise.setAssessmentDueDate(ZonedDateTime.now().minusMinutes(10L));
    } else {
        modelingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        textExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        fileUploadExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        programmingExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
        quizExercise.setAssessmentDueDate(ZonedDateTime.now().plusMinutes(10L));
    }
    // Add exercises to course
    course.addExercises(modelingExercise);
    course.addExercises(textExercise);
    course.addExercises(fileUploadExercise);
    course.addExercises(programmingExercise);
    course.addExercises(quizExercise);
    // Save course and exercises to database
    Course courseSaved = courseRepo.save(course);
    modelingExercise = exerciseRepo.save(modelingExercise);
    textExercise = exerciseRepo.save(textExercise);
    fileUploadExercise = exerciseRepo.save(fileUploadExercise);
    programmingExercise = exerciseRepo.save(programmingExercise);
    quizExercise = exerciseRepo.save(quizExercise);
    // Get user and setup participations
    User user = (userRepo.findOneByLogin("student1")).get();
    StudentParticipation participationModeling = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, modelingExercise, user);
    StudentParticipation participationText = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, textExercise, user);
    StudentParticipation participationFileUpload = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, fileUploadExercise, user);
    StudentParticipation participationQuiz = ModelFactory.generateStudentParticipation(InitializationState.FINISHED, quizExercise, user);
    StudentParticipation participationProgramming = ModelFactory.generateStudentParticipation(InitializationState.INITIALIZED, programmingExercise, user);
    // Save participations
    participationModeling = studentParticipationRepo.save(participationModeling);
    participationText = studentParticipationRepo.save(participationText);
    participationFileUpload = studentParticipationRepo.save(participationFileUpload);
    participationQuiz = studentParticipationRepo.save(participationQuiz);
    participationProgramming = studentParticipationRepo.save(participationProgramming);
    // Setup results
    Result resultModeling = ModelFactory.generateResult(true, 10D);
    resultModeling.setAssessmentType(AssessmentType.MANUAL);
    resultModeling.setCompletionDate(ZonedDateTime.now());
    Result resultText = ModelFactory.generateResult(true, 12D);
    resultText.setAssessmentType(AssessmentType.MANUAL);
    resultText.setCompletionDate(ZonedDateTime.now());
    Result resultFileUpload = ModelFactory.generateResult(true, 0D);
    resultFileUpload.setAssessmentType(AssessmentType.MANUAL);
    resultFileUpload.setCompletionDate(ZonedDateTime.now());
    Result resultQuiz = ModelFactory.generateResult(true, 0D);
    resultQuiz.setAssessmentType(AssessmentType.AUTOMATIC);
    resultQuiz.setCompletionDate(ZonedDateTime.now());
    Result resultProgramming = ModelFactory.generateResult(true, 20D);
    resultProgramming.setAssessmentType(AssessmentType.AUTOMATIC);
    resultProgramming.setCompletionDate(ZonedDateTime.now());
    // Connect participations to results and vice versa
    resultModeling.setParticipation(participationModeling);
    resultText.setParticipation(participationText);
    resultFileUpload.setParticipation(participationFileUpload);
    resultQuiz.setParticipation(participationQuiz);
    resultProgramming.setParticipation(participationProgramming);
    participationModeling.addResult(resultModeling);
    participationText.addResult(resultText);
    participationFileUpload.addResult(resultFileUpload);
    participationQuiz.addResult(resultQuiz);
    participationProgramming.addResult(resultProgramming);
    // Save results and participations
    resultModeling = resultRepo.save(resultModeling);
    resultText = resultRepo.save(resultText);
    resultFileUpload = resultRepo.save(resultFileUpload);
    resultQuiz = resultRepo.save(resultQuiz);
    resultProgramming = resultRepo.save(resultProgramming);
    participationModeling = studentParticipationRepo.save(participationModeling);
    participationText = studentParticipationRepo.save(participationText);
    participationFileUpload = studentParticipationRepo.save(participationFileUpload);
    participationQuiz = studentParticipationRepo.save(participationQuiz);
    participationProgramming = studentParticipationRepo.save(participationProgramming);
    // Connect exercises with participations
    modelingExercise.addParticipation(participationModeling);
    textExercise.addParticipation(participationText);
    fileUploadExercise.addParticipation(participationFileUpload);
    quizExercise.addParticipation(participationQuiz);
    programmingExercise.addParticipation(participationProgramming);
    // Setup submissions and connect with participations
    ModelingSubmission modelingSubmission = ModelFactory.generateModelingSubmission("model1", true);
    TextSubmission textSubmission = ModelFactory.generateTextSubmission("text of text submission", Language.ENGLISH, true);
    FileUploadSubmission fileUploadSubmission = ModelFactory.generateFileUploadSubmission(true);
    QuizSubmission quizSubmission = ModelFactory.generateQuizSubmission(true);
    ProgrammingSubmission programmingSubmission = ModelFactory.generateProgrammingSubmission(true);
    // Save submissions
    modelingSubmission = submissionRepository.save(modelingSubmission);
    textSubmission = submissionRepository.save(textSubmission);
    fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
    quizSubmission = submissionRepository.save(quizSubmission);
    programmingSubmission = submissionRepository.save(programmingSubmission);
    modelingSubmission.setParticipation(participationModeling);
    modelingSubmission.addResult(resultModeling);
    textSubmission.setParticipation(participationText);
    textSubmission.addResult(resultText);
    fileUploadSubmission.setParticipation(participationFileUpload);
    fileUploadSubmission.addResult(resultFileUpload);
    quizSubmission.setParticipation(participationQuiz);
    quizSubmission.addResult(resultQuiz);
    programmingSubmission.setParticipation(participationProgramming);
    programmingSubmission.addResult(resultProgramming);
    // Save submissions
    modelingSubmission = submissionRepository.save(modelingSubmission);
    textSubmission = submissionRepository.save(textSubmission);
    fileUploadSubmission = submissionRepository.save(fileUploadSubmission);
    quizSubmission = submissionRepository.save(quizSubmission);
    programmingSubmission = submissionRepository.save(programmingSubmission);
    // Save exercises
    exerciseRepo.save(modelingExercise);
    exerciseRepo.save(textExercise);
    exerciseRepo.save(fileUploadExercise);
    exerciseRepo.save(programmingExercise);
    exerciseRepo.save(quizExercise);
    // Connect participations with submissions
    participationModeling.setSubmissions(Set.of(modelingSubmission));
    participationText.setSubmissions(Set.of(textSubmission));
    participationFileUpload.setSubmissions(Set.of(fileUploadSubmission));
    participationQuiz.setSubmissions(Set.of(quizSubmission));
    participationProgramming.setSubmissions(Set.of(programmingSubmission));
    // Save participations
    studentParticipationRepo.save(participationModeling);
    studentParticipationRepo.save(participationText);
    studentParticipationRepo.save(participationFileUpload);
    studentParticipationRepo.save(participationQuiz);
    studentParticipationRepo.save(participationProgramming);
    return courseSaved;
}
Also used : 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)

Example 18 with Submission

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

the class DatabaseUtilService method addExampleSubmission.

public ExampleSubmission addExampleSubmission(ExampleSubmission exampleSubmission) {
    Submission submission;
    if (exampleSubmission.getSubmission() instanceof ModelingSubmission) {
        submission = modelingSubmissionRepo.save((ModelingSubmission) exampleSubmission.getSubmission());
    } else {
        submission = textSubmissionRepo.save((TextSubmission) exampleSubmission.getSubmission());
    }
    exampleSubmission.setSubmission(submission);
    return exampleSubmissionRepo.save(exampleSubmission);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)

Example 19 with Submission

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

the class DatabaseUtilService method addModelingAssessmentForSubmission.

public Result addModelingAssessmentForSubmission(ModelingExercise exercise, ModelingSubmission submission, String login, boolean submit) {
    Feedback feedback1 = feedbackRepo.save(new Feedback().detailText("detail1"));
    Feedback feedback2 = feedbackRepo.save(new Feedback().detailText("detail2"));
    List<Feedback> feedbacks = new ArrayList<>();
    feedbacks.add(feedback1);
    feedbacks.add(feedback2);
    Result result = assessmentService.saveManualAssessment(submission, feedbacks, null);
    result.setParticipation(submission.getParticipation().results(null));
    result.setAssessor(getUserByLogin(login));
    resultRepo.save(result);
    if (submit) {
        assessmentService.submitManualAssessment(result.getId(), exercise, submission.getSubmissionDate());
    }
    return resultRepo.findWithEagerSubmissionAndFeedbackAndAssessorById(result.getId()).get();
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 20 with Submission

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

the class QuizSubmissionWebsocketService method saveSubmission.

// TODO it would be nice to have some kind of startQuiz call that creates the participation with an initialization date. This should happen when the quiz is first shown
// to the user. Then we also could find out how long students work on the quiz on average
/**
 * Saves a quiz submission into the hash maps. Submitted quizzes are marked to be saved into the database in the QuizScheduleService
 *
 * @param exerciseId     the exerciseID to the corresponding QuizExercise
 * @param quizSubmission the submission which should be saved
 * @param principal      refers to the user who initiated the request
 */
@MessageMapping("/topic/quizExercise/{exerciseId}/submission")
public void saveSubmission(@DestinationVariable Long exerciseId, @Payload QuizSubmission quizSubmission, Principal principal) {
    // Without this, custom jpa repository methods don't work in websocket channel.
    SecurityUtils.setAuthorizationObject();
    String username = principal.getName();
    try {
        QuizSubmission updatedQuizSubmission = quizSubmissionService.saveSubmissionForLiveMode(exerciseId, quizSubmission, username, false);
    // send updated submission over websocket (use a thread to prevent that the outbound channel blocks the inbound channel (e.g. due a slow client))
    // to improve the performance, this is currently deactivated: slow clients might lead to bottlenecks so that more important messages can not be distributed any more
    // new Thread(() -> sendSubmissionToUser(username, exerciseId, quizSubmission)).start();
    // log.info("WS.Inbound: Sent quiz submission (async) back to user {} in quiz {} after {} µs ", principal.getName(), exerciseId, (System.nanoTime() - start) / 1000);
    } catch (QuizSubmissionException ex) {
        // send error message over websocket (use a thread to prevent that the outbound channel blocks the inbound channel (e.g. due a slow client))
        new Thread(() -> messagingTemplate.convertAndSendToUser(username, "/topic/quizExercise/" + exerciseId + "/submission", new WebsocketError(ex.getMessage()))).start();
    }
}
Also used : QuizSubmission(de.tum.in.www1.artemis.domain.quiz.QuizSubmission) QuizSubmissionException(de.tum.in.www1.artemis.exception.QuizSubmissionException) MessageMapping(org.springframework.messaging.handler.annotation.MessageMapping)

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