use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class QuizSubmissionResource method submitQuizForExam.
/**
* PUT /exercises/:exerciseId/submissions/exam : Update a QuizSubmission for exam mode
*
* @param exerciseId the id of the exercise for which to update the submission
* @param quizSubmission the quizSubmission to update
* @return the ResponseEntity with status 200 and body the result or the appropriate error code.
*/
@PutMapping("exercises/{exerciseId}/submissions/exam")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<QuizSubmission> submitQuizForExam(@PathVariable Long exerciseId, @RequestBody QuizSubmission quizSubmission) {
long start = System.currentTimeMillis();
log.debug("REST request to submit QuizSubmission for exam : {}", quizSubmission);
// recreate pointers back to submission in each submitted answer
for (SubmittedAnswer submittedAnswer : quizSubmission.getSubmittedAnswers()) {
submittedAnswer.setSubmission(quizSubmission);
}
QuizExercise quizExercise = quizExerciseRepository.findByIdWithQuestionsElseThrow(exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
// Apply further checks if it is an exam submission
examSubmissionService.checkSubmissionAllowanceElseThrow(quizExercise, user);
// Prevent multiple submissions (currently only for exam submissions)
quizSubmission = (QuizSubmission) examSubmissionService.preventMultipleSubmissions(quizExercise, quizSubmission, user);
QuizSubmission updatedQuizSubmission = quizSubmissionService.saveSubmissionForExamMode(quizExercise, quizSubmission, user.getLogin());
long end = System.currentTimeMillis();
log.info("submitQuizForExam took {}ms for exercise {} and user {}", end - start, exerciseId, user.getLogin());
return ResponseEntity.ok(updatedQuizSubmission);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class QuizSubmissionResource method submitForPractice.
/**
* POST /exercises/:exerciseId/submissions/practice : Submit a new quizSubmission for practice mode.
*
* @param exerciseId the id of the exercise for which to init a participation
* @param quizSubmission the quizSubmission to submit
* @return the ResponseEntity with status 200 (OK) and the Result as its body, or with status 4xx if the request is invalid
*/
@PostMapping("/exercises/{exerciseId}/submissions/practice")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Result> submitForPractice(@PathVariable Long exerciseId, @RequestBody QuizSubmission quizSubmission) {
log.debug("REST request to submit QuizSubmission for practice : {}", quizSubmission);
// recreate pointers back to submission in each submitted answer
for (SubmittedAnswer submittedAnswer : quizSubmission.getSubmittedAnswers()) {
submittedAnswer.setSubmission(quizSubmission);
}
if (quizSubmission.getId() != null) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, ENTITY_NAME, "idexists", "A new quizSubmission cannot already have an ID.")).body(null);
}
QuizExercise quizExercise = quizExerciseRepository.findByIdWithQuestionsElseThrow(exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
if (!authCheckService.isAllowedToSeeExercise(quizExercise, user)) {
return ResponseEntity.status(403).headers(HeaderUtil.createFailureAlert(applicationName, true, "submission", "Forbidden", "You are not allowed to participate in this exercise.")).body(null);
}
// Note that exam quiz exercises do not have an end date, so we need to check in that order
if (!Boolean.TRUE.equals(quizExercise.isIsOpenForPractice()) || !quizExercise.isQuizEnded()) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "submission", "exerciseNotOpenForPractice", "The exercise is not open for practice or hasn't ended yet.")).body(null);
}
// the following method either reuses an existing participation or creates a new one
StudentParticipation participation = participationService.startExercise(quizExercise, user, false);
// we set the exercise again to prevent issues with lazy loaded quiz questions
participation.setExercise(quizExercise);
// update and save submission
Result result = quizSubmissionService.submitForPractice(quizSubmission, quizExercise, participation);
// The quizScheduler is usually responsible for updating the participation to FINISHED in the database. If quizzes where the student did not participate are used for
// practice, the QuizScheduler does not update the participation, that's why we update it manually here
participation.setInitializationState(InitializationState.FINISHED);
studentParticipationRepository.saveAndFlush(participation);
// remove some redundant or unnecessary data that is not needed on client side
for (SubmittedAnswer answer : quizSubmission.getSubmittedAnswers()) {
answer.getQuizQuestion().setQuizQuestionStatistic(null);
}
quizExercise.setQuizPointStatistic(null);
quizExercise.setCourse(null);
messagingService.broadcastNewResult(result.getParticipation(), result);
// return result with quizSubmission, participation and quiz exercise (including the solution)
return ResponseEntity.ok(result);
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ParticipantScoreIntegrationTest method createIndividualTextExerciseForExam.
private void createIndividualTextExerciseForExam() {
Exam exam;
exam = examRepository.findWithExerciseGroupsAndExercisesById(idOfExam).get();
var exerciseGroup0 = exam.getExerciseGroups().get(0);
TextExercise textExercise = ModelFactory.generateTextExerciseForExam(exerciseGroup0);
textExercise.setMaxPoints(10.0);
textExercise.setBonusPoints(0.0);
textExercise.setKnowledge(textAssessmentKnowledgeService.createNewKnowledge());
textExercise = exerciseRepository.save(textExercise);
getIdOfIndividualTextExerciseOfExam = textExercise.getId();
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ModelingExerciseIntegrationTest method createModelingExerciseForExam.
@Test
@WithMockUser(username = "instructor1", roles = "INSTRUCTOR")
public void createModelingExerciseForExam() throws Exception {
ExerciseGroup exerciseGroup = database.addExerciseGroupWithExamAndCourse(true);
ModelingExercise modelingExercise = ModelFactory.generateModelingExerciseForExam(DiagramType.ClassDiagram, exerciseGroup);
String title = "New Exam Modeling Exercise";
DifficultyLevel difficulty = DifficultyLevel.HARD;
modelingExercise.setTitle(title);
modelingExercise.setDifficulty(difficulty);
ModelingExercise newModelingExercise = request.postWithResponseBody("/api/modeling-exercises/", modelingExercise, ModelingExercise.class, HttpStatus.CREATED);
assertThat(newModelingExercise.getTitle()).as("modeling exercise title was correctly set").isEqualTo(title);
assertThat(newModelingExercise.getDifficulty()).as("modeling exercise difficulty was correctly set").isEqualTo(difficulty);
assertThat(newModelingExercise.isCourseExercise()).as("course was not set for exam exercise").isFalse();
assertThat(newModelingExercise.getExerciseGroup()).as("exerciseGroup was set for exam exercise").isNotNull();
assertThat(newModelingExercise.getExerciseGroup().getId()).as("exerciseGroupId was set correctly").isEqualTo(exerciseGroup.getId());
}
use of de.tum.in.www1.artemis.domain.exam.Exam in project ArTEMiS by ls1intum.
the class ExerciseTest method getExamViaExerciseGroupOrCourseMember_withoutExamExercise.
@Test
public void getExamViaExerciseGroupOrCourseMember_withoutExamExercise() {
Exercise examExercise = mock(Exercise.class, CALLS_REAL_METHODS);
when(examExercise.isExamExercise()).thenReturn(false);
Exam result = examExercise.getExamViaExerciseGroupOrCourseMember();
assertThat(result).isNull();
}
Aggregations