Skip to content
Snippets Groups Projects
Commit 6b1dce19 authored by Lukáš Majdan's avatar Lukáš Majdan
Browse files

Merge branch 'add-endpoint-for-access-token' into 'develop'

Add enpoint for access token by poolId

See merge request !140
parents 82ff4d5f e8d046d3
No related branches found
No related tags found
2 merge requests!142Develop,!140Add enpoint for access token by poolId
Pipeline #491486 passed with stages
in 4 minutes and 1 second
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.
......
......@@ -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));
}
......
......@@ -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.
*
......
......@@ -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.
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment