Skip to content

Commit

Permalink
Change content entry record endpoint to GET
Browse files Browse the repository at this point in the history
  • Loading branch information
yma96 committed Jan 29, 2024
1 parent c2cf7fe commit 6499d8c
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -345,26 +345,16 @@ public File getZipRepository( String id )
return contentService.getZipRepository( dto );
}

public boolean recordArtifact( InputStream stream )
public boolean recordArtifact( TrackedContentEntry contentEntry )
{
TrackedContentEntry entry;
ObjectMapper mapper = new ObjectMapper();
boolean isRecorded = false;
try
{
entry = mapper.readValue( stream, TrackedContentEntry.class );
if ( entry != null )
{
isRecorded = recordManager.recordArtifact( entry );
}
}
catch ( IOException e )
{
logger.error( String.format( "Failed to record tracked entry. Reason: %s", e.getMessage() ), e );
isRecorded = recordManager.recordArtifact( contentEntry );
}
catch ( final ContentException | IndyWorkflowException e )
{
logger.error( "Failed to read TrackedContentEntry from event payload.", e );
logger.error( "Failed to read TrackedContentEntry.", e );
}
return isRecorded;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,18 @@
*/
package org.commonjava.indy.service.tracking.jaxrs;

import org.apache.commons.lang3.StringUtils;
import org.commonjava.indy.service.tracking.Constants;
import org.commonjava.indy.service.tracking.client.content.BatchDeleteRequest;
import org.commonjava.indy.service.tracking.client.content.MaintenanceService;
import org.commonjava.indy.service.tracking.config.IndyTrackingConfiguration;
import org.commonjava.indy.service.tracking.controller.AdminController;
import org.commonjava.indy.service.tracking.exception.ContentException;
import org.commonjava.indy.service.tracking.exception.IndyWorkflowException;
import org.commonjava.indy.service.tracking.model.AccessChannel;
import org.commonjava.indy.service.tracking.model.StoreEffect;
import org.commonjava.indy.service.tracking.model.StoreKey;
import org.commonjava.indy.service.tracking.model.StoreType;
import org.commonjava.indy.service.tracking.model.TrackedContentEntry;
import org.commonjava.indy.service.tracking.model.TrackingKey;
import org.commonjava.indy.service.tracking.model.dto.TrackedContentDTO;
import org.commonjava.indy.service.tracking.model.dto.TrackedContentEntryDTO;
Expand All @@ -49,6 +53,7 @@
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
Expand Down Expand Up @@ -156,29 +161,38 @@ public Response getReport(
@Path( "/{id}/record" )
@PUT
public Response initRecord(
@Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id,
@Context final UriInfo uriInfo )
@Parameter( description = "User-assigned tracking session key", in = PATH, required = true )
@PathParam( "id" ) final String id, @Context final UriInfo uriInfo )
{
Response.ResponseBuilder rb = Response.created( uriInfo.getRequestUri() );
return rb.build();
}

@Operation( description = "Store record for single tracking content artifact" )
@APIResponse( responseCode = "201", description = "Store tracking entry" )
@Path( "/report/recordArtifact" )
@PUT
public Response recordArtifact( final @Context UriInfo uriInfo, final @Context HttpServletRequest request )
@Operation( description = "Get record for single tracking content artifact" )
@APIResponse( responseCode = "200", description = "Tracking record" )
@APIResponse( responseCode = "404", description = "No such tracking record" )
@Path( "/{id}/artifactRecord/{path: (.*)}" )
@GET
public Response recordArtifact(
@Parameter( description = "User-assigned tracking session key", in = PATH, required = true )
@PathParam( "id" ) final String id, @PathParam( "path" ) String path,
@QueryParam( "packageType" ) String packageType, @QueryParam( "type" ) String type,
@QueryParam( "name" ) String name, @QueryParam( "originalUrl" ) String originalUrl,
@QueryParam( "size" ) long size, @QueryParam( "md5" ) String md5, @QueryParam( "sha1" ) String sha1,
@QueryParam( "sha256" ) String sha256, @Context final UriInfo uriInfo )
{
try
TrackedContentEntry contentEntry = new TrackedContentEntry( new TrackingKey( id ), new StoreKey( packageType,
StoreType.valueOf(
type ),
name ),
AccessChannel.NATIVE, originalUrl, path,
StoreEffect.DOWNLOAD, size, md5, sha1, sha256 );
Boolean result = controller.recordArtifact( contentEntry );
if ( result )
{
controller.recordArtifact( request.getInputStream() );
}
catch ( IOException e )
{
responseHelper.throwError( new IndyWorkflowException( "IO error", e ) );
return Response.ok().build();
}

return Response.created( uriInfo.getRequestUri() ).build();
return Response.status( Response.Status.NOT_FOUND ).build();
}

@Operation( description = "Seal the tracking record for the specified key, to prevent further content logging" )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void testRecalculateRecord()
@Test
void testRecordArtifact()
{
given().when().put( BASE_URL + "report/recordArtifact" ).then().statusCode( 403 );
given().when().get( BASE_URL + TRACKING_ID + "/artifactRecord/test/path/abc?type=group&packageType=maven&name=tea" ).then().statusCode( 200 );
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ void testRecalculateRecordNotFound()
@Test
void testRecordArtifact()
{
String trackingId = "tracking-id";
TrackedContentEntry entry = new TrackedContentEntry();
entry.setTrackingKey( new TrackingKey( "new-tracking-id" ) );
StoreKey storeKey = new StoreKey( PackageTypeConstants.PKG_TYPE_MAVEN, StoreType.remote, "test" );
Expand All @@ -153,7 +154,7 @@ void testRecordArtifact()
timestamps.add( 1234L );
entry.setTimestamps( timestamps );
entry.setPath( "/path/to/file" );
given().body( entry ).when().put( BASE_URL + "report/recordArtifact" ).then().statusCode( 201 );
given().body( entry ).when().get( BASE_URL + trackingId + "/artifactRecord/test/path/abc?type=group&packageType=maven&name=tea" ).then().statusCode( 200 );
}

@Test
Expand Down

0 comments on commit 6499d8c

Please sign in to comment.