From 83c19e1e80795400661d4496c01928bd5a421d3f Mon Sep 17 00:00:00 2001
From: "Lange, Dr. Herbert" <herbert.lange@uni-hamburg.de>
Date: Tue, 28 Jun 2022 10:47:31 +0200
Subject: [PATCH] include token in temp report name

---
 .../de/uni_hamburg/corpora/server/CorpusChecker.java   | 10 +++++++---
 .../java/de/uni_hamburg/corpora/server/Report.java     |  6 ++++--
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java b/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java
index 43b2428..0722cb3 100644
--- a/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java
+++ b/src/main/java/de/uni_hamburg/corpora/server/CorpusChecker.java
@@ -61,8 +61,13 @@ class CorpusThread extends Thread {
             this.inFile = infile;
         this.functionNames = functions ;
         this.props = properties;
-        if (outfile.equals("tmp"))
-          this.outFile = this.inFile + "/report.html";
+        if (outfile.equals("tmp")) {
+            File tmpDir = new File(System.getProperty("java.io.tmpdir") + "/" + token);
+            // Create parent directory if it is missing
+            if (!tmpDir.exists())
+                tmpDir.mkdirs();
+            this.outFile = System.getProperty("java.io.tmpdir") + "/" + token + "/report.html";
+        }
         else
             this.outFile = outfile;
         this.token = token ;
@@ -77,7 +82,6 @@ class CorpusThread extends Thread {
         CorpusIO cio = new CorpusIO();
         report.addNote("CorpusWebServices","Starting run at " +
                 DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss").format(LocalDateTime.now()));
-
         try {
             // Create corpus from given input file/folder
             Corpus corpus;
diff --git a/src/main/java/de/uni_hamburg/corpora/server/Report.java b/src/main/java/de/uni_hamburg/corpora/server/Report.java
index eb3ab28..0cc445f 100644
--- a/src/main/java/de/uni_hamburg/corpora/server/Report.java
+++ b/src/main/java/de/uni_hamburg/corpora/server/Report.java
@@ -2,6 +2,7 @@ package de.uni_hamburg.corpora.server;
 
 import jakarta.ws.rs.GET;
 import jakarta.ws.rs.Path;
+import jakarta.ws.rs.QueryParam;
 import jakarta.ws.rs.core.Response;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -27,8 +28,9 @@ public class Report {
      * @return Response containing the file or an error code
      */
     @GET
-    public Response getReport() {
-        String reportFileName = System.getProperty("java.io.tmpdir") + "/corpus-files/report.html";
+    public Response getReport(@QueryParam("token") String token) {
+        // TODO place report somewhere else because files should be deleted after check
+        String reportFileName = System.getProperty("java.io.tmpdir") + "/" + token + "/report.html";
         logger.info("Loading report file " + reportFileName);
         File reportFile = new File(reportFileName);
         if (!reportFile.exists()) {
-- 
GitLab