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', ['$scope', '$window', '$compile', 'PolicyAppService', 'policyNavigator', 'modalService', '$modal', 'Notification', function ($scope, $window, $compile, PolicyAppService, PolicyNavigator, modalService, $modal, Notification) {
23 $scope.policyNavigator;
24 $scope.isCheck = false;
25 $scope.savebutton = true;
26 $scope.refreshCheck = false;
28 $scope.refresh = function(){
29 if($scope.refreshCheck){
30 $scope.policyNavigator.refresh();
32 $scope.modal('createNewPolicy', true);
33 $scope.temp.policy = "";
36 $scope.modal = function(id, hide) {
37 return $('#' + id).modal(hide ? 'hide' : 'show');
40 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
41 if ($scope.temp.policy.configName == undefined){
42 $scope.isCheck = false;
44 $scope.isCheck = true;
47 $scope.isCheck = false;
50 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
52 $scope.data = JSON.parse(j.data);
53 console.log($scope.data);
54 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
55 console.log($scope.ecompNameDictionaryDatas);
57 console.log("failed");
60 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
62 $scope.data = JSON.parse(j.data);
63 console.log($scope.data);
64 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
65 console.log($scope.priorityDatas);
67 console.log("failed");
70 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
72 $scope.data = JSON.parse(j.data);
73 console.log($scope.data);
74 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
75 console.log($scope.groupPolicyScopeListDatas);
77 console.log("failed");
80 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
82 $scope.data = JSON.parse(j.data);
83 console.log($scope.data);
84 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
85 console.log($scope.microServiceCongigNameDictionaryDatas);
87 console.log("failed");
90 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
92 $scope.data = JSON.parse(j.data);
93 console.log($scope.data);
94 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
95 console.log($scope.microServiceLocationDictionaryDatas);
97 console.log("failed");
100 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
102 $scope.data = JSON.parse(j.data);
103 console.log($scope.data);
104 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
107 for(var i = 0; i < inputModelList.length; i++){
108 if(typeof unique[inputModelList[i]] == "undefined"){
109 unique[inputModelList[i]] = "";
110 uniqueList.push(inputModelList[i]);
113 $scope.microServiceModelsDictionaryDatas = uniqueList;
114 console.log($scope.microServiceModelsDictionaryDatas);
115 }, function (error) {
116 console.log("failed");
119 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
121 $scope.data = JSON.parse(j.data);
122 console.log($scope.data);
123 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
124 console.log($scope.dcaeUUIDDictionaryDatas);
125 }, function (error) {
126 console.log("failed");
129 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
131 $scope.data = JSON.parse(j.data);
132 console.log($scope.data);
133 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
134 console.log($scope.riskTypeDictionaryDatas);
135 }, function (error) {
136 console.log("failed");
139 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
141 $scope.data = JSON.parse(j.data);
142 console.log($scope.data);
143 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
144 console.log($scope.microServiceAttributeDictionaryDatas);
145 }, function (error) {
146 console.log("failed");
151 $scope.attributeDatas = [{"attributes" : $scope.choices}];
153 $scope.addNewChoice = function(value) {
155 if(value != undefined){
156 if (value.startsWith('div.')){
157 value = value.replace('div.','');
159 var parentElement = document.getElementById("div."+value);
160 var div = document.getElementById(value+"@0");
162 var clone = div.cloneNode(true);
163 var addElement = parentElement.childElementCount + 1;
164 clone.id = ''+value+'@'+addElement;
166 document.getElementById("div."+value).appendChild(clone);
167 plainAttributeKeys.push(''+value+'@'+addElement);
169 div = document.getElementById("div."+value+"@0");
170 var childElement = parentElement.firstElementChild;
171 var countParent = parentElement.childElementCount;
172 var childElementString = childElement.innerHTML;
173 var find = value+"@0";
174 var re = new RegExp(find, 'g');
175 childElementString = childElementString.replace(re,value+'@' + countParent);
176 var clone = childElement.cloneNode(true);
177 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
178 var childId = parentElement.childNodes[ii].id;
179 if(ii = parentElement.childNodes.length){
180 var childnewId = childId.slice(0, -1);
181 var count = childId.slice(-1);
184 var countvalue = parseInt(count) + 1;
185 clone.id = childnewId+countvalue;
187 clone.innerHTML=childElementString;
188 document.getElementById("div."+value).appendChild(clone);
189 var selects = clone.getElementsByTagName("select");
190 var inputs = clone.getElementsByTagName("input");
191 var removeValues = [];
192 for(var i=0; i<inputs.length; i++){
193 if ($scope.temp.policy.ruleData!=undefined){
194 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
195 if (checkValue!=undefined){
196 if($scope.temp.policy.ruleData != null){
197 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
198 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
199 plainAttributeKeys.push(inputs[i].id);
202 // removeValues.push(inputs[i].id);
203 plainAttributeKeys.push(inputs[i].id);
206 plainAttributeKeys.push(inputs[i].id);
210 for(var i=0; i<selects.length; i++){
211 if ($scope.temp.policy.ruleData!=undefined){
212 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
213 if (checkValue!=undefined){
214 if($scope.temp.policy.ruleData != null){
215 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
216 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
217 plainAttributeKeys.push(selects[i].id);
220 plainAttributeKeys.push(selects[i].id);
223 plainAttributeKeys.push(selects[i].id);
227 for (var k=0; k<removeValues.length; k++){
228 var elem = document.getElementById(removeValues[k]);
229 elem.parentNode.removeChild(elem);
231 var ele = angular.element(document.getElementById("div."+value));
232 $compile(ele.contents())($scope);
238 $scope.removeChoice = function(value) {
240 if(value != undefined){
241 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
245 $scope.pullVersion = function(serviceName) {
246 console.log(serviceName);
247 if(serviceName != undefined){
248 var uuu = "policyController/getModelServiceVersioneData.htm";
249 var postData={policyData: serviceName};
254 contentType: 'application/json',
255 data: JSON.stringify(postData),
256 success : function(data){
257 $scope.$apply(function(){
258 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
261 error : function(data){
262 alert("Error While Retriving the Template Layout Pattren.");
269 var splitEqual = '=';
270 var splitComma = ',';
271 var splitcolon = ':';
272 var splitsemicolon = ";";
273 var splitEnum = "],";
274 var plainAttributeKeys = [];
276 var enumKeyList = [];
277 var dictionaryList = [];
278 var dictionaryNameList = [];
279 $scope.addDataToFields = function(serviceName, version){
280 if(serviceName != null && version !=null){
281 var service=serviceName+"-v"+version;
282 var myNode = document.getElementById("DynamicTemplate");
283 myNode.innerHTML = '';
284 var uuu = "policyController/getDCAEMSTemplateData.htm";
285 var postData={policyData: service};
290 contentType: 'application/json',
291 data: JSON.stringify(postData),
292 success : function(data){
293 $scope.$apply(function(){
294 $scope.addNewChoice();
295 var plainAttributeKeys = [];
296 $scope.dcaeModelData = data[0].dcaeModelData;
297 $scope.dcaeJsonDate = data[0].jsonValue;
298 var attributes = $scope.dcaeModelData.attributes;
299 var refAttributes = $scope.dcaeModelData.ref_attributes;
300 var subAttributes = $scope.dcaeModelData.sub_attributes;
301 var enumAttributes = $scope.dcaeModelData.enumValues;
302 var annotation = $scope.dcaeModelData.annotation;
303 var dictionary = $scope.microServiceAttributeDictionaryDatas;
305 if (annotation == null || annotation.length<1){
306 $scope.isCheck = true;
308 $scope.isCheck = false;
309 var annoationList = annotation.split(splitComma);
310 for (k = 0; k < annoationList.length; k++){
311 var splitAnnotation = annoationList[k].split(splitEqual);
312 if (splitAnnotation[1].includes("matching-true")){
313 matching.push(splitAnnotation[0].trim());
319 if (dictionary!= null || dictionary>1){
320 if (dictionary!= null || dictionary.length>1){
321 for (m=0; m < dictionary.length; m += 1){
322 var keyCompare = dictionary[m].name;
323 var valueCompare = dictionary[m].value;
324 var valueModel = dictionary[m].modelName;
325 var conpairService = serviceName;
326 if (valueModel.includes('-v')){
327 conpairService = service;
329 if(valueModel.localeCompare(conpairService) == 0){
330 console.log(valueCompare);
331 dictionaryList.push(dictionary[m]);
332 if (!dictionaryNameList.includes(dictionary[m].name)){
333 dictionaryNameList.push(dictionary[m].name)
340 $scope.temp.policy.ruleGridData = [];
342 $scope.jsonLayout($scope.dcaeJsonDate);
345 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
348 if($scope.temp.policy.ruleData != null){
349 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
350 propNames.forEach(function(name) {
353 for(a = 0; a < data.length; a++){
354 var splitPlainAttributeKey1 = data[a].split(".");
355 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
356 var key = splitPlainAttributeKey1[0];
360 var unique = checkData.filter(onlyUnique);
361 for(i =0; i < unique.length; i++){
362 if(unique[i].indexOf("@0") == -1){
363 var finalkey = unique[i].split("@")[0];
364 $scope.addNewChoice(finalkey);
369 var ele = angular.element(document.getElementById("DynamicTemplate"));
370 $compile(ele.contents())($scope);
373 error : function(data){
374 alert("Error While Retriving the Template Layout Pattren.");
380 function getDictionary(attribute){
381 var dicName = attribute;
383 if(attribute.includes(":")){
384 dicName = attribute.split(":")[0];
387 var dictionaryRegExp = new RegExp(dicName);
388 listemunerateValues = [];
389 if (dictionaryRegExp.test(dictionaryNameList)) {
390 for (p=0; p < dictionaryList.length; p += 1) {
391 if (dicName == dictionaryList[p].name) {
392 listemunerateValues.push(dictionaryList[p].value);
396 return listemunerateValues;
399 function getList(attribute) {
400 var enumName = attribute;
401 console.log("In getList: attribute => " + attribute);
403 if(attribute.includes(":")){
404 enumName = attribute.split(":")[0];
407 var baseEnum = $scope.dcaeModelData.enumValues;
408 var enumList = baseEnum.split(splitEnum);
410 var patternTest = new RegExp(enumName);
411 for (k=0; k < enumList.length; k += 1){
412 if(patternTest.test(enumList[k]) == true){
413 enumAttributes = enumList[k].trim();
418 enumAttributes = enumAttributes.replace("[", "");
419 enumAttributes = enumAttributes.replace("]", "");
420 enumAttributes = enumAttributes.replace(/ /g, '');
421 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
422 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
423 //enumKeyList.push(attribute);
424 return listemunerateValues;
430 function getBooleanList(){
431 var booleanList = [];
432 booleanList.push(true);
433 booleanList.push(false);
438 function isArray(arrayTest) {
439 return Object.prototype.toString.call(arrayTest) === '[object Array]';
443 function deconstructJSON(dataTest, level , name) {
446 var stringValue = "java.lang.String";
447 var intValue = "int";
448 var double = "double";
449 var boolean = "boolean";
450 var baseLevel = level;
452 if (name.length > 1){
453 label = label + name + '.';
456 for (key in dataTest) {
457 array = isArray(dataTest[key]);
458 console.log(key , dataTest[key]);
459 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
460 if (array==false && key!=="0"){
461 $scope.labelLayout(label, key, array );
464 if (array == true && key!=0){
468 if (lableList.length > 0){
472 var newKey = lableList.pop();
473 $scope.labelLayout(baseLevel, newKey, array );
475 label = baseLevel + newKey + '@0.';
477 label = baseLevel + newKey + '.';
480 deconstructJSON(dataTest[key] , label, key);
482 var attirbuteLabel = label;
484 var isRequired = false;
485 if (dataTest[key].includes('defaultValue-')){
486 defaultValue = dataTest[key].split('defaultValue-')[1];
491 attributekey = lableList.pop();
492 attirbuteLabel = baseLevel;
494 attributekey = key.split();
497 if (dataTest[key].includes('required-true')){
500 console.log("attirbuteLabel = " + attirbuteLabel);
501 switch (dataTest[key].split(splitcolon)[0]){
503 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
506 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
509 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
512 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
515 if (dataTest[key].includes('dictionary-')){
516 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
518 var list = getList(dataTest[key]);
520 if (list.length===0){
521 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
523 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
531 $scope.jsonLayout = function(dataTest){
532 deconstructJSON(dataTest , "", "");
536 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
537 $scope.temp.policy.ruleGridData.push(attibuteKey);
538 var br = document.createElement("BR");
540 var label = document.createElement("Label");
541 var labeltext = null;
542 var requiredLabName = "";
543 if (matching.includes(attibuteKey)){
544 labeltext = document.createTextNode(attibuteKey + "*!");
546 //var labeltext = document.createTextNode(refattributeLabel);
548 requiredLabName = attibuteKey + " *";
549 labeltext = document.createTextNode(requiredLabName);
551 labeltext = document.createTextNode(attibuteKey);
556 var divID = labelValue;
558 if (labelValue.length < 1){
559 divID = "DynamicTemplate";
560 }else if (labelValue.endsWith('.')){
561 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
564 label.appendChild(labeltext);
566 var textField = document.createElement("INPUT");
568 textField.setAttribute("class" , "form-control");
569 textField.setAttribute("type" , "text");
570 textField.setAttribute("style" , "width:300px;");
571 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
573 if(attributeManyKey){
574 checkKey = labelValue + attibuteKey+'@0';
575 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
576 var divTag = document.createElement("div");
577 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
578 var addButton = document.createElement("BUTTON");
579 var buttonaddLabel = document.createTextNode("+");
580 addButton.appendChild(buttonaddLabel);
581 addButton.setAttribute("id", labelValue + attibuteKey);
582 addButton.setAttribute("class", "btn btn-default");
583 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
584 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
585 var removeButton = document.createElement("BUTTON");
586 var buttonremoveLabel = document.createTextNode("-");
587 removeButton.appendChild(buttonremoveLabel);
588 removeButton.setAttribute("class", "btn btn-default");
589 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
590 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
591 document.getElementById(divID).appendChild(addButton);
592 document.getElementById(divID).appendChild(removeButton);
593 document.getElementById(divID).appendChild(label);
594 document.getElementById(divID).appendChild(textField);
595 document.getElementById(divID).appendChild(br);
596 document.getElementById(divID).appendChild(divTag);
598 checkKey = labelValue + attibuteKey;
599 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
600 if(requiredLabName.includes("*")){
601 textField.setAttribute("required", "true");
603 document.getElementById(divID).appendChild(label);
604 document.getElementById(divID).appendChild(textField);
605 document.getElementById(divID).appendChild(br);
609 if (defaultValue.length > 0){
610 if(defaultValue.includes(":")){
611 defaultValue = defaultValue.split(":")[0];
612 if(defaultValue === "NA") {
616 document.getElementById(checkKey).value = defaultValue;
619 if($scope.temp.policy.ruleData != null){
620 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
621 if (attributeManyKey){
622 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
623 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
626 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
630 $scope.addNewChoice(newCheckKey);
631 document.getElementById(newCheckKey+'@'+i).value = newValue;
637 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
640 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
643 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
644 var label = document.createElement("Label")
645 var divID = labelValue;
646 if (labelValue.endsWith('.')){
647 var workingLabel = labelValue.substring(0, labelValue.length-1);
649 var workingLabel = labelValue;
652 if (labelValue.length < 1){
653 divID = "DynamicTemplate";
654 } else if (labelValue.endsWith('.')){
655 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
658 var labeltext = document.createTextNode(lableName);
660 label.appendChild(labeltext);
663 var addButton = document.createElement("BUTTON");
664 var buttonLabel = document.createTextNode("+");
665 addButton.appendChild(buttonLabel);
666 addButton.setAttribute("class", "btn btn-default");
667 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
668 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
669 var removeButton = document.createElement("BUTTON");
670 var buttonremoveLabel = document.createTextNode("-");
671 removeButton.appendChild(buttonremoveLabel);
672 removeButton.setAttribute("class", "btn btn-default");
673 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
674 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
675 document.getElementById(divID).appendChild(addButton);
676 document.getElementById(divID).appendChild(removeButton);
677 document.getElementById(divID).appendChild(label);
678 var id = "div."+labelValue+lableName;
679 var divTag = document.createElement("div");
680 divTag.setAttribute("id", id);
681 document.getElementById(divID).appendChild(divTag);
683 var divTag = document.createElement("div");
684 divTag.setAttribute("id", id +'@0');
685 document.getElementById(id).appendChild(divTag);
687 var divTag = document.createElement("div");
688 divTag.setAttribute("id", "div."+labelValue+lableName);
689 document.getElementById(divID).appendChild(label);
690 document.getElementById(divID).appendChild(divTag);
694 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
695 var br = document.createElement("BR");
697 if (labelLevel.length < 1){
698 var divID = "DynamicTemplate";
699 } else if (labelLevel.endsWith('.')){
700 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
704 var label = document.createElement("Label")
705 if (matching.includes(attributeName)){
706 var labeltext = document.createTextNode(attributeName + "*!");
708 var labeltext = document.createTextNode(attributeName);
710 label.appendChild(labeltext);
712 var listField = document.createElement("SELECT");
713 listField.setAttribute("class" , "form-control");
714 listField.setAttribute("style" , "width:300px;");
715 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
717 for (i=0; i < listemunerateValues.length; i += 1) {
718 option = document.createElement('option');
719 option.setAttribute('value', listemunerateValues[i]);
720 option.appendChild(document.createTextNode(listemunerateValues[i]));
721 listField.appendChild(option);
723 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
725 enumKeyList.push(attributeName);
727 document.getElementById(divID).appendChild(label);
728 document.getElementById(divID).appendChild(br);
731 document.getElementById(divID).appendChild(listField).multiple = true;
732 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
734 document.getElementById(divID).appendChild(listField).multiple = false;
735 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
738 if($scope.temp.policy.ruleData != null){
740 document.getElementById(labelLevel +attributeName).options[0].selected = false;
741 for (i=0; i < listemunerateValues.length; i += 1) {
742 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
743 if (testValue === undefined){
744 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
746 var location = listemunerateValues.indexOf(testValue);
748 document.getElementById(labelLevel +attributeName).options[location].selected = true;
752 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
758 function onlyUnique(value, index, self) {
759 return self.indexOf(value) === index;
763 function checkDictionary(value){
764 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
765 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
771 $scope.savePolicy = function(policy){
772 if(policy.itemContent != undefined){
773 $scope.refreshCheck = true;
774 $scope.policyNavigator = policy.itemContent;
775 policy.itemContent = "";
777 $scope.savebutton = false;
781 if(plainAttributeKeys != null){
782 for(a = 0; a < plainAttributeKeys.length; a++){
783 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
784 console.log(splitPlainAttributeKey[1]);
785 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
786 var key = splitPlainAttributeKey[0];
787 if(searchElement == null){
788 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
789 key = splitPlainAttributeKey[0]+'@0';
790 }else if (searchElement.nodeName == 'BUTTON'){
791 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
792 key = splitPlainAttributeKey[0]+'@0';
794 if(searchElement != null){
795 var keySplit = key.split(dot);
796 var elumentLocation = keySplit.length;
798 if (elumentLocation > 1){
799 enumKey = keySplit[keySplit.length - 1];
801 var aWhiteSpace = " ";
802 if (enumKeyList.indexOf(enumKey) != -1){
803 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
805 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
806 multiSlect.push(searchElement.selectedOptions[i].value);
808 jsonPolicy[key]= multiSlect;
810 //set a space due to empty value caused JSON format error in PolicyRestAdapter and remove it in back-end.
811 if(searchElement.value == ""){
812 searchElement.value = aWhiteSpace;
814 console.log(" searchElement.value = > " + searchElement.value);
815 jsonPolicy[key]= searchElement.value;
818 if(searchElement.value != null){
819 //set a default value due to empty value caused JSON format error in PolicyRestAdapter
820 if(searchElement.value == ""){
821 searchElement.value = aWhiteSpace;
823 console.log(" searchElement.value = > " + searchElement.value);
824 jsonPolicy[key]= searchElement.value;
830 var uuu = "policycreation/save_policy";
831 var postData={policyData: policy, policyJSON : jsonPolicy};
836 contentType: 'application/json',
837 data: JSON.stringify(postData),
838 success : function(data){
839 $scope.$apply(function(){
840 $scope.data=data.policyData;
841 if($scope.data == 'success'){
842 $scope.temp.policy.readOnly = 'true';
843 $scope.safetyChecker = data.policyData.split("#")[2];
844 if ($scope.safetyChecker!=undefined) {
845 Notification.success($scope.safetyChecker);
847 $scope.pushStatus=data.policyData.split("&")[1];
848 if($scope.pushStatus=="successPush"){
849 Notification.success("Policy pushed successfully");
851 Notification.success("Policy Saved Successfully.");
852 }else if ($scope.data == 'PolicyExists'){
853 $scope.savebutton = true;
854 Notification.error("Policy Already Exists with Same Name in Scope.");
857 console.log($scope.data);
859 error : function(data){
860 Notification.error("Error Occured while saving Policy.");
865 $scope.validatePolicy = function(policy){
866 document.getElementById("validate").innerHTML = "";
870 if(plainAttributeKeys != null){
871 for(a = 0; a < plainAttributeKeys.length; a++){
872 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
873 console.log(splitPlainAttributeKey[1]);
874 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
875 var key = splitPlainAttributeKey[0];
876 if(searchElement == null){
877 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
878 key = splitPlainAttributeKey[0]+'@0';
879 }else if (searchElement.nodeName == 'BUTTON'){
880 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
881 key = splitPlainAttributeKey[0]+'@0';
883 if(searchElement != null){
884 if (enumKeyList.indexOf(key) != -1){
885 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
887 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
888 multiSlect.push(searchElement.selectedOptions[i].value);
890 jsonPolicy[key]= multiSlect;
892 jsonPolicy[key]= searchElement.value;
895 if(searchElement.value != null){
896 jsonPolicy[key]= searchElement.value;
897 if(searchElement.getAttribute("required")){
898 if(!searchElement.value){
907 var uuu = "policyController/validate_policy.htm";
908 var postData={policyData: policy, policyJSON : jsonPolicy};
913 contentType: 'application/json',
914 data: JSON.stringify(postData),
915 success : function(data){
916 $scope.$apply(function(){
917 $scope.validateData = data.data.replace(/\"/g, "");
918 $scope.data=data.data.substring(1,8);
919 var size = data.data.length;
920 if($scope.data == 'success'){
921 Notification.success("Validation Success.");
922 $scope.savebutton = false;
924 var displayWarning = data.data.substring(19,size - 1);
925 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
926 document.getElementById("validate").style.color = "white";
927 document.getElementById("validate").style.backgroundColor = "skyblue";
930 Notification.error("Validation Failed.");
931 document.getElementById("validate").innerHTML = $scope.validateData;
932 document.getElementById("validate").style.color = "white";
933 document.getElementById("validate").style.backgroundColor = "red";
934 $scope.savebutton = true;
938 console.log($scope.data);
940 error : function(data){
941 Notification.error("Validation Failed.");
942 $scope.savebutton = true;
947 function extend(obj, src) {
948 for (var key in src) {
949 if (src.hasOwnProperty(key)) obj[key] = src[key];