Skip to content

Commit

Permalink
rename Exercise.participations to Exercise.studentParticipations
Browse files Browse the repository at this point in the history
cast more often from Participation to StudentParticipation
  • Loading branch information
Stephan Krusche committed Sep 23, 2019
1 parent a714635 commit d6ff1ff
Show file tree
Hide file tree
Showing 57 changed files with 271 additions and 244 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public JCacheManagerCustomizer cacheManagerCustomizer() {
createIfNotExists(cm, Course.class.getName(), jcacheConfiguration);
createIfNotExists(cm, Course.class.getName() + ".exercises", jcacheConfiguration);
createIfNotExists(cm, Exercise.class.getName(), jcacheConfiguration);
createIfNotExists(cm, Exercise.class.getName() + ".participations", jcacheConfiguration);
createIfNotExists(cm, Exercise.class.getName() + ".studentParticipations", jcacheConfiguration);
createIfNotExists(cm, Exercise.class.getName() + ".exampleSubmissions", jcacheConfiguration);
createIfNotExists(cm, LtiOutcomeUrl.class.getName(), jcacheConfiguration);
createIfNotExists(cm, LtiUserId.class.getName(), jcacheConfiguration);
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/de/tum/in/www1/artemis/domain/Exercise.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public abstract class Exercise implements Serializable {
@OneToMany(mappedBy = "exercise", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
@JsonIgnoreProperties("exercise")
private Set<StudentParticipation> participations = new HashSet<>();
private Set<StudentParticipation> studentParticipations = new HashSet<>();

@OneToMany(mappedBy = "assessedExercise", cascade = CascadeType.REMOVE, orphanRemoval = true, fetch = FetchType.LAZY)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
Expand Down Expand Up @@ -298,29 +298,29 @@ public void setCategories(Set<String> categories) {
this.categories = categories;
}

public Set<StudentParticipation> getParticipations() {
return participations;
public Set<StudentParticipation> getStudentParticipations() {
return studentParticipations;
}

public Exercise participations(Set<StudentParticipation> participations) {
this.participations = participations;
this.studentParticipations = participations;
return this;
}

public Exercise addParticipation(StudentParticipation participation) {
this.participations.add(participation);
this.studentParticipations.add(participation);
participation.setExercise(this);
return this;
}

public Exercise removeParticipation(StudentParticipation participation) {
this.participations.remove(participation);
this.studentParticipations.remove(participation);
participation.setExercise(null);
return this;
}

public void setParticipations(Set<StudentParticipation> participations) {
this.participations = participations;
public void setStudentParticipations(Set<StudentParticipation> studentParticipations) {
this.studentParticipations = studentParticipations;
}

public Course getCourse() {
Expand Down Expand Up @@ -593,7 +593,7 @@ public void filterForCourseDashboard(List<StudentParticipation> participations,
participation.setExercise(null);

// add participation into an array
setParticipations(Sets.newHashSet(participation));
setStudentParticipations(Sets.newHashSet(participation));
}
}

Expand Down
10 changes: 4 additions & 6 deletions src/main/java/de/tum/in/www1/artemis/domain/Participation.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public abstract class Participation implements Serializable {
// objects would cause more issues (Subclasses don't work properly for Proxy objects)
// and the gain from fetching lazy here is minimal
@ManyToOne
@JsonIgnoreProperties("participations")
@JsonIgnoreProperties("studentParticipations")
@JsonView(QuizView.Before.class)
protected Exercise exercise;

Expand Down Expand Up @@ -118,15 +118,13 @@ public void setInitializationDate(ZonedDateTime initializationDate) {
}

/**
* This is a compatibility method that reduces the amount of casting. It should only be invoked if it is clear that the participation has an exercise
*
* @return exrcise object
*
* @return exercise object
*/
public abstract Exercise getExercise();

/**
* This is a compatibility method that reduces the amount of casting. It should only be invoked if it is clear that the participation has an exercise
*
*
* @param exercise that will be set
*/
public abstract void setExercise(Exercise exercise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void filterSensitiveInformation() {

private <T extends Submission> Optional<T> findLatestSubmissionOfType(Class<T> submissionType) {
Optional<Submission> optionalSubmission = findLatestSubmission();
if (!optionalSubmission.isPresent()) {
if (optionalSubmission.isEmpty()) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface ExerciseRepository extends JpaRepository<Exercise, Long> {
@Query("select e from Exercise e where e.course.id = :#{#courseId}")
List<Exercise> findAllByCourseId(@Param("courseId") Long courseId);

@Query("select distinct exercise from Exercise exercise left join fetch exercise.participations where exercise.id = :#{#exerciseId}")
@Query("select distinct exercise from Exercise exercise left join fetch exercise.studentParticipations where exercise.id = :#{#exerciseId}")
Optional<Exercise> findByIdWithEagerParticipations(@Param("exerciseId") Long exerciseId);

@Query("select distinct exercise from Exercise exercise left join fetch exercise.categories where exercise.id = :#{#exerciseId}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,14 @@ public interface ProgrammingExerciseRepository extends JpaRepository<Programming
@Query("select distinct pe from ProgrammingExercise pe where pe.id = :#{#exerciseId}")
Optional<ProgrammingExercise> findByIdWithTemplateAndSolutionParticipationAndAllResultsAndSubmissions(@Param("exerciseId") Long exerciseId);

@Query("select distinct pe from ProgrammingExercise as pe left join fetch pe.participations")
@Query("select distinct pe from ProgrammingExercise as pe left join fetch pe.studentParticipations")
List<ProgrammingExercise> findAllWithEagerParticipations();

@EntityGraph(attributePaths = "participations")
@EntityGraph(attributePaths = "studentParticipations")
@Query("select distinct pe from ProgrammingExercise pe where pe.id = :#{#exerciseId}")
Optional<ProgrammingExercise> findByIdWithEagerParticipations(@Param("exerciseId") Long exerciseId);

@Query("select distinct pe from ProgrammingExercise as pe left join fetch pe.participations pep left join fetch pep.submissions")
@Query("select distinct pe from ProgrammingExercise as pe left join fetch pe.studentParticipations pep left join fetch pep.submissions")
List<ProgrammingExercise> findAllWithEagerParticipationsAndSubmissions();

ProgrammingExercise findOneByTemplateParticipationId(Long templateParticipationId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import de.tum.in.www1.artemis.domain.Complaint;
import de.tum.in.www1.artemis.domain.ComplaintResponse;
import de.tum.in.www1.artemis.domain.StudentParticipation;
import de.tum.in.www1.artemis.domain.User;
import de.tum.in.www1.artemis.domain.enumeration.ComplaintType;
import de.tum.in.www1.artemis.repository.ComplaintRepository;
Expand Down Expand Up @@ -72,9 +73,9 @@ public ComplaintResponse createComplaintResponse(ComplaintResponse complaintResp
throw new BadRequestAlertException("The complaint you are referring to does already have a response", ENTITY_NAME, "complaintresponseexists");
}
// Only tutors who are not the original assessor of the submission can reply to a complaint
if (!authorizationCheckService.isAtLeastTeachingAssistantForExercise(originalComplaint.getResult().getParticipation().getExercise())
|| (originalComplaint.getResult().getAssessor().equals(reviewer)
&& (originalComplaint.getComplaintType() == null || originalComplaint.getComplaintType().equals(ComplaintType.COMPLAINT)))) {
StudentParticipation studentParticipation = (StudentParticipation) originalComplaint.getResult().getParticipation();
if (!authorizationCheckService.isAtLeastTeachingAssistantForExercise(studentParticipation.getExercise()) || (originalComplaint.getResult().getAssessor().equals(reviewer)
&& (originalComplaint.getComplaintType() == null || originalComplaint.getComplaintType().equals(ComplaintType.COMPLAINT)))) {
throw new AccessForbiddenException("Insufficient permission for creating a complaint response");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,25 +54,25 @@ public Complaint createComplaint(Complaint complaint, Principal principal) {
Result originalResult = resultRepository.findByIdWithEagerFeedbacksAndAssessor(complaint.getResult().getId())
.orElseThrow(() -> new BadRequestAlertException("The result you are referring to does not exist", ENTITY_NAME, "resultnotfound"));
StudentParticipation studentParticipation = (StudentParticipation) originalResult.getParticipation();
User originalSubmissor = studentParticipation.getStudent();
Long courseId = originalResult.getParticipation().getExercise().getCourse().getId();
User student = studentParticipation.getStudent();
Long courseId = studentParticipation.getExercise().getCourse().getId();

long numberOfUnacceptedComplaints = countUnacceptedComplaintsByStudentIdAndCourseId(originalSubmissor.getId(), courseId);
long numberOfUnacceptedComplaints = countUnacceptedComplaintsByStudentIdAndCourseId(student.getId(), courseId);
if (numberOfUnacceptedComplaints >= MAX_COMPLAINT_NUMBER_PER_STUDENT && complaint.getComplaintType() == ComplaintType.COMPLAINT) {
throw new BadRequestAlertException("You cannot have more than " + MAX_COMPLAINT_NUMBER_PER_STUDENT + " open or rejected complaints at the same time.", ENTITY_NAME,
"toomanycomplaints");
}
if (!isTimeOfComplaintValid(originalResult, originalResult.getParticipation().getExercise())) {
if (!isTimeOfComplaintValid(originalResult, studentParticipation.getExercise())) {
throw new BadRequestAlertException("You cannot submit a complaint for a result that is older than one week.", ENTITY_NAME, "resultolderthanaweek");
}
if (!originalSubmissor.getLogin().equals(principal.getName())) {
if (!student.getLogin().equals(principal.getName())) {
throw new BadRequestAlertException("You can create a complaint only for a result you submitted", ENTITY_NAME, "differentuser");
}

originalResult.setHasComplaint(true);

complaint.setSubmittedTime(ZonedDateTime.now());
complaint.setStudent(originalSubmissor);
complaint.setStudent(student);
complaint.setResult(originalResult);
try {
// Store the original result with the complaint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ public Collection<Result> getAllOverallScoresOfCourse(Long courseId) {
Map<Long, Result> allOverallSummedScoresOfCourse = new HashMap<>();

for (Exercise exercise : exercisesOfCourse) {
Set<StudentParticipation> participations = exercise.getParticipations();
Set<StudentParticipation> participations = exercise.getStudentParticipations();
boolean exerciseHasDueDate = exercise.getDueDate() != null;

for (StudentParticipation participation : participations) {
Expand Down Expand Up @@ -293,7 +293,7 @@ public Collection<Result> getAllOverallScoresOfCourse(Long courseId) {
* @return the best result a student had within the time of the exercise
*/
@Transactional(readOnly = true)
public Result choseResultInParticipation(Participation participation, boolean hasDueDate) {
public Result choseResultInParticipation(StudentParticipation participation, boolean hasDueDate) {
List<Result> results = new ArrayList<>(participation.getResults());

// TODO take the field result.isRated into account
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ public void cleanup(Long id, boolean deleteRepositories) {
log.info("Request to cleanup all participations for Exercise : {}", exercise.getTitle());

if (exercise instanceof ProgrammingExercise) {
for (StudentParticipation participation : exercise.getParticipations()) {
for (StudentParticipation participation : exercise.getStudentParticipations()) {
participationService.cleanupBuildPlan((ProgrammingExerciseStudentParticipation) participation);
}

if (!deleteRepositories) {
return; // in this case, we are done
}

for (StudentParticipation participation : exercise.getParticipations()) {
for (StudentParticipation participation : exercise.getStudentParticipations()) {
participationService.cleanupRepository((ProgrammingExerciseStudentParticipation) participation);
}

Expand All @@ -335,7 +335,7 @@ public java.io.File exportParticipations(Long exerciseId, List<String> studentId
log.debug("Exercise with id {} is not an instance of ProgrammingExercise. Ignoring the request to export repositories", exerciseId);
return null;
}
for (StudentParticipation participation : exercise.getParticipations()) {
for (StudentParticipation participation : exercise.getStudentParticipations()) {
ProgrammingExerciseStudentParticipation studentParticipation = (ProgrammingExerciseStudentParticipation) participation;
try {
if (studentParticipation.getRepositoryUrl() == null || studentParticipation.getStudent() == null
Expand Down Expand Up @@ -373,7 +373,7 @@ public java.io.File exportParticipations(Long exerciseId, List<String> studentId
log.error("export repository Participation for " + studentParticipation.getRepositoryUrlAsUrl() + "and Students" + studentIds + " did not work as expected: " + ex);
}
}
if (exercise.getParticipations().isEmpty() || zippedRepoFiles.isEmpty()) {
if (exercise.getStudentParticipations().isEmpty() || zippedRepoFiles.isEmpty()) {
log.debug("The zip file could not be created. Ignoring the request to export repositories", exerciseId);
return null;
}
Expand Down Expand Up @@ -411,7 +411,7 @@ public java.io.File archive(Long id) {
List<Path> zippedRepoFiles = new ArrayList<>();
Path finalZipFilePath = null;
if (exercise instanceof ProgrammingExercise) {
exercise.getParticipations().forEach(participation -> {
exercise.getStudentParticipations().forEach(participation -> {
ProgrammingExerciseStudentParticipation studentParticipation = (ProgrammingExerciseStudentParticipation) participation;
try {
if (studentParticipation.getRepositoryUrl() != null) { // ignore participations without repository URL and without student
Expand All @@ -430,7 +430,7 @@ public java.io.File archive(Long id) {
}
});

if (!exercise.getParticipations().isEmpty() && !zippedRepoFiles.isEmpty()) {
if (!exercise.getStudentParticipations().isEmpty() && !zippedRepoFiles.isEmpty()) {
try {
// create a large zip file with all zipped repos and provide it for download
log.info("Create zip file for all repositories");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public FileUploadSubmission handleFileUploadSubmission(FileUploadSubmission file
public List<FileUploadSubmission> getFileUploadSubmissions(Long exerciseId, boolean submittedOnly) {
List<StudentParticipation> participations = studentParticipationRepository.findAllByExerciseIdWithEagerSubmissionsAndEagerResultsAndEagerAssessor(exerciseId);
List<FileUploadSubmission> submissions = new ArrayList<>();
participations.stream().peek(participation -> participation.getExercise().setParticipations(null)).map(StudentParticipation::findLatestFileUploadSubmission)
participations.stream().peek(participation -> participation.getExercise().setStudentParticipations(null)).map(StudentParticipation::findLatestFileUploadSubmission)
// filter out non submitted submissions if the flag is set to true
.filter(submission -> submission.isPresent() && (!submittedOnly || submission.get().isSubmitted())).forEach(submission -> submissions.add(submission.get()));
return submissions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import de.tum.in.www1.artemis.domain.Feedback;
import de.tum.in.www1.artemis.domain.Result;
import de.tum.in.www1.artemis.domain.StudentParticipation;
import de.tum.in.www1.artemis.domain.User;
import de.tum.in.www1.artemis.domain.enumeration.AssessmentType;
import de.tum.in.www1.artemis.domain.modeling.ModelingExercise;
Expand Down Expand Up @@ -114,7 +115,8 @@ public Result saveManualAssessment(ModelingSubmission modelingSubmission, List<F
*/
public void cancelAssessmentOfSubmission(ModelingSubmission modelingSubmission) {
super.cancelAssessmentOfSubmission(modelingSubmission);
ModelingExercise modelingExercise = (ModelingExercise) modelingSubmission.getParticipation().getExercise();
var studentParticipation = (StudentParticipation) modelingSubmission.getParticipation();
ModelingExercise modelingExercise = (ModelingExercise) studentParticipation.getExercise();
compassService.cancelAssessmentForSubmission(modelingExercise, modelingSubmission.getId());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public List<ModelingSubmission> getModelingSubmissions(Long exerciseId, boolean
submissions.add(submission.get());
}
// avoid infinite recursion
participation.getExercise().setParticipations(null);
participation.getExercise().setStudentParticipations(null);
}
return submissions;
}
Expand Down Expand Up @@ -283,8 +283,8 @@ private ModelingSubmission assignAutomaticResultToSubmission(ModelingSubmission
if (existingResult != null && existingResult.getAssessmentType() != null && existingResult.getAssessmentType().equals(AssessmentType.MANUAL)) {
return modelingSubmission;
}

long exerciseId = modelingSubmission.getParticipation().getExercise().getId();
StudentParticipation studentParticipation = (StudentParticipation) modelingSubmission.getParticipation();
long exerciseId = studentParticipation.getExercise().getId();
Result automaticResult = compassService.getAutomaticResultForSubmission(modelingSubmission.getId(), exerciseId);
if (automaticResult != null) {
automaticResult.setSubmission(modelingSubmission);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,14 +122,15 @@ public ProgrammingExerciseService(ProgrammingExerciseRepository programmingExerc
*/
public List<ProgrammingSubmission> notifyChangedTestCases(Long exerciseId, Object requestBody) throws EntityNotFoundException {
Optional<ProgrammingExercise> exerciseOpt = programmingExerciseRepository.findByIdWithEagerParticipations(exerciseId);
if (!exerciseOpt.isPresent())
if (exerciseOpt.isEmpty()) {
throw new EntityNotFoundException("Programming exercise with id " + exerciseId + " not found.");
}
ProgrammingExercise programmingExercise = exerciseOpt.get();
// All student repository builds and the builds of the template & solution repository must be triggered now!
Set<ProgrammingExerciseParticipation> participations = new HashSet<>();
participations.add(programmingExercise.getSolutionParticipation());
participations.add(programmingExercise.getTemplateParticipation());
participations.addAll(programmingExercise.getParticipations().stream().map(p -> (ProgrammingExerciseParticipation) p).collect(Collectors.toSet()));
participations.addAll(programmingExercise.getStudentParticipations().stream().map(p -> (ProgrammingExerciseParticipation) p).collect(Collectors.toSet()));

List<ProgrammingSubmission> submissions = new ArrayList<>();

Expand Down
Loading

0 comments on commit d6ff1ff

Please sign in to comment.