use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ExerciseResource method createExercise.
/**
* POST /exercises : Create a new exercise.
*
* @param exercise the exercise to create
* @return the ResponseEntity with status 201 (Created) and with body the new exercise, or with status 400 (Bad Request) if the exercise has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public // TODO: test if it still works with abstract entity in body
ResponseEntity<Exercise> createExercise(@RequestBody Exercise exercise) throws URISyntaxException {
log.debug("REST request to save Exercise : {}", exercise);
Course course = exercise.getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (exercise.getId() != null) {
throw new BadRequestAlertException("A new exercise cannot already have an ID", ENTITY_NAME, "idexists");
}
if (exercise instanceof ProgrammingExercise) {
ResponseEntity<Exercise> errorResponse = checkProgrammingExerciseForError((ProgrammingExercise) exercise);
if (errorResponse != null) {
return errorResponse;
}
}
Exercise result = exerciseRepository.save(exercise);
return ResponseEntity.created(new URI("/api/exercises/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class FeedbackResource method updateFeedback.
/**
* PUT /feedbacks : Updates an existing feedback.
*
* @param feedback the feedback to update
* @return the ResponseEntity with status 200 (OK) and with body the updated feedback,
* or with status 400 (Bad Request) if the feedback is not valid,
* or with status 500 (Internal Server Error) if the feedback couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/feedbacks")
@Timed
public ResponseEntity<Feedback> updateFeedback(@RequestBody Feedback feedback) throws URISyntaxException {
log.debug("REST request to update Feedback : {}", feedback);
if (feedback.getId() == null) {
return createFeedback(feedback);
}
Feedback result = feedbackRepository.save(feedback);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, feedback.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class JiraAuthenticationProvider method getUsernameForEmail.
/**
* Checks if an JIRA user for the given email address exists.
*
* @param email The JIRA user email address
* @return Optional String of JIRA username
* @throws ArtemisAuthenticationException
*/
@Override
public Optional<String> getUsernameForEmail(String email) throws ArtemisAuthenticationException {
HttpHeaders headers = HeaderUtil.createAuthorization(JIRA_USER, JIRA_PASSWORD);
HttpEntity<?> entity = new HttpEntity<>(headers);
RestTemplate restTemplate = new RestTemplate();
try {
ResponseEntity<ArrayList> authenticationResponse = restTemplate.exchange(JIRA_URL + "/rest/api/2/user/search?username=" + email, HttpMethod.GET, entity, ArrayList.class);
ArrayList results = authenticationResponse.getBody();
if (results.size() == 0) {
// no result
return Optional.empty();
}
Map firstResult = (Map) results.get(0);
return Optional.of((String) firstResult.get("name"));
} catch (HttpClientErrorException e) {
log.error("Could not get JIRA username for email address " + email, e);
throw new ArtemisAuthenticationException("Error while checking eMail address");
}
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class ResultResource method createResult.
/**
* POST /results : Create a new manual result.
*
* @param result the result to create
* @return the ResponseEntity with status 201 (Created) and with body the new result, or with status 400 (Bad Request) if the result has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/results")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<Result> createResult(@RequestBody Result result) throws URISyntaxException {
log.debug("REST request to save Result : {}", result);
Participation participation = result.getParticipation();
Course course = participation.getExercise().getCourse();
User user = userService.getUserWithGroupsAndAuthorities();
if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (result.getId() != null) {
throw new BadRequestAlertException("A new result cannot already have an ID.", ENTITY_NAME, "idexists");
} else if (result.getResultString() == null) {
throw new BadRequestAlertException("Result string is required.", ENTITY_NAME, "resultStringNull");
} else if (result.getScore() == null) {
throw new BadRequestAlertException("Score is required.", ENTITY_NAME, "scoreNull");
} else if (result.getScore() != 100 && result.isSuccessful()) {
throw new BadRequestAlertException("Only result with score 100% can be successful.", ENTITY_NAME, "scoreAndSuccessfulNotMatching");
} else if (!result.getFeedbacks().isEmpty() && result.getFeedbacks().stream().filter(feedback -> feedback.getText() == null).count() != 0) {
throw new BadRequestAlertException("In case feedback is present, feedback text and detail text are mandatory.", ENTITY_NAME, "feedbackTextOrDetailTextNull");
}
if (!result.getFeedbacks().isEmpty()) {
result.setHasFeedback(true);
}
Result savedResult = resultRepository.save(result);
result.getFeedbacks().forEach(feedback -> {
feedback.setResult(savedResult);
feedbackService.save(feedback);
});
ltiService.ifPresent(ltiService -> ltiService.onNewBuildResult(savedResult.getParticipation()));
return ResponseEntity.created(new URI("/api/results/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.
the class QuizSubmissionService method submitForPractice.
/**
* Submit the given submission for practice
*
* @param quizSubmission the submission to submit
* @param quizExercise the exercise to submit in
* @param participation the participation where the result should be saved
* @return the result entity
*/
@Transactional
public Result submitForPractice(QuizSubmission quizSubmission, QuizExercise quizExercise, Participation participation) {
// update submission properties
quizSubmission.setSubmitted(true);
quizSubmission.setType(SubmissionType.MANUAL);
// calculate scores
quizSubmission.calculateAndUpdateScores(quizExercise);
// create and save result
Result result = new Result().participation(participation).submission(quizSubmission);
result.setRated(false);
result.setCompletionDate(ZonedDateTime.now());
// calculate score and update result accordingly
result.evaluateSubmission();
// save result
resultRepository.save(result);
// replace proxy with submission, because of Lazy-fetching
result.setSubmission(quizSubmission);
// add result to statistics
QuizScheduleService.addResultToStatistic(quizExercise.getId(), result);
return result;
}
Aggregations