Merge from ECOMP's repository
[vid.git] / vid-app-common / src / main / java / org / onap / vid / aai / util / SystemPropertyHelper.java
index ebf39c4..939bfe5 100644 (file)
@@ -23,8 +23,10 @@ package org.onap.vid.aai.util;
 import org.eclipse.jetty.util.security.Password;
 import org.onap.portalsdk.core.util.SystemProperties;
 import org.onap.vid.aai.exceptions.InvalidPropertyException;
+import org.onap.vid.utils.Unchecked;
 
 import java.io.UnsupportedEncodingException;
+import java.net.URI;
 import java.util.Base64;
 import java.util.Optional;
 
@@ -38,6 +40,10 @@ public class SystemPropertyHelper {
         return getSystemProperty(AAIProperties.AAI_SERVER_URL);
     }
 
+    public Optional<String> getAAIServerBaseUrl(){
+        return getSystemProperty(AAIProperties.AAI_SERVER_URL_BASE);
+    }
+
     public Optional<String> getAAIVIDUsername(){
         return getSystemProperty(AAIProperties.AAI_VID_USERNAME);
     }
@@ -70,6 +76,19 @@ public class SystemPropertyHelper {
         return getAAIServerUrl().orElse("") + path;
     }
 
+    public String getFullServicePath(URI requestUri) {
+        // resolve() will merge two paths, handling the restiveness:
+        // Especially if requestUri starts with a '/' -- result will be
+        // AAI_SERVER_URL host, post, etc., and the path will be just
+        // requestUri.
+        return Unchecked.toURI(getAAIServerUrl().orElse(""))
+                .resolve(requestUri).toASCIIString();
+    }
+
+    public String getServiceBasePath(String path) {
+        return getAAIServerBaseUrl().orElse("") + path;
+    }
+
     public String getEncodedCredentials() throws InvalidPropertyException, UnsupportedEncodingException {
         String vidUsername = getAAIVIDUsername().orElseThrow(InvalidPropertyException::new);
         String vidPassword = Password.deobfuscate(getAAIVIDPasswd().orElseThrow(InvalidPropertyException::new));