From c7f523d64c6548ee4a781aaae09807fe15ea613b Mon Sep 17 00:00:00 2001
From: vkovtun <viktor.kovtun@id.ethz.ch>
Date: Mon, 17 Jun 2024 14:32:25 +0200
Subject: [PATCH] BIS-1390: Made the error that
 server-public-information.afs-server.url is not set appear only when this
 parameter is needed.

---
 api-openbis-javascript/src/v3/openbis.js |  4 ++
 ui-admin/src/js/services/openbis/api.js  | 57 +++++++++++++++---------
 2 files changed, 41 insertions(+), 20 deletions(-)

diff --git a/api-openbis-javascript/src/v3/openbis.js b/api-openbis-javascript/src/v3/openbis.js
index f311a65ff8c..03da29d5977 100644
--- a/api-openbis-javascript/src/v3/openbis.js
+++ b/api-openbis-javascript/src/v3/openbis.js
@@ -664,6 +664,10 @@ define([ 'jquery', 'util/Json', 'as/dto/datastore/search/DataStoreSearchCriteria
             thisFacade._private.sessionToken = sessionToken
         }
 
+		this.getAfsUrl = function() {
+			return this._private.afsUrl;
+		}
+
 		this.login = function(user, password) {
 			var thisFacade = this;
 			thisFacade._private.checkTransactionDoesNotExist();
diff --git a/ui-admin/src/js/services/openbis/api.js b/ui-admin/src/js/services/openbis/api.js
index 40bd2e7e6cc..b0bd075f576 100644
--- a/ui-admin/src/js/services/openbis/api.js
+++ b/ui-admin/src/js/services/openbis/api.js
@@ -13,21 +13,18 @@ class Facade {
       requirejs(
         ['openbis', 'util/Json'],
         (openbis, stjs) => {
-          new openbis().getServerPublicInformation()
-            .then(result => {
+          new openbis().getServerPublicInformation().then(
+            result => {
               const afsServerUrlKey = 'server-public-information.afs-server.url'
               const afsServerUrl = result[afsServerUrlKey]
-              if (afsServerUrl) {
-                _this.v3 = new openbis(null, afsServerUrl)
-                _this.stjs = stjs
-                resolve()
-              } else {
-                reject(new Error(afsServerUrlKey + ' is not set.'))
-              }
+              _this.v3 = new openbis(null, afsServerUrl)
+              _this.stjs = stjs
+              resolve()
             },
             error => {
               reject(error)
-            })
+            }
+          )
         },
         error => {
           reject(error)
@@ -36,6 +33,14 @@ class Facade {
     })
   }
 
+  _getAfsServerFacade() {
+    if (!this.v3.getAfsUrl()) {
+      throw new Error('server-public-information.afs-server.url is not set.')
+    } else {
+      return this.v3.getAfsServerFacade();
+    }
+  }
+
   useSession(sessionToken) {
     this.v3._private.sessionToken = sessionToken
   }
@@ -257,43 +262,55 @@ class Facade {
   }
 
   executeCustomDSSService(serviceId, options) {
-    return this.promise(this.v3.getDataStoreFacade().executeCustomDSSService(serviceId, options));
+    return this.promise(this.v3.getDataStoreFacade().executeCustomDSSService(serviceId, options))
   }
 
   fromJson(jsonType, jsonObject) {
-    return this.promise(this.stjs.fromJson(jsonType, jsonObject));
+    return this.promise(this.stjs.fromJson(jsonType, jsonObject))
   }
 
   list(owner, source, recursively) {
-    return this.promise(this.v3.getAfsServerFacade().list(owner, source, recursively))
+    return this.promise(
+      this._getAfsServerFacade().list(owner, source, recursively)
+    )
   }
 
   read(owner, source, offset, limit) {
-    return this.promise(this.v3.getAfsServerFacade().read(owner, source, offset, limit))
+    return this.promise(
+      this._getAfsServerFacade().read(owner, source, offset, limit)
+    )
   }
 
   write(owner, source, offset, data) {
-    return this.promise(this.v3.getAfsServerFacade().write(owner, source, offset, data))
+    return this.promise(
+      this._getAfsServerFacade().write(owner, source, offset, data)
+    )
   }
 
   delete(owner, source) {
-    return this.promise(this.v3.getAfsServerFacade().delete(owner, source))
+    return this.promise(this._getAfsServerFacade().delete(owner, source))
   }
 
   copy(sourceOwner, source, targetOwner, target) {
-    return this.promise(this.v3.getAfsServerFacade().copy(sourceOwner, source, targetOwner, target))
+    return this.promise(
+      this._getAfsServerFacade().copy(sourceOwner, source, targetOwner, target)
+    )
   }
 
   move(sourceOwner, source, targetOwner, target) {
-    return this.promise(this.v3.getAfsServerFacade().move(sourceOwner, source, targetOwner, target))
+    return this.promise(
+      this._getAfsServerFacade().move(sourceOwner, source, targetOwner, target)
+    )
   }
 
   create(owner, source, directory) {
-    return this.promise(this.v3.getAfsServerFacade().create(owner, source, directory))
+    return this.promise(
+      this._getAfsServerFacade().create(owner, source, directory)
+    )
   }
 
   free(owner, source) {
-    return this.promise(this.v3.getAfsServerFacade().free(owner, source))
+    return this.promise(this._getAfsServerFacade().free(owner, source))
   }
 
   async executeService(id, options) {
-- 
GitLab