use of de.tum.in.www1.artemis.domain.participation 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.participation 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;
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testCommitAndPush.
@Test
public void testCommitAndPush() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
Ref oldHead = repo.findRef("HEAD");
gitService.commitAndPush(repo, "test commit");
Ref head = repo.findRef("HEAD");
assertThat(head).isNotEqualTo(oldHead);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(head.getObjectId());
assertThat(commit.getFullMessage()).isEqualTo("test commit");
// get remote ref
Git git = new Git(repo);
Collection<Ref> refs = git.lsRemote().setHeads(true).call();
Ref remoteHead = refs.iterator().next();
assertThat(head.getObjectId()).isEqualTo(remoteHead.getObjectId());
gitService.deleteLocalRepository(repo);
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testGetOrCheckoutRepositoryForNewRepo.
@Test
public void testGetOrCheckoutRepositoryForNewRepo() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
assertThat(repo.getBranch()).isEqualTo("master");
assertThat(repo.getDirectory()).exists();
gitService.deleteLocalRepository(repo);
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class GitServiceIntTest method testPull.
@Test
public void testPull() throws IOException, GitAPIException {
Participation participation = new Participation();
participation.setRepositoryUrl(remoteTestRepo);
Repository repo = gitService.getOrCheckoutRepository(participation);
Ref oldHead = repo.findRef("HEAD");
// commit
File tempDir = Files.createTempDir();
Git git = Git.cloneRepository().setURI(remoteTestRepo).setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).setDirectory(tempDir).call();
git.commit().setMessage("a commit").setAllowEmpty(true).call();
git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(GIT_USER, GIT_PASSWORD)).call();
// pull
PullResult pullResult = gitService.pull(repo);
Ref newHead = repo.findRef("HEAD");
assertThat(oldHead).isNotEqualTo(newHead);
RevWalk walk = new RevWalk(repo);
RevCommit commit = walk.parseCommit(newHead.getObjectId());
assertThat(commit.getFullMessage()).isEqualTo("a commit");
FileUtils.deleteDirectory(tempDir);
}
Aggregations