• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Commonjava / indy-tracking-service / 44786446415

20 Nov 2026 05:46PM UTC coverage: 37.562% (-29.5%) from 67.036%
44786446415

push

github

rnc
Bump org.commonjava.atlas:atlas-relationships-api from 1.2.2 to 1.2.3

Bumps [org.commonjava.atlas:atlas-relationships-api](https://github.com/Commonjava/atlas) from 1.2.2 to 1.2.3.
- [Release notes](https://github.com/Commonjava/atlas/releases)
- [Commits](https://github.com/Commonjava/atlas/compare/atlas-parent-1.2.2...atlas-parent-1.2.3)

---
updated-dependencies:
- dependency-name: org.commonjava.atlas:atlas-relationships-api
  dependency-version: 1.2.3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

678 of 1805 relevant lines covered (37.56%)

0.75 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

75.24
/src/main/java/org/commonjava/indy/service/tracking/jaxrs/AdminResource.java
1
/**
2
 * Copyright (C) 2022-2023 Red Hat, Inc. (https://github.com/Commonjava/indy-tracking-service)
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *         http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package org.commonjava.indy.service.tracking.jaxrs;
17

18
import org.commonjava.indy.service.tracking.Constants;
19
import org.commonjava.indy.service.tracking.client.content.BatchDeleteRequest;
20
import org.commonjava.indy.service.tracking.client.content.MaintenanceService;
21
import org.commonjava.indy.service.tracking.config.IndyTrackingConfiguration;
22
import org.commonjava.indy.service.tracking.controller.AdminController;
23
import org.commonjava.indy.service.tracking.exception.ContentException;
24
import org.commonjava.indy.service.tracking.exception.IndyWorkflowException;
25
import org.commonjava.indy.service.tracking.model.AccessChannel;
26
import org.commonjava.indy.service.tracking.model.StoreEffect;
27
import org.commonjava.indy.service.tracking.model.StoreKey;
28
import org.commonjava.indy.service.tracking.model.StoreType;
29
import org.commonjava.indy.service.tracking.model.TrackedContentEntry;
30
import org.commonjava.indy.service.tracking.model.TrackingKey;
31
import org.commonjava.indy.service.tracking.model.dto.TrackedContentDTO;
32
import org.commonjava.indy.service.tracking.model.dto.TrackedContentEntryDTO;
33
import org.commonjava.indy.service.tracking.model.dto.TrackingIdsDTO;
34
import org.eclipse.microprofile.openapi.annotations.Operation;
35
import org.eclipse.microprofile.openapi.annotations.media.Content;
36
import org.eclipse.microprofile.openapi.annotations.media.Schema;
37
import org.eclipse.microprofile.openapi.annotations.parameters.Parameter;
38
import org.eclipse.microprofile.openapi.annotations.parameters.Parameters;
39
import org.eclipse.microprofile.openapi.annotations.parameters.RequestBody;
40
import org.eclipse.microprofile.openapi.annotations.responses.APIResponse;
41
import org.eclipse.microprofile.openapi.annotations.tags.Tag;
42
import org.eclipse.microprofile.rest.client.inject.RestClient;
43
import org.slf4j.Logger;
44
import org.slf4j.LoggerFactory;
45

46
import jakarta.enterprise.context.ApplicationScoped;
47
import jakarta.inject.Inject;
48
import jakarta.servlet.http.HttpServletRequest;
49
import jakarta.ws.rs.Consumes;
50
import jakarta.ws.rs.DELETE;
51
import jakarta.ws.rs.GET;
52
import jakarta.ws.rs.POST;
53
import jakarta.ws.rs.PUT;
54
import jakarta.ws.rs.Path;
55
import jakarta.ws.rs.PathParam;
56
import jakarta.ws.rs.Produces;
57
import jakarta.ws.rs.QueryParam;
58
import jakarta.ws.rs.core.Context;
59
import jakarta.ws.rs.core.Response;
60
import jakarta.ws.rs.core.UriInfo;
61
import java.io.File;
62
import java.io.IOException;
63
import java.util.HashSet;
64
import java.util.List;
65
import java.util.Set;
66
import java.util.concurrent.CompletableFuture;
67
import java.util.concurrent.Executor;
68

69
import static java.util.Collections.emptySet;
70
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON;
71
import static org.commonjava.indy.service.tracking.Constants.ALL;
72
import static org.commonjava.indy.service.tracking.Constants.LEGACY;
73
import static org.commonjava.indy.service.tracking.Constants.TRACKING_TYPE.IN_PROGRESS;
74
import static org.commonjava.indy.service.tracking.Constants.TRACKING_TYPE.SEALED;
75
import static org.eclipse.microprofile.openapi.annotations.enums.ParameterIn.PATH;
76
import static org.eclipse.microprofile.openapi.annotations.enums.ParameterIn.QUERY;
77

78
@Tag( name = "Tracking Record Access", description = "Manages tracking records." )
79
@Path( "/api/folo/admin" )
80
@ApplicationScoped
81
public class AdminResource
82
{
83
    public static final String MEDIATYPE_APPLICATION_ZIP = "application/zip";
84

85
    private final Logger logger = LoggerFactory.getLogger( getClass() );
2 ✔
86

87
    @Inject
88
    @RestClient
89
    MaintenanceService maintenanceService;
90

91
    @Inject
92
    private AdminController controller;
93

94
    @Inject
95
    private ResponseHelper responseHelper;
96

97
    @Inject
98
    private IndyTrackingConfiguration config;
99

100
    // Inject a managed Executor for running async post-actions without blocking the main thread
101
    @Inject
102
    Executor executor;
103

104
    public AdminResource()
105
    {
2 ✔
106
    }
2 ✔
107

108
    @Operation( description = "Recalculate sizes and checksums for every file listed in a tracking record." )
109
    @APIResponse( responseCode = "200", description = "Recalculated tracking report" )
110
    @APIResponse( responseCode = "404", description = "No such tracking record found" )
111
    @Path( "/{id}/record/recalculate" )
112
    @GET
113
    public Response recalculateRecord(
114
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id,
115
                    @Context final UriInfo uriInfo )
116
    {
117
        Response response;
118
        try
119
        {
120
            final String baseUrl = config.contentServiceURL();
2 ✔
121
            final TrackedContentDTO report = controller.recalculateRecord( id, baseUrl );
2 ✔
122

123
            if ( report == null )
2 ✔
124
            {
125
                response = Response.status( Response.Status.NOT_FOUND ).build();
2 ✔
126
            }
127
            else
128
            {
129
                response = responseHelper.formatOkResponseWithJsonEntity( report );
2 ✔
130
            }
131
        }
132
        catch ( final IndyWorkflowException e )
×
133
        {
134
            logger.error( String.format( "Failed to serialize tracking report for: %s. Reason: %s", id,
×
135
                                         e.getMessage() ), e );
×
136

137
            response = responseHelper.formatResponse( e );
×
138
        }
2 ✔
139

140
        return response;
2 ✔
141
    }
142

143
    @Operation( description = "Retrieve the content referenced in a tracking record as a ZIP-compressed Maven repository directory." )
144
    @APIResponse( responseCode = "200", content = @Content( schema = @Schema( implementation = File.class ) ), description = "ZIP repository content" )
145
    @APIResponse( responseCode = "404", description = "No such tracking record" )
146
    @Path( "/{id}/record/zip" )
147
    @GET
148
    @Produces( MEDIATYPE_APPLICATION_ZIP )
149
    public File getZipRepository(
150
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id )
151
    {
152
        return controller.getZipRepository( id );
2 ✔
153
    }
154

155
    @Operation( description = "Alias of /{id}/record, returns the tracking record for the specified key" )
156
    @APIResponse( responseCode = "200", description = "Tracking record" )
157
    @APIResponse( responseCode = "404", description = "No such tracking record" )
158
    @Path( "/{id}/report" )
159
    @GET
160
    public Response getReport(
161
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id,
162
                    @Context final UriInfo uriInfo )
163
    {
164
        return getRecord( id, uriInfo );
×
165
    }
166

167
    @Operation( description = "Explicitly setup a new tracking record for the specified key, to prevent 404 if the record is never used." )
168
    @APIResponse( responseCode = "201", description = "Tracking record was created" )
169
    @Path( "/{id}/record" )
170
    @PUT
171
    public Response initRecord(
172
            @Parameter( description = "User-assigned tracking session key", in = PATH, required = true )
173
            @PathParam( "id" ) final String id, @Context final UriInfo uriInfo )
174
    {
175
        Response.ResponseBuilder rb = Response.created( uriInfo.getRequestUri() );
×
176
        return rb.build();
×
177
    }
178

179
    @Operation( description = "Get record for single tracking content artifact" )
180
    @Parameters( value = {
181
            @Parameter( name = "packageType", in = QUERY, description = "The package type of the repository.",
182
                        example = "maven, npm, generic-http", required = true ),
183
            @Parameter( name = "type", in = QUERY, description = "The type of the repository.",
184
                        example = "group, remote, hosted", required = true ) } )
185
    @APIResponse( responseCode = "200", description = "Tracking record" )
186
    @APIResponse( responseCode = "404", description = "No such tracking record" )
187
    @Path( "/{id}/artifactRecord/{path: (.*)}" )
188
    @GET
189
    public Response recordArtifact( @Parameter( in = PATH, required = true ) @PathParam( "id" ) final String id,
190
                                    @Parameter( in = PATH, required = true ) @PathParam( "path" ) String path,
191
                                    @Parameter( in = QUERY, required = true ) @QueryParam( "packageType" )
192
                                    String packageType,
193
                                    @Parameter( in = QUERY, required = true ) @QueryParam( "type" ) String type,
194
                                    @Parameter( in = QUERY, required = true ) @QueryParam( "name" ) String name,
195
                                    @QueryParam( "originalUrl" ) String originalUrl, @QueryParam( "size" ) long size,
196
                                    @QueryParam( "md5" ) String md5, @QueryParam( "sha1" ) String sha1,
197
                                    @QueryParam( "sha256" ) String sha256, @Context final UriInfo uriInfo )
198
    {
199
        final StoreType st = StoreType.get( type );
2 ✔
200
        if ( null == packageType || null == type || null == st )
2 ✔
201
        {
202
            logger.error( "Unsupported package type: {} or unsupported repo type: {} for path: {}, tracking id: {}.",
×
203
                          packageType, type, path, id );
204
            return Response.status( Response.Status.NOT_FOUND ).build();
×
205
        }
206
        TrackedContentEntry contentEntry =
2 ✔
207
                new TrackedContentEntry( new TrackingKey( id ), new StoreKey( packageType, st, name ),
208
                                         AccessChannel.NATIVE, originalUrl, path, StoreEffect.DOWNLOAD, size, md5, sha1,
2 ✔
209
                                         sha256 );
210
        Boolean result = controller.recordArtifact( contentEntry );
×
211
        if ( result )
×
212
        {
213
            logger.info( "Entry record done, path: {}, id: {}.", path, id );
×
214
            return Response.ok().build();
×
215
        }
216
        return Response.status( Response.Status.NOT_FOUND ).build();
×
217
    }
218

219
    @Operation( description = "Seal the tracking record for the specified key, to prevent further content logging" )
220
    @APIResponse( responseCode = "200", description = "Tracking record" )
221
    @APIResponse( responseCode = "404", description = "No such tracking record" )
222
    @Path( "/{id}/record" )
223
    @POST
224
    public Response sealRecord(
225
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id,
226
                    @Context final UriInfo uriInfo )
227
    {
228
        final String baseUrl = config.contentServiceURL();
2 ✔
229
        TrackedContentDTO record = controller.seal( id, baseUrl );
2 ✔
230
        if ( record == null )
2 ✔
231
        {
232
            return Response.status( Response.Status.NOT_FOUND ).build();
×
233
        }
234
        else
235
        {
236
            return Response.ok().build();
2 ✔
237
        }
238
    }
239

240
    @Operation( description = "Alias of /{id}/record, returns the tracking record for the specified key" )
241
    @APIResponse( responseCode = "200", description = "Tracking record" )
242
    @APIResponse( responseCode = "404", description = "No such tracking record" )
243
    @Path( "/{id}/record" )
244
    @GET
245
    public Response getRecord(
246
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id,
247
                    @Context final UriInfo uriInfo )
248
    {
249
        Response response;
250
        try
251
        {
252
            final String baseUrl = config.contentServiceURL();
2 ✔
253
            TrackedContentDTO record = controller.getRecord( id, baseUrl );
2 ✔
254
            if ( record == null )
2 ✔
255
            {
256
                record = controller.getLegacyRecord( id, baseUrl ); // Try legacy record
2 ✔
257
            }
258
            if ( record == null )
2 ✔
259
            {
260
                // if not found, return an empty report
261
                record = new TrackedContentDTO( new TrackingKey( id ), emptySet(), emptySet() );
×
262
            }
263
            response = responseHelper.formatOkResponseWithJsonEntity( record );
2 ✔
264
        }
265
        catch ( final IndyWorkflowException e )
2 ✔
266
        {
267
            logger.error( String.format( "Failed to retrieve tracking report for: %s. Reason: %s", id, e.getMessage() ),
2 ✔
268
                          e );
269

270
            response = responseHelper.formatResponse( e );
2 ✔
271
        }
2 ✔
272

273
        return response;
2 ✔
274
    }
275

276
    @Operation( description = "Delete the tracking record for the specified key" )
277
    @Path( "/{id}/record" )
278
    @DELETE
279
    public Response clearRecord(
280
                    @Parameter( description = "User-assigned tracking session key", in = PATH, required = true ) @PathParam( "id" ) final String id )
281
    {
282
        Response response;
283
        try
284
        {
285
            controller.clearRecord( id );
2 ✔
286
            response = Response.status( Response.Status.NO_CONTENT ).build();
2 ✔
287
        }
288
        catch ( ContentException e )
2 ✔
289
        {
290
            response = responseHelper.formatResponse( e );
2 ✔
291
        }
2 ✔
292

293
        return response;
2 ✔
294
    }
295

296
    @Operation( description = "Retrieve tracking ids for records of given type." )
297
    @APIResponse( responseCode = "200", content = @Content( schema = @Schema( implementation = List.class ) ), description = "tracking ids with sealed or in_progress" )
298
    @APIResponse( responseCode = "404", description = "No ids found for type" )
299
    @Path( "/report/ids/{type}" )
300
    @GET
301
    public Response getRecordIds(
302
                    @Parameter( description = "Report type, should be in_progress|sealed|all|legacy", in = PATH, required = true ) @PathParam( "type" ) final String type )
303
    {
304
        Response response;
305
        TrackingIdsDTO ids;
306
        if ( LEGACY.equals( type ) )
2 ✔
307
        {
308
            ids = controller.getLegacyTrackingIds();
2 ✔
309
        }
310
        else
311
        {
312
            Set<Constants.TRACKING_TYPE> types = getRequiredTypes( type );
2 ✔
313
            ids = controller.getTrackingIds( types );
2 ✔
314
        }
315
        if ( ids != null )
2 ✔
316
        {
317
            response = responseHelper.formatOkResponseWithJsonEntity( ids );
2 ✔
318
        }
319
        else
320
        {
321
            response = Response.status( Response.Status.NOT_FOUND ).build();
2 ✔
322
        }
323

324
        return response;
2 ✔
325
    }
326

327
    private Set<Constants.TRACKING_TYPE> getRequiredTypes( String type )
328
    {
329
        Set<Constants.TRACKING_TYPE> types = new HashSet<>();
2 ✔
330

331
        if ( IN_PROGRESS.getValue().equals( type ) || ALL.equals( type ) )
2 ✔
332
        {
333
            types.add( IN_PROGRESS );
×
334
        }
335
        if ( SEALED.getValue().equals( type ) || ALL.equals( type ) )
2 ✔
336
        {
337
            types.add( SEALED );
2 ✔
338
        }
339
        return types;
2 ✔
340
    }
341

342
    @Operation( description = "Export the records as a ZIP file." )
343
    @APIResponse( responseCode = "200", description = "ZIP content" )
344
    @Path( "/report/export" )
345
    @GET
346
    @Produces( MEDIATYPE_APPLICATION_ZIP )
347
    public File exportReport()
348
    {
349
        try
350
        {
351
            return controller.renderReportZip();
2 ✔
352
        }
353
        catch ( IndyWorkflowException e )
2 ✔
354
        {
355
            responseHelper.throwError( e );
×
356
        }
357

358
        return null;
×
359
    }
360

361
    @Operation( description = "Import records from a ZIP file." )
362
    @APIResponse( responseCode = "201", description = "Import ZIP content" )
363
    @Path( "/report/import" )
364
    @PUT
365
    public Response importReport( final @Context UriInfo uriInfo, final @Context HttpServletRequest request )
366
    {
367
        try
368
        {
369
            controller.importRecordZip( request.getInputStream() );
2 ✔
370
        }
371
        catch ( IndyWorkflowException e )
2 ✔
372
        {
373
            responseHelper.throwError( e );
×
374
        }
375
        catch ( IOException e )
×
376
        {
377
            responseHelper.throwError( new IndyWorkflowException( "IO error", e ) );
×
378
        }
2 ✔
379

380
        return Response.created( uriInfo.getRequestUri() ).build();
2 ✔
381
    }
382

383
    @Operation( description = "Batch delete files uploaded through FOLO trackingID under the given storeKey." )
384
    @APIResponse( responseCode = "200", description = "Batch delete operation finished." )
385
    @RequestBody( description = "JSON object, specifying trackingID and storeKey, with other configuration options", name = "body", required = true )
386
    @Path( "/batch/delete" )
387
    @POST
388
    @Consumes( APPLICATION_JSON )
389
    @Produces( APPLICATION_JSON )
390
    public Response doDelete( @Context final UriInfo uriInfo, final BatchDeleteRequest request )
391
    {
392
        logger.info( "Batch delete request: {}", request );
2 ✔
393
        String trackingID = request.getTrackingID();
2 ✔
394

395
        if ( trackingID == null || request.getStoreKey() == null )
2 ✔
396
        {
397
            Response.ResponseBuilder builder = Response.status( 400 );
2 ✔
398
            return builder.build();
2 ✔
399
        }
400

401
        if ( !controller.deletionAdditionalGuardCheck(request) )
2 ✔
402
        {
403
            Response.ResponseBuilder builder = Response.status( 400 );
×
404
            return builder.build();
×
405
        }
406

407
        if ( request.getPaths() == null || request.getPaths().isEmpty() )
2 ✔
408
        {
409
            final String baseUrl = config.contentServiceURL();
2 ✔
410
            try
411
            {
412
                final TrackedContentDTO record = controller.getRecord( trackingID, baseUrl );
2 ✔
413
                if ( record == null || record.getUploads().isEmpty() )
2 ✔
414
                {
415
                    Response.ResponseBuilder builder = Response.status( 400 );
2 ✔
416
                    return builder.build();
2 ✔
417
                }
418

419
                Set<String> paths = new HashSet<>();
2 ✔
420
                for ( TrackedContentEntryDTO entry : record.getUploads() )
2 ✔
421
                {
422
                    paths.add( entry.getPath() );
2 ✔
423
                }
2 ✔
424
                logger.info( "Set batch delete paths: {}", paths );
2 ✔
425
                request.setPaths( paths );
2 ✔
426
            }
427
            catch ( IndyWorkflowException e )
×
428
            {
429
                responseHelper.throwError( e );
×
430
            }
2 ✔
431
        }
432

433
        Response response = maintenanceService.doDelete( request );
2 ✔
434
        if (response.getStatus() == Response.Status.OK.getStatusCode()) {
2 ✔
435
            // Run the cleanupEmptyFolder post-action asynchronously
436
            CompletableFuture.runAsync(() -> controller.cleanupEmptyFolders( request.getTrackingID(),
2 ✔
437
                request.getStoreKey().toString(), request.getPaths()), executor);
2 ✔
438
        }
439
        return response;
2 ✔
440
    }
441
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc