use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method findRandomSubmissionWithoutExistingAssessment.
/**
* retrieves a modeling submission without assessment for the specified correction round and potentially locks the submission
*
* In case Compass is supported (and activated), this method also assigns a result with feedback suggestions to the submission
*
* @param lockSubmission whether the submission should be locked
* @param correctionRound the correction round (0 = first correction, 1 = second correction
* @param modelingExercise the modeling exercise for which a
* @param isExamMode whether the exercise belongs to an exam
* @return a random modeling submission (potentially based on compass)
*/
public ModelingSubmission findRandomSubmissionWithoutExistingAssessment(boolean lockSubmission, int correctionRound, ModelingExercise modelingExercise, boolean isExamMode) {
var submissionWithoutResult = super.getRandomSubmissionEligibleForNewAssessment(modelingExercise, isExamMode, correctionRound).orElseThrow(() -> new EntityNotFoundException("Modeling submission for exercise " + modelingExercise.getId() + " could not be found"));
ModelingSubmission modelingSubmission = (ModelingSubmission) submissionWithoutResult;
if (lockSubmission) {
if (compassService.isSupported(modelingExercise) && correctionRound == 0L) {
modelingSubmission = assignResultWithFeedbackSuggestionsToSubmission(modelingSubmission, modelingExercise);
setNumberOfAffectedSubmissionsPerElement(modelingSubmission);
}
lockSubmission(modelingSubmission, correctionRound);
}
return modelingSubmission;
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ModelingSubmissionService method save.
/**
* Saves the given submission and the corresponding model and creates the result if necessary. This method used for creating and updating modeling submissions.
*
* @param modelingSubmission the submission that should be saved
* @param modelingExercise the exercise the submission belongs to
* @param username the name of the corresponding user
* @return the saved modelingSubmission entity
*/
public ModelingSubmission save(ModelingSubmission modelingSubmission, ModelingExercise modelingExercise, String username) {
Optional<StudentParticipation> optionalParticipation = participationService.findOneByExerciseAndStudentLoginWithEagerSubmissionsAnyState(modelingExercise, username);
if (optionalParticipation.isEmpty()) {
throw new EntityNotFoundException("No participation found for " + username + " in exercise with id " + modelingExercise.getId());
}
StudentParticipation participation = optionalParticipation.get();
final Optional<ZonedDateTime> dueDate = exerciseDateService.getDueDate(participation);
if (dueDate.isPresent() && exerciseDateService.isAfterDueDate(participation) && participation.getInitializationDate().isBefore(dueDate.get())) {
throw new ResponseStatusException(HttpStatus.FORBIDDEN);
}
// remove result from submission (in the unlikely case it is passed here), so that students cannot inject a result
modelingSubmission.setResults(new ArrayList<>());
// NOTE: from now on we always set submitted to true to prevent problems here! Except for late submissions of course exercises to prevent issues in auto-save
if (modelingExercise.isExamExercise() || exerciseDateService.isBeforeDueDate(participation)) {
modelingSubmission.setSubmitted(true);
}
modelingSubmission.setSubmissionDate(ZonedDateTime.now());
modelingSubmission.setType(SubmissionType.MANUAL);
modelingSubmission.setParticipation(participation);
modelingSubmission = modelingSubmissionRepository.save(modelingSubmission);
// versioning of submission
try {
if (modelingExercise.isTeamMode()) {
submissionVersionService.saveVersionForTeam(modelingSubmission, username);
} else if (modelingExercise.isExamExercise()) {
submissionVersionService.saveVersionForIndividual(modelingSubmission, username);
}
} catch (Exception ex) {
log.error("Modeling submission version could not be saved", ex);
}
participation.addSubmission(modelingSubmission);
participation.setInitializationState(InitializationState.FINISHED);
StudentParticipation savedParticipation = studentParticipationRepository.save(participation);
if (modelingSubmission.getId() == null) {
Optional<Submission> optionalSubmission = savedParticipation.findLatestSubmission();
if (optionalSubmission.isPresent()) {
modelingSubmission = (ModelingSubmission) optionalSubmission.get();
}
}
log.debug("return model: {}", modelingSubmission.getModel());
return modelingSubmission;
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class ExampleSubmissionRepository method getFeedbackForExampleSubmission.
/**
* Given the id of an example submission, it returns the results of the linked submission, if any
*
* @param exampleSubmissionId the id of the example submission we want to retrieve
* @return list of feedback for an example submission
*/
default List<Feedback> getFeedbackForExampleSubmission(long exampleSubmissionId) {
var exampleSubmission = findByIdWithResultsAndFeedback(exampleSubmissionId).orElseThrow(() -> new EntityNotFoundException("Example Submission", exampleSubmissionId));
var submission = exampleSubmission.getSubmission();
if (submission == null) {
return List.of();
}
Result result = submission.getLatestResult();
// result.isExampleResult() can have 3 values: null, false, true. We return if it is not true
if (result == null || !Boolean.TRUE.equals(result.isExampleResult())) {
return List.of();
}
return result.getFeedbacks();
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class AccountResource method getAccount.
/**
* {@code GET /account} : get the current user.
*
* @return the current user.
* @throws EntityNotFoundException {@code 404 (User not found)} if the user couldn't be returned.
*/
@GetMapping("/account")
public UserDTO getAccount() {
long start = System.currentTimeMillis();
User user = userRepository.getUserWithGroupsAuthoritiesAndGuidedTourSettings();
user.setVisibleRegistrationNumber();
UserDTO userDTO = new UserDTO(user);
log.info("GET /account {} took {}ms", user.getLogin(), System.currentTimeMillis() - start);
return userDTO;
}
use of de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException in project ArTEMiS by ls1intum.
the class AssessmentResource method getAssessmentBySubmissionId.
/**
* Get the result of the submission with the given id. Returns a 403 Forbidden response if the user is not allowed to retrieve the assessment. The user is not allowed
* to retrieve the assessment if he is not a student of the corresponding course, the submission is not his submission, the result is not finished or the assessment due date of
* the corresponding exercise is in the future (or not set).
*
* @param submissionId the id of the submission that should be sent to the client
* @return the assessment of the given id
*/
ResponseEntity<Result> getAssessmentBySubmissionId(Long submissionId) {
log.debug("REST request to get assessment for submission with id {}", submissionId);
Submission submission = submissionRepository.findOneWithEagerResultAndFeedback(submissionId);
StudentParticipation participation = (StudentParticipation) submission.getParticipation();
Exercise exercise = participation.getExercise();
Result result = submission.getLatestResult();
if (result == null) {
throw new EntityNotFoundException("Result with submission", submissionId);
}
if (!authCheckService.isUserAllowedToGetResult(exercise, participation, result)) {
throw new AccessForbiddenException();
}
// remove sensitive information for students
if (!authCheckService.isAtLeastTeachingAssistantForExercise(exercise)) {
exercise.filterSensitiveInformation();
result.setAssessor(null);
}
return ResponseEntity.ok(result);
}
Aggregations