From ff6a3bbec3b19397d707d0346949f959b2a1ed76 Mon Sep 17 00:00:00 2001
From: Nicola Fulvio Calabria <nicola.calabria@inaf.it>
Date: Wed, 13 Oct 2021 18:22:38 +0200
Subject: [PATCH] Removed job_id from external link generated endpoint

---
 .../java/it/inaf/oats/vospace/UriService.java | 21 +++++++++----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/main/java/it/inaf/oats/vospace/UriService.java b/src/main/java/it/inaf/oats/vospace/UriService.java
index 87557c9..171c49b 100644
--- a/src/main/java/it/inaf/oats/vospace/UriService.java
+++ b/src/main/java/it/inaf/oats/vospace/UriService.java
@@ -130,9 +130,9 @@ public class UriService {
                                 Protocol protocol = new Protocol();
                                 protocol.setUri(p.getUri());
                                 protocol.setEndpoint(endpoint);
-                                return protocol;                                
+                                return protocol;
                             } else {
-                                return null;                                
+                                return null;
                             }
                         }).filter(Objects::nonNull)
                         .collect(Collectors.toList());
@@ -224,6 +224,10 @@ public class UriService {
 
         if (isLinkNode) {
             endpoint = ((LinkNode) node).getTarget();
+            String linkTarget = ((LinkNode) node).getTarget();
+            if (linkedServiceDAO.isLinkedServiceUrl(linkTarget)) {
+                endpoint += "&token=" + getEndpointToken(linkTarget);
+            }
         } else {
 
             Location location = locationDAO.getNodeLocation(relativePath).orElse(null);
@@ -238,17 +242,12 @@ public class UriService {
             } else {
                 endpoint = fileServiceUrl + urlEncodePath(relativePath);
             }
-        }
 
-        endpoint += "?jobId=" + job.getJobId();
+            endpoint += "?jobId=" + job.getJobId();
 
-        if (isLinkNode) {
-            String linkTarget = ((LinkNode) node).getTarget();
-            if (linkedServiceDAO.isLinkedServiceUrl(linkTarget)) {
-                endpoint += "&token=" + getEndpointToken(linkTarget);
+            if (!"true".equals(NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI))) {
+                endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath);
             }
-        } else if (!"true".equals(NodeProperties.getNodePropertyByURI(node, NodeProperties.PUBLIC_READ_URI))) {
-            endpoint += "&token=" + getEndpointToken(fileServiceUrl + relativePath);
         }
 
         return endpoint;
@@ -364,7 +363,7 @@ public class UriService {
             return this.uri;
         }
 
-        public boolean isEndpointCompliant(String endpoint) {            
+        public boolean isEndpointCompliant(String endpoint) {
             return endpoint.toLowerCase()
                     .startsWith(this.protocolString + "://");
         }
-- 
GitLab