Search in sources :

Example 6 with de.tum.in.www1.artemis.domain.participation

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);
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 7 with de.tum.in.www1.artemis.domain.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);
}
Also used : Participation(de.tum.in.www1.artemis.domain.Participation) Result(de.tum.in.www1.artemis.domain.Result) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 8 with de.tum.in.www1.artemis.domain.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);
}
Also used : BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 9 with de.tum.in.www1.artemis.domain.participation

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());
}
Also used : Path(java.nio.file.Path) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) ExerciseRepository(de.tum.in.www1.artemis.repository.ExerciseRepository) BambooException(de.tum.in.www1.artemis.exception.BambooException) IOException(java.io.IOException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with de.tum.in.www1.artemis.domain.participation

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;
}
Also used : Repository(de.tum.in.www1.artemis.domain.Repository) URL(java.net.URL)

Aggregations

Participation (de.tum.in.www1.artemis.domain.Participation)14 Test (org.junit.Test)14 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)14 Repository (de.tum.in.www1.artemis.domain.Repository)7 Transactional (org.springframework.transaction.annotation.Transactional)7 Result (de.tum.in.www1.artemis.domain.Result)5 Timed (com.codahale.metrics.annotation.Timed)4 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)4 URI (java.net.URI)4 ResponseEntity (org.springframework.http.ResponseEntity)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)3 de.tum.in.www1.artemis.service (de.tum.in.www1.artemis.service)3 HeaderUtil (de.tum.in.www1.artemis.web.rest.util.HeaderUtil)3 URISyntaxException (java.net.URISyntaxException)3 URL (java.net.URL)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 HttpStatus (org.springframework.http.HttpStatus)3 Authentication (org.springframework.security.core.Authentication)3