From 083fe1cc0653b8c29bc65c9452972873914ff392 Mon Sep 17 00:00:00 2001 From: Gang Li Date: Thu, 11 Jan 2024 18:17:25 +0800 Subject: [PATCH] Add new API to get all store keys --- .../controller/StatsController.java | 23 +++++++++++++ .../jaxrs/version/StatsHandler.java | 32 +++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/src/main/java/org/commonjava/indy/service/repository/controller/StatsController.java b/src/main/java/org/commonjava/indy/service/repository/controller/StatsController.java index 54b8301..c044250 100644 --- a/src/main/java/org/commonjava/indy/service/repository/controller/StatsController.java +++ b/src/main/java/org/commonjava/indy/service/repository/controller/StatsController.java @@ -28,7 +28,10 @@ import javax.enterprise.context.ApplicationScoped; import javax.inject.Inject; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; @@ -85,4 +88,24 @@ public EndpointViewListing getEndpointsListing( final String baseUri, final JaxR return new EndpointViewListing( points ); } + public Map> getAllStoreKeys() + throws IndyWorkflowException + { + final List stores; + try + { + final Map> result = new HashMap<>(); + stores = new ArrayList<>( dataManager.getAllArtifactStores() ); + List items = stores.stream().map( s-> s.getKey().toString() ).collect( Collectors.toList() ); + result.put("items", items); + return result; + } + catch ( final IndyDataException e ) + { + throw new IndyWorkflowException( INTERNAL_SERVER_ERROR.getStatusCode(), + "Failed to retrieve all store keys: {}", e, e.getMessage() ); + } + + } + } diff --git a/src/main/java/org/commonjava/indy/service/repository/jaxrs/version/StatsHandler.java b/src/main/java/org/commonjava/indy/service/repository/jaxrs/version/StatsHandler.java index 44c1fac..78eaaef 100644 --- a/src/main/java/org/commonjava/indy/service/repository/jaxrs/version/StatsHandler.java +++ b/src/main/java/org/commonjava/indy/service/repository/jaxrs/version/StatsHandler.java @@ -37,7 +37,10 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.TreeSet; @@ -132,4 +135,33 @@ public Response getAllEndpoints( @Context final UriInfo uriInfo ) return response; } + @Operation( + summary = "Retrieve a listing of the artifact stores keys available on the system." ) + @APIResponse( responseCode = "200", + content = @Content( schema = @Schema( implementation = EndpointViewListing.class ) ), + description = "The artifact store keys listing" ) + @Path( "/all-storekeys" ) + @GET + @Produces( APPLICATION_JSON ) + public Response getAllStoreKeys( @Context final UriInfo uriInfo ) + { + Response response; + try + { + + Map> result = statsController.getAllStoreKeys(); + + response = responseHelper.formatOkResponseWithJsonEntity( result ); + + logger.debug( "\n\n\n\n\n\n{} Sent all-keys:\n\n{}\n\n\n\n\n\n\n", new Date(), result ); + } + catch ( final IndyWorkflowException e ) + { + logger.error( String.format( "Failed to retrieve store keys listing: %s", responseHelper.formatEntity( e ) ), + e ); + response = responseHelper.formatResponse( e ); + } + return response; + } + }