2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 angular.module('abs').controller('dcaeMicroServiceController', function ($scope, $window, $compile, PolicyAppService, modalService, $modal, Notification) {
22 $scope.isCheck = false;
23 $scope.savebutton = true;
24 $scope.finalPath = null;
26 // $scope.temp.policy.ttlDate = "2016-12-31";
27 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
28 if ($scope.temp.policy.configName == undefined){
29 $scope.isCheck = false;
31 $scope.isCheck = true;
34 $scope.isCheck = false;
37 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
39 $scope.data = JSON.parse(j.data);
40 console.log($scope.data);
41 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
42 console.log($scope.ecompNameDictionaryDatas);
44 console.log("failed");
47 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
49 $scope.data = JSON.parse(j.data);
50 console.log($scope.data);
51 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
52 console.log($scope.priorityDatas);
54 console.log("failed");
57 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
59 $scope.data = JSON.parse(j.data);
60 console.log($scope.data);
61 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
62 console.log($scope.groupPolicyScopeListDatas);
64 console.log("failed");
67 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
69 $scope.data = JSON.parse(j.data);
70 console.log($scope.data);
71 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
72 console.log($scope.microServiceCongigNameDictionaryDatas);
74 console.log("failed");
77 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
79 $scope.data = JSON.parse(j.data);
80 console.log($scope.data);
81 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
82 console.log($scope.microServiceLocationDictionaryDatas);
84 console.log("failed");
87 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
89 $scope.data = JSON.parse(j.data);
90 console.log($scope.data);
91 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
94 for(var i = 0; i < inputModelList.length; i++){
95 if(typeof unique[inputModelList[i]] == "undefined"){
96 unique[inputModelList[i]] = "";
97 uniqueList.push(inputModelList[i]);
100 $scope.microServiceModelsDictionaryDatas = uniqueList;
101 console.log($scope.microServiceModelsDictionaryDatas);
102 }, function (error) {
103 console.log("failed");
106 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
108 $scope.data = JSON.parse(j.data);
109 console.log($scope.data);
110 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
111 console.log($scope.dcaeUUIDDictionaryDatas);
112 }, function (error) {
113 console.log("failed");
116 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
118 $scope.data = JSON.parse(j.data);
119 console.log($scope.data);
120 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
121 console.log($scope.riskTypeDictionaryDatas);
122 }, function (error) {
123 console.log("failed");
126 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
128 $scope.data = JSON.parse(j.data);
129 console.log($scope.data);
130 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
131 console.log($scope.microServiceAttributeDictionaryDatas);
132 }, function (error) {
133 console.log("failed");
138 $scope.attributeDatas = [{"attributes" : $scope.choices}];
140 $scope.addNewChoice = function(value) {
142 if(value != undefined){
143 if (value.startsWith('div.')){
144 value = value.replace('div.','');
146 var parentElement = document.getElementById("div."+value);
147 var div = document.getElementById(value+"@0");
149 var clone = div.cloneNode(true);
150 var addElement = parentElement.childElementCount + 1;
151 clone.id = ''+value+'@'+addElement;
153 document.getElementById("div."+value).appendChild(clone);
154 plainAttributeKeys.push(''+value+'@'+addElement);
156 div = document.getElementById("div."+value+"@0");
157 var childElement = parentElement.firstElementChild;
158 var countParent = parentElement.childElementCount;
159 var childElementString = childElement.innerHTML;
160 var find = value+"@0";
161 var re = new RegExp(find, 'g');
162 childElementString = childElementString.replace(re,value+'@' + countParent);
163 var clone = childElement.cloneNode(true);
164 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
165 var childId = parentElement.childNodes[ii].id;
166 if(ii = parentElement.childNodes.length){
167 var childnewId = childId.slice(0, -1);
168 var count = childId.slice(-1);
171 var countvalue = parseInt(count) + 1;
172 clone.id = childnewId+countvalue;
174 clone.innerHTML=childElementString;
175 document.getElementById("div."+value).appendChild(clone);
176 var selects = clone.getElementsByTagName("select");
177 var inputs = clone.getElementsByTagName("input");
178 var removeValues = [];
179 for(var i=0; i<inputs.length; i++){
180 if ($scope.temp.policy.ruleData!=undefined){
181 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
182 if (checkValue!=undefined){
183 if($scope.temp.policy.ruleData != null){
184 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
185 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
186 plainAttributeKeys.push(inputs[i].id);
189 // removeValues.push(inputs[i].id);
190 plainAttributeKeys.push(inputs[i].id);
193 plainAttributeKeys.push(inputs[i].id);
197 for(var i=0; i<selects.length; i++){
198 if ($scope.temp.policy.ruleData!=undefined){
199 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
200 if (checkValue!=undefined){
201 if($scope.temp.policy.ruleData != null){
202 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
203 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
204 plainAttributeKeys.push(selects[i].id);
207 plainAttributeKeys.push(selects[i].id);
210 plainAttributeKeys.push(selects[i].id);
214 for (var k=0; k<removeValues.length; k++){
215 var elem = document.getElementById(removeValues[k]);
216 elem.parentNode.removeChild(elem);
218 var ele = angular.element(document.getElementById("div."+value));
219 $compile(ele.contents())($scope);
225 $scope.removeChoice = function(value) {
227 if(value != undefined){
228 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
232 $scope.pullVersion = function(serviceName) {
233 console.log(serviceName);
234 if(serviceName != undefined){
235 var uuu = "policyController/getModelServiceVersioneData.htm";
236 var postData={policyData: serviceName};
241 contentType: 'application/json',
242 data: JSON.stringify(postData),
243 success : function(data){
244 $scope.$apply(function(){
245 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
248 error : function(data){
249 alert("Error While Retriving the Template Layout Pattren.");
256 var splitEqual = '=';
257 var splitComma = ',';
258 var splitcolon = ':';
259 var splitsemicolon = ";";
260 var splitEnum = "],";
261 var plainAttributeKeys = [];
263 var enumKeyList = [];
264 var dictionaryList = [];
265 var dictionaryNameList = [];
266 $scope.addDataToFields = function(serviceName, version){
267 if(serviceName != null && version !=null){
268 var service=serviceName+"-v"+version;
269 var myNode = document.getElementById("DynamicTemplate");
270 myNode.innerHTML = '';
271 var uuu = "policyController/getDCAEMSTemplateData.htm";
272 var postData={policyData: service};
277 contentType: 'application/json',
278 data: JSON.stringify(postData),
279 success : function(data){
280 $scope.$apply(function(){
281 $scope.addNewChoice();
282 var plainAttributeKeys = [];
283 $scope.dcaeModelData = data[0].dcaeModelData;
284 $scope.dcaeJsonDate = data[0].jsonValue;
285 var attributes = $scope.dcaeModelData.attributes;
286 var refAttributes = $scope.dcaeModelData.ref_attributes;
287 var subAttributes = $scope.dcaeModelData.sub_attributes;
288 var enumAttributes = $scope.dcaeModelData.enumValues;
289 var annotation = $scope.dcaeModelData.annotation;
290 var dictionary = $scope.microServiceAttributeDictionaryDatas;
292 if (annotation == null || annotation.length<1){
293 $scope.isCheck = true;
295 $scope.isCheck = false;
296 var annoationList = annotation.split(splitComma);
297 for (k = 0; k < annoationList.length; k++){
298 var splitAnnotation = annoationList[k].split(splitEqual);
299 if (splitAnnotation[1].includes("matching-true")){
300 matching.push(splitAnnotation[0].trim());
306 if (dictionary!= null || dictionary>1){
307 if (dictionary!= null || dictionary.length>1){
308 for (m=0; m < dictionary.length; m += 1){
309 var keyCompare = dictionary[m].name;
310 var valueCompare = dictionary[m].value;
311 var valueModel = dictionary[m].modelName;
312 var conpairService = serviceName;
313 if (valueModel.includes('-v')){
314 conpairService = service;
316 if(valueModel.localeCompare(conpairService) == 0){
317 console.log(valueCompare);
318 dictionaryList.push(dictionary[m]);
319 if (!dictionaryNameList.includes(dictionary[m].name)){
320 dictionaryNameList.push(dictionary[m].name)
327 $scope.temp.policy.ruleGridData = [];
329 $scope.jsonLayout($scope.dcaeJsonDate);
332 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
335 if($scope.temp.policy.ruleData != null){
336 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
337 propNames.forEach(function(name) {
340 for(a = 0; a < data.length; a++){
341 var splitPlainAttributeKey1 = data[a].split(".");
342 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
343 var key = splitPlainAttributeKey1[0];
347 var unique = checkData.filter(onlyUnique);
348 for(i =0; i < unique.length; i++){
349 if(unique[i].indexOf("@0") == -1){
350 var finalkey = unique[i].split("@")[0];
351 $scope.addNewChoice(finalkey);
356 var ele = angular.element(document.getElementById("DynamicTemplate"));
357 $compile(ele.contents())($scope);
360 error : function(data){
361 alert("Error While Retriving the Template Layout Pattren.");
367 function getDictionary(attribute){
368 var dicName = attribute;
370 if(attribute.includes(":")){
371 dicName = attribute.split(":")[0];
374 var dictionaryRegExp = new RegExp(dicName);
375 listemunerateValues = [];
376 if (dictionaryRegExp.test(dictionaryNameList)) {
377 for (p=0; p < dictionaryList.length; p += 1) {
378 if (dicName == dictionaryList[p].name) {
379 listemunerateValues.push(dictionaryList[p].value);
383 return listemunerateValues;
386 function getList(attribute) {
388 var baseEnum = $scope.dcaeModelData.enumValues;
389 var enumList = baseEnum.split(splitEnum);
391 var patternTest = new RegExp(attribute);
392 for (k=0; k < enumList.length; k += 1){
393 if(patternTest.test(enumList[k]) == true){
394 enumAttributes = enumList[k].trim();
399 enumAttributes = enumAttributes.replace("[", "");
400 enumAttributes = enumAttributes.replace("]", "");
401 enumAttributes = enumAttributes.replace(/ /g, '');
403 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
404 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
406 enumKeyList.push(attribute);
408 return listemunerateValues;
414 function getBooleanList(){
415 var booleanList = [];
416 booleanList.push(true);
417 booleanList.push(false);
422 function isArray(arrayTest) {
423 return Object.prototype.toString.call(arrayTest) === '[object Array]';
427 function deconstructJSON(dataTest, level , name) {
430 var stringValue = "java.lang.String";
431 var intValue = "int";
432 var double = "double";
433 var boolean = "boolean";
434 var baseLevel = level;
436 if (name.length > 1){
437 label = label + name + '.';
440 for (key in dataTest) {
441 array = isArray(dataTest[key]);
442 console.log(key , dataTest[key]);
443 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
444 if (array==false && key!=="0"){
445 $scope.labelLayout(label, key, array );
448 if (array == true && key!=0){
452 if (lableList.length > 0){
456 var newKey = lableList.pop();
457 $scope.labelLayout(baseLevel, newKey, array );
459 label = baseLevel + newKey + '@0.';
461 label = baseLevel + newKey + '.';
464 deconstructJSON(dataTest[key] , label, key);
466 var attirbuteLabel = label;
468 var isRequired = false;
469 if (dataTest[key].includes('defaultValue-')){
470 defaultValue = dataTest[key].split('defaultValue-')[1];
475 attributekey = lableList.pop();
476 attirbuteLabel = baseLevel;
478 attributekey = key.split();
481 if (dataTest[key].includes('required-true')){
484 console.log("attirbuteLabel = " + attirbuteLabel);
485 switch (dataTest[key].split(splitcolon)[0]){
487 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
490 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
493 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
496 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
499 if (dataTest[key].includes('dictionary-')){
500 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
502 var list = getList(dataTest[key]);
504 if (list.length===0){
505 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
507 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
515 $scope.jsonLayout = function(dataTest){
516 deconstructJSON(dataTest , "", "");
520 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
521 $scope.temp.policy.ruleGridData.push(attibuteKey);
522 var br = document.createElement("BR");
524 var label = document.createElement("Label");
525 var labeltext = null;
526 var requiredLabName = "";
527 if (matching.includes(attibuteKey)){
528 labeltext = document.createTextNode(attibuteKey + "*!");
530 //var labeltext = document.createTextNode(refattributeLabel);
532 requiredLabName = attibuteKey + " *";
533 labeltext = document.createTextNode(requiredLabName);
535 labeltext = document.createTextNode(attibuteKey);
540 var divID = labelValue;
542 if (labelValue.length < 1){
543 divID = "DynamicTemplate";
544 }else if (labelValue.endsWith('.')){
545 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
548 label.appendChild(labeltext);
550 var textField = document.createElement("INPUT");
552 textField.setAttribute("class" , "form-control");
553 textField.setAttribute("type" , "text");
554 textField.setAttribute("style" , "width:300px;");
555 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
557 if(attributeManyKey){
558 checkKey = labelValue + attibuteKey+'@0';
559 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
560 var divTag = document.createElement("div");
561 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
562 var addButton = document.createElement("BUTTON");
563 var buttonaddLabel = document.createTextNode("+");
564 addButton.appendChild(buttonaddLabel);
565 addButton.setAttribute("id", labelValue + attibuteKey);
566 addButton.setAttribute("class", "btn btn-default");
567 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
568 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
569 var removeButton = document.createElement("BUTTON");
570 var buttonremoveLabel = document.createTextNode("-");
571 removeButton.appendChild(buttonremoveLabel);
572 removeButton.setAttribute("class", "btn btn-default");
573 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
574 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
575 document.getElementById(divID).appendChild(addButton);
576 document.getElementById(divID).appendChild(removeButton);
577 document.getElementById(divID).appendChild(label);
578 document.getElementById(divID).appendChild(textField);
579 document.getElementById(divID).appendChild(br);
580 document.getElementById(divID).appendChild(divTag);
582 checkKey = labelValue + attibuteKey;
583 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
584 if(requiredLabName.includes("*")){
585 textField.setAttribute("required", "true");
587 document.getElementById(divID).appendChild(label);
588 document.getElementById(divID).appendChild(textField);
589 document.getElementById(divID).appendChild(br);
593 if (defaultValue.length > 0){
594 if(defaultValue.includes(":")){
595 defaultValue = defaultValue.split(":")[0];
596 if(defaultValue === "NA") {
600 document.getElementById(checkKey).value = defaultValue;
603 if($scope.temp.policy.ruleData != null){
604 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
605 if (attributeManyKey){
606 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
607 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
610 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
614 $scope.addNewChoice(newCheckKey);
615 document.getElementById(newCheckKey+'@'+i).value = newValue;
621 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
624 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
627 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
628 var label = document.createElement("Label")
629 var divID = labelValue;
630 if (labelValue.endsWith('.')){
631 var workingLabel = labelValue.substring(0, labelValue.length-1);
633 var workingLabel = labelValue;
636 if (labelValue.length < 1){
637 divID = "DynamicTemplate";
638 } else if (labelValue.endsWith('.')){
639 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
642 var labeltext = document.createTextNode(lableName);
644 label.appendChild(labeltext);
647 var addButton = document.createElement("BUTTON");
648 var buttonLabel = document.createTextNode("+");
649 addButton.appendChild(buttonLabel);
650 addButton.setAttribute("class", "btn btn-default");
651 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
652 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
653 var removeButton = document.createElement("BUTTON");
654 var buttonremoveLabel = document.createTextNode("-");
655 removeButton.appendChild(buttonremoveLabel);
656 removeButton.setAttribute("class", "btn btn-default");
657 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
658 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
659 document.getElementById(divID).appendChild(addButton);
660 document.getElementById(divID).appendChild(removeButton);
661 document.getElementById(divID).appendChild(label);
662 var id = "div."+labelValue+lableName;
663 var divTag = document.createElement("div");
664 divTag.setAttribute("id", id);
665 document.getElementById(divID).appendChild(divTag);
667 var divTag = document.createElement("div");
668 divTag.setAttribute("id", id +'@0');
669 document.getElementById(id).appendChild(divTag);
671 var divTag = document.createElement("div");
672 divTag.setAttribute("id", "div."+labelValue+lableName);
673 document.getElementById(divID).appendChild(label);
674 document.getElementById(divID).appendChild(divTag);
678 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
679 var br = document.createElement("BR");
681 if (labelLevel.length < 1){
682 var divID = "DynamicTemplate";
683 } else if (labelLevel.endsWith('.')){
684 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
688 var label = document.createElement("Label")
689 if (matching.includes(attributeName)){
690 var labeltext = document.createTextNode(attributeName + "*!");
692 var labeltext = document.createTextNode(attributeName);
694 label.appendChild(labeltext);
696 var listField = document.createElement("SELECT");
697 listField.setAttribute("class" , "form-control");
698 listField.setAttribute("style" , "width:300px;");
699 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
701 for (i=0; i < listemunerateValues.length; i += 1) {
702 option = document.createElement('option');
703 option.setAttribute('value', listemunerateValues[i]);
704 option.appendChild(document.createTextNode(listemunerateValues[i]));
705 listField.appendChild(option);
707 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');;
708 document.getElementById(divID).appendChild(label);
709 document.getElementById(divID).appendChild(br);
712 document.getElementById(divID).appendChild(listField).multiple = true;
713 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
715 document.getElementById(divID).appendChild(listField).multiple = false;
716 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
719 if($scope.temp.policy.ruleData != null){
721 document.getElementById(labelLevel +attributeName).options[0].selected = false;
722 for (i=0; i < listemunerateValues.length; i += 1) {
723 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
724 if (testValue === undefined){
725 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
727 var location = listemunerateValues.indexOf(testValue);
729 document.getElementById(labelLevel +attributeName).options[location].selected = true;
733 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
739 function onlyUnique(value, index, self) {
740 return self.indexOf(value) === index;
744 function checkDictionary(value){
745 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
746 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
752 $scope.savePolicy = function(policy){
753 $scope.savebutton = false;
757 if(plainAttributeKeys != null){
758 for(a = 0; a < plainAttributeKeys.length; a++){
759 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
760 console.log(splitPlainAttributeKey[1]);
761 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
762 var key = splitPlainAttributeKey[0];
763 if(searchElement == null){
764 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
765 key = splitPlainAttributeKey[0]+'@0';
766 }else if (searchElement.nodeName == 'BUTTON'){
767 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
768 key = splitPlainAttributeKey[0]+'@0';
770 if(searchElement != null){
771 var keySplit = key.split(dot);
772 var elumentLocation = keySplit.length;
774 if (elumentLocation > 1){
775 enumKey = keySplit[keySplit.length - 1];
777 var aWhiteSpace = " ";
778 if (enumKeyList.indexOf(enumKey) != -1){
779 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
781 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
782 multiSlect.push(searchElement.selectedOptions[i].value);
784 jsonPolicy[key]= multiSlect;
786 //set a space due to empty value caused JSON format error in PolicyRestAdapter and remove it in back-end.
787 if(searchElement.value == ""){
788 searchElement.value = aWhiteSpace;
790 console.log(" searchElement.value = > " + searchElement.value);
791 jsonPolicy[key]= searchElement.value;
794 if(searchElement.value != null){
795 //set a default value due to empty value caused JSON format error in PolicyRestAdapter
796 if(searchElement.value == ""){
797 searchElement.value = aWhiteSpace;
799 console.log(" searchElement.value = > " + searchElement.value);
800 jsonPolicy[key]= searchElement.value;
806 var uuu = "policycreation/save_policy";
807 var postData={policyData: policy, policyJSON : jsonPolicy};
812 contentType: 'application/json',
813 data: JSON.stringify(postData),
814 success : function(data){
815 $scope.$apply(function(){
816 $scope.data=data.policyData;
817 if($scope.data == 'success'){
818 $scope.temp.policy.readOnly = 'true';
819 $scope.safetyChecker = data.policyData.split("#")[2];
820 if ($scope.safetyChecker!=undefined) {
821 Notification.success($scope.safetyChecker);
823 $scope.pushStatus=data.policyData.split("&")[1];
824 if($scope.pushStatus=="successPush"){
825 Notification.success("Policy pushed successfully");
827 Notification.success("Policy Saved Successfully.");
828 }else if ($scope.data == 'PolicyExists'){
829 $scope.savebutton = true;
830 Notification.error("Policy Already Exists with Same Name in Scope.");
833 console.log($scope.data);
835 error : function(data){
836 Notification.error("Error Occured while saving Policy.");
841 $scope.validatePolicy = function(policy){
842 document.getElementById("validate").innerHTML = "";
846 if(plainAttributeKeys != null){
847 for(a = 0; a < plainAttributeKeys.length; a++){
848 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
849 console.log(splitPlainAttributeKey[1]);
850 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
851 var key = splitPlainAttributeKey[0];
852 if(searchElement == null){
853 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
854 key = splitPlainAttributeKey[0]+'@0';
855 }else if (searchElement.nodeName == 'BUTTON'){
856 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
857 key = splitPlainAttributeKey[0]+'@0';
859 if(searchElement != null){
860 if (enumKeyList.indexOf(key) != -1){
861 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
863 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
864 multiSlect.push(searchElement.selectedOptions[i].value);
866 jsonPolicy[key]= multiSlect;
868 jsonPolicy[key]= searchElement.value;
871 if(searchElement.value != null){
872 jsonPolicy[key]= searchElement.value;
873 if(searchElement.getAttribute("required")){
874 if(!searchElement.value){
883 var uuu = "policyController/validate_policy.htm";
884 var postData={policyData: policy, policyJSON : jsonPolicy};
889 contentType: 'application/json',
890 data: JSON.stringify(postData),
891 success : function(data){
892 $scope.$apply(function(){
893 $scope.validateData = data.data.replace(/\"/g, "");
894 $scope.data=data.data.substring(1,8);
895 var size = data.data.length;
896 if($scope.data == 'success'){
897 Notification.success("Validation Success.");
898 $scope.savebutton = false;
900 var displayWarning = data.data.substring(19,size - 1);
901 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
902 document.getElementById("validate").style.color = "white";
903 document.getElementById("validate").style.backgroundColor = "skyblue";
906 Notification.error("Validation Failed.");
907 document.getElementById("validate").innerHTML = $scope.validateData;
908 document.getElementById("validate").style.color = "white";
909 document.getElementById("validate").style.backgroundColor = "red";
910 $scope.savebutton = true;
914 console.log($scope.data);
916 error : function(data){
917 Notification.error("Validation Failed.");
918 $scope.savebutton = true;
923 function extend(obj, src) {
924 for (var key in src) {
925 if (src.hasOwnProperty(key)) obj[key] = src[key];