Search in sources :

Example 16 with StudentParticipation

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

the class DatabaseUtilService method addModelingSubmissionWithResultAndAssessor.

public ModelingSubmission addModelingSubmissionWithResultAndAssessor(ModelingExercise exercise, ModelingSubmission submission, String login, String assessorLogin) {
    StudentParticipation participation = createAndSaveParticipationForExercise(exercise, login);
    participation.addSubmission(submission);
    submission = modelingSubmissionRepo.save(submission);
    Result result = new Result();
    result.setAssessor(getUserByLogin(assessorLogin));
    result.setAssessmentType(AssessmentType.MANUAL);
    result = resultRepo.save(result);
    submission = modelingSubmissionRepo.save(submission);
    studentParticipationRepo.save(participation);
    result = resultRepo.save(result);
    result.setSubmission(submission);
    submission.setParticipation(participation);
    submission.addResult(result);
    submission.getParticipation().addResult(result);
    submission = modelingSubmissionRepo.save(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 17 with StudentParticipation

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

the class ScoreService method updateOrCreateParticipantScore.

/**
 * Either updates an existing participant score or creates a new participant score if a new result comes in
 * The annotation "@Transactional" is ok because it means that this method does not support run in an outer transactional context, instead the outer transaction is paused
 *
 * @param createdOrUpdatedResult newly created or updated result
 */
// ok (see JavaDoc)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void updateOrCreateParticipantScore(Result createdOrUpdatedResult) {
    if (createdOrUpdatedResult.getScore() == null || createdOrUpdatedResult.getCompletionDate() == null) {
        return;
    }
    // There is a deadlock problem with programming exercises here if we use the participation from the result (reason unknown at the moment)
    // therefore we get the participation from the database
    Optional<StudentParticipation> studentParticipationOptional = getStudentParticipationForResult(createdOrUpdatedResult);
    if (studentParticipationOptional.isEmpty()) {
        return;
    }
    StudentParticipation studentParticipation = studentParticipationOptional.get();
    // we ignore test runs of exams
    if (studentParticipation.isTestRun()) {
        return;
    }
    Exercise exercise = studentParticipation.getExercise();
    ParticipantScore existingParticipationScoreForExerciseAndParticipant = getExistingParticipationScore(studentParticipation, exercise);
    // there already exists a participant score -> we need to update it
    if (existingParticipationScoreForExerciseAndParticipant != null) {
        updateExistingParticipantScore(existingParticipationScoreForExerciseAndParticipant, createdOrUpdatedResult, exercise);
    } else {
        // there does not already exist a participant score -> we need to create it
        createNewParticipantScore(createdOrUpdatedResult, studentParticipation, exercise);
    }
}
Also used : ParticipantScore(de.tum.in.www1.artemis.domain.scores.ParticipantScore) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) Transactional(org.springframework.transaction.annotation.Transactional)

Example 18 with StudentParticipation

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

the class ScoreService method createNewTeamScore.

private void createNewTeamScore(Result newResult, StudentParticipation studentParticipation, Exercise exercise) {
    TeamScore newTeamScore = new TeamScore();
    newTeamScore.setExercise(exercise);
    newTeamScore.setTeam(studentParticipation.getTeam().get());
    setLastAttributes(newTeamScore, newResult, exercise);
    if (newResult.isRated() != null && newResult.isRated()) {
        setLastRatedAttributes(newTeamScore, newResult, exercise);
    }
    TeamScore teamScore = teamScoreRepository.saveAndFlush(newTeamScore);
    logger.info("Saved a new team score: " + teamScore);
}
Also used : TeamScore(de.tum.in.www1.artemis.domain.scores.TeamScore)

Example 19 with StudentParticipation

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

the class SubmissionExportService method createZipFileFromParticipations.

/**
 * Creates a zip file from a list of participations for an exercise.
 *
 * The outputDir is used to store the zip file and temporary files used for zipping so make
 * sure to delete it if it's no longer used.
 *
 * @param exercise the exercise in question
 * @param participations a list of participations to include
 * @param enableFilterAfterDueDate true, if all submissions that have been submitted after the due date should not be included in the file
 * @param lateSubmissionFilter an optional date filter for submissions
 * @param outputDir directory to store the temporary files in
 * @param exportErrors a list of errors for submissions that couldn't be exported and are not included in the file
 * @param reportData   a list of all exercises and their statistics
 * @return the zipped file
 * @throws IOException if an error occurred while zipping
 */
private Optional<File> createZipFileFromParticipations(Exercise exercise, List<StudentParticipation> participations, boolean enableFilterAfterDueDate, @Nullable ZonedDateTime lateSubmissionFilter, Path outputDir, List<String> exportErrors, List<ArchivalReportEntry> reportData) throws IOException {
    Course course = exercise.getCourseViaExerciseGroupOrCourseMember();
    // Create unique name for directory
    String zipGroupName = course.getShortName() + "-" + exercise.getTitle() + "-" + exercise.getId();
    String cleanZipGroupName = fileService.removeIllegalCharacters(zipGroupName);
    String zipFileName = cleanZipGroupName + "-" + ZonedDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMdd-Hmss")) + ".zip";
    // Create directory
    Path submissionsFolderPath = Path.of(outputDir.toString(), "zippedSubmissions", zipGroupName);
    Path zipFilePath = Path.of(outputDir.toString(), "zippedSubmissions", zipFileName);
    File submissionFolder = submissionsFolderPath.toFile();
    if (!submissionFolder.exists() && !submissionFolder.mkdirs()) {
        log.error("Couldn't create dir: {}", submissionFolder);
        exportErrors.add("Cannot create directory: " + submissionFolder.toPath());
        return Optional.empty();
    }
    // Create counter for log entry
    MutableInt skippedEntries = new MutableInt();
    // Save all Submissions
    List<Path> submissionFilePaths = participations.stream().map(participation -> {
        Submission latestSubmission = latestSubmission(participation, enableFilterAfterDueDate, lateSubmissionFilter);
        if (latestSubmission == null) {
            skippedEntries.increment();
            return Optional.<Path>empty();
        }
        // create file path
        String submissionFileName = exercise.getTitle() + "-" + participation.getParticipantIdentifier() + "-" + latestSubmission.getId() + this.getFileEndingForSubmission(latestSubmission);
        Path submissionFilePath = Path.of(submissionsFolderPath.toString(), submissionFileName);
        // store file
        try {
            this.saveSubmissionToFile(exercise, latestSubmission, submissionFilePath.toFile());
            return Optional.of(submissionFilePath);
        } catch (Exception ex) {
            String message = "Could not create file " + submissionFilePath + "  for exporting: " + ex.getMessage();
            log.error(message, ex);
            exportErrors.add(message);
            return Optional.<Path>empty();
        }
    }).flatMap(Optional::stream).collect(Collectors.toList());
    // Add report entry
    reportData.add(new ArchivalReportEntry(exercise, fileService.removeIllegalCharacters(exercise.getTitle()), participations.size(), submissionFilePaths.size(), skippedEntries.intValue()));
    if (submissionFilePaths.isEmpty()) {
        return Optional.empty();
    }
    // zip stores submissions
    try {
        zipFileService.createZipFile(zipFilePath, submissionFilePaths, submissionsFolderPath);
    } finally {
        log.debug("Delete all temporary files");
        fileService.deleteFiles(submissionFilePaths);
    }
    return Optional.of(zipFilePath.toFile());
}
Also used : Path(java.nio.file.Path) ArchivalReportEntry(de.tum.in.www1.artemis.service.archival.ArchivalReportEntry) Submission(de.tum.in.www1.artemis.domain.Submission) MutableInt(org.apache.commons.lang.mutable.MutableInt) Course(de.tum.in.www1.artemis.domain.Course) File(java.io.File) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) IOException(java.io.IOException)

Example 20 with StudentParticipation

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

the class SubmissionExportService method exportStudentSubmissions.

/**
 * Exports student submissions to a zip file for an exercise.
 *
 * The outputDir is used to store the zip file and temporary files used for zipping so make
 * sure to delete it if it's no longer used.
 *
 * @param exerciseId the id of the exercise to be exported
 * @param submissionExportOptions the options for the export
 * @param outputDir directory to store the temporary files in
 * @param exportErrors a list of errors for submissions that couldn't be exported and are not included in the file
 * @param reportData   a list of all exercises and their statistics
 * @return a reference to the zipped file
 * @throws IOException if an error occurred while zipping
 */
public Optional<File> exportStudentSubmissions(Long exerciseId, SubmissionExportOptionsDTO submissionExportOptions, Path outputDir, List<String> exportErrors, List<ArchivalReportEntry> reportData) throws IOException {
    Optional<Exercise> exerciseOpt = exerciseRepository.findWithEagerStudentParticipationsStudentAndSubmissionsById(exerciseId);
    if (exerciseOpt.isEmpty()) {
        return Optional.empty();
    }
    Exercise exercise = exerciseOpt.get();
    // Select the participations that should be exported
    List<StudentParticipation> exportedStudentParticipations;
    if (submissionExportOptions.isExportAllParticipants()) {
        exportedStudentParticipations = new ArrayList<>(exercise.getStudentParticipations());
    } else {
        List<String> participantIds = Arrays.stream(submissionExportOptions.getParticipantIdentifierList().split(",")).map(String::trim).toList();
        exportedStudentParticipations = exercise.getStudentParticipations().stream().filter(participation -> participantIds.contains(participation.getParticipantIdentifier())).collect(Collectors.toList());
    }
    boolean enableFilterAfterDueDate = false;
    ZonedDateTime filterLateSubmissionsDate = null;
    if (submissionExportOptions.isFilterLateSubmissions()) {
        if (submissionExportOptions.getFilterLateSubmissionsDate() == null) {
            enableFilterAfterDueDate = true;
        } else {
            filterLateSubmissionsDate = submissionExportOptions.getFilterLateSubmissionsDate();
        }
    }
    // Sort the student participations by id
    exportedStudentParticipations.sort(Comparator.comparing(DomainObject::getId));
    return this.createZipFileFromParticipations(exercise, exportedStudentParticipations, enableFilterAfterDueDate, filterLateSubmissionsDate, outputDir, exportErrors, reportData);
}
Also used : Exercise(de.tum.in.www1.artemis.domain.Exercise) ZonedDateTime(java.time.ZonedDateTime) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation)

Aggregations

StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)219 Test (org.junit.jupiter.api.Test)118 WithMockUser (org.springframework.security.test.context.support.WithMockUser)112 ModelingSubmission (de.tum.in.www1.artemis.domain.modeling.ModelingSubmission)60 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)50 ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)48 ZonedDateTime (java.time.ZonedDateTime)44 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)42 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)40 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)36 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)36 Exam (de.tum.in.www1.artemis.domain.exam.Exam)30 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)30 TextPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.text.TextPlagiarismResult)28 de.tum.in.www1.artemis.repository (de.tum.in.www1.artemis.repository)28 ModelingPlagiarismResult (de.tum.in.www1.artemis.domain.plagiarism.modeling.ModelingPlagiarismResult)26 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)24 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)24 Participation (de.tum.in.www1.artemis.domain.participation.Participation)24 Collectors (java.util.stream.Collectors)24