From 4801483131c142e9412f0d0072365dd886a6976f Mon Sep 17 00:00:00 2001 From: "sergey.smirnov" Date: Tue, 14 May 2019 13:17:34 +0400 Subject: [PATCH] [RM] Feature #55360. Add functionality to drop ml dump after download (cherry picked from commit dbe3f0c11c901d4d254a506093c88db7e00b0e43) Change-Id: I22138b3f2c8418a0d7429c97052b795545e24b41 --- .../sf/testwebgui/restapi/MachineLearningResource.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/restapi/MachineLearningResource.java b/FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/restapi/MachineLearningResource.java index 6ebd6333..a59cb1f6 100644 --- a/FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/restapi/MachineLearningResource.java +++ b/FrontEnd/SailfishFrontEnd/src/main/java/com/exactpro/sf/testwebgui/restapi/MachineLearningResource.java @@ -15,6 +15,7 @@ ******************************************************************************/ package com.exactpro.sf.testwebgui.restapi; +import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -37,6 +38,7 @@ import javax.ws.rs.core.Response.Status; import javax.ws.rs.core.StreamingOutput; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -132,7 +134,7 @@ public Response predictTrainingData(InputStream requestBody) { @GET @Produces(MediaType.APPLICATION_OCTET_STREAM) @Path("get_dump") - public Response getDump(@DefaultValue("4") @QueryParam("compression_lvl") int compression) { + public Response getDump(@DefaultValue("4") @QueryParam("compression_lvl") int compression, @DefaultValue("false") @QueryParam("remove") boolean remove) { MachineLearningService mlService = getMachineLearningService(); @@ -140,6 +142,11 @@ public Response getDump(@DefaultValue("4") @QueryParam("compression_lvl") int co try (OutputStream os = outputStream) { mlService.getStorage().zipDocumentsToStream(os, compression); + if (remove) { + for (File doc : mlService.getStorage().getDocuments()) { + FileUtils.deleteQuietly(doc); + } + } } };