Skip to content

Commit

Permalink
Bugfix: TransientObjectException when submitting a modeling assessment (
Browse files Browse the repository at this point in the history
  • Loading branch information
SiggZ authored and Stephan Krusche committed Sep 23, 2019
1 parent 1137738 commit 4eadb94
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ public interface ResultRepository extends JpaRepository<Result, Long> {
@Query("select r from Result r left join fetch r.feedbacks left join fetch r.assessor where r.id = :resultId")
Optional<Result> findByIdWithEagerFeedbacksAndAssessor(@Param("resultId") Long id);

@Query("select r from Result r left join fetch r.submission left join fetch r.feedbacks left join fetch r.assessor where r.id = :resultId")
Optional<Result> findByIdWithEagerSubmissionAndFeedbacksAndAssessor(@Param("resultId") Long id);
/**
* Load a result from the database by its id together with the associated submission, the list of feedback items and the assessor.
*
* @param resultId the id of the result to load from the database
* @return an optional containing the result with submission, feedback list and assessor, or an empty optional if no result could be found for the given id
*/
@EntityGraph(attributePaths = { "submission", "feedbacks", "assessor" })
Optional<Result> findWithEagerSubmissionAndFeedbackAndAssessorById(Long resultId);

/**
* This SQL query is used for inserting results if only one unrated result should exist per participation. This prevents multiple (concurrent) inserts with the same
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ void deleteAllConflictsForParticipation(Participation participation) {
private void loadSubmissionsAndFeedbacksAndAssessorOfConflictingResults(List<ModelAssessmentConflict> conflicts) {
conflicts.forEach(conflict -> {
conflict.getCausingConflictingResult()
.setResult(resultRepository.findByIdWithEagerSubmissionAndFeedbacksAndAssessor(conflict.getCausingConflictingResult().getResult().getId()).get());
.setResult(resultRepository.findWithEagerSubmissionAndFeedbackAndAssessorById(conflict.getCausingConflictingResult().getResult().getId()).get());
conflict.getResultsInConflict().forEach(conflictingResult -> conflictingResult
.setResult(resultRepository.findByIdWithEagerSubmissionAndFeedbacksAndAssessor(conflictingResult.getResult().getId()).get()));
.setResult(resultRepository.findWithEagerSubmissionAndFeedbackAndAssessorById(conflictingResult.getResult().getId()).get()));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,23 +47,24 @@ public ModelingAssessmentService(UserService userService, ComplaintResponseServi
}

/**
* This function is used for submitting a manual assessment/result. It updates the completion date, sets the assessment type to MANUAL and sets the assessor attribute.
* Furthermore, it saves the result in the database.
* This function is used for submitting a manual assessment/result. It gets the result that belongs to the given resultId, updates the completion date, sets the assessment type
* to MANUAL and sets the assessor attribute. Afterwards, it saves the update result in the database again.
*
* @param result the result the assessment belongs to
* @param resultId the id of the result that should be submitted
* @param exercise the exercise the assessment belongs to
* @param submissionDate the date manual assessment was submitted
* @return the ResponseEntity with result as body
*/
@Transactional
public Result submitManualAssessment(Result result, ModelingExercise exercise, ZonedDateTime submissionDate) {
public Result submitManualAssessment(long resultId, ModelingExercise exercise, ZonedDateTime submissionDate) {
// TODO CZ: use AssessmentService#submitResult() function instead
Result result = resultRepository.findWithEagerSubmissionAndFeedbackAndAssessorById(resultId)
.orElseThrow(() -> new EntityNotFoundException("No result for the given resultId could be found"));
result.setRatedIfNotExceeded(exercise.getDueDate(), submissionDate);
result.setCompletionDate(ZonedDateTime.now());
result.evaluateFeedback(exercise.getMaxScore()); // TODO CZ: move to AssessmentService class, as it's the same for
// modeling and text exercises (i.e. total score is sum of feedback credits)
resultRepository.save(result);
return result;
result.evaluateFeedback(exercise.getMaxScore()); // TODO CZ: move to AssessmentService class, as it's the same for modeling and text exercises (i.e. total score is sum of
// feedback credits)
return resultRepository.save(result);
}

/**
Expand Down Expand Up @@ -101,8 +102,7 @@ public Result saveManualAssessment(ModelingSubmission modelingSubmission, List<F
modelingSubmission.setResult(result);
modelingSubmissionRepository.save(modelingSubmission);
}
// Note: This also saves the feedback objects in the database because of the 'cascade =
// CascadeType.ALL' option.
// Note: This also saves the feedback objects in the database because of the 'cascade = CascadeType.ALL' option.
return resultRepository.save(result);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public ResponseEntity<Object> saveModelingAssessment(@PathVariable Long submissi
// return ResponseEntity.status(HttpStatus.CONFLICT).body(conflicts);
// }
// else {
modelingAssessmentService.submitManualAssessment(result, modelingExercise, modelingSubmission.getSubmissionDate());
result = modelingAssessmentService.submitManualAssessment(result.getId(), modelingExercise, modelingSubmission.getSubmissionDate());
if (compassService.isSupported(modelingExercise.getDiagramType())) {
compassService.addAssessment(exerciseId, submissionId, result.getFeedbacks());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,11 @@ public Result addModelingAssessmentForSubmission(ModelingExercise exercise, Mode
Result result = modelingAssessmentService.saveManualAssessment(submission, assessment, exercise);
result.setParticipation(submission.getParticipation().results(null));
result.setAssessor(getUserByLogin(login));
resultRepo.save(result);
if (submit) {
result = modelingAssessmentService.submitManualAssessment(result, exercise, submission.getSubmissionDate());
modelingAssessmentService.submitManualAssessment(result.getId(), exercise, submission.getSubmissionDate());
}
return result;
return resultRepo.findWithEagerSubmissionAndFeedbackAndAssessorById(result.getId()).get();
}

public ExampleSubmission addExampleSubmission(ExampleSubmission exampleSubmission, String login) {
Expand Down

0 comments on commit 4eadb94

Please sign in to comment.