use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ResultResource method getLatestResultWithFeedbacks.
/**
* GET /participations/:participationId/latest-result : get the latest result with feedbacks for the given participation.
* The order of results is determined by completionDate desc.
*
* @param participationId the id of the participation for which to retrieve the latest result.
* @return the ResponseEntity with status 200 (OK) and with body the result, or with status 404 (Not Found)
*/
@GetMapping("participations/{participationId}/latest-result")
@PreAuthorize("hasRole('TA')")
public ResponseEntity<Result> getLatestResultWithFeedbacks(@PathVariable Long participationId) {
log.debug("REST request to get latest result for participation : {}", participationId);
Participation participation = participationRepository.findByIdElseThrow(participationId);
if (participation instanceof StudentParticipation && !authCheckService.canAccessParticipation((StudentParticipation) participation) || participation instanceof ProgrammingExerciseParticipation && !programmingExerciseParticipationService.canAccessParticipation((ProgrammingExerciseParticipation) participation)) {
throw new AccessForbiddenException();
}
Result result = resultRepository.findFirstWithFeedbacksByParticipationIdOrderByCompletionDateDescElseThrow(participation.getId());
return new ResponseEntity<>(result, HttpStatus.OK);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ResultResource method createResultForExternalSubmission.
/**
* POST exercises/:exerciseId/external-submission-results : Creates a new result for the provided exercise and student (a participation and an empty submission will also be created if they do not exist yet)
*
* @param exerciseId The exercise ID for which a result should get created
* @param studentLogin The student login (username) for which a result should get created
* @param result The result to be created
* @return The newly created result
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("exercises/{exerciseId}/external-submission-results")
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<Result> createResultForExternalSubmission(@PathVariable Long exerciseId, @RequestParam String studentLogin, @RequestBody Result result) throws URISyntaxException {
log.debug("REST request to create Result for External Submission for Exercise : {}", exerciseId);
if (result.getParticipation() != null && result.getParticipation().getExercise() != null && !result.getParticipation().getExercise().getId().equals(exerciseId)) {
throw new BadRequestAlertException("exerciseId in RequestBody doesnt match exerciseId in path!", "Exercise", "400");
}
Exercise exercise = exerciseRepository.findByIdElseThrow(exerciseId);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, exercise, null);
if (!exercise.isExamExercise()) {
if (exercise.getDueDate() == null || ZonedDateTime.now().isBefore(exercise.getDueDate())) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionBeforeDueDate", "External submissions are not supported before the exercise due date.")).build();
}
} else {
Exam exam = exercise.getExerciseGroup().getExam();
ZonedDateTime latestIndividualExamEndDate = examDateService.getLatestIndividualExamEndDate(exam);
if (latestIndividualExamEndDate == null || ZonedDateTime.now().isBefore(latestIndividualExamEndDate)) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionBeforeDueDate", "External submissions are not supported before the end of the exam.")).build();
}
}
if (exercise instanceof QuizExercise) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "externalSubmissionForQuizExercise", "External submissions are not supported for Quiz exercises.")).build();
}
Optional<User> student = userRepository.findOneWithGroupsAndAuthoritiesByLogin(studentLogin);
authCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, exercise, null);
if (student.isEmpty() || !authCheckService.isAtLeastStudentInCourse(exercise.getCourseViaExerciseGroupOrCourseMember(), student.get())) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "studentNotFound", "The student could not be found in this course.")).build();
}
// Check if a result exists already for this exercise and student. If so, do nothing and just inform the instructor.
Optional<StudentParticipation> optionalParticipation = participationService.findOneByExerciseAndStudentLoginAnyStateWithEagerResults(exercise, studentLogin);
if (optionalParticipation.isPresent() && optionalParticipation.get().getResults() != null && !optionalParticipation.get().getResults().isEmpty()) {
return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(applicationName, true, "result", "resultAlreadyExists", "A result already exists for this student in this exercise.")).build();
}
// Create a participation and a submitted empty submission if they do not exist yet
StudentParticipation participation = participationService.createParticipationWithEmptySubmissionIfNotExisting(exercise, student.get(), SubmissionType.EXTERNAL);
Submission submission = participationRepository.findByIdWithLegalSubmissionsElseThrow(participation.getId()).findLatestSubmission().get();
result.setParticipation(participation);
result.setSubmission(submission);
// Create a new manual result which can be rated or unrated depending on what was specified in the create form
Result savedResult = resultService.createNewManualResult(result, exercise instanceof ProgrammingExercise, result.isRated());
return ResponseEntity.created(new URI("/api/results/" + savedResult.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, savedResult.getId().toString())).body(savedResult);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ComplaintResource method createComplaintForExamExercise.
/**
* POST complaints/exam/examId: create a new complaint for an exam exercise
*
* @param complaint the complaint to create
* @param principal that wants to complain
* @param examId the examId of the exam which contains the exercise
* @return the ResponseEntity with status 201 (Created) and with body the new complaints
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
// TODO: should be exams/{examId}/(participations/{participationId}/)complaints
@PostMapping("complaints/exam/{examId}")
@PreAuthorize("hasRole('USER')")
public ResponseEntity<Complaint> createComplaintForExamExercise(@PathVariable Long examId, @RequestBody Complaint complaint, Principal principal) throws URISyntaxException {
log.debug("REST request to save Complaint for exam exercise: {}", complaint);
if (complaint.getId() != null) {
throw new BadRequestAlertException("A new complaint cannot already have an id", COMPLAINT_ENTITY_NAME, "idexists");
}
if (complaint.getResult() == null || complaint.getResult().getId() == null) {
throw new BadRequestAlertException("A complaint can be only associated to a result", COMPLAINT_ENTITY_NAME, "noresultid");
}
if (complaintRepository.findByResultId(complaint.getResult().getId()).isPresent()) {
throw new BadRequestAlertException("A complaint for this result already exists", COMPLAINT_ENTITY_NAME, "complaintexists");
}
Result result = resultRepository.findByIdElseThrow(complaint.getResult().getId());
// For non-exam exercises, the POST complaints should be used
if (!result.getParticipation().getExercise().isExamExercise()) {
throw new BadRequestAlertException("A complaint for an course exercise cannot be filed using this component", COMPLAINT_ENTITY_NAME, "complaintAboutCourseExerciseWrongComponent");
}
authCheckService.isOwnerOfParticipationElseThrow((StudentParticipation) result.getParticipation());
// To build correct creation alert on the front-end we must check which type is the complaint to apply correct i18n key.
String entityName = complaint.getComplaintType() == ComplaintType.MORE_FEEDBACK ? MORE_FEEDBACK_ENTITY_NAME : COMPLAINT_ENTITY_NAME;
Complaint savedComplaint = complaintService.createComplaint(complaint, OptionalLong.of(examId), principal);
// Remove assessor information from client request
savedComplaint.getResult().setAssessor(null);
return ResponseEntity.created(new URI("/api/complaints/" + savedComplaint.getId())).headers(HeaderUtil.createEntityCreationAlert(applicationName, true, entityName, savedComplaint.getId().toString())).body(savedComplaint);
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation in project ArTEMiS by ls1intum.
the class ComplaintResource method filterOutStudentFromComplaint.
private void filterOutStudentFromComplaint(Complaint complaint) {
complaint.setParticipant(null);
if (complaint.getResult() != null && complaint.getResult().getParticipation() != null) {
StudentParticipation studentParticipation = (StudentParticipation) complaint.getResult().getParticipation();
studentParticipation.setParticipant(null);
}
}
use of de.tum.in.www1.artemis.domain.participation.StudentParticipation 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);
}
}
Aggregations