Merge "Sonar Fix: NotifyApprovals.java"
[aaf/authz.git] / cadi / core / src / main / java / org / onap / aaf / cadi / config / RegistrationPropHolder.java
index c813964..68a018d 100644 (file)
@@ -28,7 +28,7 @@ import org.onap.aaf.cadi.CadiException;
 import org.onap.aaf.cadi.util.Split;
 
 public class RegistrationPropHolder {
-
+       private final String PUBLIC_NAME="%NS.%N";
        private final Access access;
        public String hostname;
        private int port;
@@ -38,8 +38,10 @@ public class RegistrationPropHolder {
        public Float longitude;
        public final String default_fqdn;
        public final String default_container_ns;
+       public final String default_name;
        public final String lentries;
        public final String lcontainer;
+       public final String default_container;
 
        public RegistrationPropHolder(final Access access, final int port) throws UnknownHostException, CadiException {
                this.access = access;
@@ -49,15 +51,15 @@ public class RegistrationPropHolder {
 
                lentries=access.getProperty(Config.AAF_LOCATOR_ENTRIES,"");
                
-               str = access.getProperty(Config.AAF_LOCATOR_CONTAINER, "");
-               if(!str.isEmpty()) {
-                       lcontainer=',' + str; // "" makes a blank default Public Entry
-                       str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT+'.'+str, null);
+               default_container = access.getProperty(Config.AAF_LOCATOR_CONTAINER, "");
+               if(!default_container.isEmpty()) {
+                       lcontainer=',' + default_container; // "" makes a blank default Public Entry
+                       str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT+'.'+default_container, null);
                        if(str==null) {
                                str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT, null);
                        }
                } else {
-                       lcontainer=str;
+                       lcontainer=default_container;
                        str = access.getProperty(Config.AAF_LOCATOR_PUBLIC_PORT, null);
                }
                if(str!=null) {
@@ -74,6 +76,8 @@ public class RegistrationPropHolder {
 
                public_hostname = access.getProperty(Config.AAF_LOCATOR_PUBLIC_HOSTNAME, hostname);
                                
+               default_name = access.getProperty(Config.AAF_LOCATOR_NAME, "%CNS.%NS.%N");
+               
                latitude=null;
                String slatitude = access.getProperty(Config.CADI_LATITUDE, null);
                if(slatitude == null) {
@@ -100,7 +104,7 @@ public class RegistrationPropHolder {
                        }
                }
                
-               default_fqdn = access.getProperty(Config.AAF_LOCATOR_FQDN, public_hostname);
+               default_fqdn = access.getProperty(Config.AAF_LOCATOR_FQDN, hostname);
                default_container_ns = access.getProperty(Config.AAF_LOCATOR_CONTAINER_NS,"");
                
                if(errs.length()>0) {
@@ -120,17 +124,18 @@ public class RegistrationPropHolder {
                if(public_hostname!=null && dot_le.isEmpty()) {
                        str = public_hostname;
                } else {
-                       str = access.getProperty(Config.AAF_LOCATOR_FQDN+dot_le, null);
-                       if(str==null) {
-                               str = access.getProperty(Config.AAF_LOCATOR_FQDN, hostname);
-                       }
+                       str = access.getProperty(Config.AAF_LOCATOR_FQDN+dot_le, default_fqdn);
                }
                return replacements(str,entry,dot_le);
        }
        
        public String getEntryName(final String entry, final String dot_le) {
                String str;
-               str = access.getProperty(Config.AAF_LOCATOR_NAME+dot_le, "%NS.%N");
+               if(dot_le.isEmpty()) {
+                       str = PUBLIC_NAME;
+               } else {
+                       str = access.getProperty(Config.AAF_LOCATOR_NAME+dot_le, default_name);
+               }
                return replacements(str,entry,dot_le);
        }
        
@@ -145,47 +150,42 @@ public class RegistrationPropHolder {
        }
 
        
-       public String replacements(String source, final String name, final String dot_le) {
+       public String replacements(String source, final String name, final String _dot_le) {
                if(source == null) {
                        return "";
                } else if(source.isEmpty()) {
                        return source;
                }
-               String str;
-               // aaf_locate_url
-               if(source.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) {
-                       str = access.getProperty(Config.AAF_LOCATE_URL, null);
-                       if(str!=null) {
-                               if(!str.endsWith("/")) {
-                                       str+='/';
-                               }
-                               if(!str.endsWith("/locate/")) {
-                                       str+="locate/";
-                               }
-                               source = source.replace("https://AAF_LOCATE_URL/", str);
-                       }
-               }
-
-               if(source.indexOf("%NS")>=0) {
-                       str = getNS(dot_le);
-                       if(str==null || str.isEmpty()) {
-                               source = source.replace("%NS"+'.', str);
-                       }
-                       source = source.replace("%NS", str);
-               }
-
-               // aaf_root_ns
-               if(source.indexOf("AAF_NS")>=0) {
-                       str = access.getProperty(Config.AAF_ROOT_NS, null);
-                       if(str!=null) {
-                               String temp = source.replace("%AAF_NS", str);
-                               if(temp == source) { // intended
-                                       source = source.replace("AAF_NS", str); // Backward Compatibility
-                               } else {
-                                       source = temp;
+               
+               String dot_le;
+               if(_dot_le==null) {
+                       dot_le = default_container.isEmpty()?"":'.'+default_container;
+               } else {
+                       dot_le = _dot_le;
+               }
+
+        String aaf_locator_host = access.getProperty(Config.AAF_LOCATE_URL+dot_le,null);
+        if(aaf_locator_host==null) {
+               aaf_locator_host = access.getProperty(Config.AAF_LOCATE_URL,null);
+        }
+
+        String str;
+        if(aaf_locator_host!=null) {
+                       if("https://AAF_LOCATE_URL".equals(source)) {
+                               source = aaf_locator_host;
+                       } else {
+                       str = aaf_locator_host;
+                               if(source.indexOf(Config.AAF_LOCATE_URL_TAG)>=0) {
+                                       if(!str.endsWith("/")) {
+                                               str+='/';
+                                       }
+                                       if(!str.endsWith("/locate/")) {
+                                               str+="locate/";
+                                       }
+                                       source = source.replace("https://AAF_LOCATE_URL/", str);
                                }
                        }
-               }
+        }
 
                int atC = source.indexOf("%C"); 
                if(atC>=0) {
@@ -196,18 +196,44 @@ public class RegistrationPropHolder {
                        }
                        source = source.replace("%CNS", str);
                        
-                       str = access.getProperty(Config.AAF_LOCATOR_CONTAINER+dot_le, "");
+                       str = access.getProperty(Config.AAF_LOCATOR_CONTAINER+dot_le,default_container);
                        if(str.isEmpty()) {
                                source = source.replace("%C"+'.', str);
                        }
                        source = source.replace("%C", str);
                }
                
+               if(source.indexOf("%NS")>=0) {
+                       str = getNS(dot_le);
+                       if(str==null || str.isEmpty()) {
+                               source = source.replace("%NS"+'.', str);
+                       }
+                       source = source.replace("%NS", str);
+               }
+
+               // aaf_root_ns
+               if(source.indexOf("AAF_NS")>=0) {
+                       str = access.getProperty(Config.AAF_ROOT_NS, Config.AAF_ROOT_NS_DEF);
+                       String temp = source.replace("%AAF_NS", str);
+                       if(temp.equals(source)) { // intended
+                               source = source.replace("AAF_NS", str); // Backward Compatibility
+                       } else {
+                               source = temp;
+                       }
+               }
+
+               
                if(source.indexOf('%')>=0) {
-                       // These shouldn't be expected to have dot elements
-                       source = source.replace("%N", name);
-                       source = source.replace("%DF", default_fqdn);
-                       source = source.replace("%PH", public_hostname);
+            // These shouldn't be expected to have dot elements
+            if(name!=null) {
+              source = source.replace("%N", name);
+            }
+            if(default_fqdn!=null) {
+              source = source.replace("%DF", default_fqdn);
+            }
+            if(public_hostname!=null) {
+              source = source.replace("%PH", public_hostname);
+            }
                }
                return source;
        }
@@ -217,4 +243,8 @@ public class RegistrationPropHolder {
                                public_port:
                                port;
        }
+
+       public Access access() {
+               return access;
+       }
 }
\ No newline at end of file