Commit includes ControlLoopPolicy API and bugfixes
[policy/engine.git] / POLICY-SDK-APP / src / main / java / org / openecomp / policy / controller / CreateBRMSParamController.java
index 786e17a..daab6e3 100644 (file)
@@ -57,6 +57,7 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
 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.AttributeAssignmentExpressionType;
+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;
@@ -87,7 +88,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
 
        @RequestMapping(value={"/policyController/getBRMSTemplateData.htm"}, method={org.springframework.web.bind.annotation.RequestMethod.POST})
        public ModelAndView getBRMSParamPolicyRuleData(HttpServletRequest request, HttpServletResponse response) throws Exception{
-               dynamicLayoutMap = new HashMap<String, String>();
+               dynamicLayoutMap = new HashMap<>();
                ObjectMapper mapper = new ObjectMapper();
                mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
                JsonNode root = mapper.readTree(request.getReader());
@@ -210,8 +211,8 @@ public class CreateBRMSParamController extends RestrictedBaseController {
 
        @SuppressWarnings("unchecked")
        public void prePopulateBRMSParamPolicyData(PolicyRestAdapter policyAdapter, PolicyEntity entity) {
-               attributeList = new ArrayList<Object>();
-               dynamicLayoutMap = new HashMap<String, String>();
+               attributeList = new ArrayList<>();
+               dynamicLayoutMap = new HashMap<>();
                if (policyAdapter.getPolicyData() instanceof PolicyType) {
                        PolicyType policy = (PolicyType) policyAdapter.getPolicyData();
                        policyAdapter.setOldPolicyFileName(policyAdapter.getPolicyName());
@@ -234,7 +235,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
                        for( AdviceExpressionType adviceExpression: expressionTypes.getAdviceExpression()){
                                for(AttributeAssignmentExpressionType attributeAssignment: adviceExpression.getAttributeAssignmentExpression()){
                                        if(attributeAssignment.getAttributeId().startsWith("key:")){
-                                               Map<String, String> attribute = new HashMap<String, String>();
+                                               Map<String, String> attribute = new HashMap<>();
                                                String key = attributeAssignment.getAttributeId().replace("key:", "");
                                                attribute.put("key", key);
                                                JAXBElement<AttributeValueType> attributevalue = (JAXBElement<AttributeValueType>) attributeAssignment.getExpression();
@@ -257,7 +258,7 @@ public class CreateBRMSParamController extends RestrictedBaseController {
                        // Get the target data under policy.
                        policyAdapter.setDynamicLayoutMap(dynamicLayoutMap);
                        if(policyAdapter.getDynamicLayoutMap().size() > 0){
-                               LinkedHashMap<String,String> drlRule = new LinkedHashMap<String, String>();
+                               LinkedHashMap<String,String> drlRule = new LinkedHashMap<>();
                                for(Object keyValue: policyAdapter.getDynamicLayoutMap().keySet()){
                                        drlRule.put(keyValue.toString(), policyAdapter.getDynamicLayoutMap().get(keyValue).toString());
                                }
@@ -275,7 +276,6 @@ public class CreateBRMSParamController extends RestrictedBaseController {
                                                List<AllOfType> allOfList = anyOf.getAllOf();
                                                if (allOfList != null) {
                                                        Iterator<AllOfType> iterAllOf = allOfList.iterator();
-                                                       int index = 0;
                                                        while (iterAllOf.hasNext()) {
                                                                AllOfType allOf = iterAllOf.next();
                                                                // Under AllOFType we have Match
@@ -285,29 +285,27 @@ public class CreateBRMSParamController extends RestrictedBaseController {
                                                                        while (iterMatch.hasNext()) {
                                                                                MatchType match = iterMatch.next();
                                                                                //
-                                                                               // Under the match we have attributevalue and
+                                                                               // 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 (index ==  3){
+                                                                               if (attributeId.equals("RiskType")){
                                                                                        policyAdapter.setRiskType(value);
                                                                                }
-
-                                                                               if (index ==  4){
+                                                                               if (attributeId.equals("RiskLevel")){
                                                                                        policyAdapter.setRiskLevel(value);
                                                                                }
-                                                                               
-                                                                               if (index ==  5){
+                                                                               if (attributeId.equals("guard")){
                                                                                        policyAdapter.setGuard(value);
                                                                                }
-                                                                               if (index == 6 && !value.contains("NA")){
+                                                                               if (attributeId.equals("TTLDate") && !value.contains("NA")){
                                                                                        String newDate = convertDate(value, true);
                                                                                        policyAdapter.setTtlDate(newDate);
                                                                                }
-
-                                                                               index++;
                                                                        }
                                                                }
                                                        }