Fix issue for policies not loading on GUI push tab
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / CreateFirewallController.java
index b4a8fd8..3e24dc7 100644 (file)
@@ -113,7 +113,9 @@ public class CreateFirewallController extends RestrictedBaseController {
                CreateFirewallController.commonClassDao = commonClassDao;
        }
 
-       public CreateFirewallController(){}
+       public CreateFirewallController(){
+               // Empty constructor
+       }
        private List<String> termCollectorList;
        
 
@@ -336,28 +338,30 @@ public class CreateFirewallController extends RestrictedBaseController {
                        String ruleDestPort;
                        String ruleAction;
                        List <String> valueDesc;
-                       StringBuffer displayString = new StringBuffer();
+                       StringBuilder displayString = new StringBuilder();
                        for (String id : termCollectorList) {
                                List<Object> tmList = commonClassDao.getDataById(TermList.class, "termName", id);
                                jpaTermList = (TermList) tmList.get(0);
                                if (jpaTermList != null){                               
                                        ruleSrcList= jpaTermList.getSrcIPList();        
-                                       if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !ruleSrcList.equals("null")){
+                                       if ((ruleSrcList!= null) && (!ruleSrcList.isEmpty()) && !"null".equals(ruleSrcList)){
                                                displayString.append("Source IP List: " + jpaTermList.getSrcIPList());
                                                displayString.append(" ; \t\n");
                                                for(String srcList:ruleSrcList.split(",")){     
                                                        if(srcList.startsWith(GROUP)){
                                                                AddressGroup ag;
                                                                ag= mappingAddressGroup(srcList);
-                                                               displayString.append("\n\t"+"Group has  :"+ag.getPrefixList()+"\n");
-                                                               for(String groupItems:ag.getPrefixList().split(",")){
-                                                                       valueDesc=mapping(groupItems);
-                                                                       displayString.append("\n\t"+"Name: "+groupItems);
-                                                                       if(!valueDesc.isEmpty()){
-                                                                               displayString.append("\n\t"+"Description: "+valueDesc.get(1));
-                                                                               displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+                                                               displayString.append("\n\t"+"Group has  :"+(ag != null ? ag.getPrefixList() : "") +"\n");
+                                                               if (ag != null) {
+                                                                       for(String groupItems:ag.getPrefixList().split(",")){
+                                                                               valueDesc=mapping(groupItems);
+                                                                               displayString.append("\n\t"+"Name: "+groupItems);
+                                                                               if(!valueDesc.isEmpty()){
+                                                                                       displayString.append("\n\t"+"Description: "+valueDesc.get(1));
+                                                                                       displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+                                                                               }
+                                                                               displayString.append("\n");
                                                                        }
-                                                                       displayString.append("\n");
                                                                }
                                                        }else{
                                                                if(!srcList.equals(ANY)){
@@ -379,13 +383,15 @@ public class CreateFirewallController extends RestrictedBaseController {
                                                        if(destList.startsWith(GROUP)){
                                                                AddressGroup ag;
                                                                ag= mappingAddressGroup(destList);
-                                                               displayString.append("\n\t"+"Group has  :"+ag.getPrefixList()+"\n");
-                                                               for(String groupItems:ag.getPrefixList().split(",")){
-                                                                       valueDesc=mapping(groupItems);
-                                                                       displayString.append("\n\t"+"Name: "+groupItems);
-                                                                       displayString.append("\n\t"+"Description: "+valueDesc.get(1));
-                                                                       displayString.append("\n\t"+"Value: "+valueDesc.get(0));
-                                                                       displayString.append("\n\t");
+                                                               displayString.append("\n\t"+"Group has  :"+ (ag != null ? ag.getPrefixList() : "") +"\n");
+                                                               if (ag != null) {
+                                                                       for(String groupItems:ag.getPrefixList().split(",")){
+                                                                               valueDesc=mapping(groupItems);
+                                                                               displayString.append("\n\t"+"Name: "+groupItems);
+                                                                               displayString.append("\n\t"+"Description: "+valueDesc.get(1));
+                                                                               displayString.append("\n\t"+"Value: "+valueDesc.get(0));
+                                                                               displayString.append("\n\t");
+                                                                       }
                                                                }
                                                        }else{
                                                                if(!destList.equals(ANY)){
@@ -416,19 +422,21 @@ public class CreateFirewallController extends RestrictedBaseController {
                                                        if(destServices.startsWith(GROUP)){
                                                                GroupServiceList sg;
                                                                sg= mappingServiceGroup(destServices);
-                                                               displayString.append("\n\t"+"Service Group has  :"+sg.getServiceList()+"\n");
-                                                               for(String groupItems:sg.getServiceList().split(",")){
-                                                                       ServiceList sl;
-                                                                       sl= mappingServiceList(groupItems);
-                                                                       displayString.append("\n\t"+"Name:  "+
-                                                                                       sl.getServiceName());
-                                                                       displayString.append("\n\t"+"Description:  "+
-                                                                                       sl.getServiceDescription());    
-                                                                       displayString.append("\n\t"+"Transport-Protocol:  "+
-                                                                                       sl.getServiceTransProtocol());
-                                                                       displayString.append("\n\t"+"Ports:  "+
-                                                                                       sl.getServicePorts());
-                                                                       displayString.append("\n");
+                                                               displayString.append("\n\t"+"Service Group has  :"+ (sg != null ? sg.getServiceList() : "") +"\n");
+                                                               if (sg != null) {
+                                                                       for(String groupItems:sg.getServiceList().split(",")){
+                                                                               ServiceList sl;
+                                                                               sl= mappingServiceList(groupItems);
+                                                                               displayString.append("\n\t"+"Name:  "+
+                                                                                               sl.getServiceName());
+                                                                               displayString.append("\n\t"+"Description:  "+
+                                                                                               sl.getServiceDescription());    
+                                                                               displayString.append("\n\t"+"Transport-Protocol:  "+
+                                                                                               sl.getServiceTransProtocol());
+                                                                               displayString.append("\n\t"+"Ports:  "+
+                                                                                               sl.getServicePorts());
+                                                                               displayString.append("\n");
+                                                                       }
                                                                }
                                                        }
                                                        else{