Fixed the Policy API issues and Bugfixes
[policy/engine.git] / ECOMP-PDP-REST / src / main / java / org / openecomp / policy / pdp / rest / PapUrlResolver.java
index d9a3688..924c2b5 100644 (file)
@@ -28,31 +28,29 @@ import java.util.Date;
 import java.util.NoSuchElementException;
 import java.util.Properties;
 
+import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
+import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.rest.XACMLRestProperties;
 
 import com.att.research.xacml.util.XACMLProperties;
 
-import org.openecomp.policy.common.logging.flexlogger.*;
-
 public class PapUrlResolver {
-       private static final Logger logger = FlexLogger.getLogger(PapUrlResolver.class);
+       private static final Logger LOGGER = FlexLogger.getLogger(PapUrlResolver.class);
        //how long to keep a pap failed before making it un-failed, in milli-seconds
        private static final long FAIL_TIMEOUT = 18000000;
        
        //thread locks
-       public static Object propertyLock = new Object();
+       public static final Object propertyLock = new Object();
        
-       public static void setPapUrls(String[] papUrls){
-               
-       }
        //keeping this here for backward compatibility
        public static String extractIdFromUrl(String url){
                return extractQuery(url);
        }
        public static String extractQuery(String url){
                try{
-               return URI.create(url).getQuery();
+                       return URI.create(url).getQuery();
                } catch(Exception e){
+                       LOGGER.error("Exception occured while extracting query. So, empty string is returned"+e);
                        return "";
                }
        }
@@ -92,22 +90,24 @@ public class PapUrlResolver {
        //because it is used for a difference purpose.
        private PapUrlResolver(String urlList, String failedList, String succeededList, boolean autoUpdateProperties){  
                this.autoUpdateProperties = autoUpdateProperties;
-               //synchronized(propertyLock){
-               if(urlList == null){
-                       urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS);
-                       if(urlList == null){
-                               urlList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
+               String papUrlLists = urlList;
+               String papUrlFailedList = failedList;
+               String papUrlSuccessList = succeededList;
+               if(papUrlLists == null){
+                       papUrlLists = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URLS);
+                       if(papUrlLists == null){
+                               papUrlLists = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_URL);
                        }
-                       failedList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS);
-                       succeededList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS);
+                       papUrlFailedList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS);
+                       papUrlSuccessList = XACMLProperties.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS);
                }
-               //}             
-               String[] urls = urlList.split(",");
+               
+               String[] urls = papUrlLists.split(",");
                if(urls.length == 0){           
                        //log error
                }
-               String[] failed = emptyOrSplit(failedList,urls.length);
-               String[] succeeded = emptyOrSplit(succeededList,urls.length);
+               String[] failed = emptyOrSplit(papUrlFailedList,urls.length);
+               String[] succeeded = emptyOrSplit(papUrlSuccessList,urls.length);
                
                sortedUrlNodes = new PapUrlNode[urls.length];
                for(int i=0;i<urls.length;i++){
@@ -130,7 +130,6 @@ public class PapUrlResolver {
                        if(sortedUrlNodes[i] == null){
                                sortedUrlNodes[i] = newNode;
                        }
-                       
                }
                originalUrlNodes = sortedUrlNodes.clone();
                sort(sortedUrlNodes);
@@ -177,7 +176,7 @@ public class PapUrlResolver {
        //sets the current PAP url as being failed
        //this will set the failed time to now and remove any succeeded time
        public void failed(){
-               logger.error("PAP Server FAILED: "+sortedUrlNodes[pointer].getUrl());
+               LOGGER.error("PAP Server FAILED: "+sortedUrlNodes[pointer].getUrl());
 
                sortedUrlNodes[pointer].setFailedTime(new Date());
                sortedUrlNodes[pointer].setSucceededTime(null);
@@ -195,7 +194,7 @@ public class PapUrlResolver {
        public void registered(){
                sortedUrlNodes[pointer].setFailedTime(null);
                sortedUrlNodes[pointer].setSucceededTime(new Date());
-               logger.info("PAP server SUCCEEDED "+sortedUrlNodes[pointer].getUrl());
+               LOGGER.info("PAP server SUCCEEDED "+sortedUrlNodes[pointer].getUrl());
                propertiesUpdated();
        }
        
@@ -226,8 +225,8 @@ public class PapUrlResolver {
                }
                Properties prop = getProperties();
 
-               logger.debug("Failed PAP Url List: "+prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS));
-               logger.debug("Succeeded PAP Url List: "+prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS));
+               LOGGER.debug("Failed PAP Url List: "+prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS));
+               LOGGER.debug("Succeeded PAP Url List: "+prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS));
                XACMLProperties.setProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS,prop.getProperty(XACMLRestProperties.PROP_PAP_FAILED_URLS));
                XACMLProperties.setProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS,prop.getProperty(XACMLRestProperties.PROP_PAP_SUCCEEDED_URLS));
        }
@@ -243,8 +242,7 @@ public class PapUrlResolver {
                if(sortedUrlNodes[pointer]== null){
                        throw new NoSuchElementException();
                } else {
-                       String finalUrl = sortedUrlNodes[pointer].getUrl().concat("?").concat(query);
-                       return finalUrl;
+                       return sortedUrlNodes[pointer].getUrl().concat("?").concat(query);
                }
        }
        
@@ -287,14 +285,6 @@ public class PapUrlResolver {
                private String userId;
                private String pass;
                
-               public PapUrlNode(String url){
-                       this.papUrl = url;
-                       failedTime = null;
-                       this.succeededTime = null;
-                       this.userId = "";
-                       this.pass = "";
-                       
-               }
                public PapUrlNode(String url,String userId,String pass){
                        this.papUrl = url;
                        failedTime = null;
@@ -332,13 +322,12 @@ public class PapUrlResolver {
                //parses string into a date or a null date, if the url never failed/succeeded (since -1 will be in the property)
                private Date setHandler(Object time){
                        if(time instanceof String){
-                               if(((String)time).equals("-1")){
+                               if("-1".equals((String)time)){
                                        return null;
                                }
                                try {
                                        DateFormat df = new SimpleDateFormat();
-                                       Date parsedTime = df.parse((String)time);
-                                       return parsedTime;
+                                       return df.parse((String)time);
                                } catch (ParseException e) {                                    
                                        return null;
                                }
@@ -370,7 +359,8 @@ public class PapUrlResolver {
                public String getUrl(){
                        return papUrl;
                }
-
+               
+               @Override
                public int compareTo(PapUrlNode other){
                        if(this.failedTime == null && other.failedTime != null){
                                return -1;