Fixed the Policy API issues and Bugfixes
[policy/engine.git] / PolicyEngineAPI / src / main / java / org / openecomp / policy / std / StdPolicyEngine.java
index abe5ee7..0732c3c 100644 (file)
@@ -82,7 +82,7 @@ import org.openecomp.policy.common.logging.flexlogger.FlexLogger;
 import org.openecomp.policy.common.logging.flexlogger.Logger;
 import org.openecomp.policy.models.APIDictionaryResponse;
 import org.openecomp.policy.models.APIPolicyConfigResponse;
-import org.openecomp.policy.utils.AAFPolicyClient.Environment;
+import org.openecomp.policy.utils.AAFEnvironment;
 import org.openecomp.policy.utils.PolicyUtils;
 import org.openecomp.policy.xacml.api.XACMLErrorConstants;
 import org.springframework.core.io.FileSystemResource;
@@ -97,9 +97,9 @@ import org.springframework.web.client.HttpClientErrorException;
 import org.springframework.web.client.RestTemplate;
 import org.xml.sax.InputSource;
 
-import com.att.aft.dme2.internal.gson.Gson;
-import com.att.aft.dme2.internal.gson.GsonBuilder;
 import com.fasterxml.jackson.core.JsonProcessingException;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
 
 /**
  * PolicyEngine Implementation class
@@ -565,7 +565,7 @@ public class StdPolicyEngine {
        
     public Collection<PolicyConfig> getConfigImpl(ConfigRequestParameters configRequestParameters) throws PolicyConfigException{
            String resource= "getConfig";
-               ArrayList<PolicyConfig> response = new ArrayList<PolicyConfig>();
+               ArrayList<PolicyConfig> response = new ArrayList<>();
                String body = new String();
                // Create Request. 
                try {
@@ -598,7 +598,7 @@ public class StdPolicyEngine {
        }
     
     private ArrayList<PolicyConfig> configResult(APIPolicyConfigResponse[] response) throws PolicyConfigException {
-        ArrayList<PolicyConfig> result = new ArrayList<PolicyConfig>();
+        ArrayList<PolicyConfig> result = new ArrayList<>();
         if(response!=null && response.length>0){
             for(APIPolicyConfigResponse policyConfigResponse: response){
                 StdPolicyConfig policyConfig = new StdPolicyConfig();
@@ -647,7 +647,7 @@ public class StdPolicyEngine {
 
     private void setMatches(Map<String, String> matchingConditions) {
         Matches match = new Matches();
-        HashMap<String, String> configAttributes = new HashMap<String,String>();
+        HashMap<String, String> configAttributes = new HashMap<>();
         try{
             for(String key: matchingConditions.keySet()){
                 if(key.equalsIgnoreCase("ECOMPName")){
@@ -689,15 +689,13 @@ public class StdPolicyEngine {
                 LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Error while connecting to " + pdps.get(0), e);
                 exception = new HttpClientErrorException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
             }
-            finally{
-                if(result == null){
-                    Collections.rotate(pdps, -1);
-                    Collections.rotate(encoding, -1);
-                    pdpsCount++;
-                }else{
-                    break;
-                }
-            }
+            if(result == null){
+                       Collections.rotate(pdps, -1);
+                       Collections.rotate(encoding, -1);
+                       pdpsCount++;
+               }else{
+                       break;
+               }
         }
         if(exception != null && exception.getStatusCode()!=null){
             if(exception.getStatusCode().equals(HttpStatus.UNAUTHORIZED)){
@@ -741,7 +739,7 @@ public class StdPolicyEngine {
     }
 
     public Collection<String> listConfigImpl(ConfigRequestParameters listRequestParameters) throws PolicyConfigException{
-               Collection<String> policyList = new ArrayList<String>();
+               Collection<String> policyList = new ArrayList<>();
                if (junit){
                        policyList.add("Policy Name: listConfigTest");
                        return policyList;
@@ -796,7 +794,7 @@ public class StdPolicyEngine {
        }
 
        private ArrayList<PolicyResponse> eventResult(StdPolicyResponse[] response) throws PolicyEventException{
-        ArrayList<PolicyResponse> eventResult = new ArrayList<PolicyResponse>();
+        ArrayList<PolicyResponse> eventResult = new ArrayList<>();
         if(response!=null && response.length>0){
             for(StdPolicyResponse policyConfigResponse: response){
                 eventResult.add(policyConfigResponse);
@@ -860,7 +858,7 @@ public class StdPolicyEngine {
                                        typeDefault = new ArrayList<String>(Arrays.asList(prop.getProperty("NOTIFICATION_TYPE").split(",")));
                                        notificationType = typeDefault; 
                                } else {
-                                               notificationType = new ArrayList<String>();
+                                               notificationType = new ArrayList<>();
                                                notificationType.add(check_type);
                                }
                        }
@@ -873,7 +871,7 @@ public class StdPolicyEngine {
                                if(serverList.contains(",")) {
                                        notificationURLList = new ArrayList<String>(Arrays.asList(serverList.split(","))); 
                                } else {
-                                       notificationURLList = new ArrayList<String>();
+                                       notificationURLList = new ArrayList<>();
                                        notificationURLList.add(serverList);
                                }
                        }
@@ -902,17 +900,17 @@ public class StdPolicyEngine {
                                pass = clientKey.trim();
                        }
                        setClientEncoding();
-                       environment = prop.getProperty("ENVIRONMENT", Environment.DEVL.toString());
-                       if(environment.equalsIgnoreCase(Environment.TEST.toString())){
-                               environment = Environment.TEST.toString();
-                       }else if(environment.equalsIgnoreCase(Environment.PROD.toString())){
-                               environment = Environment.PROD.toString();
+                       environment = prop.getProperty("ENVIRONMENT", AAFEnvironment.DEVL.toString());
+                       if(environment.equalsIgnoreCase(AAFEnvironment.TEST.toString())){
+                               environment = AAFEnvironment.TEST.toString();
+                       }else if(environment.equalsIgnoreCase(AAFEnvironment.PROD.toString())){
+                               environment = AAFEnvironment.PROD.toString();
                        }else{
-                               environment = Environment.DEVL.toString();
+                               environment = AAFEnvironment.DEVL.toString();
                        }
                        // Initializing the values.
-                       pdps = new ArrayList<String>();
-                       encoding = new ArrayList<String>();
+                       pdps = new ArrayList<>();
+                       encoding = new ArrayList<>();
                        // Check the Keys for PDP_URLs
                        Collection<Object> unsorted = prop.keySet();
                        @SuppressWarnings({ "rawtypes", "unchecked" })