use of de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy in project ArTEMiS by ls1intum.
the class ProgrammingExerciseImportService method importSubmissionPolicy.
/**
* Persists the submission policy of the new exercise. We ensure that the submission policy does not
* have any id or programming exercise set.
*
* @param newExercise containing the submission policy to persist
*/
private void importSubmissionPolicy(ProgrammingExercise newExercise) {
if (newExercise.getSubmissionPolicy() != null) {
SubmissionPolicy newSubmissionPolicy = newExercise.getSubmissionPolicy();
newSubmissionPolicy.setId(null);
newSubmissionPolicy.setProgrammingExercise(null);
newExercise.setSubmissionPolicy(submissionPolicyRepository.save(newSubmissionPolicy));
}
}
use of de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy in project ArTEMiS by ls1intum.
the class SubmissionPolicyResource method getSubmissionPolicyOfExercise.
/**
* GET programming-exercises/:exerciseId/submission-policy : Gets the submission policy of a programming exercise
*
* @param exerciseId of the programming exercise for which the submission policy should be fetched
* @return the ResponseEntity with status 200 (OK) and the submission policy in body. Status 404 when
* the programming exercise does not exist and status 403 when the requester is not at least a student
* in the course the programming exercise belongs to.
*/
@GetMapping(PROGRAMMING_EXERCISE_SUBMISSION_POLICY)
@PreAuthorize("hasRole('USER')")
public ResponseEntity<SubmissionPolicy> getSubmissionPolicyOfExercise(@PathVariable Long exerciseId) {
log.debug("REST request to get submission policy of programming exercise {}", exerciseId);
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithSubmissionPolicyElseThrow(exerciseId);
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.STUDENT, programmingExercise, null);
return ResponseEntity.ok().body(programmingExercise.getSubmissionPolicy());
}
use of de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy in project ArTEMiS by ls1intum.
the class SubmissionPolicyResource method addSubmissionPolicyToProgrammingExercise.
/**
* POST programming-exercises/:exerciseId/submission-policy
* <br><br>
* Adds a submission policy to the programming exercise. When a submission policy is added to a programming
* exercise retroactively, it is disabled by default. More information on adding submission policies
* can be found at {@link SubmissionPolicyService#addSubmissionPolicyToProgrammingExercise(SubmissionPolicy, ProgrammingExercise)}.
*
* @param exerciseId of the programming exercise for which the submission policy in request body should be added
* @param submissionPolicy that should be added to the programming exercise
* @return the ResponseEntity with status 200 (OK) and the added submission policy in body. Status 404 when
* the programming exercise does not exist, status 403 when the requester is not at least an instructor
* in the course the programming exercise belongs to and 400 when the submission policy has an id or
* is invalid. More information on submission policy validation can be found at {@link SubmissionPolicyService#validateSubmissionPolicy(SubmissionPolicy)}.
*/
@PostMapping(PROGRAMMING_EXERCISE_SUBMISSION_POLICY)
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<SubmissionPolicy> addSubmissionPolicyToProgrammingExercise(@PathVariable Long exerciseId, @RequestBody SubmissionPolicy submissionPolicy) throws URISyntaxException {
log.debug("REST request to add submission policy to programming exercise {}", exerciseId);
SubmissionPolicy addedSubmissionPolicy;
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithSubmissionPolicyElseThrow(exerciseId);
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, programmingExercise, null);
if (programmingExercise.getSubmissionPolicy() != null) {
throw new BadRequestAlertException("The submission policy could not be added to the programming exercise, because it already has a submission policy.", ENTITY_NAME, "programmingExercisePolicyPresent");
}
if (submissionPolicy.getId() != null) {
throw new BadRequestAlertException("The submission policy could not be added to the programming exercise, because it already has an id.", ENTITY_NAME, "submissionPolicyHasId");
}
submissionPolicyService.validateSubmissionPolicy(submissionPolicy);
addedSubmissionPolicy = submissionPolicyService.addSubmissionPolicyToProgrammingExercise(submissionPolicy, programmingExercise);
HttpHeaders responseHeaders = HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, Long.toString(addedSubmissionPolicy.getId()));
return ResponseEntity.created(new URI(PROGRAMMING_EXERCISE_SUBMISSION_POLICY.replace("{exerciseId}", Long.toString(exerciseId)))).headers(responseHeaders).body(addedSubmissionPolicy);
}
use of de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy in project Artemis by ls1intum.
the class ProgrammingExerciseImportService method importSubmissionPolicy.
/**
* Persists the submission policy of the new exercise. We ensure that the submission policy does not
* have any id or programming exercise set.
*
* @param newExercise containing the submission policy to persist
*/
private void importSubmissionPolicy(ProgrammingExercise newExercise) {
if (newExercise.getSubmissionPolicy() != null) {
SubmissionPolicy newSubmissionPolicy = newExercise.getSubmissionPolicy();
newSubmissionPolicy.setId(null);
newSubmissionPolicy.setProgrammingExercise(null);
newExercise.setSubmissionPolicy(submissionPolicyRepository.save(newSubmissionPolicy));
}
}
use of de.tum.in.www1.artemis.domain.submissionpolicy.SubmissionPolicy in project Artemis by ls1intum.
the class SubmissionPolicyResource method addSubmissionPolicyToProgrammingExercise.
/**
* POST programming-exercises/:exerciseId/submission-policy
* <br><br>
* Adds a submission policy to the programming exercise. When a submission policy is added to a programming
* exercise retroactively, it is disabled by default. More information on adding submission policies
* can be found at {@link SubmissionPolicyService#addSubmissionPolicyToProgrammingExercise(SubmissionPolicy, ProgrammingExercise)}.
*
* @param exerciseId of the programming exercise for which the submission policy in request body should be added
* @param submissionPolicy that should be added to the programming exercise
* @return the ResponseEntity with status 200 (OK) and the added submission policy in body. Status 404 when
* the programming exercise does not exist, status 403 when the requester is not at least an instructor
* in the course the programming exercise belongs to and 400 when the submission policy has an id or
* is invalid. More information on submission policy validation can be found at {@link SubmissionPolicyService#validateSubmissionPolicy(SubmissionPolicy)}.
*/
@PostMapping(PROGRAMMING_EXERCISE_SUBMISSION_POLICY)
@PreAuthorize("hasRole('INSTRUCTOR')")
public ResponseEntity<SubmissionPolicy> addSubmissionPolicyToProgrammingExercise(@PathVariable Long exerciseId, @RequestBody SubmissionPolicy submissionPolicy) throws URISyntaxException {
log.debug("REST request to add submission policy to programming exercise {}", exerciseId);
SubmissionPolicy addedSubmissionPolicy;
ProgrammingExercise programmingExercise = programmingExerciseRepository.findByIdWithSubmissionPolicyElseThrow(exerciseId);
authorizationCheckService.checkHasAtLeastRoleForExerciseElseThrow(Role.INSTRUCTOR, programmingExercise, null);
if (programmingExercise.getSubmissionPolicy() != null) {
throw new BadRequestAlertException("The submission policy could not be added to the programming exercise, because it already has a submission policy.", ENTITY_NAME, "programmingExercisePolicyPresent");
}
if (submissionPolicy.getId() != null) {
throw new BadRequestAlertException("The submission policy could not be added to the programming exercise, because it already has an id.", ENTITY_NAME, "submissionPolicyHasId");
}
submissionPolicyService.validateSubmissionPolicy(submissionPolicy);
addedSubmissionPolicy = submissionPolicyService.addSubmissionPolicyToProgrammingExercise(submissionPolicy, programmingExercise);
HttpHeaders responseHeaders = HeaderUtil.createEntityCreationAlert(applicationName, true, ENTITY_NAME, Long.toString(addedSubmissionPolicy.getId()));
return ResponseEntity.created(new URI(PROGRAMMING_EXERCISE_SUBMISSION_POLICY.replace("{exerciseId}", Long.toString(exerciseId)))).headers(responseHeaders).body(addedSubmissionPolicy);
}
Aggregations