[Policy-52, Policy-92, Policy-93] Policy Enhancements and bugfixes
[policy/engine.git] / ECOMP-PDP-REST / src / main / java / org / openecomp / policy / pdp / rest / notifications / NotificationController.java
index 4c93377..214151d 100644 (file)
@@ -36,6 +36,7 @@ import java.nio.file.Paths;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
+import java.util.Map;
 
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.filefilter.WildcardFileFilter;
@@ -81,12 +82,12 @@ public class NotificationController {
        private static String pdpURL = null;
        private static Boolean notificationFlag = false; 
        
-       public void check(PDPStatus newStatus,HashMap<String, PolicyDef> policyContainer) {
+       public void check(PDPStatus newStatus,Map<String, PolicyDef> policyContainer) {
                boolean updated = false;
                boolean removed = false;
                Notification notification = new Notification();
-               HashSet<Removed> removedPolicies = new HashSet<Removed>();
-               HashSet<Updated> updatedPolicies = new HashSet<Updated>();
+               HashSet<Removed> removedPolicies = new HashSet<>();
+               HashSet<Updated> updatedPolicies = new HashSet<>();
 
                if (oldStatus == null) {
                        oldStatus = newStatus;
@@ -167,15 +168,11 @@ public class NotificationController {
                                        notificationJSON= record(notification);
                                }catch(Exception e){
                                        LOGGER.error(e);
-                                       // TODO:EELF Cleanup - Remove LOGGER
-                                       //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
                                }
                                NotificationServer.setUpdate(notificationJSON);
                                ManualNotificationUpdateThread.setUpdate(notificationJSON);
                        } catch (JsonProcessingException e) {
                                LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage());
-                               // TODO:EELF Cleanup - Remove LOGGER
-                               //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
                        }
                }
        }
@@ -194,15 +191,13 @@ public class NotificationController {
        private void sendremove(PDPPolicy oldPolicy) {
                removed = new Removed();
                // Want to know what is removed ?
-               // LOGGER.info("The Policy removed is: " + oldPolicy.getId());
-               // LOGGER.info("The version no. is: " + oldPolicy.getVersion());
                LOGGER.info("Policy removed: " + oldPolicy.getId()+ " with version number: " + oldPolicy.getVersion());
                removed.setPolicyName(oldPolicy.getId());
                removed.setVersionNo(oldPolicy.getVersion());
                removeFile(oldPolicy);
        }
 
-       private void sendUpdate(PDPPolicy newPolicy,HashMap<String, PolicyDef> policyContainer) {
+       private void sendUpdate(PDPPolicy newPolicy,Map<String, PolicyDef> policyContainer) {
                updated = new Updated();
                // Want to know what is new ?
                LOGGER.info("The new Policy is: " + newPolicy.getId());
@@ -229,7 +224,7 @@ public class NotificationController {
                                while (allOfs.hasNext()) {
                                        AllOf allOf = allOfs.next();
                                        Iterator<Match> matches = allOf.getMatches();
-                                       HashMap<String, String> matchValues = new HashMap<String, String>();
+                                       HashMap<String, String> matchValues = new HashMap<>();
                                        while (matches.hasNext()) {
                                                Match match = matches.next();
                                                LOGGER.info("Attribute Value is: "+ match.getAttributeValue().getValue().toString());
@@ -327,8 +322,6 @@ public class NotificationController {
                        json = om.writeValueAsString(record);
                } catch (JsonProcessingException e) {
                        LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE + e.getMessage());
-                       // TODO:EELF Cleanup - Remove LOGGER
-                       //PolicyLogger.error(MessageCodes.ERROR_DATA_ISSUE, e, "");
                }
                LOGGER.info(json);
                return json;
@@ -339,7 +332,7 @@ public class NotificationController {
             if(updated && removed){
                 notification.setNotificationType(NotificationType.BOTH);
                 if(notification.getLoadedPolicies()!=null){
-                    HashSet<Updated> updatedPolicies = new HashSet<Updated>(); 
+                    HashSet<Updated> updatedPolicies = new HashSet<>(); 
                     for(Updated oldUpdatedPolicy: notification.getLoadedPolicies()){
                         Updated updatePolicy = oldUpdatedPolicy;
                         if(notification.getRemovedPolicies()!=null){
@@ -377,7 +370,7 @@ public class NotificationController {
                                delete = true;
                                dir = new File(XACMLProperties.getProperty(XACMLRestProperties.PROP_PDP_WEBAPPS)+File.separator+"Action");
                        }
-                       if(delete && dir!=null){
+                       if(delete){
                                FileFilter fileFilter = new WildcardFileFilter(oldPolicy.getId().substring(0, oldPolicy.getId().lastIndexOf("."))+".*");
                                File[] configFile = dir.listFiles(fileFilter);
                                if(configFile.length==1){
@@ -385,9 +378,7 @@ public class NotificationController {
                                }
                        }
                }catch(Exception e){
-                       LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Couldn't remove the policy/config file " + oldPolicy.getName());
-                       // TODO:EELF Cleanup - Remove LOGGER
-                       //PolicyLogger.error(MessageCodes.ERROR_PROCESS_FLOW, e, "Couldn't remove the policy file " + oldPolicy.getName());
+                       LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Couldn't remove the policy/config file " + oldPolicy.getName() + e);
                }
        }