use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState.
// TEST
public void resumeProgrammingExerciseByTriggeringInstructorBuild_correctInitializationState(ExerciseMode exerciseMode) throws Exception {
var participation = createStudentParticipationWithSubmission(exerciseMode);
var participant = participation.getParticipant();
mockDelegate.mockTriggerInstructorBuildAll(participation);
// We need to mock the call again because we are triggering the build twice in order to verify that the submission isn't re-created
mockDelegate.mockTriggerInstructorBuildAll(participation);
mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
// These will be updated triggering a failed build
participation.setInitializationState(InitializationState.INACTIVE);
participation.setBuildPlanId(null);
programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
var url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build-all";
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
Awaitility.setDefaultTimeout(Duration.ofSeconds(20));
await().until(() -> programmingExerciseRepository.findWithTemplateAndSolutionParticipationTeamAssignmentConfigCategoriesById(exercise.getId()).isPresent());
// Fetch updated participation and assert
ProgrammingExerciseStudentParticipation updatedParticipation = (ProgrammingExerciseStudentParticipation) participationRepository.findByIdElseThrow(participation.getId());
assertThat(updatedParticipation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
assertThat(updatedParticipation.getBuildPlanId()).as("Build Plan Id should be set").isEqualTo(exercise.getProjectKey().toUpperCase() + "-" + participant.getParticipantIdentifier().toUpperCase());
// Trigger the build again and make sure no new submission is created
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
var submissions = submissionRepository.findAll();
assertThat(submissions).hasSize(1);
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingSubmissionIntegrationTest method triggerBuildForParticipationsInstructorEmpty.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
void triggerBuildForParticipationsInstructorEmpty() throws Exception {
bambooRequestMockProvider.enableMockingOfRequests();
String login1 = "student1";
String login2 = "student2";
String login3 = "student3";
ProgrammingExerciseStudentParticipation participation1 = database.addStudentParticipationForProgrammingExercise(exercise, login1);
database.addStudentParticipationForProgrammingExercise(exercise, login2);
ProgrammingExerciseStudentParticipation participation3 = database.addStudentParticipationForProgrammingExercise(exercise, login3);
// We only trigger two participations here: 1 and 3.
bambooRequestMockProvider.mockTriggerBuild(participation1);
bambooRequestMockProvider.mockTriggerBuild(participation3);
// Mock again because we call the trigger request two times
bambooRequestMockProvider.mockTriggerBuild(participation1);
bambooRequestMockProvider.mockTriggerBuild(participation3);
List<Long> participationsToTrigger = new ArrayList<>(Arrays.asList(participation1.getId(), participation3.getId()));
doReturn(COMMIT_HASH_OBJECT_ID).when(gitService).getLastCommitHash(any());
// Perform a call to trigger-instructor-build-all twice. We want to check that the submissions
// aren't being re-created.
String url = "/api/programming-exercises/" + exercise.getId() + "/trigger-instructor-build";
request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
request.postWithoutLocation(url, participationsToTrigger, HttpStatus.OK, new HttpHeaders());
List<ProgrammingSubmission> submissions = submissionRepository.findAll();
// Note: the participations above have no submissions, so the builds will not be triggered
assertThat(submissions).isEmpty();
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ProgrammingExerciseGradingServiceTest method setUp.
@BeforeEach
public void setUp() {
database.addUsers(5, 1, 0, 1);
database.addCourseWithOneProgrammingExerciseAndTestCases();
programmingExercise = generateDefaultProgrammingExercise();
database.addTestCasesToProgrammingExercise(programmingExercise);
programmingExerciseSCAEnabled = generateScaProgrammingExercise();
database.addTestCasesToProgrammingExercise(programmingExerciseSCAEnabled);
ProgrammingExerciseStudentParticipation participation = database.addStudentParticipationForProgrammingExercise(programmingExercise, "student1");
result = new Result();
result.setParticipation(participation);
bambooRequestMockProvider.enableMockingOfRequests();
}
use of de.tum.in.www1.artemis.domain.participation.ProgrammingExerciseStudentParticipation in project Artemis by ls1intum.
the class ExerciseDeletionService method cleanup.
/**
* Delete student build plans (except BASE/SOLUTION) and optionally git repositories of all exercise student participations.
*
* @param exerciseId programming exercise for which build plans in respective student participations are deleted
* @param deleteRepositories if true, the repositories gets deleted
*/
public void cleanup(Long exerciseId, boolean deleteRepositories) {
Exercise exercise = exerciseRepository.findByIdWithStudentParticipationsElseThrow(exerciseId);
log.info("Request to cleanup all participations for Exercise : {}", exercise.getTitle());
if (exercise instanceof ProgrammingExercise) {
for (StudentParticipation participation : exercise.getStudentParticipations()) {
participationService.cleanupBuildPlan((ProgrammingExerciseStudentParticipation) participation);
}
if (!deleteRepositories) {
// in this case, we are done
return;
}
for (StudentParticipation participation : exercise.getStudentParticipations()) {
participationService.cleanupRepository((ProgrammingExerciseStudentParticipation) participation);
}
} else {
log.warn("Exercise with exerciseId {} is not an instance of ProgrammingExercise. Ignoring the request to cleanup repositories and build plan", exerciseId);
}
}
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;
}
Aggregations