diff --git a/VERSION.txt b/VERSION.txt index 51cfa716ace8da49b6e640a1141d7575498fb5c1..4d89c4b7b3974ce3309a46f052740c3a8c4174cb 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -1,4 +1,4 @@ -2.3.0 Add training access tokens to sandbox api calls. +2.3.0 Add training access tokens to sandbox api calls. Add access token endpoints. 2.2.10 Fix user ref creation failing on parallel requests. 2.2.9 Add check to prevent reviving an expired training instance. 2.2.8 Add check for training definition being in use when trying to add, remove and update tasks. diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/controller/TrainingInstancesRestController.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/controller/TrainingInstancesRestController.java index 6034f7d7e3e5c43439df769023956a0f0c36ed00..6384e86eec1ca390116579e2b98b4770f3e6d42d 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/controller/TrainingInstancesRestController.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/controller/TrainingInstancesRestController.java @@ -89,7 +89,7 @@ public class TrainingInstancesRestController { /** * Get requested Training Instance by pool id. * - * @param poolId id of the assigned pool. + * @param poolId id of the assigned pool. * @return Requested Training Instance by pool id. */ @ApiOperation(httpMethod = "GET", @@ -112,6 +112,32 @@ public class TrainingInstancesRestController { return ResponseEntity.ok(trainingInstanceResource); } + /** + * Get Training instance access token by pool id. + * + * @param poolId id of the assigned pool. + * @return Requested access token by pool id if it exists. + */ + @ApiOperation(httpMethod = "GET", + value = "Get training instance access token by pool id.", + response = String.class, + nickname = "findTrainingInstanceAccessTokenByPoolId", + notes = "Returns training instance access token by pool id.", + produces = MediaType.APPLICATION_JSON_VALUE + ) + @ApiResponses(value = { + @ApiResponse(code = 200, message = "The access token has been found", response = TrainingInstanceDTO.class), + @ApiResponse(code = 404, message = "The access token has not been found.", response = ApiError.class), + @ApiResponse(code = 500, message = "Unexpected condition was encountered.", response = ApiError.class) + }) + @GetMapping(path = "/access/{poolId}", produces = MediaType.APPLICATION_JSON_VALUE) + public ResponseEntity<String> findInstanceAccessTokenByPoolId( + @ApiParam(value = "Pool ID", required = true) + @PathVariable("poolId") Long poolId) { + String accessToken = trainingInstanceFacade.findInstanceAccessTokenByPoolId(poolId); + return ResponseEntity.ok(accessToken); + } + /** * Get all Training Instances. * @@ -133,7 +159,7 @@ public class TrainingInstancesRestController { @GetMapping(produces = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Object> findAllTrainingInstances(@QuerydslPredicate(root = TrainingInstance.class) Predicate predicate, @ApiParam(value = "Pagination support.", required = false) - Pageable pageable, + Pageable pageable, @ApiParam(value = "Fields which should be returned in REST API response", required = false) @RequestParam(value = "fields", required = false) String fields) { PageResultResource<TrainingInstanceFindAllResponseDTO> trainingInstanceResource = trainingInstanceFacade.findAll(predicate, pageable); @@ -301,7 +327,7 @@ public class TrainingInstancesRestController { @ApiParam(value = "If only active or not active training runs should be returned.") @RequestParam(value = "isActive", required = false) Boolean isActive, @ApiParam(value = "Pagination support.") - Pageable pageable, + Pageable pageable, @ApiParam(value = "Fields which should be returned in REST API response", required = false) @RequestParam(value = "fields", required = false) String fields) { PageResultResource<TrainingRunDTO> trainingRunResource = trainingInstanceFacade.findTrainingRunsByTrainingInstance(instanceId, isActive, pageable); @@ -338,7 +364,7 @@ public class TrainingInstancesRestController { @ApiParam(value = "Family name filter.", required = true) @RequestParam(value = "familyName", required = false) String familyName, @ApiParam(value = "Pagination support.") - Pageable pageable) { + Pageable pageable) { PageResultResource<UserRefDTO> designers = trainingInstanceFacade.getOrganizersOfTrainingInstance(trainingInstanceId, pageable, givenName, familyName); return ResponseEntity.ok(SquigglyUtils.stringify(objectMapper, designers)); } @@ -373,7 +399,7 @@ public class TrainingInstancesRestController { @ApiParam(value = "Family name filter.", required = false) @RequestParam(value = "familyName", required = false) String familyName, @ApiParam(value = "Pagination support.") - Pageable pageable) { + Pageable pageable) { PageResultResource<UserRefDTO> designers = trainingInstanceFacade.getOrganizersNotInGivenTrainingInstance(trainingInstanceId, pageable, givenName, familyName); return ResponseEntity.ok(SquigglyUtils.stringify(objectMapper, designers)); } diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java index 51141490e8c0276402dba793e03bd13b78257ad7..5e45f5354267a2016cb0664a634b89d398d3638a 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/facade/TrainingInstanceFacade.java @@ -118,6 +118,18 @@ public class TrainingInstanceFacade { return trainingInstanceMapper.mapToDTO(trainingInstanceService.findByPoolId(poolId)); } + /** + * Get Training instance access token by pool id. + * + * @param poolId id of the assigned pool. + * @return Requested access token by pool id if it exists. + */ + @IsOrganizerOrAdmin + @TransactionalRO + public String findInstanceAccessTokenByPoolId(Long poolId) { + return trainingInstanceService.findInstanceAccessTokenByPoolId(poolId); + } + /** * Find all Training Instances. * diff --git a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java index d9b70dd58def5a808b209ac5d62c1e5f58635496..e1345ce8334a21e93d6fdff2681cc01ee3102df2 100644 --- a/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java +++ b/src/main/java/cz/muni/ics/kypo/training/adaptive/service/training/TrainingInstanceService.java @@ -85,6 +85,17 @@ public class TrainingInstanceService { .orElseThrow(() -> new EntityNotFoundException(new EntityErrorDetail(TrainingInstance.class, "poolId", poolId.getClass(), poolId))); } + /** + * Find Training instance access token by pool id if exists. + * + * @param poolId the pool id + * @return the access token + */ + public String findInstanceAccessTokenByPoolId(Long poolId) { + Optional<TrainingInstance> instance = trainingInstanceRepository.findByPoolId(poolId); + return instance.map(TrainingInstance::getAccessToken).orElse(null); + } + /** * Find specific Training instance by id including its associated Training definition. *