From 244816c657f7a6dd176bc8885593a06b8af23c95 Mon Sep 17 00:00:00 2001
From: Robert Butora <robert.butora@inaf.it>
Date: Mon, 29 Apr 2024 11:21:34 +0200
Subject: [PATCH] removes DataLink from ServletMerge response-serialization
 (uses CutResult instead)

---
 .../src/main/java/webapi/ServletCutout.java   |  8 ----
 .../src/main/java/webapi/ServletMerge.java    | 46 ++++++++++++++-----
 .../src/main/java/webapi/UWSMergeWork.java    | 35 ++++++++++++--
 .../src/main/java/webapi/UWSSodaWork.java     | 25 ++++++----
 4 files changed, 81 insertions(+), 33 deletions(-)

diff --git a/data-access/servlet/src/main/java/webapi/ServletCutout.java b/data-access/servlet/src/main/java/webapi/ServletCutout.java
index 74fff09..8747ce9 100644
--- a/data-access/servlet/src/main/java/webapi/ServletCutout.java
+++ b/data-access/servlet/src/main/java/webapi/ServletCutout.java
@@ -128,7 +128,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
 
 
 
-   //protected DataLink doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
    protected CutResult doCutoutFile(String id, Pos pos, Band band, Time time, Pol pol, String pixels,
          boolean countNullValues, String respFormat)
          throws IOException, InterruptedException
@@ -174,8 +173,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
 
       CutResult cutResult = cutout.doFile(relPathname, hdunum, pos, band, time, pol, pixels, false, null);
 
-      //DataLink dlk = new DataLink(settings, cutResult, id, pos, band, time, pol, countNullValues);
-
       return cutResult;
    }
 
@@ -286,8 +283,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
                boolean  countNullValues = vlkbReq_getNullValues(request);
                response.setContentType(respFormat);
 
-//               DataLink respDataLink = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues,
-//                     respFormat);
                CutResult cutResult = doCutoutFile(id, pos, band, time, pol, pixels, countNullValues,
                      respFormat);
 
@@ -296,9 +291,6 @@ public class ServletCutout extends javax.servlet.http.HttpServlet
 
                PrintWriter writer =new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING));
 
-//               XmlSerializer.serializeToLegacyCutResults(writer,
-//                     respEncoding, respDataLink, showDuration, startTime_msec);
-
                String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName,
                      settings.fitsPaths.cutouts(),
                      settings.fitsPaths.cutoutsUrl());
diff --git a/data-access/servlet/src/main/java/webapi/ServletMerge.java b/data-access/servlet/src/main/java/webapi/ServletMerge.java
index 7fce57f..2b34a4e 100644
--- a/data-access/servlet/src/main/java/webapi/ServletMerge.java
+++ b/data-access/servlet/src/main/java/webapi/ServletMerge.java
@@ -118,6 +118,7 @@ public class ServletMerge extends javax.servlet.http.HttpServlet
             Band   band = null;
             Time   time = null;
             Pol    pol  = null;
+            String pixels = null;
 
 
 
@@ -135,8 +136,6 @@ public class ServletMerge extends javax.servlet.http.HttpServlet
 
             CutResult cutResult = datasets.doMerge(parseLegacyPubdidArr(id), coord, countNullValues);
 
-            DataLink dlk = new DataLink(cutResult);
-
             String contentType = respContentType;
             String respEncoding = RESPONSE_ENCODING;
 
@@ -144,14 +143,24 @@ public class ServletMerge extends javax.servlet.http.HttpServlet
             {
                LOGGER.info("writing xml");
                PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, respEncoding));
-               XmlSerializer.serializeToLegacyCutResults(writer, respEncoding, dlk, showDuration, startTime_msec);
+
+               String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName,
+                     settings.fitsPaths.cutouts(),
+                     settings.fitsPaths.cutoutsUrl());
+
+               XmlSerializer.serializeToLegacyCutResult(writer, RESPONSE_ENCODING,
+                     cutResult, accessUrl,
+                     id, pos, band, time, pol, pixels, countNullValues,
+                     showDuration, startTime_msec);
+
                writer.close();
             }
             else if(contentType.equals("application/fits"))
             {
                LOGGER.info("streaming the file");
 
-               File downloadFile = new File(dlk.absCutPathname);
+               String absCutPathname = cutResult.fileName;
+               File downloadFile = new File(absCutPathname);
                FileInputStream input = new FileInputStream(downloadFile);
 
                input.transferTo(respOutputStream);
@@ -190,18 +199,18 @@ public class ServletMerge extends javax.servlet.http.HttpServlet
          LOGGER.info("processRequest normal exit");
       }
 
-/*
-   private Map<SodaParam, String[]> collectSodaParams(HttpServletRequest req)
-   {
+   /*
+      private Map<SodaParam, String[]> collectSodaParams(HttpServletRequest req)
+      {
       Map<SodaParam, String[]> params = new HashMap<SodaParam, String[]>();
       for(SodaParam paramToken : SodaParam.values())
       {
-         String[] paramValue = req.getParameterValues(paramToken.toString());
-         params.put(paramToken, paramValue);
+      String[] paramValue = req.getParameterValues(paramToken.toString());
+      params.put(paramToken, paramValue);
       }
       return params;
-   }
-*/
+      }
+      */
 
    /* semi-colon separated list of pudids convert to arra */
    private String[] parseLegacyPubdidArr(String pubdids)
@@ -217,5 +226,20 @@ public class ServletMerge extends javax.servlet.http.HttpServlet
    }   
 
 
+
+      private String convertLocalPathnameToRemoteUrl(String localPathname,
+         String FITScutpath, String FITSRemoteUrlCutouts)
+   {
+      LOGGER.info("trace " + localPathname);
+      String fileName = localPathname.replaceAll(FITScutpath + "/", "");
+      LOGGER.info("local filename: " + fileName);
+      String remotefname = FITSRemoteUrlCutouts + "/" + fileName;
+      LOGGER.info("remote url    : " + remotefname);
+      return remotefname;
+   }
+
+
+
+
 }
 
diff --git a/data-access/servlet/src/main/java/webapi/UWSMergeWork.java b/data-access/servlet/src/main/java/webapi/UWSMergeWork.java
index 3e1ab78..a6e75ce 100644
--- a/data-access/servlet/src/main/java/webapi/UWSMergeWork.java
+++ b/data-access/servlet/src/main/java/webapi/UWSMergeWork.java
@@ -64,6 +64,7 @@ public class UWSMergeWork extends JobThread
          Band   band = null;
          Time   time = null;
          Pol    pol  = null;
+         String pixels = null;
 
          if(parser.sodaReq_hasSodaId())
          {
@@ -80,10 +81,9 @@ public class UWSMergeWork extends JobThread
             band = parser.vlkbReq_getVelocity();
          }
 
-         Coord coord = new Coord(DEFAULT_SKY_SYSTEM, pos, DEFAULT_SPEC_SYSTEM, band, time, pol);
+         Coord coord = new Coord(pos, band, time, pol);
 
          CutResult cutResult  = datasets.doMerge(parseLegacyPubdidArr(id), coord, false);//countNullValues);
-         DataLink dlk = new DataLink(cutResult);
 
          final String respFormat = "text/xml";// FIXME read from param RESPONSEFORMAT ?
 
@@ -97,12 +97,22 @@ public class UWSMergeWork extends JobThread
          if(contentType.equals("text/xml") || contentType.equals("application/xml"))
          {
             PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, respEncoding));
-            XmlSerializer.serializeToLegacyCutResults(writer, respEncoding, dlk, showDuration, startTime_msec);
+
+            String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName,
+                  settings.fitsPaths.cutouts(),
+                  settings.fitsPaths.cutoutsUrl());
+
+            XmlSerializer.serializeToLegacyCutResult(writer, RESPONSE_ENCODING,
+                  cutResult, accessUrl,
+                  id, pos, band, time, pol, pixels, false,//countNullValues,
+                  showDuration, startTime_msec);
+
             writer.close();
          }
          else if(contentType.equals("application/fits"))
          {
-            File downloadFile = new File(dlk.absCutPathname);
+            String absCutPathname = cutResult.fileName;
+            File downloadFile = new File(absCutPathname);
             FileInputStream input = new FileInputStream(downloadFile);
             input.transferTo(respOutputStream);
             downloadFile.delete();
@@ -130,6 +140,23 @@ public class UWSMergeWork extends JobThread
    }
 
 
+
+
+
+   private String convertLocalPathnameToRemoteUrl(String localPathname,
+         String FITScutpath, String FITSRemoteUrlCutouts)
+   {
+      LOGGER.info("trace " + localPathname);
+      String fileName = localPathname.replaceAll(FITScutpath + "/", "");
+      LOGGER.info("local filename: " + fileName);
+      String remotefname = FITSRemoteUrlCutouts + "/" + fileName;
+      LOGGER.info("remote url    : " + remotefname);
+      return remotefname;
+   }
+
+
+
+
    /* semi-colon separated list of pudids convert to arra */
    private String[] parseLegacyPubdidArr(String pubdids)
    {
diff --git a/data-access/servlet/src/main/java/webapi/UWSSodaWork.java b/data-access/servlet/src/main/java/webapi/UWSSodaWork.java
index 5ac6b0a..cc6c31a 100644
--- a/data-access/servlet/src/main/java/webapi/UWSSodaWork.java
+++ b/data-access/servlet/src/main/java/webapi/UWSSodaWork.java
@@ -46,8 +46,6 @@ public class UWSSodaWork extends JobThread
    @Override
    protected void jobWork() throws UWSException, InterruptedException
    {
-      // result.setSize(size); // FIXME how to add this? not set in ServeltCutout either (only inside DataLink)
-
       long startTime_msec = System.currentTimeMillis();
       boolean showDuration = true;
 
@@ -105,10 +103,6 @@ public class UWSSodaWork extends JobThread
 
          CutResult cutResult = datasets.doCutoutFile(rsl.relPathname, rsl.hdunum, pos, band, time, pol, false, null);
 
-//         DataLink respDataLink = new DataLink(cutResult);
-
-//         respDataLink.inputs = new Inputs(id, coord, false);//countNullValues);
-
          /* send Results */
 
          Result result = createResult("cutout");
@@ -119,8 +113,6 @@ public class UWSSodaWork extends JobThread
          {
             PrintWriter writer = new PrintWriter(new OutputStreamWriter(respOutputStream, RESPONSE_ENCODING));
 
-            // XmlSerializer.serializeToLegacyCutResults(writer, RESPONSE_ENCODING, respDataLink, showDuration, startTime_msec);
-
             String accessUrl = convertLocalPathnameToRemoteUrl(cutResult.fileName,
                   settings.fitsPaths.cutouts(),
                   settings.fitsPaths.cutoutsUrl());
@@ -130,13 +122,12 @@ public class UWSSodaWork extends JobThread
                   id, pos, band, time, pol, null, false,
                   showDuration, startTime_msec);
 
-
                writer.close();
          }
          else if(respContentType.equals("application/fits"))
          {
             String absCutPathname = cutResult.fileName;
-            File downloadFile = new File(/*respDataLink.*/absCutPathname);
+            File downloadFile = new File(absCutPathname);
             FileInputStream input = new FileInputStream(downloadFile);
 
             input.transferTo(respOutputStream);
@@ -164,6 +155,20 @@ public class UWSSodaWork extends JobThread
    }
 
 
+   private String convertLocalPathnameToRemoteUrl(String localPathname,
+         String FITScutpath, String FITSRemoteUrlCutouts)
+   {
+      LOGGER.info("trace " + localPathname);
+      String fileName = localPathname.replaceAll(FITScutpath + "/", "");
+      LOGGER.info("local filename: " + fileName);
+      String remotefname = FITSRemoteUrlCutouts + "/" + fileName;
+      LOGGER.info("remote url    : " + remotefname);
+      return remotefname;
+   }
+
+
+
+
    /* see UWSParameters::getAdditionalParameter -> UWSParameters.java.l465: ...returned value maybe an array... */
    /* Object getAdditionalParameterValue(String paramName) --> calls UWSParameters::getAdditionalParameters()   */
    private Map<SodaParam, String[]> collectSodaParams(UWSJob job)
-- 
GitLab