diff options
author | uj426b <uj426b@att.com> | 2020-04-28 15:43:20 -0400 |
---|---|---|
committer | uj426b <uj426b@att.com> | 2020-04-29 15:25:52 -0400 |
commit | cddeb280a0d2e897d5b373068023d23dd5ca084e (patch) | |
tree | 2dfca60c12124cf7795b8e09e9e8fd7bde17c7cc | |
parent | 663156eea876121cecc341e642100d11c1e20f9e (diff) |
Fix for MS Policy Tosca Model and other items
Issue-ID: POLICY-2520
Change-Id: I35fac9e7d157aa4a137cd9dd5a30830eaf63f586
Signed-off-by: uj426b <uj426b@att.com>
3 files changed, 141 insertions, 113 deletions
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java index 5dee2e61f..4be31dd1e 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/controller/CreateDcaeMicroServiceController.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import com.fasterxml.jackson.databind.node.ArrayNode; import com.fasterxml.jackson.databind.node.JsonNodeFactory; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.gson.Gson; - import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; @@ -38,10 +37,12 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.StringReader; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; +import java.util.Base64; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; @@ -58,7 +59,6 @@ import java.util.UUID; import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; - import javax.json.Json; import javax.json.JsonArray; import javax.json.JsonArrayBuilder; @@ -75,7 +75,6 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType; 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; - import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.fileupload.FileItem; import org.apache.commons.fileupload.FileUploadException; @@ -83,6 +82,7 @@ import org.apache.commons.fileupload.disk.DiskFileItemFactory; import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; +import org.apache.commons.lang3.StringEscapeUtils; import org.json.JSONArray; import org.json.JSONObject; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -175,9 +175,7 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { String tempJson = root.get(POLICYJSON).toString(); JSONObject policyJson = new JSONObject(root.get(POLICYJSON).toString()); - if (policyJson != null) { - tempJson = saveOriginalJsonObject(policyJson, jsonStringValues).toString(); - } + tempJson = decodeJsonVal(tempJson, policyJson); // ---replace empty value with the value below before calling decodeContent method. String dummyValue = "*empty-value*" + UUID.randomUUID().toString(); LOGGER.info("dummyValue:" + dummyValue); @@ -198,12 +196,28 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { JSONObject content = contentJson.getJSONObject("content"); content = setOriginalJsonObject(content, jsonStringValues); contentJson.put("content", content); - policyData.setJsonBody(contentJson.toString()); + policyData.setJsonBody(StringEscapeUtils.unescapeJava(contentJson.toString())); } return policyData; } + private String decodeJsonVal(String tempJson, JSONObject policyJson) { + if (policyJson != null) { + for (Object key : policyJson.keySet()) { + String keyStr = (String) key; + Object keyvalue = policyJson.get(keyStr); + String decodedString = keyvalue.toString();//.replace("\"", ""); + if(!decodedString.equals("true") && !decodedString.equals("false")) { + String decodedJson = new String(Base64.getDecoder().decode(decodedString), StandardCharsets.UTF_8).replace("\"", "\\\""); + policyJson.put(keyStr, decodedJson); + } + } + tempJson = saveOriginalJsonObject(policyJson, jsonStringValues).toString(); + } + return tempJson; + } + private JSONObject saveOriginalJsonObject(JSONObject jsonObj, Map<String, String> jsonStringValues) { for (Object key : jsonObj.keySet()) { String keyStr = (String) key; @@ -564,14 +578,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { if (arrOfKeys[i].contains(".")) { arrOfKeys[i] = arrOfKeys[i].substring(arrOfKeys[i].indexOf(".") + 1); if (arrOfKeys[i].equals(key)) { - return StringUtils.replaceEach(jsonStringValues.get(k), new String[] {"\""}, - new String[] {"\\\""}); + return jsonStringValues.get(k); } } } } if (k.endsWith(key)) { - return StringUtils.replaceEach(jsonStringValues.get(k), new String[] {"\""}, new String[] {"\\\""}); + return jsonStringValues.get(k); } } @@ -645,25 +658,12 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { case OBJECT: JsonObject object = removeNull(obj.getJsonObject(key)); if (!object.isEmpty()) { - if (!jsonStringValues.isEmpty()) { - String originalValue = getOriginalValue(key); - if (originalValue != null) { - builder.add(key, object.toString()); - break; - } - } builder.add(key, object); } break; case STRING: String str = obj.getString(key); if (str != null && !str.isEmpty()) { - if (!jsonStringValues.isEmpty()) { - String originalValue = getOriginalValue(key); - if (originalValue != null) { - str = getOriginalValue(key); - } - } builder.add(key, str); } break; @@ -1108,7 +1108,13 @@ public class CreateDcaeMicroServiceController extends RestrictedBaseController { } if (obj instanceof JSONArray) { - convertToArrayElement(json.getJSONArray(key).getJSONObject(0), keyValue); + try { + if (json.getJSONArray(key).length() > 0) { + convertToArrayElement(json.getJSONArray(key).getJSONObject(0), keyValue); + } + } catch (Exception ex) { + LOGGER.info("XMI Model load issue : " + ex); + } } } diff --git a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js index 873bdb104..1e452e830 100644 --- a/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js +++ b/POLICY-SDK-APP/src/main/webapp/app/policyApp/policy-models/Editor/PolicyTemplateController/DCAEMicroServicePolicyController.js @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * ONAP Policy Engine * ================================================================================ - * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. + * Copyright (C) 2017-2020 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -150,8 +150,10 @@ angular.module('abs').controller('dcaeMicroServiceController', var addElement = parentElement.childElementCount; clone.id = ''+value+'@'+addElement; clone.value = ''; - if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ //if it's view or edit - if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){ // Only append child if its value found in ruleData or edit mode + if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){ + //if it's vi or edit + if($scope.temp.policy.ruleData[clone.id] || $scope.temp.policy.editPolicy){ + //Only append child if its value found in ruleData or edit mode if($scope.temp.policy.ruleData[clone.id]){ clone.value = $scope.temp.policy.ruleData[clone.id]; isFoundInRuleData = true; @@ -160,14 +162,14 @@ angular.module('abs').controller('dcaeMicroServiceController', return; } if(!clone.className.includes("child_single")){ - clone.className += ' child_single'; //here cloned is single element + clone.className += ' child_single'; // here cloned is single element } document.getElementById("div."+value).appendChild(clone); plainAttributeKeys.push(''+value+'@'+addElement); } - }else{ //not view or edit + }else{ // not view or edit if(!clone.className.includes("child_single")){ - clone.className += ' child_single'; //here cloned is single element + clone.className += ' child_single'; // here cloned is single element } document.getElementById("div."+value).appendChild(clone); plainAttributeKeys.push(''+value+'@'+addElement); @@ -185,7 +187,7 @@ angular.module('abs').controller('dcaeMicroServiceController', if(layer > 4){ layer = 1 } - div.className += ' children_group border' + layer; //here is div with a group of children. + div.className += ' children_group border' + layer; // here is div with a group of children. } } var childElement = parentElement.firstElementChild; @@ -211,18 +213,27 @@ angular.module('abs').controller('dcaeMicroServiceController', var inputs = clone.getElementsByTagName("input"); var removeValues = []; for(var i=0; i<inputs.length; i++){ + plainAttributeKeys.push(inputs[i].id); if ($scope.temp.policy.ruleData!=undefined){ var checkValue = $scope.temp.policy.ruleData[inputs[i].id]; if (checkValue!=undefined && checkValue != "undefined"){ - document.getElementById(inputs[i].id).value = checkValue; - plainAttributeKeys.push(inputs[i].id); - } else { - plainAttributeKeys.push(inputs[i].id); + if(checkValue == "false"){ + document.getElementById(inputs[i].id).removeAttribute("checked"); + } + else if(checkValue == "true"){ + document.getElementById(inputs[i].id).setAttribute("checked", true); + }else{ + document.getElementById(inputs[i].id).value = checkValue; + } + } else { + if(inputs[i].type == "checkbox"){ + inputs[i].checked = false; } - }else { - plainAttributeKeys.push(inputs[i].id); } + }else { + document.getElementById(inputs[i].id).removeAttribute("checked"); } + } for(var i=0; i<selects.length; i++){ if ($scope.temp.policy.ruleData!=undefined){ @@ -408,16 +419,24 @@ angular.module('abs').controller('dcaeMicroServiceController', isInitViewEdit = true; var checkData = []; var data = []; - // If ruleData contains extra elements created by clicked add button + // If ruleData contains extra elements created by clicked add button if($scope.temp.policy.ruleData != null){ var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData); propNames.forEach(function(name) { + if(document.getElementById(name) != null){ + if(document.getElementById(name).getAttribute("class") == "onoffswitch-checkbox"){ + if($scope.temp.policy.ruleData[name] == "true"){ + document.getElementById(name).setAttribute("checked", true); + } + else{ + document.getElementById(name).removeAttribute("checked"); + } + } + } data.push(name); }); - - var extraElements = data; - - if(plainAttributeKeys != null){ + var extraElements = data; + if(plainAttributeKeys != null){ for(var b = 0; b < plainAttributeKeys.length; b++){ // Remove already populated elements from data array var newValue = plainAttributeKeys[b].split("*"); for(var a = 0; a < data.length; a++){ @@ -425,17 +444,15 @@ angular.module('abs').controller('dcaeMicroServiceController', extraElements.splice(a, 1); } } - } - - //--- Populate these extra elements created by clicked add button + } + // --- Populate these extra elements created by clicked add button for(var a = 0; a < extraElements.length; a++){ if(extraElements[a].includes("@")){ var index = extraElements[a].lastIndexOf("@"); if(index > 0){ // Get the number after @ var n = getNumOfDigits(extraElements[a], index+1); - - var key = extraElements[a].substring(0, index+n+1); //include @x in key also by n+2 since x can be 1,12, etc + var key = extraElements[a].substring(0, index+n+1); // include @x in key also by n+2 since x can be 1,12,etc checkData.push(key); } } @@ -443,19 +460,17 @@ angular.module('abs').controller('dcaeMicroServiceController', var unique = checkData.filter(onlyUnique); var parentLevelElements = []; if(unique){ - //--- get all root level exta elments first (only contains one "@") + // --- get all root level exta elments first (only contains one "@") for(var i =0; i < unique.length; i++){ var firstIndex = unique[i].indexOf("@"); var lastIndex = unique[i].lastIndexOf("@"); - if(firstIndex == lastIndex){ + if(firstIndex == lastIndex){ var newKey = unique[i].substring(0, firstIndex); parentLevelElements.push(newKey); unique[i] = "*processed*"; } - } } - - + } for (var i = 0; i < $scope.labelManyKeys.length; i++) { var label = $scope.labelManyKeys[i]; if(parentLevelElements){ @@ -467,7 +482,7 @@ angular.module('abs').controller('dcaeMicroServiceController', } } - //if no layout order info, keep the process as before + // if no layout order info, keep the process as before if(!dataOrderInfo){ for(var i =0; i < unique.length; i++){ if(unique[i] != "*processed*"){ @@ -475,7 +490,7 @@ angular.module('abs').controller('dcaeMicroServiceController', var newKey = unique[i].substring(0, index); var newElement = document.getElementById("div."+unique[j]); - //check weather it has been created already + // check weather it has been created already if(newElement != null){ continue; }else{ @@ -491,11 +506,11 @@ angular.module('abs').controller('dcaeMicroServiceController', } } }else{ - //---reset to default + // ---reset to default dataOrderInfo = []; $scope.labelManyKeys = []; - //---process none labels + // ---process none labels for (var j = 0; j < unique.length; j++){ if(unique[j] != "*processed*"){ // if not created yet @@ -505,7 +520,7 @@ angular.module('abs').controller('dcaeMicroServiceController', var newElement = document.getElementById("div."+unique[j]); - //check weather it has been created already + // check weather it has been created already if(newElement != null){ continue; }else{ @@ -514,7 +529,7 @@ angular.module('abs').controller('dcaeMicroServiceController', continue; } } - //if not created yet, then create it. + // if not created yet,then create it. addNewChoice(newKey); } @@ -600,7 +615,7 @@ angular.module('abs').controller('dcaeMicroServiceController', enumAttributes = enumAttributes.replace(/ /g, ''); var dropListAfterCommaSplit = enumAttributes.split(splitEqual); listemunerateValues = dropListAfterCommaSplit[1].split(splitComma); - //enumKeyList.push(attribute); + // enumKeyList.push(attribute); return listemunerateValues; } @@ -652,11 +667,11 @@ angular.module('abs').controller('dcaeMicroServiceController', if($scope.dataOrderInfo){ var labelObject = {"label" : key, "level" : label, "array" : array}; - //save it to the list + // save it to the list $scope.layOutOnlyLableList.push(labelObject); }else { - //call label layout + // call label layout $scope.labelLayout(label, key, array ); } @@ -675,11 +690,11 @@ angular.module('abs').controller('dcaeMicroServiceController', if($scope.dataOrderInfo){ var labelObject = {"label" : newKey, "level" : baseLevel, "array" : array}; - //save it to the list + // save it to the list $scope.layOutOnlyLableList.push(labelObject); }else { - //call label layout + // call label layout $scope.labelLayout(baseLevel, newKey, array ); } @@ -716,7 +731,7 @@ angular.module('abs').controller('dcaeMicroServiceController', isRequired = true; } - var subAttributes = $scope.dcaeModelData.sub_attributes; + var subAttributes = $scope.dcaeModelData.subAttributes; if(subAttributes){ var jsonObject = JSON.parse(subAttributes); @@ -806,10 +821,10 @@ angular.module('abs').controller('dcaeMicroServiceController', if (layOutData[key].includes('dictionary-')){ var list = getDictionary(layOutData[key].split('dictionary-')[1]); }else{ - //--- get dropdown values from enumValues + // --- get dropdown values from enumValues var list = getList(layOutData[key]); } - if (list.length===0){ //not dropdown element + if (list.length===0){ // not dropdown element if($scope.dataOrderInfo){ elementOrderNum++; elementObject = {"id": elementOrderNum,"attributekey" : attributekey, "array": array, "attirbuteLabel" : attirbuteLabel, "defaultValue": defaultValue,"isRequired": isRequired, "type":"text", "description":description}; @@ -865,7 +880,7 @@ angular.module('abs').controller('dcaeMicroServiceController', var layOutElementList = $scope.layOutElementList; var labelList = $scope.layOutOnlyLableList; - //reset to default + // reset to default elementOrderNum = 0; $scope.layOutElementList = []; $scope.layOutOnlyLableList = []; @@ -883,7 +898,7 @@ angular.module('abs').controller('dcaeMicroServiceController', for (var i = 0; i < orderValue.length; i++) { var key = orderValue[i].trim(); - //--- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array}; + // --- Create labels first {"label" : newKey, "level" : baseLevel, "array" : array}; if(labelList){ for (var k = 0; k < labelList.length; k++){ @@ -893,13 +908,13 @@ angular.module('abs').controller('dcaeMicroServiceController', if(key == label){ $scope.labelLayout(level, label, array); - //in case to have duplicate label names + // in case to have duplicate label names labelList[k].label = "*processed*"; break; } } } - //--- then layout each element based on its order defined in YAML file + // --- then layout each element based on its order defined in YAML file for (var j = 0; j < layOutElementList.length; j++) { var attributekey = layOutElementList[j].attributekey.toString().trim(); @@ -919,7 +934,7 @@ angular.module('abs').controller('dcaeMicroServiceController', } - //in case to have duplicate attribute names + // in case to have duplicate attribute names layOutElementList[j].attributekey = "*processed*"; break; } @@ -938,7 +953,7 @@ angular.module('abs').controller('dcaeMicroServiceController', var requiredLabName = ""; if (matching.includes(attibuteKey)){ labeltext = document.createTextNode(attibuteKey + "*!"); - isRequired = true; //set required as true for matching element + isRequired = true; // set required as true for matching element }else { if(isRequired){ requiredLabName = attibuteKey + " * "; @@ -967,12 +982,12 @@ angular.module('abs').controller('dcaeMicroServiceController', textField.setAttribute("type" , "number"); textField.setAttribute("step" , "any"); - }else if(dataType == "boolean"){ //gw1218 testing boolean + }else if(dataType == "boolean"){ // gw1218 testing boolean var booleanDiv = document.createElement("div"); booleanDiv.setAttribute("class" , "onoffswitch"); - //var checkField = document.createElement("INPUT"); + // var checkField = document.createElement("INPUT"); textField.setAttribute("type" , "checkbox"); textField.setAttribute("name" , "onoffswitch"); textField.setAttribute("class" , "onoffswitch-checkbox"); @@ -982,7 +997,7 @@ angular.module('abs').controller('dcaeMicroServiceController', }else{ textField.removeAttribute("checked"); } - + textField.setAttribute("ng-click" , "validateOnAndOff('"+labelValue +attibuteKey+"', $event)"); var booleanlabel = document.createElement("Label"); booleanlabel.setAttribute("class" , "onoffswitch-label"); booleanlabel.setAttribute("for" , ''+labelValue +attibuteKey+''); @@ -1002,7 +1017,7 @@ angular.module('abs').controller('dcaeMicroServiceController', document.getElementById(divID).appendChild(label); document.getElementById(divID).appendChild(booleanDiv); - //return; + // return; } else{ textField.setAttribute("type" , dataType); } @@ -1043,7 +1058,7 @@ angular.module('abs').controller('dcaeMicroServiceController', document.getElementById(divID).appendChild(removeButton); document.getElementById(divID).appendChild(label); id = "div."+labelValue+attibuteKey; - //var divTag = document.createElement("div"); + // var divTag = document.createElement("div"); divTag.setAttribute("id", id); document.getElementById(divID).appendChild(divTag); textField.className += ' first_child'; @@ -1094,7 +1109,7 @@ angular.module('abs').controller('dcaeMicroServiceController', if(layer > 4){ layer = 1 } - firstChild_element.className += ' children_group border' + layer; //here is div with a group of children. + firstChild_element.className += ' children_group border' + layer; // here is div with a group of children. } } } @@ -1112,7 +1127,8 @@ angular.module('abs').controller('dcaeMicroServiceController', } if($scope.temp.policy.ruleData != null){ - //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey]; + // document.getElementById(checkKey).value = + // $scope.temp.policy.ruleData[checkKey]; if (attributeManyKey){ var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey); if($scope.temp.policy.ruleData[newCheckKey +'@0'] != undefined && $scope.temp.policy.ruleData[newCheckKey +'@0'] != "undefined"){ @@ -1131,19 +1147,32 @@ angular.module('abs').controller('dcaeMicroServiceController', plainAttributeKeys.push(labelValue + attibuteKey+'*'+"boolean"); } }; - + + $scope.validateOnAndOff = function(id , value) { + console.log(id, value); + if (value.target.checked) { + document.getElementById(id).setAttribute("checked", true); + } else { + document.getElementById(id).removeAttribute("checked"); + } + }; + $scope.labelManyKeys = []; $scope.labelLayout = function(labelValue, lableName, labelManyKey ){ var label = document.createElement("Label") var divID = labelValue; - + if (labelValue.endsWith('.')){ + var workingLabel = labelValue.substring(0, labelValue.length-1); + }else { + var workingLabel = labelValue; + } if (labelValue.length < 1){ divID = "DynamicTemplate"; } else if (labelValue.endsWith('.')){ var divID = 'div.'+ labelValue.substring(0, labelValue.length-1); } - var subAttributes = $scope.dcaeModelData.sub_attributes; + var subAttributes = $scope.dcaeModelData.subAttributes; var jsonObject = JSON.parse(subAttributes); var lablInfo = findVal(jsonObject, lableName); var star = ""; @@ -1193,7 +1222,7 @@ angular.module('abs').controller('dcaeMicroServiceController', if(layer > 4){ layer = 1 } - divTag.className += ' children_group border' + layer; //here is div with a group of children. + divTag.className += ' children_group border' + layer; // here is div with a group of children. } if(required){ divTag.setAttribute("required", required); @@ -1214,7 +1243,7 @@ angular.module('abs').controller('dcaeMicroServiceController', if(layer > 4){ layer = 1 } - divTag.className += ' children_group border' + layer; //here is div with a group of children. + divTag.className += ' children_group border' + layer; // here is div with a group of children. } if(required){ divTag.setAttribute("required", required); @@ -1238,8 +1267,8 @@ angular.module('abs').controller('dcaeMicroServiceController', var label = document.createElement("Label") - var refAttributes = $scope.dcaeModelData.ref_attributes; - if(isRequired != true && refAttributes){ //check refAttributes also + var refAttributes = $scope.dcaeModelData.refAttributes; + if(isRequired != true && refAttributes){ // check refAttributes also var refAttributesList = refAttributes.split(splitComma); for (k = 0; k < refAttributesList.length; k++){ var refAttribute = refAttributesList[k].split(splitEqual); @@ -1252,8 +1281,9 @@ angular.module('abs').controller('dcaeMicroServiceController', if (matching.includes(attributeName)){ var labeltext = document.createTextNode(attributeName + "*!"); label.appendChild(labeltext); - isRequired = true; //set required as true for matching element + isRequired = true; // set required as true for matching element }else { + var labeltext = document.createTextNode(attributeName); if(isRequired){ var requiredLabName = attributeName+ " * "; labeltext = document.createTextNode(requiredLabName); @@ -1452,7 +1482,7 @@ angular.module('abs').controller('dcaeMicroServiceController', if (elumentLocation > 1){ enumKey = keySplit[keySplit.length - 1]; } - //check it is undefined or not + // check it is undefined or not if (enumKeyList != undefined && enumKeyList.indexOf(enumKey) != -1){ if (splitPlainAttributeKey[1]!= undefined && splitPlainAttributeKey[1].indexOf("true") !== -1){ var multiSlect = []; @@ -1474,18 +1504,15 @@ angular.module('abs').controller('dcaeMicroServiceController', } } } else { - if(searchElement.value != null){ - jsonPolicy[key]= searchElement.value; - if(splitPlainAttributeKey[1] == "boolean"){ - jsonPolicy[key]= false; - for(var i=0; i<booleanTrueElements.length; i++){ - if(booleanTrueElements[i] == key){ - jsonPolicy[key]= true; + if(searchElement.value != null){ + if(searchElement.parentElement.children[0].checked == true){ + jsonPolicy[key]= searchElement.checked; } + else{ + jsonPolicy[key]= window.btoa(searchElement.value); } - } } - } + } } } } @@ -1510,6 +1537,8 @@ angular.module('abs').controller('dcaeMicroServiceController', if($scope.pushStatus=="successPush"){ Notification.success("Policy pushed successfully"); } + $scope.temp.policy.readOnly = 'true'; + $scope.savebutton = true; Notification.success("Policy Saved Successfully."); }else if ($scope.data == 'PolicyExists'){ $scope.savebutton = true; @@ -1558,7 +1587,12 @@ angular.module('abs').controller('dcaeMicroServiceController', } } else { if(searchElement.value != null){ - jsonPolicy[key]= searchElement.value; + if(searchElement.parentElement.children[0].checked == true){ + jsonPolicy[key]= searchElement.checked; + } + else{ + jsonPolicy[key]= searchElement.value; + } if(searchElement.getAttribute("required")){ if(!searchElement.value){ return; diff --git a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java index cb7ffbb2f..8966f47a9 100644 --- a/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java +++ b/POLICY-SDK-APP/src/test/java/org/onap/policy/controller/CreateDcaeMicroServiceControllerTest.java @@ -30,12 +30,10 @@ import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; - import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.fge.jackson.JsonLoader; - import java.io.BufferedReader; import java.io.File; import java.io.FileInputStream; @@ -47,11 +45,9 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; - import javax.servlet.ReadListener; import javax.servlet.ServletInputStream; import javax.servlet.http.HttpServletRequest; - 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; @@ -59,7 +55,6 @@ 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; - import org.junit.Before; import org.junit.Test; import org.onap.policy.common.logging.flexlogger.FlexLogger; @@ -167,15 +162,8 @@ public class CreateDcaeMicroServiceControllerTest { + "\"asdafadf\",\"guard\":\"True\",\"riskType\":\"sfsgs\",\"riskLevel\":\"1\"," + "\"priority\":\"1\",\"configName\":\"Search\",\"location\":\"Search\"," + "\"uuid\":\"Search\",\"policyScope\":\"PolicyScope_ssaaa123\"}}," - + "\"policyJSON\":{\"Correlation Priority\":\"testttt\",\"Correlation Window\":" - + "\"testttt\",\"Email Notification for failures\":\"sds@l.com\"," - + "\"Select Server Scope\":\"testttt\",\"Parent Correlation Name\":" - + "\"testttt\",\"Parent Correlation Traversal\":\"testttt\",\"logicalConnector\":" - + "\"OR\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.traversal\":\"testttt\"," - + "\"triggerSignature@0.signaturesAlarm.alarmSignatures@0.alarmSignature@0.VnfType\":" - + "\" testttt\",\"triggerSignature@0.signaturesAlarm.alarmSignatures@0." - + "alarmSignature@0.Contains\":\"AND\",\"triggerSignature@0.signaturesAlarm." - + "alarmSignatures@0.alarmSignature@0.FilterValue\":\"testttt\"}}"; + + "\"policyJSON\":{\"DCAEProcessingRules@0.processingRules_json\":" + + "\"eyJuYW1lIjogIkpvaG4iLCAiYWdlIjogIjI4IiwgImNpdHkiOiAiTmV3IFlvcmsifQ==\"}}"; configBodyString = "{\"service\":\"SniroPolicyEntityTest\",\"policyName\":\"someone\",\"description\":\"test\"," + "\"templateVersion\":\"1607\",\"version\":\"HD\",\"priority\":\"2\"," |