use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ScoreService method removeOrUpdateAssociatedParticipantScore.
/**
* Either updates or removes an existing participant score when a result is removed
* 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 resultToBeDeleted result that will be removes
*/
// ok (see JavaDoc)
@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void removeOrUpdateAssociatedParticipantScore(Result resultToBeDeleted) {
// In this method we use custom @Query methods that will fail if no authentication is available, therefore
// we check this here and set a dummy authentication if none is available (this is the case in a scheduled service or
// websocket)
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (authentication == null) {
SecurityUtils.setAuthorizationObject();
}
Optional<ParticipantScore> associatedParticipantScoreOptional;
if (resultToBeDeleted.isRated() != null && resultToBeDeleted.isRated()) {
associatedParticipantScoreOptional = participantScoreRepository.findParticipantScoreByLastRatedResult(resultToBeDeleted);
} else {
associatedParticipantScoreOptional = participantScoreRepository.findParticipantScoresByLastResult(resultToBeDeleted);
}
if (associatedParticipantScoreOptional.isEmpty()) {
return;
}
// There is a participant score connected to the result that will be deleted
ParticipantScore associatedParticipantScore = associatedParticipantScoreOptional.get();
Exercise exercise = associatedParticipantScore.getExercise();
String originalParticipantScoreStructure = associatedParticipantScore.toString();
// There are two possibilities now:
// A: Another result exists for the exercise and the student / team -> update participant score with the newest one
// B: No other result exists for the exercise and the student / team -> remove participant score
tryToFindNewLastResult(resultToBeDeleted, associatedParticipantScore, exercise);
if (associatedParticipantScore.getLastResult() == null && associatedParticipantScore.getLastRatedResult() == null) {
participantScoreRepository.deleteById(associatedParticipantScore.getId());
logger.info("Deleted an existing participant score: " + originalParticipantScoreStructure);
} else {
ParticipantScore updatedParticipantScore = participantScoreRepository.saveAndFlush(associatedParticipantScore);
logger.info("Updated an existing participant score. Was: " + originalParticipantScoreStructure + ". Is: " + updatedParticipantScore);
}
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ScoreService method getExistingParticipationScore.
/**
* Gets the existing participation score for an exercise and a participant or null if none can be found
*
* @param studentParticipation participation containing the information about the participant
* @param exercise exercise for which to find the participation score of the participant
* @return existing participation score or null if none can be found
*/
private ParticipantScore getExistingParticipationScore(StudentParticipation studentParticipation, Exercise exercise) {
ParticipantScore existingParticipationScoreForExerciseAndParticipant = null;
if (exercise.isTeamMode()) {
Team team = studentParticipation.getTeam().get();
Optional<TeamScore> teamScoreOptional = teamScoreRepository.findTeamScoreByExerciseAndTeam(exercise, team);
if (teamScoreOptional.isPresent()) {
existingParticipationScoreForExerciseAndParticipant = teamScoreOptional.get();
}
} else {
User user = studentParticipation.getStudent().get();
Optional<StudentScore> studentScoreOptional = studentScoreRepository.findStudentScoreByExerciseAndUser(exercise, user);
if (studentScoreOptional.isPresent()) {
existingParticipationScoreForExerciseAndParticipant = studentScoreOptional.get();
}
}
return existingParticipationScoreForExerciseAndParticipant;
}
use of de.tum.in.www1.artemis.domain.participation.Participant in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestService method startProgrammingExercise_correctInitializationState.
// TEST
public void startProgrammingExercise_correctInitializationState() throws Exception {
var user = userRepo.findOneByLogin(studentLogin).orElseThrow();
user.setLogin("edx_student1");
user.setInternal(true);
user = userRepo.save(user);
final Course course = setupCourseWithProgrammingExercise(ExerciseMode.INDIVIDUAL);
Participant participant = user;
mockDelegate.mockConnectorRequestsForStartParticipation(exercise, participant.getParticipantIdentifier(), participant.getParticipants(), true, HttpStatus.CREATED);
final var path = ParticipationResource.Endpoints.ROOT + ParticipationResource.Endpoints.START_PARTICIPATION.replace("{courseId}", String.valueOf(course.getId())).replace("{exerciseId}", String.valueOf(exercise.getId()));
final var participation = request.postWithResponseBody(path, null, ProgrammingExerciseStudentParticipation.class, HttpStatus.CREATED);
assertThat(participation.getInitializationState()).as("Participation should be initialized").isEqualTo(InitializationState.INITIALIZED);
}
use of de.tum.in.www1.artemis.domain.participation.Participant 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.Participant in project ArTEMiS by ls1intum.
the class ProgrammingExerciseTestService method resumeProgrammingExerciseByTriggeringBuild_correctInitializationState.
// TEST
public void resumeProgrammingExerciseByTriggeringBuild_correctInitializationState(ExerciseMode exerciseMode, SubmissionType submissionType) throws Exception {
var participation = createStudentParticipationWithSubmission(exerciseMode);
var participant = participation.getParticipant();
mockDelegate.mockTriggerParticipationBuild(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.mockTriggerParticipationBuild(participation);
mockDelegate.mockDefaultBranch(participation.getProgrammingExercise());
// These will be updated when triggering a build
participation.setInitializationState(InitializationState.INACTIVE);
participation.setBuildPlanId(null);
programmingExerciseStudentParticipationRepository.saveAndFlush(participation);
// Construct trigger-build url and execute request
submissionType = submissionType == null ? SubmissionType.MANUAL : submissionType;
String url = "/api/programming-submissions/" + participation.getId() + "/trigger-build?submissionType=" + submissionType.name();
request.postWithoutLocation(url, null, HttpStatus.OK, new HttpHeaders());
// 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);
}
Aggregations