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);
35 $scope.modal = function(id, hide) {
36 return $('#' + id).modal(hide ? 'hide' : 'show');
39 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
40 if ($scope.temp.policy.configName == undefined){
41 $scope.isCheck = false;
43 $scope.isCheck = true;
46 $scope.isCheck = false;
49 PolicyAppService.getData('getDictionary/get_EcompNameDataByName').then(function (data) {
51 $scope.data = JSON.parse(j.data);
52 console.log($scope.data);
53 $scope.ecompNameDictionaryDatas = JSON.parse($scope.data.ecompNameDictionaryDatas);
54 console.log($scope.ecompNameDictionaryDatas);
56 console.log("failed");
59 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
61 $scope.data = JSON.parse(j.data);
62 console.log($scope.data);
63 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
64 console.log($scope.priorityDatas);
66 console.log("failed");
69 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
71 $scope.data = JSON.parse(j.data);
72 console.log($scope.data);
73 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
74 console.log($scope.groupPolicyScopeListDatas);
76 console.log("failed");
79 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
81 $scope.data = JSON.parse(j.data);
82 console.log($scope.data);
83 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
84 console.log($scope.microServiceCongigNameDictionaryDatas);
86 console.log("failed");
89 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
91 $scope.data = JSON.parse(j.data);
92 console.log($scope.data);
93 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
94 console.log($scope.microServiceLocationDictionaryDatas);
96 console.log("failed");
99 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
101 $scope.data = JSON.parse(j.data);
102 console.log($scope.data);
103 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
106 for(var i = 0; i < inputModelList.length; i++){
107 if(typeof unique[inputModelList[i]] == "undefined"){
108 unique[inputModelList[i]] = "";
109 uniqueList.push(inputModelList[i]);
112 $scope.microServiceModelsDictionaryDatas = uniqueList;
113 console.log($scope.microServiceModelsDictionaryDatas);
114 }, function (error) {
115 console.log("failed");
118 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
120 $scope.data = JSON.parse(j.data);
121 console.log($scope.data);
122 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
123 console.log($scope.dcaeUUIDDictionaryDatas);
124 }, function (error) {
125 console.log("failed");
128 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
130 $scope.data = JSON.parse(j.data);
131 console.log($scope.data);
132 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
133 console.log($scope.riskTypeDictionaryDatas);
134 }, function (error) {
135 console.log("failed");
138 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
140 $scope.data = JSON.parse(j.data);
141 console.log($scope.data);
142 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
143 console.log($scope.microServiceAttributeDictionaryDatas);
144 }, function (error) {
145 console.log("failed");
150 $scope.attributeDatas = [{"attributes" : $scope.choices}];
152 $scope.addNewChoice = function(value) {
154 if(value != undefined){
155 if (value.startsWith('div.')){
156 value = value.replace('div.','');
158 var parentElement = document.getElementById("div."+value);
159 var div = document.getElementById(value+"@0");
161 var clone = div.cloneNode(true);
162 var addElement = parentElement.childElementCount + 1;
163 clone.id = ''+value+'@'+addElement;
165 document.getElementById("div."+value).appendChild(clone);
166 plainAttributeKeys.push(''+value+'@'+addElement);
168 div = document.getElementById("div."+value+"@0");
169 var childElement = parentElement.firstElementChild;
170 var countParent = parentElement.childElementCount;
171 var childElementString = childElement.innerHTML;
172 var find = value+"@0";
173 var re = new RegExp(find, 'g');
174 childElementString = childElementString.replace(re,value+'@' + countParent);
175 var clone = childElement.cloneNode(true);
176 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
177 var childId = parentElement.childNodes[ii].id;
178 if(ii = parentElement.childNodes.length){
179 var childnewId = childId.slice(0, -1);
180 var count = childId.slice(-1);
183 var countvalue = parseInt(count) + 1;
184 clone.id = childnewId+countvalue;
186 clone.innerHTML=childElementString;
187 document.getElementById("div."+value).appendChild(clone);
188 var selects = clone.getElementsByTagName("select");
189 var inputs = clone.getElementsByTagName("input");
190 var removeValues = [];
191 for(var i=0; i<inputs.length; i++){
192 if ($scope.temp.policy.ruleData!=undefined){
193 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
194 if (checkValue!=undefined){
195 if($scope.temp.policy.ruleData != null){
196 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
197 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
198 plainAttributeKeys.push(inputs[i].id);
201 // removeValues.push(inputs[i].id);
202 plainAttributeKeys.push(inputs[i].id);
205 plainAttributeKeys.push(inputs[i].id);
209 for(var i=0; i<selects.length; i++){
210 if ($scope.temp.policy.ruleData!=undefined){
211 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
212 if (checkValue!=undefined){
213 if($scope.temp.policy.ruleData != null){
214 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
215 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
216 plainAttributeKeys.push(selects[i].id);
219 plainAttributeKeys.push(selects[i].id);
222 plainAttributeKeys.push(selects[i].id);
226 for (var k=0; k<removeValues.length; k++){
227 var elem = document.getElementById(removeValues[k]);
228 elem.parentNode.removeChild(elem);
230 var ele = angular.element(document.getElementById("div."+value));
231 $compile(ele.contents())($scope);
237 $scope.removeChoice = function(value) {
239 if(value != undefined){
240 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
244 $scope.pullVersion = function(serviceName) {
245 console.log(serviceName);
246 if(serviceName != undefined){
247 var uuu = "policyController/getModelServiceVersioneData.htm";
248 var postData={policyData: serviceName};
253 contentType: 'application/json',
254 data: JSON.stringify(postData),
255 success : function(data){
256 $scope.$apply(function(){
257 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
260 error : function(data){
261 alert("Error While Retriving the Template Layout Pattren.");
268 var splitEqual = '=';
269 var splitComma = ',';
270 var splitcolon = ':';
271 var splitsemicolon = ";";
272 var splitEnum = "],";
273 var plainAttributeKeys = [];
275 var enumKeyList = [];
276 var dictionaryList = [];
277 var dictionaryNameList = [];
278 $scope.addDataToFields = function(serviceName, version){
279 if(serviceName != null && version !=null){
280 var service=serviceName+"-v"+version;
281 var myNode = document.getElementById("DynamicTemplate");
282 myNode.innerHTML = '';
283 var uuu = "policyController/getDCAEMSTemplateData.htm";
284 var postData={policyData: service};
289 contentType: 'application/json',
290 data: JSON.stringify(postData),
291 success : function(data){
292 $scope.$apply(function(){
293 $scope.addNewChoice();
294 var plainAttributeKeys = [];
295 $scope.dcaeModelData = data[0].dcaeModelData;
296 $scope.dcaeJsonDate = data[0].jsonValue;
297 var attributes = $scope.dcaeModelData.attributes;
298 var refAttributes = $scope.dcaeModelData.ref_attributes;
299 var subAttributes = $scope.dcaeModelData.sub_attributes;
300 var enumAttributes = $scope.dcaeModelData.enumValues;
301 var annotation = $scope.dcaeModelData.annotation;
302 var dictionary = $scope.microServiceAttributeDictionaryDatas;
304 if (annotation == null || annotation.length<1){
305 $scope.isCheck = true;
307 $scope.isCheck = false;
308 var annoationList = annotation.split(splitComma);
309 for (k = 0; k < annoationList.length; k++){
310 var splitAnnotation = annoationList[k].split(splitEqual);
311 if (splitAnnotation[1].includes("matching-true")){
312 matching.push(splitAnnotation[0].trim());
318 if (dictionary!= null || dictionary>1){
319 if (dictionary!= null || dictionary.length>1){
320 for (m=0; m < dictionary.length; m += 1){
321 var keyCompare = dictionary[m].name;
322 var valueCompare = dictionary[m].value;
323 var valueModel = dictionary[m].modelName;
324 var conpairService = serviceName;
325 if (valueModel.includes('-v')){
326 conpairService = service;
328 if(valueModel.localeCompare(conpairService) == 0){
329 console.log(valueCompare);
330 dictionaryList.push(dictionary[m]);
331 if (!dictionaryNameList.includes(dictionary[m].name)){
332 dictionaryNameList.push(dictionary[m].name)
339 $scope.temp.policy.ruleGridData = [];
341 $scope.jsonLayout($scope.dcaeJsonDate);
344 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
347 if($scope.temp.policy.ruleData != null){
348 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
349 propNames.forEach(function(name) {
352 for(a = 0; a < data.length; a++){
353 var splitPlainAttributeKey1 = data[a].split(".");
354 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
355 var key = splitPlainAttributeKey1[0];
359 var unique = checkData.filter(onlyUnique);
360 for(i =0; i < unique.length; i++){
361 if(unique[i].indexOf("@0") == -1){
362 var finalkey = unique[i].split("@")[0];
363 $scope.addNewChoice(finalkey);
368 var ele = angular.element(document.getElementById("DynamicTemplate"));
369 $compile(ele.contents())($scope);
372 error : function(data){
373 alert("Error While Retriving the Template Layout Pattren.");
379 function getDictionary(attribute){
380 var dicName = attribute;
382 if(attribute.includes(":")){
383 dicName = attribute.split(":")[0];
386 var dictionaryRegExp = new RegExp(dicName);
387 listemunerateValues = [];
388 if (dictionaryRegExp.test(dictionaryNameList)) {
389 for (p=0; p < dictionaryList.length; p += 1) {
390 if (dicName == dictionaryList[p].name) {
391 listemunerateValues.push(dictionaryList[p].value);
395 return listemunerateValues;
398 function getList(attribute) {
399 var enumName = attribute;
400 console.log("In getList: attribute => " + attribute);
402 if(attribute.includes(":")){
403 enumName = attribute.split(":")[0];
406 var baseEnum = $scope.dcaeModelData.enumValues;
407 var enumList = baseEnum.split(splitEnum);
409 var patternTest = new RegExp(enumName);
410 for (k=0; k < enumList.length; k += 1){
411 if(patternTest.test(enumList[k]) == true){
412 enumAttributes = enumList[k].trim();
417 enumAttributes = enumAttributes.replace("[", "");
418 enumAttributes = enumAttributes.replace("]", "");
419 enumAttributes = enumAttributes.replace(/ /g, '');
420 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
421 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
422 //enumKeyList.push(attribute);
423 return listemunerateValues;
429 function getBooleanList(){
430 var booleanList = [];
431 booleanList.push(true);
432 booleanList.push(false);
437 function isArray(arrayTest) {
438 return Object.prototype.toString.call(arrayTest) === '[object Array]';
442 function deconstructJSON(dataTest, level , name) {
445 var stringValue = "java.lang.String";
446 var intValue = "int";
447 var double = "double";
448 var boolean = "boolean";
449 var baseLevel = level;
451 if (name.length > 1){
452 label = label + name + '.';
455 for (key in dataTest) {
456 array = isArray(dataTest[key]);
457 console.log(key , dataTest[key]);
458 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
459 if (array==false && key!=="0"){
460 $scope.labelLayout(label, key, array );
463 if (array == true && key!=0){
467 if (lableList.length > 0){
471 var newKey = lableList.pop();
472 $scope.labelLayout(baseLevel, newKey, array );
474 label = baseLevel + newKey + '@0.';
476 label = baseLevel + newKey + '.';
479 deconstructJSON(dataTest[key] , label, key);
481 var attirbuteLabel = label;
483 var isRequired = false;
484 if (dataTest[key].includes('defaultValue-')){
485 defaultValue = dataTest[key].split('defaultValue-')[1];
490 attributekey = lableList.pop();
491 attirbuteLabel = baseLevel;
493 attributekey = key.split();
496 if (dataTest[key].includes('required-true')){
499 console.log("attirbuteLabel = " + attirbuteLabel);
500 switch (dataTest[key].split(splitcolon)[0]){
502 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
505 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
508 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
511 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
514 if (dataTest[key].includes('dictionary-')){
515 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
517 var list = getList(dataTest[key]);
519 if (list.length===0){
520 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
522 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
530 $scope.jsonLayout = function(dataTest){
531 deconstructJSON(dataTest , "", "");
535 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
536 $scope.temp.policy.ruleGridData.push(attibuteKey);
537 var br = document.createElement("BR");
539 var label = document.createElement("Label");
540 var labeltext = null;
541 var requiredLabName = "";
542 if (matching.includes(attibuteKey)){
543 labeltext = document.createTextNode(attibuteKey + "*!");
545 //var labeltext = document.createTextNode(refattributeLabel);
547 requiredLabName = attibuteKey + " *";
548 labeltext = document.createTextNode(requiredLabName);
550 labeltext = document.createTextNode(attibuteKey);
555 var divID = labelValue;
557 if (labelValue.length < 1){
558 divID = "DynamicTemplate";
559 }else if (labelValue.endsWith('.')){
560 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
563 label.appendChild(labeltext);
565 var textField = document.createElement("INPUT");
567 textField.setAttribute("class" , "form-control");
568 textField.setAttribute("type" , "text");
569 textField.setAttribute("style" , "width:300px;");
570 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
572 if(attributeManyKey){
573 checkKey = labelValue + attibuteKey+'@0';
574 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
575 var divTag = document.createElement("div");
576 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
577 var addButton = document.createElement("BUTTON");
578 var buttonaddLabel = document.createTextNode("+");
579 addButton.appendChild(buttonaddLabel);
580 addButton.setAttribute("id", labelValue + attibuteKey);
581 addButton.setAttribute("class", "btn btn-default");
582 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
583 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
584 var removeButton = document.createElement("BUTTON");
585 var buttonremoveLabel = document.createTextNode("-");
586 removeButton.appendChild(buttonremoveLabel);
587 removeButton.setAttribute("class", "btn btn-default");
588 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
589 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
590 document.getElementById(divID).appendChild(addButton);
591 document.getElementById(divID).appendChild(removeButton);
592 document.getElementById(divID).appendChild(label);
593 document.getElementById(divID).appendChild(textField);
594 document.getElementById(divID).appendChild(br);
595 document.getElementById(divID).appendChild(divTag);
597 checkKey = labelValue + attibuteKey;
598 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
599 if(requiredLabName.includes("*")){
600 textField.setAttribute("required", "true");
602 document.getElementById(divID).appendChild(label);
603 document.getElementById(divID).appendChild(textField);
604 document.getElementById(divID).appendChild(br);
608 if (defaultValue.length > 0){
609 if(defaultValue.includes(":")){
610 defaultValue = defaultValue.split(":")[0];
611 if(defaultValue === "NA") {
615 document.getElementById(checkKey).value = defaultValue;
618 if($scope.temp.policy.ruleData != null){
619 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
620 if (attributeManyKey){
621 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
622 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
625 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
629 $scope.addNewChoice(newCheckKey);
630 document.getElementById(newCheckKey+'@'+i).value = newValue;
636 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
639 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
642 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
643 var label = document.createElement("Label")
644 var divID = labelValue;
645 if (labelValue.endsWith('.')){
646 var workingLabel = labelValue.substring(0, labelValue.length-1);
648 var workingLabel = labelValue;
651 if (labelValue.length < 1){
652 divID = "DynamicTemplate";
653 } else if (labelValue.endsWith('.')){
654 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
657 var labeltext = document.createTextNode(lableName);
659 label.appendChild(labeltext);
662 var addButton = document.createElement("BUTTON");
663 var buttonLabel = document.createTextNode("+");
664 addButton.appendChild(buttonLabel);
665 addButton.setAttribute("class", "btn btn-default");
666 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
667 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
668 var removeButton = document.createElement("BUTTON");
669 var buttonremoveLabel = document.createTextNode("-");
670 removeButton.appendChild(buttonremoveLabel);
671 removeButton.setAttribute("class", "btn btn-default");
672 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
673 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
674 document.getElementById(divID).appendChild(addButton);
675 document.getElementById(divID).appendChild(removeButton);
676 document.getElementById(divID).appendChild(label);
677 var id = "div."+labelValue+lableName;
678 var divTag = document.createElement("div");
679 divTag.setAttribute("id", id);
680 document.getElementById(divID).appendChild(divTag);
682 var divTag = document.createElement("div");
683 divTag.setAttribute("id", id +'@0');
684 document.getElementById(id).appendChild(divTag);
686 var divTag = document.createElement("div");
687 divTag.setAttribute("id", "div."+labelValue+lableName);
688 document.getElementById(divID).appendChild(label);
689 document.getElementById(divID).appendChild(divTag);
693 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
694 var br = document.createElement("BR");
696 if (labelLevel.length < 1){
697 var divID = "DynamicTemplate";
698 } else if (labelLevel.endsWith('.')){
699 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
703 var label = document.createElement("Label")
704 if (matching.includes(attributeName)){
705 var labeltext = document.createTextNode(attributeName + "*!");
707 var labeltext = document.createTextNode(attributeName);
709 label.appendChild(labeltext);
711 var listField = document.createElement("SELECT");
712 listField.setAttribute("class" , "form-control");
713 listField.setAttribute("style" , "width:300px;");
714 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
716 for (i=0; i < listemunerateValues.length; i += 1) {
717 option = document.createElement('option');
718 option.setAttribute('value', listemunerateValues[i]);
719 option.appendChild(document.createTextNode(listemunerateValues[i]));
720 listField.appendChild(option);
722 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
724 enumKeyList.push(attributeName);
726 document.getElementById(divID).appendChild(label);
727 document.getElementById(divID).appendChild(br);
730 document.getElementById(divID).appendChild(listField).multiple = true;
731 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
733 document.getElementById(divID).appendChild(listField).multiple = false;
734 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
737 if($scope.temp.policy.ruleData != null){
739 document.getElementById(labelLevel +attributeName).options[0].selected = false;
740 for (i=0; i < listemunerateValues.length; i += 1) {
741 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
742 if (testValue === undefined){
743 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
745 var location = listemunerateValues.indexOf(testValue);
747 document.getElementById(labelLevel +attributeName).options[location].selected = true;
751 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
757 function onlyUnique(value, index, self) {
758 return self.indexOf(value) === index;
762 function checkDictionary(value){
763 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
764 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
770 $scope.savePolicy = function(policy){
771 if(policy.itemContent != undefined){
772 $scope.refreshCheck = true;
773 $scope.policyNavigator = policy.itemContent;
774 policy.itemContent = "";
776 $scope.savebutton = false;
780 if(plainAttributeKeys != null){
781 for(a = 0; a < plainAttributeKeys.length; a++){
782 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
783 console.log(splitPlainAttributeKey[1]);
784 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
785 var key = splitPlainAttributeKey[0];
786 if(searchElement == null){
787 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
788 key = splitPlainAttributeKey[0]+'@0';
789 }else if (searchElement.nodeName == 'BUTTON'){
790 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
791 key = splitPlainAttributeKey[0]+'@0';
793 if(searchElement != null){
794 var keySplit = key.split(dot);
795 var elumentLocation = keySplit.length;
797 if (elumentLocation > 1){
798 enumKey = keySplit[keySplit.length - 1];
800 var aWhiteSpace = " ";
801 if (enumKeyList.indexOf(enumKey) != -1){
802 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
804 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
805 multiSlect.push(searchElement.selectedOptions[i].value);
807 jsonPolicy[key]= multiSlect;
809 //set a space due to empty value caused JSON format error in PolicyRestAdapter and remove it in back-end.
810 if(searchElement.value == ""){
811 searchElement.value = aWhiteSpace;
813 console.log(" searchElement.value = > " + searchElement.value);
814 jsonPolicy[key]= searchElement.value;
817 if(searchElement.value != null){
818 //set a default value due to empty value caused JSON format error in PolicyRestAdapter
819 if(searchElement.value == ""){
820 searchElement.value = aWhiteSpace;
822 console.log(" searchElement.value = > " + searchElement.value);
823 jsonPolicy[key]= searchElement.value;
829 var uuu = "policycreation/save_policy";
830 var postData={policyData: policy, policyJSON : jsonPolicy};
835 contentType: 'application/json',
836 data: JSON.stringify(postData),
837 success : function(data){
838 $scope.$apply(function(){
839 $scope.data=data.policyData;
840 if($scope.data == 'success'){
841 $scope.temp.policy.readOnly = 'true';
842 $scope.safetyChecker = data.policyData.split("#")[2];
843 if ($scope.safetyChecker!=undefined) {
844 Notification.success($scope.safetyChecker);
846 $scope.pushStatus=data.policyData.split("&")[1];
847 if($scope.pushStatus=="successPush"){
848 Notification.success("Policy pushed successfully");
850 Notification.success("Policy Saved Successfully.");
851 }else if ($scope.data == 'PolicyExists'){
852 $scope.savebutton = true;
853 Notification.error("Policy Already Exists with Same Name in Scope.");
856 console.log($scope.data);
858 error : function(data){
859 Notification.error("Error Occured while saving Policy.");
864 $scope.validatePolicy = function(policy){
865 document.getElementById("validate").innerHTML = "";
869 if(plainAttributeKeys != null){
870 for(a = 0; a < plainAttributeKeys.length; a++){
871 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
872 console.log(splitPlainAttributeKey[1]);
873 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
874 var key = splitPlainAttributeKey[0];
875 if(searchElement == null){
876 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
877 key = splitPlainAttributeKey[0]+'@0';
878 }else if (searchElement.nodeName == 'BUTTON'){
879 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
880 key = splitPlainAttributeKey[0]+'@0';
882 if(searchElement != null){
883 if (enumKeyList.indexOf(key) != -1){
884 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
886 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
887 multiSlect.push(searchElement.selectedOptions[i].value);
889 jsonPolicy[key]= multiSlect;
891 jsonPolicy[key]= searchElement.value;
894 if(searchElement.value != null){
895 jsonPolicy[key]= searchElement.value;
896 if(searchElement.getAttribute("required")){
897 if(!searchElement.value){
906 var uuu = "policyController/validate_policy.htm";
907 var postData={policyData: policy, policyJSON : jsonPolicy};
912 contentType: 'application/json',
913 data: JSON.stringify(postData),
914 success : function(data){
915 $scope.$apply(function(){
916 $scope.validateData = data.data.replace(/\"/g, "");
917 $scope.data=data.data.substring(1,8);
918 var size = data.data.length;
919 if($scope.data == 'success'){
920 Notification.success("Validation Success.");
921 $scope.savebutton = false;
923 var displayWarning = data.data.substring(19,size - 1);
924 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
925 document.getElementById("validate").style.color = "white";
926 document.getElementById("validate").style.backgroundColor = "skyblue";
929 Notification.error("Validation Failed.");
930 document.getElementById("validate").innerHTML = $scope.validateData;
931 document.getElementById("validate").style.color = "white";
932 document.getElementById("validate").style.backgroundColor = "red";
933 $scope.savebutton = true;
937 console.log($scope.data);
939 error : function(data){
940 Notification.error("Validation Failed.");
941 $scope.savebutton = true;
946 function extend(obj, src) {
947 for (var key in src) {
948 if (src.hasOwnProperty(key)) obj[key] = src[key];