use of de.tum.in.www1.artemis.domain.Submission in project ArTEMiS by ls1intum.
the class ComplaintResource method filterOutUselessDataFromComplaint.
private void filterOutUselessDataFromComplaint(Complaint complaint) {
if (complaint.getResult() == null) {
return;
}
StudentParticipation originalParticipation = (StudentParticipation) complaint.getResult().getParticipation();
if (originalParticipation != null && originalParticipation.getExercise() != null) {
Exercise exerciseWithOnlyTitle = originalParticipation.getExercise();
if (exerciseWithOnlyTitle instanceof TextExercise) {
exerciseWithOnlyTitle = new TextExercise();
} else if (exerciseWithOnlyTitle instanceof ModelingExercise) {
exerciseWithOnlyTitle = new ModelingExercise();
} else if (exerciseWithOnlyTitle instanceof FileUploadExercise) {
exerciseWithOnlyTitle = new FileUploadExercise();
} else if (exerciseWithOnlyTitle instanceof ProgrammingExercise) {
exerciseWithOnlyTitle = new ProgrammingExercise();
}
exerciseWithOnlyTitle.setTitle(originalParticipation.getExercise().getTitle());
exerciseWithOnlyTitle.setId(originalParticipation.getExercise().getId());
originalParticipation.setExercise(exerciseWithOnlyTitle);
}
Submission originalSubmission = complaint.getResult().getSubmission();
if (originalSubmission != null) {
Submission submissionWithOnlyId;
if (originalSubmission instanceof TextSubmission) {
submissionWithOnlyId = new TextSubmission();
} else if (originalSubmission instanceof ModelingSubmission) {
submissionWithOnlyId = new ModelingSubmission();
} else if (originalSubmission instanceof FileUploadSubmission) {
submissionWithOnlyId = new FileUploadSubmission();
} else if (originalSubmission instanceof ProgrammingSubmission) {
submissionWithOnlyId = new ProgrammingSubmission();
} else {
return;
}
submissionWithOnlyId.setId(originalSubmission.getId());
complaint.getResult().setSubmission(submissionWithOnlyId);
}
}
use of de.tum.in.www1.artemis.domain.Submission 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.Submission 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.Submission in project ArTEMiS by ls1intum.
the class TextSubmissionResource method getTextSubmissionWithResults.
/**
* GET /text-submissions/:id : get the "id" textSubmission.
*
* @param submissionId the id of the textSubmission to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the textSubmission, or with status 404 (Not Found)
*/
@GetMapping("/text-submissions/{submissionId}")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<TextSubmission> getTextSubmissionWithResults(@PathVariable Long submissionId) {
log.debug("REST request to get TextSubmission : {}", submissionId);
var textSubmission = textSubmissionRepository.findWithEagerResultsById(submissionId).orElseThrow(() -> new EntityNotFoundException("TextSubmission", submissionId));
if (!authCheckService.isAtLeastTeachingAssistantForExercise(textSubmission.getParticipation().getExercise())) {
// anonymize and throw exception if not authorized to view submission
plagiarismService.anonymizeSubmissionForStudent(textSubmission, userRepository.getUser().getLogin());
return ResponseEntity.ok(textSubmission);
}
// Add the jwt token as a header to the response for tutor-assessment tracking to the request if the athene profile is set
final ResponseEntity.BodyBuilder bodyBuilder = ResponseEntity.ok();
if (textSubmission.getLatestResult() != null) {
this.atheneTrackingTokenProvider.ifPresent(atheneTrackingTokenProvider -> atheneTrackingTokenProvider.addTokenToResponseEntity(bodyBuilder, textSubmission.getLatestResult()));
}
return bodyBuilder.body(textSubmission);
}
use of de.tum.in.www1.artemis.domain.Submission in project ArTEMiS by ls1intum.
the class TutorParticipationResource method deleteTutorParticipationForGuidedTour.
/**
* DELETE /guided-tour/exercises/:exerciseId/example-submission: delete the tutor participation for example submissions of the "exerciseId" exercise for guided tutorials (e.g. when restarting a tutorial)
* Please note: all tutors can delete their own tutor participation for example submissions when it belongs to a guided tutorial
* @param exerciseId the exercise id which has example submissions and tutor participations
* @return the ResponseEntity with status 200 (OK) or 403 (FORBIDDEN)
*/
@DeleteMapping(value = "/guided-tour/exercises/{exerciseId}/example-submission")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<TutorParticipation> deleteTutorParticipationForGuidedTour(@PathVariable Long exerciseId) {
log.debug("REST request to remove tutor participation of the example submission for exercise id : {}", exerciseId);
Exercise exercise = this.exerciseRepository.findByIdElseThrow(exerciseId);
User user = userRepository.getUserWithGroupsAndAuthorities();
// Allow all tutors to delete their own participation if it's for a tutorial
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.TEACHING_ASSISTANT, exercise, user);
guidedTourConfiguration.checkExerciseForTutorialElseThrow(exercise);
tutorParticipationService.removeTutorParticipations(exercise, user);
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(applicationName, true, ENTITY_NAME, exerciseId.toString())).build();
}
Aggregations