Search in sources :

Example 6 with Participation

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

the class DatabaseUtilService method addSubmissionWithFinishedResultsWithAssessor.

public Submission addSubmissionWithFinishedResultsWithAssessor(StudentParticipation participation, Submission submission, String assessorLogin) {
    Result result = new Result();
    result.setAssessor(getUserByLogin(assessorLogin));
    result.setCompletionDate(ZonedDateTime.now());
    result.setSubmission(submission);
    submission.setParticipation(participation);
    submission.addResult(result);
    submission.getParticipation().addResult(result);
    submission = saveSubmissionToRepo(submission);
    studentParticipationRepo.save(participation);
    return submission;
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 7 with Participation

use of de.tum.in.www1.artemis.domain.participation.Participation 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 8 with Participation

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

the class JenkinsService method onBuildCompleted.

@Override
public Result onBuildCompleted(ProgrammingExerciseParticipation participation, Object requestBody) {
    final var buildResult = TestResultsDTO.convert(requestBody);
    var newResult = createResultFromBuildResult(buildResult, participation);
    // Fetch submission or create a fallback
    var latestSubmission = super.getSubmissionForBuildResult(participation.getId(), buildResult).orElseGet(() -> createAndSaveFallbackSubmission(participation, buildResult));
    latestSubmission.setBuildFailed("No tests found".equals(newResult.getResultString()));
    // Parse, filter, and save the build logs if they exist
    if (buildResult.getLogs() != null) {
        ProgrammingLanguage programmingLanguage = participation.getProgrammingExercise().getProgrammingLanguage();
        List<BuildLogEntry> buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(buildResult.getLogs());
        buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
        buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, latestSubmission);
        // Set the received logs in order to avoid duplicate entries (this removes existing logs)
        latestSubmission.setBuildLogEntries(buildLogEntries);
    }
    // Note: we only set one side of the relationship because we don't know yet whether the result will actually be saved
    newResult.setSubmission(latestSubmission);
    newResult.setRatedIfNotExceeded(exerciseDateService.getDueDate(participation).orElse(null), latestSubmission);
    return newResult;
}
Also used : ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage)

Example 9 with Participation

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

the class DatabaseUtilService method addResultToSubmission.

public Submission addResultToSubmission(final Submission submission, AssessmentType assessmentType, User user, String resultString, Double score, boolean rated, ZonedDateTime completionDate) {
    Result result = new Result().participation(submission.getParticipation()).assessmentType(assessmentType).resultString(resultString).score(score).rated(rated).completionDate(completionDate);
    result.setAssessor(user);
    result = resultRepo.save(result);
    result.setSubmission(submission);
    submission.addResult(result);
    var savedSubmission = submissionRepository.save(submission);
    return submissionRepository.findWithEagerResultsAndAssessorById(savedSubmission.getId()).orElseThrow();
}
Also used : TextPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult) ModelingPlagiarismResult(de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)

Example 10 with Participation

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

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)181 WithMockUser (org.springframework.security.test.context.support.WithMockUser)138 Test (org.junit.jupiter.api.Test)124 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)70 Participation (de.tum.in.www1.artemis.domain.participation.Participation)54 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)50 ZonedDateTime (java.time.ZonedDateTime)47 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)44 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)44 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)42 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)38 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)38 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)34 Collectors (java.util.stream.Collectors)34 HttpHeaders (org.springframework.http.HttpHeaders)34 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)33 Result (de.tum.in.www1.artemis.domain.Result)33 Exam (de.tum.in.www1.artemis.domain.exam.Exam)32 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)32