4545import org .slf4j .LoggerFactory ;
4646
4747import java .io .File ;
48+ import java .io .FileOutputStream ;
4849import java .io .IOException ;
4950import java .io .InputStream ;
51+ import java .time .LocalDateTime ;
52+ import java .time .format .DateTimeFormatter ;
5053import java .util .Optional ;
54+ import java .util .zip .ZipEntry ;
55+ import java .util .zip .ZipOutputStream ;
5156
5257import static jakarta .ws .rs .core .MediaType .APPLICATION_JSON ;
5358import static jakarta .ws .rs .core .MediaType .APPLICATION_OCTET_STREAM ;
@@ -213,7 +218,7 @@ public Uni<Response> deleteWithChecksum( final @PathParam( "buildConfigId" ) Str
213218 @ APIResponse ( responseCode = "204" , description = "The workplace cleanup is finished" )
214219 @ Path ( "cleanup" )
215220 @ DELETE
216- public Uni <Response > delete ( final @ Context UriInfo uriInfo )
221+ public Uni <Response > cleanup ( final @ Context UriInfo uriInfo )
217222 {
218223 try
219224 {
@@ -227,4 +232,41 @@ public Uni<Response> delete( final @Context UriInfo uriInfo )
227232 }
228233 return Uni .createFrom ().item ( noContent ().build () );
229234 }
235+
236+ @ Operation ( description = "Create a test archive with timestamp suffix for testing purposes" )
237+ @ APIResponse ( responseCode = "200" , description = "Test archive created successfully" )
238+ @ APIResponse ( responseCode = "500" , description = "Failed to create test archive - directory may not be writable" )
239+ @ POST
240+ @ Path ( "test" )
241+ @ Produces ( APPLICATION_JSON )
242+ public Uni <Response > createTestArchive ( final @ Context UriInfo uriInfo )
243+ {
244+ try
245+ {
246+ String timestamp = LocalDateTime .now ().format ( DateTimeFormatter .ofPattern ( "yyyyMMdd-HHmmss" ) );
247+ String testArchiveName = "test-archive-" + timestamp ;
248+
249+ File archiveFile = controller .createTestArchive ( testArchiveName );
250+
251+ String message = String .format ( "Test archive created successfully: %s.zip" , testArchiveName );
252+ logger .info ( message );
253+
254+ return Uni .createFrom ().item ( Response .ok ()
255+ .type ( MediaType .APPLICATION_JSON )
256+ .entity ( String .format ( "{\" message\" :\" %s\" ,\" archiveName\" :\" %s.zip\" }" ,
257+ message , testArchiveName ) )
258+ .build () );
259+ }
260+ catch ( final IOException e )
261+ {
262+ final String message = "Failed to create test archive: " + e .getMessage ();
263+ logger .error ( message , e );
264+ return Uni .createFrom ().item ( Response .status ( Response .Status .INTERNAL_SERVER_ERROR )
265+ .type ( MediaType .APPLICATION_JSON )
266+ .entity ( String .format ( "{\" error\" :\" %s\" ,\" exceptionType\" :\" %s\" }" ,
267+ message .replace ("\" " , "\\ \" " ),
268+ e .getClass ().getSimpleName () ) )
269+ .build () );
270+ }
271+ }
230272}
0 commit comments