Skip to content

Commit

Permalink
Add new API to get all store keys
Browse files Browse the repository at this point in the history
  • Loading branch information
ligangty committed Jan 11, 2024
1 parent 0e148b7 commit be84178
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -85,4 +88,24 @@ public EndpointViewListing getEndpointsListing( final String baseUri, final JaxR
return new EndpointViewListing( points );
}

public Map<String, List<String>> getAllStoreKeys()
throws IndyWorkflowException
{
final List<ArtifactStore> stores;
try
{
final Map<String, List<String>> result = new HashMap<>();
stores = new ArrayList<>( dataManager.getAllArtifactStores() );
List<String> 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() );
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, List<String>> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,14 @@ public void testGetAllEndpoints()
.body( "size()", is( 1 ) )
.body( "items.size()", greaterThan( 1 ) );
}

@Test
public void testGetAllStoreKeys()
{
given().get( "/api/stats/all-storekeys" )
.then()
.statusCode( OK.getStatusCode() )
.body( "size()", is( 1 ) )
.body( "items.size()", greaterThan( 1 ) );
}
}

0 comments on commit be84178

Please sign in to comment.