Search in sources :

Example 6 with ProgrammingSubmission

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

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

Example 8 with ProgrammingSubmission

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

the class ProgrammingSubmissionResultSimulationService method createSubmission.

/**
 * This method creates a new submission for the provided user
 * @param exerciseId the exerciseId of the exercise for which a submission should be created
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 * @return the newly created and stored submission
 */
public ProgrammingSubmission createSubmission(Long exerciseId) {
    User user = userRepository.getUserWithGroupsAndAuthorities();
    Participant participant = user;
    ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation;
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
    Optional<StudentParticipation> optionalStudentParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(programmingExercise, user.getLogin());
    if (optionalStudentParticipation.isEmpty()) {
        programmingExerciseStudentParticipation = createParticipation(programmingExercise, participant, user);
    } else {
        programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) optionalStudentParticipation.get();
    }
    ProgrammingSubmission programmingSubmission = new ProgrammingSubmission();
    programmingSubmission.setCommitHash(VCSSimulationUtils.simulateCommitHash());
    programmingSubmission.setSubmitted(true);
    programmingSubmission.setSubmissionDate(ZonedDateTime.now());
    programmingSubmission.setType(SubmissionType.MANUAL);
    programmingExerciseStudentParticipation.addSubmission(programmingSubmission);
    programmingSubmissionRepository.save(programmingSubmission);
    return programmingSubmission;
}
Also used : Participant(de.tum.in.www1.artemis.domain.participation.Participant) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Example 9 with ProgrammingSubmission

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

the class JenkinsService method getLatestBuildLogs.

@Override
public List<BuildLogEntry> getLatestBuildLogs(ProgrammingSubmission programmingSubmission) {
    ProgrammingExerciseParticipation programmingExerciseParticipation = (ProgrammingExerciseParticipation) programmingSubmission.getParticipation();
    String projectKey = programmingExerciseParticipation.getProgrammingExercise().getProjectKey();
    String buildPlanId = programmingExerciseParticipation.getBuildPlanId();
    ProgrammingLanguage programmingLanguage = programmingExerciseParticipation.getProgrammingExercise().getProgrammingLanguage();
    try {
        final var build = jenkinsJobService.getJobInFolder(projectKey, buildPlanId).getLastBuild();
        List<BuildLogEntry> buildLogEntries;
        // Attempt to parse pipeline logs
        final String pipelineLogs = build.details().getConsoleOutputText();
        if (pipelineLogs != null && pipelineLogs.contains("[Pipeline] Start of Pipeline")) {
            buildLogEntries = JenkinsBuildLogParseUtils.parseBuildLogsFromJenkinsLogs(List.of(pipelineLogs.split("\n")));
        } else {
            // Fallback to legacy logs
            final var logHtml = Jsoup.parse(build.details().getConsoleOutputHtml()).body();
            buildLogEntries = JenkinsBuildLogParseUtils.parseLogsLegacy(logHtml);
        }
        // Filter and save build logs
        buildLogEntries = filterUnnecessaryLogs(buildLogEntries, programmingLanguage);
        buildLogEntries = buildLogService.saveBuildLogs(buildLogEntries, programmingSubmission);
        programmingSubmission.setBuildLogEntries(buildLogEntries);
        programmingSubmissionRepository.save(programmingSubmission);
        return buildLogEntries;
    } catch (IOException e) {
        log.error(e.getMessage(), e);
        throw new JenkinsException(e.getMessage(), e);
    }
}
Also used : ProgrammingExerciseParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation) JenkinsException(de.tum.in.www1.artemis.exception.JenkinsException) ProgrammingLanguage(de.tum.in.www1.artemis.domain.enumeration.ProgrammingLanguage) IOException(java.io.IOException)

Example 10 with ProgrammingSubmission

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

the class ComplaintResource method filterOutUselessDataFromComplaint.

private void filterOutUselessDataFromComplaint(Complaint complaint) {
    if (complaint.getResult() == null) {
        return;
    }
    StudentParticipation originalParticipation = (StudentParticipation) complaint.getResult().getParticipation();
    if (originalParticipation != null && originalParticipation.getExercise() != null) {
        Exercise exerciseWithOnlyTitle = originalParticipation.getExercise();
        if (exerciseWithOnlyTitle instanceof TextExercise) {
            exerciseWithOnlyTitle = new TextExercise();
        } else if (exerciseWithOnlyTitle instanceof ModelingExercise) {
            exerciseWithOnlyTitle = new ModelingExercise();
        } else if (exerciseWithOnlyTitle instanceof FileUploadExercise) {
            exerciseWithOnlyTitle = new FileUploadExercise();
        } else if (exerciseWithOnlyTitle instanceof ProgrammingExercise) {
            exerciseWithOnlyTitle = new ProgrammingExercise();
        }
        exerciseWithOnlyTitle.setTitle(originalParticipation.getExercise().getTitle());
        exerciseWithOnlyTitle.setId(originalParticipation.getExercise().getId());
        originalParticipation.setExercise(exerciseWithOnlyTitle);
    }
    Submission originalSubmission = complaint.getResult().getSubmission();
    if (originalSubmission != null) {
        Submission submissionWithOnlyId;
        if (originalSubmission instanceof TextSubmission) {
            submissionWithOnlyId = new TextSubmission();
        } else if (originalSubmission instanceof ModelingSubmission) {
            submissionWithOnlyId = new ModelingSubmission();
        } else if (originalSubmission instanceof FileUploadSubmission) {
            submissionWithOnlyId = new FileUploadSubmission();
        } else if (originalSubmission instanceof ProgrammingSubmission) {
            submissionWithOnlyId = new ProgrammingSubmission();
        } else {
            return;
        }
        submissionWithOnlyId.setId(originalSubmission.getId());
        complaint.getResult().setSubmission(submissionWithOnlyId);
    }
}
Also used : ModelingExercise(de.tum.in.www1.artemis.domain.modeling.ModelingExercise) 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) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Aggregations

ProgrammingSubmission (de.tum.in.www1.artemis.domain.ProgrammingSubmission)30 WithMockUser (org.springframework.security.test.context.support.WithMockUser)26 Test (org.junit.jupiter.api.Test)24 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)16 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)16 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)16 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 HttpHeaders (org.springframework.http.HttpHeaders)10 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)8 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)8 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)8 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)8 ArrayList (java.util.ArrayList)8 AbstractSpringIntegrationJenkinsGitlabTest (de.tum.in.www1.artemis.AbstractSpringIntegrationJenkinsGitlabTest)6 ProgrammingExerciseParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseParticipation)6 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)6 Path (java.nio.file.Path)6 BeforeEach (org.junit.jupiter.api.BeforeEach)5 AbstractSpringDevelopmentTest (de.tum.in.www1.artemis.AbstractSpringDevelopmentTest)4