Unit/SONAR/Checkstyle in ONAP-REST
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / onap / policy / controller / CreateFirewallController.java
index 0fbc34d..3da703a 100644 (file)
@@ -39,8 +39,6 @@ import javax.servlet.http.HttpServletResponse;
 
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
-import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
@@ -68,13 +66,14 @@ import org.onap.policy.rest.adapter.TermCollector;
 import org.onap.policy.rest.adapter.VendorSpecificData;
 import org.onap.policy.rest.dao.CommonClassDao;
 import org.onap.policy.rest.jpa.AddressGroup;
-import org.onap.policy.rest.jpa.FWTagPicker;
+import org.onap.policy.rest.jpa.FwTagPicker;
 import org.onap.policy.rest.jpa.GroupServiceList;
 import org.onap.policy.rest.jpa.PolicyEntity;
 import org.onap.policy.rest.jpa.PrefixList;
 import org.onap.policy.rest.jpa.SecurityZone;
 import org.onap.policy.rest.jpa.ServiceList;
 import org.onap.policy.rest.jpa.TermList;
+import org.onap.policy.utils.PolicyUtils;
 import org.onap.policy.xacml.api.XACMLErrorConstants;
 import org.onap.portalsdk.core.controller.RestrictedBaseController;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -278,27 +277,8 @@ public class CreateFirewallController extends RestrictedBaseController {
                     // Under the match we have attribute value and
                     // attributeDesignator. So,finally down to the actual attribute.
                     //
-                    AttributeValueType attributeValue = match.getAttributeValue();
-                    String value = (String) attributeValue.getContent().get(0);
-                    AttributeDesignatorType designator = match.getAttributeDesignator();
-                    String attributeId = designator.getAttributeId();
-                    if (("ConfigName").equals(attributeId)) {
-                        policyAdapter.setConfigName(value);
-                    }
-                    if (("RiskType").equals(attributeId)) {
-                        policyAdapter.setRiskType(value);
-                    }
-                    if (("RiskLevel").equals(attributeId)) {
-                        policyAdapter.setRiskLevel(value);
-                    }
-                    if (("guard").equals(attributeId)) {
-                        policyAdapter.setGuard(value);
-                    }
-                    if ("TTLDate".equals(attributeId) && !value.contains("NA")) {
-                        PolicyController controller = new PolicyController();
-                        String newDate = controller.convertDate(value);
-                        policyAdapter.setTtlDate(newDate);
-                    }
+                    policyAdapter.setupUsingAttribute(match.getAttributeDesignator().getAttributeId(),
+                            (String) match.getAttributeValue().getContent().get(0));
                 }
             }
         }
@@ -341,9 +321,9 @@ public class CreateFirewallController extends RestrictedBaseController {
                 List<Object> tmList = commonClassDao.getDataById(TermList.class, "termName", id);
                 jpaTermList = (TermList) tmList.get(0);
                 if (jpaTermList != null) {
-                    ruleSrcList = jpaTermList.getSrcIPList();
+                    ruleSrcList = jpaTermList.getSrcIpList();
                     if ((ruleSrcList != null) && (!ruleSrcList.isEmpty()) && !"null".equals(ruleSrcList)) {
-                        displayString.append("Source IP List: " + jpaTermList.getSrcIPList());
+                        displayString.append("Source IP List: " + jpaTermList.getSrcIpList());
                         displayString.append(" ; \t\n");
                         for (String srcList : ruleSrcList.split(",")) {
                             if (srcList.startsWith(GROUP)) {
@@ -374,9 +354,9 @@ public class CreateFirewallController extends RestrictedBaseController {
                         }
                         displayString.append("\n");
                     }
-                    ruleDestList = jpaTermList.getDestIPList();
+                    ruleDestList = jpaTermList.getDestIpList();
                     if (ruleDestList != null && (!ruleDestList.isEmpty()) && !"null".equals(ruleDestList)) {
-                        displayString.append("Destination IP List: " + jpaTermList.getDestIPList());
+                        displayString.append("Destination IP List: " + jpaTermList.getDestIpList());
                         displayString.append(" ; \t\n");
                         for (String destList : ruleDestList.split(",")) {
                             if (destList.startsWith(GROUP)) {
@@ -429,7 +409,7 @@ public class CreateFirewallController extends RestrictedBaseController {
                                         displayString.append("\n\t" + "Name:  " + sl.getServiceName());
                                         displayString.append("\n\t" + "Description:  " + sl.getServiceDescription());
                                         displayString.append(
-                                                "\n\t" + "Transport-Protocol:  " + sl.getServiceTransProtocol());
+                                                "\n\t" + "Transport-Protocol:  " + sl.getServiceTransportProtocol());
                                         displayString.append("\n\t" + "Ports:  " + sl.getServicePorts());
                                         displayString.append("\n");
                                     }
@@ -441,7 +421,7 @@ public class CreateFirewallController extends RestrictedBaseController {
                                     displayString.append("\n\t" + "Name:  " + sl.getServiceName());
                                     displayString.append("\n\t" + "Description:  " + sl.getServiceDescription());
                                     displayString
-                                            .append("\n\t" + "Transport-Protocol:  " + sl.getServiceTransProtocol());
+                                            .append("\n\t" + "Transport-Protocol:  " + sl.getServiceTransportProtocol());
                                     displayString.append("\n\t" + "Ports:  " + sl.getServicePorts());
                                     displayString.append("\n");
                                 }
@@ -457,9 +437,9 @@ public class CreateFirewallController extends RestrictedBaseController {
                     }
                 }
             }
-            response.setCharacterEncoding("UTF-8");
-            response.setContentType("application / json");
-            request.setCharacterEncoding("UTF-8");
+            response.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
+            response.setContentType(PolicyUtils.APPLICATION_JSON);
+            request.setCharacterEncoding(PolicyUtils.CHARACTER_ENCODING);
 
             String responseString = mapper.writeValueAsString(displayString);
             response.getWriter().write(new JSONObject("{policyData: " + responseString + "}").toString());
@@ -510,9 +490,9 @@ public class CreateFirewallController extends RestrictedBaseController {
             String networkRole = "";
             for (String tag : tagCollectorList) {
                 tags = new Tags();
-                List<Object> tagListData = commonClassDao.getData(FWTagPicker.class);
+                List<Object> tagListData = commonClassDao.getData(FwTagPicker.class);
                 for (int tagCounter = 0; tagCounter < tagListData.size(); tagCounter++) {
-                    FWTagPicker jpaTagPickerList = (FWTagPicker) tagListData.get(tagCounter);
+                    FwTagPicker jpaTagPickerList = (FwTagPicker) tagListData.get(tagCounter);
                     if (jpaTagPickerList.getTagPickerName().equals(tag)) {
                         String tagValues = jpaTagPickerList.getTagValues();
                         tagList = new ArrayList<>();
@@ -549,7 +529,7 @@ public class CreateFirewallController extends RestrictedBaseController {
                 for (int j = 0; j < termListData.size(); j++) {
                     jpaTermList = (TermList) termListData.get(j);
                     if (jpaTermList.getTermName().equals(termCollectorList.get(tl))) {
-                        ruleDesc = jpaTermList.getTermDescription();
+                        ruleDesc = jpaTermList.getDescription();
                         if ((ruleDesc != null) && (!ruleDesc.isEmpty())) {
                             targetTerm.setDescription(ruleDesc);
                         }
@@ -565,14 +545,14 @@ public class CreateFirewallController extends RestrictedBaseController {
                             mapToZone = new HashMap<>();
                             mapToZone.put(tl, ruleToZone);
                         }
-                        ruleSrcPrefixList = jpaTermList.getSrcIPList();
+                        ruleSrcPrefixList = jpaTermList.getSrcIpList();
 
                         if ((ruleSrcPrefixList != null) && (!ruleSrcPrefixList.isEmpty())) {
                             mapSrcIp = new HashMap<>();
                             mapSrcIp.put(tl, ruleSrcPrefixList);
                         }
 
-                        ruleDestPrefixList = jpaTermList.getDestIPList();
+                        ruleDestPrefixList = jpaTermList.getDestIpList();
                         if ((ruleDestPrefixList != null) && (!ruleDestPrefixList.isEmpty())) {
                             mapDestIP = new HashMap<>();
                             mapDestIP.put(tl, ruleDestPrefixList);
@@ -761,7 +741,7 @@ public class CreateFirewallController extends RestrictedBaseController {
                             sl = mappingServiceList(t);
                             targetSl.setName(sl.getServiceName());
                             targetSl.setDescription(sl.getServiceDescription());
-                            targetSl.setTransportProtocol(sl.getServiceTransProtocol());
+                            targetSl.setTransportProtocol(sl.getServiceTransportProtocol());
                             targetSl.setType(sl.getServiceType());
                             targetSl.setPorts(sl.getServicePorts());
                             servListArray.add(targetSl);
@@ -814,7 +794,7 @@ public class CreateFirewallController extends RestrictedBaseController {
 
                             targetSl.setName(expandGroupSl.getServiceName());
                             targetSl.setDescription(expandGroupSl.getServiceDescription());
-                            targetSl.setTransportProtocol(expandGroupSl.getServiceTransProtocol());
+                            targetSl.setTransportProtocol(expandGroupSl.getServiceTransportProtocol());
                             targetSl.setType(expandGroupSl.getServiceType());
                             targetSl.setPorts(expandGroupSl.getServicePorts());
                             servListArray.add(targetSl);