use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class LtiServiceIntTest method assertThatNoResultReturnsZeroScore.
@Test
public void assertThatNoResultReturnsZeroScore() {
Participation participation = new Participation();
participationRepository.save(participation);
// String score = ltiService.getScoreForParticipation(participation);
// assertThat(score).isEqualTo("0.00");
// cleanup
participationRepository.delete(participation);
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class LtiServiceIntTest method assertThatUnsuccessfulResultWith2of3FailedTestsReturnsCorrectScore.
@Test
public void assertThatUnsuccessfulResultWith2of3FailedTestsReturnsCorrectScore() {
Participation participation = new Participation();
participationRepository.save(participation);
Result result = new Result();
result.setParticipation(participation);
result.setSuccessful(false);
result.setResultString("2 of 3 failed");
resultRepository.save(result);
// String score = ltiService.getScoreForParticipation(participation);
// assertThat(score).isEqualTo("0.33");
// cleanup
resultRepository.delete(result);
participationRepository.delete(participation);
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class ParticipationResource method createParticipation.
/**
* POST /participations : Create a new participation.
*
* @param participation the participation to create
* @return the ResponseEntity with status 201 (Created) and with body the new participation, or with status 400 (Bad Request) if the participation has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/participations")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<Participation> createParticipation(@RequestBody Participation participation) throws URISyntaxException {
log.debug("REST request to save Participation : {}", participation);
Course course = participation.getExercise().getCourse();
if (!courseService.userHasTAPermissions(course)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (participation.getId() != null) {
throw new BadRequestAlertException("A new participation cannot already have an ID", ENTITY_NAME, "idexists");
}
Participation result = participationService.save(participation);
return ResponseEntity.created(new URI("/api/participations/" + 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 ExerciseService method cleanup.
/**
* Delete build plans (except BASE) and optionally repositores of all exercise participations.
*
* @param id id of the exercise for which build plans in respective participations are deleted
*/
@Transactional
public java.io.File cleanup(Long id, boolean deleteRepositories) throws java.io.IOException {
Exercise exercise = findOneLoadParticipations(id);
log.info("Request to cleanup all participations for Exercise : {}", exercise.getTitle());
List<Repository> studentRepositories = new ArrayList<>();
Path finalZipFilePath = null;
if (Optional.ofNullable(exercise).isPresent() && exercise instanceof ProgrammingExercise) {
exercise.getParticipations().forEach(participation -> {
if (participation.getBuildPlanId() != null) {
// ignore participations without build plan id
try {
continuousIntegrationService.get().deleteBuildPlan(participation.getBuildPlanId());
} catch (BambooException ex) {
log.error(ex.getMessage());
if (ex.getCause() != null) {
log.error(ex.getCause().getMessage());
}
}
participation.setInitializationState(ParticipationState.INACTIVE);
participation.setBuildPlanId(null);
participationService.save(participation);
}
if (deleteRepositories == true && participation.getRepositoryUrl() != null) {
// ignore participations without repository URL
try {
// 1. clone the repository
Repository repo = gitService.get().getOrCheckoutRepository(participation);
// 2. collect the repo file
studentRepositories.add(repo);
} catch (GitAPIException | IOException ex) {
log.error("Archiving and deleting the repository " + participation.getRepositoryUrlAsUrl() + " did not work as expected", ex);
}
}
});
if (deleteRepositories == false) {
// in this case, we are done
return null;
}
if (studentRepositories.isEmpty()) {
log.info("No student repositories have been found.");
return null;
}
// from here on, deleteRepositories is true and does not need to be evaluated again
log.info("Create zip file for all repositories");
Files.createDirectories(Paths.get("zippedRepos"));
finalZipFilePath = Paths.get("zippedRepos", exercise.getCourse().getTitle() + " " + exercise.getTitle() + " Student Repositories.zip");
zipAllRepositories(studentRepositories, finalZipFilePath);
exercise.getParticipations().forEach(participation -> {
if (participation.getRepositoryUrl() != null) {
// ignore participations without repository URL
try {
// 3. delete the locally cloned repo again
gitService.get().deleteLocalRepository(participation);
} catch (IOException e) {
log.error("Archiving and deleting the repository " + participation.getRepositoryUrlAsUrl() + " did not work as expected", e);
}
// 4. finally delete the repository on the VC Server
versionControlService.get().deleteRepository(participation.getRepositoryUrlAsUrl());
participation.setRepositoryUrl(null);
participation.setInitializationState(ParticipationState.FINISHED);
participationService.save(participation);
}
});
scheduleForDeletion(finalZipFilePath, 300);
} else {
log.info("Exercise with id {} is not an instance of ProgrammingExercise. Ignoring the request to cleanup repositories and build plan", id);
return null;
}
return new java.io.File(finalZipFilePath.toString());
}
use of de.tum.in.www1.artemis.domain.participation in project ArTEMiS by ls1intum.
the class GitService method getOrCheckoutRepository.
/**
* Get the local repository for a given participation.
* If the local repo does not exist yet, it will be checked out.
*
* @param participation Participation the remote repository belongs to.
* @return
* @throws IOException
* @throws GitAPIException
*/
public Repository getOrCheckoutRepository(Participation participation) throws IOException, GitAPIException {
URL repoUrl = participation.getRepositoryUrlAsUrl();
Repository repository = getOrCheckoutRepository(repoUrl);
repository.setParticipation(participation);
return repository;
}
Aggregations