Search in sources :

Example 6 with EntityNotFoundException

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;
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 7 with EntityNotFoundException

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;
}
Also used : Submission(de.tum.in.www1.artemis.domain.Submission) ModelingSubmission(de.tum.in.www1.artemis.domain.modeling.ModelingSubmission) ZonedDateTime(java.time.ZonedDateTime) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) ResponseStatusException(org.springframework.web.server.ResponseStatusException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) ResponseStatusException(org.springframework.web.server.ResponseStatusException) EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)

Example 8 with EntityNotFoundException

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();
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) Result(de.tum.in.www1.artemis.domain.Result)

Example 9 with EntityNotFoundException

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;
}
Also used : User(de.tum.in.www1.artemis.domain.User) UserDTO(de.tum.in.www1.artemis.service.dto.UserDTO)

Example 10 with EntityNotFoundException

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);
}
Also used : EntityNotFoundException(de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException) StudentParticipation(de.tum.in.www1.artemis.domain.participation.StudentParticipation) AccessForbiddenException(de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)

Aggregations

EntityNotFoundException (de.tum.in.www1.artemis.web.rest.errors.EntityNotFoundException)96 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)42 StudentParticipation (de.tum.in.www1.artemis.domain.participation.StudentParticipation)20 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)20 StudentExam (de.tum.in.www1.artemis.domain.exam.StudentExam)16 AccessForbiddenException (de.tum.in.www1.artemis.web.rest.errors.AccessForbiddenException)12 Exam (de.tum.in.www1.artemis.domain.exam.Exam)10 QuizExercise (de.tum.in.www1.artemis.domain.quiz.QuizExercise)10 AuditEvent (org.springframework.boot.actuate.audit.AuditEvent)10 User (de.tum.in.www1.artemis.domain.User)9 ExerciseGroup (de.tum.in.www1.artemis.domain.exam.ExerciseGroup)8 ModelingExercise (de.tum.in.www1.artemis.domain.modeling.ModelingExercise)8 java.util (java.util)8 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 Service (org.springframework.stereotype.Service)8 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)6 Course (de.tum.in.www1.artemis.domain.Course)6 Result (de.tum.in.www1.artemis.domain.Result)6