Search in sources :

Example 21 with Result

use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.

the class ModelingSubmissionResource method updateModelingSubmission.

/**
 * PUT  /modeling-submissions : Updates an existing modelingSubmission.
 *
 * @param modelingSubmission the modelingSubmission to update
 * @return the ResponseEntity with status 200 (OK) and with body the updated modelingSubmission,
 * or with status 400 (Bad Request) if the modelingSubmission is not valid,
 * or with status 500 (Internal Server Error) if the modelingSubmission couldn't be updated
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PutMapping("/modeling-submissions")
@Timed
public ResponseEntity<ModelingSubmission> updateModelingSubmission(@RequestBody ModelingSubmission modelingSubmission) throws URISyntaxException {
    log.debug("REST request to update ModelingSubmission : {}", modelingSubmission);
    if (modelingSubmission.getId() == null) {
        return createModelingSubmission(modelingSubmission);
    }
    ModelingSubmission result = modelingSubmissionRepository.save(modelingSubmission);
    return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, modelingSubmission.getId().toString())).body(result);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.ModelingSubmission) Timed(com.codahale.metrics.annotation.Timed)

Example 22 with Result

use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.

the class ModelingSubmissionResource method createModelingSubmission.

/**
 * POST  /modeling-submissions : Create a new modelingSubmission.
 *
 * @param modelingSubmission the modelingSubmission to create
 * @return the ResponseEntity with status 201 (Created) and with body the new modelingSubmission, or with status 400 (Bad Request) if the modelingSubmission has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/modeling-submissions")
@Timed
public ResponseEntity<ModelingSubmission> createModelingSubmission(@RequestBody ModelingSubmission modelingSubmission) throws URISyntaxException {
    log.debug("REST request to save ModelingSubmission : {}", modelingSubmission);
    if (modelingSubmission.getId() != null) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new modelingSubmission cannot already have an ID")).body(null);
    }
    ModelingSubmission result = modelingSubmissionRepository.save(modelingSubmission);
    return ResponseEntity.created(new URI("/api/modeling-submissions/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : ModelingSubmission(de.tum.in.www1.artemis.domain.ModelingSubmission) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 23 with Result

use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.

the class ParticipationResource method getParticipationRepositoryWebUrl.

@GetMapping(value = "/participations/{id}/repositoryWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationRepositoryWebUrl(@PathVariable Long id, Authentication authentication) {
    log.debug("REST request to get Participation : {}", id);
    Participation participation = participationService.findOne(id);
    Course course = participation.getExercise().getCourse();
    if (!authCheckService.isOwnerOfParticipation(participation)) {
        if (!courseService.userHasTAPermissions(course)) {
            return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
        }
    }
    URL url = versionControlService.get().getRepositoryWebUrl(participation);
    return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
Also used : de.tum.in.www1.artemis.service(de.tum.in.www1.artemis.service) Logger(org.slf4j.Logger) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Timed(com.codahale.metrics.annotation.Timed) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) Principal(java.security.Principal) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) Authentication(org.springframework.security.core.Authentication) HeaderUtil(de.tum.in.www1.artemis.web.rest.util.HeaderUtil) ResponseEntity(org.springframework.http.ResponseEntity) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 24 with Result

use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.

the class ParticipationResource method getParticipationBuildPlanWebUrl.

@GetMapping(value = "/participations/{id}/buildPlanWebUrl")
@PreAuthorize("hasAnyRole('USER', 'TA', 'INSTRUCTOR', 'ADMIN')")
public ResponseEntity<String> getParticipationBuildPlanWebUrl(@PathVariable Long id) {
    log.debug("REST request to get Participation : {}", id);
    Participation participation = participationService.findOne(id);
    Course course = participation.getExercise().getCourse();
    if (!authCheckService.isOwnerOfParticipation(participation)) {
        if (!courseService.userHasTAPermissions(course)) {
            return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
        }
    }
    URL url = continuousIntegrationService.get().getBuildPlanWebUrl(participation);
    return Optional.ofNullable(url).map(result -> new ResponseEntity<>(url.toString(), HttpStatus.OK)).orElse(new ResponseEntity<>(HttpStatus.NOT_FOUND));
}
Also used : de.tum.in.www1.artemis.service(de.tum.in.www1.artemis.service) Logger(org.slf4j.Logger) BadRequestAlertException(de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) LoggerFactory(org.slf4j.LoggerFactory) Timed(com.codahale.metrics.annotation.Timed) HttpStatus(org.springframework.http.HttpStatus) List(java.util.List) de.tum.in.www1.artemis.domain(de.tum.in.www1.artemis.domain) Principal(java.security.Principal) AbstractAuthenticationToken(org.springframework.security.authentication.AbstractAuthenticationToken) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Optional(java.util.Optional) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) Authentication(org.springframework.security.core.Authentication) HeaderUtil(de.tum.in.www1.artemis.web.rest.util.HeaderUtil) ResponseEntity(org.springframework.http.ResponseEntity) URL(java.net.URL) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 25 with Result

use of de.tum.in.www1.artemis.domain.Result in project ArTEMiS by ls1intum.

the class ProgrammingExerciseResource method createProgrammingExercise.

/**
 * POST  /programming-exercises : Create a new programmingExercise.
 *
 * @param programmingExercise the programmingExercise to create
 * @return the ResponseEntity with status 201 (Created) and with body the new programmingExercise, or with status 400 (Bad Request) if the programmingExercise has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/programming-exercises")
@PreAuthorize("hasAnyRole('TA', 'INSTRUCTOR', 'ADMIN')")
@Timed
public ResponseEntity<ProgrammingExercise> createProgrammingExercise(@RequestBody ProgrammingExercise programmingExercise) throws URISyntaxException {
    log.debug("REST request to save ProgrammingExercise : {}", programmingExercise);
    if (programmingExercise.getId() != null) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "idexists", "A new programmingExercise cannot already have an ID")).body(null);
    }
    // fetch course from database to make sure client didn't change groups
    Course course = courseService.findOne(programmingExercise.getCourse().getId());
    if (course == null) {
        return ResponseEntity.badRequest().headers(HeaderUtil.createFailureAlert(ENTITY_NAME, "courseNotFound", "The course belonging to this programming exercise does not exist")).body(null);
    }
    User user = userService.getUserWithGroupsAndAuthorities();
    if (!authCheckService.isTeachingAssistantInCourse(course, user) && !authCheckService.isInstructorInCourse(course, user) && !authCheckService.isAdmin()) {
        return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
    }
    ResponseEntity<ProgrammingExercise> errorResponse = checkProgrammingExerciseForError(programmingExercise);
    if (errorResponse != null) {
        return errorResponse;
    }
    ProgrammingExercise result = programmingExerciseRepository.save(programmingExercise);
    return ResponseEntity.created(new URI("/api/programming-exercises/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : User(de.tum.in.www1.artemis.domain.User) ProgrammingExercise(de.tum.in.www1.artemis.domain.ProgrammingExercise) Course(de.tum.in.www1.artemis.domain.Course) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

Timed (com.codahale.metrics.annotation.Timed)15 URI (java.net.URI)10 Result (de.tum.in.www1.artemis.domain.Result)8 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)8 Test (org.junit.Test)7 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)7 BadRequestAlertException (de.tum.in.www1.artemis.web.rest.errors.BadRequestAlertException)6 RestTemplate (org.springframework.web.client.RestTemplate)6 MalformedURLException (java.net.MalformedURLException)5 Transactional (org.springframework.transaction.annotation.Transactional)5 Participation (de.tum.in.www1.artemis.domain.Participation)4 BambooException (de.tum.in.www1.artemis.exception.BambooException)4 GitException (de.tum.in.www1.artemis.exception.GitException)4 HeaderUtil (de.tum.in.www1.artemis.web.rest.util.HeaderUtil)4 IOException (java.io.IOException)4 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)4 HttpEntity (org.springframework.http.HttpEntity)4 HttpHeaders (org.springframework.http.HttpHeaders)4 ResponseEntity (org.springframework.http.ResponseEntity)4 de.tum.in.www1.artemis.domain (de.tum.in.www1.artemis.domain)3