Search in sources :

Example 6 with ProgrammingExerciseStudentParticipation

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

the class ProgrammingExerciseScheduleService method invokeOperationOnAllParticipationsThatSatisfy.

/**
 * Invokes the given <code>operation</code> on all student participations that satisfy the <code>condition</code>-{@link Predicate}.
 * <p>
 *
 * @param programmingExerciseId the programming exercise whose participations should be processed
 * @param operation the operation to perform
 * @param condition the condition that tests whether to invoke the operation on a participation
 * @param operationName the name of the operation, this is only used for logging
 * @return a list containing all participations for which the operation has failed with an exception
 * @throws EntityNotFoundException if the programming exercise can't be found.
 */
private List<ProgrammingExerciseStudentParticipation> invokeOperationOnAllParticipationsThatSatisfy(Long programmingExerciseId, BiConsumer<ProgrammingExercise, ProgrammingExerciseStudentParticipation> operation, Predicate<ProgrammingExerciseStudentParticipation> condition, String operationName) {
    log.info("Invoking (scheduled) task '{}' for programming exercise with id {}.", operationName, programmingExerciseId);
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findWithEagerStudentParticipationsById(programmingExerciseId).orElseThrow(() -> new EntityNotFoundException("ProgrammingExercise", programmingExerciseId));
    List<ProgrammingExerciseStudentParticipation> failedOperations = new ArrayList<>();
    for (StudentParticipation studentParticipation : programmingExercise.getStudentParticipations()) {
        ProgrammingExerciseStudentParticipation programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
        try {
            if (condition.test(programmingExerciseStudentParticipation)) {
                operation.accept(programmingExercise, programmingExerciseStudentParticipation);
            }
        } catch (Exception e) {
            log.error(String.format("'%s' failed for programming exercise with id %d for student repository with participation id %d", operationName, programmingExercise.getId(), studentParticipation.getId()), e);
            failedOperations.add(programmingExerciseStudentParticipation);
        }
    }
    return failedOperations;
}
Also used : ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 7 with ProgrammingExerciseStudentParticipation

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

the class ProgrammingExerciseParticipation method isLocked.

/**
 * Check if the participation is locked.
 * This is the case when the participation is a ProgrammingExerciseStudentParticipation,
 * the buildAndTestAfterDueDate of the exercise is set and the due date has passed,
 * or if manual correction is involved and the due date has passed.
 *
 * Locked means that the student can't make any changes to their repository anymore.
 * While we can control this easily in the remote VCS, we need to check this manually
 * for the local repository on the Artemis server.
 *
 * @return true if repository is locked, false if not.
 */
@JsonIgnore
default boolean isLocked() {
    if (!(this instanceof ProgrammingExerciseStudentParticipation)) {
        return false;
    }
    final ProgrammingExercise programmingExercise = getProgrammingExercise();
    final ZonedDateTime now = ZonedDateTime.now();
    boolean isAfterDueDate = false;
    if (getIndividualDueDate() != null) {
        isAfterDueDate = now.isAfter(getIndividualDueDate());
    } else if (programmingExercise.getDueDate() != null) {
        isAfterDueDate = now.isAfter(programmingExercise.getDueDate());
    }
    // Editing is allowed if build and test after due date is not set and no manual correction is involved
    // (this should match CodeEditorStudentContainerComponent.repositoryIsLocked on the client-side)
    boolean isEditingAfterDueAllowed = programmingExercise.getBuildAndTestStudentSubmissionsAfterDueDate() == null && programmingExercise.getAssessmentType() != AssessmentType.MANUAL && programmingExercise.getAssessmentType() != AssessmentType.SEMI_AUTOMATIC && !programmingExercise.areManualResultsAllowed();
    return isAfterDueDate && !isEditingAfterDueAllowed;
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Example 8 with ProgrammingExerciseStudentParticipation

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

the class ProgrammingExerciseParticipationResource method getParticipationWithLatestResultForStudentParticipation.

/**
 * Get the given student participation with its latest result and feedbacks.
 *
 * @param participationId for which to retrieve the student participation with latest result and feedbacks.
 * @return the ResponseEntity with status 200 (OK) and the participation with its latest result in the body.
 */
@GetMapping("/programming-exercise-participations/{participationId}/student-participation-with-latest-result-and-feedbacks")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Participation> getParticipationWithLatestResultForStudentParticipation(@PathVariable Long participationId) {
    ProgrammingExerciseStudentParticipation participation = programmingExerciseStudentParticipationRepository.findStudentParticipationWithLatestResultAndFeedbacksAndRelatedSubmissions(participationId).orElseThrow(() -> new EntityNotFoundException("Participation", participationId));
    if (!programmingExerciseParticipationService.canAccessParticipation(participation)) {
        throw new AccessForbiddenException("participation", participationId);
    }
    if (!authCheckService.isAtLeastTeachingAssistantForExercise(participation.getExercise())) {
        // hide details that should not be shown to the students
        participation.getExercise().filterSensitiveInformation();
        participation.getResults().forEach(result -> filterSensitiveInformationInResult(participation, result));
    }
    return ResponseEntity.ok(participation);
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with ProgrammingExerciseStudentParticipation

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

the class ProgrammingSubmissionResultSimulationResource method createNewProgrammingExerciseResult.

/**
 * This method is used to notify artemis that there is a new programming exercise build result.
 * This result is only a SIMULATION for the testing of programming exercises without a connection
 * to the VCS and CI server
 * This functionality is only for testing purposes (noVersionControlAndContinuousIntegrationAvailable)
 * @param exerciseId id of the exercise
 * @return HTTP OK and Result
 */
@PostMapping(Endpoints.RESULTS_SIMULATION)
@PreAuthorize("hasRole('EDITOR')")
public ResponseEntity<Result> createNewProgrammingExerciseResult(@PathVariable Long exerciseId) {
    log.debug("Received result notify (NEW)");
    User user = userRepository.getUserWithGroupsAndAuthorities();
    ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithStudentParticipationsAndLegalSubmissionsElseThrow(exerciseId);
    var studentParticipation = participationService.findOneByExerciseAndParticipantAnyState(programmingExercise, user).orElseThrow(() -> new EntityNotFoundException("Participation for programming exercise " + programmingExercise.getId() + " and user " + user.getLogin() + " not found!"));
    var programmingExerciseStudentParticipation = (ProgrammingExerciseStudentParticipation) studentParticipation;
    Result result = programmingSubmissionResultSimulationService.createResult(programmingExerciseStudentParticipation);
    messagingService.broadcastNewResult(programmingExerciseStudentParticipation, result);
    log.info("The new result for {} was saved successfully", programmingExerciseStudentParticipation.getBuildPlanId());
    try {
        return ResponseEntity.created(new URI("/api/results" + result.getId())).body(result);
    } catch (URISyntaxException e) {
        log.error("Error while simulating a result", e);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).headers(HeaderUtil.createAlert(applicationName, "An error occurred while simulating a result: " + e.getMessage(), "errorResult")).body(null);
    }
}
Also used : ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) PostMapping(org.springframework.web.bind.annotation.PostMapping) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 10 with ProgrammingExerciseStudentParticipation

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

the class ProgrammingExerciseTest method findAppropriateSubmissionRespectingIndividualDueDate.

@ParameterizedTest(name = "{displayName} [{index}] {argumentsWithNames}")
@ValueSource(booleans = { true, false })
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void findAppropriateSubmissionRespectingIndividualDueDate(boolean isSubmissionAfterIndividualDueDate) {
    ProgrammingExercise exercise = programmingExerciseRepository.findByIdElseThrow(programmingExerciseId);
    exercise.setDueDate(ZonedDateTime.now());
    exercise = programmingExerciseRepository.save(exercise);
    ProgrammingSubmission submission = new ProgrammingSubmission();
    submission.setType(SubmissionType.OTHER);
    if (isSubmissionAfterIndividualDueDate) {
        submission.setSubmissionDate(ZonedDateTime.now().plusHours(26));
    } else {
        // submission time after exercise due date but before individual due date
        submission.setSubmissionDate(ZonedDateTime.now().plusHours(1));
    }
    submission = database.addProgrammingSubmission(exercise, submission, "student1");
    ProgrammingExerciseStudentParticipation participation = participationRepository.findByExerciseIdAndStudentLogin(programmingExerciseId, "student1").get();
    participation.setIndividualDueDate(ZonedDateTime.now().plusDays(1));
    submission.setParticipation(participation);
    Submission latestValidSubmission = exercise.findAppropriateSubmissionByResults(Set.of(submission));
    if (isSubmissionAfterIndividualDueDate) {
        assertThat(latestValidSubmission).isNull();
    } else {
        assertThat(latestValidSubmission).isEqualTo(submission);
    }
}
Also used : ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) Submission(de.tum.in.www1.artemis.domain.Submission) ProgrammingSubmission(de.tum.in.www1.artemis.domain.ProgrammingSubmission) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) ProgrammingExerciseStudentParticipation(de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation) WithMockUser(org.springframework.security.test.context.support.WithMockUser) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ProgrammingExerciseStudentParticipation (de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation)58 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)26 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 WithMockUser (org.springframework.security.test.context.support.WithMockUser)24 ProgrammingExercise (de.tum.in.www1.artemis.domain.ProgrammingExercise)20 Test (org.junit.jupiter.api.Test)20 Result (de.tum.in.www1.artemis.domain.Result)18 BeforeEach (org.junit.jupiter.api.BeforeEach)18 AbstractSpringIntegrationBambooBitbucketJiraTest (de.tum.in.www1.artemis.AbstractSpringIntegrationBambooBitbucketJiraTest)16 ZonedDateTime (java.time.ZonedDateTime)16 EnumSource (org.junit.jupiter.params.provider.EnumSource)16 Feedback (de.tum.in.www1.artemis.domain.Feedback)14 ProgrammingExerciseRepository (de.tum.in.www1.artemis.repository.ProgrammingExerciseRepository)14 ModelFactory (de.tum.in.www1.artemis.util.ModelFactory)14 EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)14 List (java.util.List)14 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)14 AfterEach (org.junit.jupiter.api.AfterEach)14 Autowired (org.springframework.beans.factory.annotation.Autowired)14 AssessmentType (de.tum.in.www1.artemis.domain.enumeration.AssessmentType)12