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;
409 if(baseEnum != null){
410 enumList = baseEnum.split(splitEnum);
413 var patternTest = new RegExp(enumName);
414 for (k=0; k < enumList.length; k += 1){
415 if(patternTest.test(enumList[k]) == true){
416 enumAttributes = enumList[k].trim();
421 enumAttributes = enumAttributes.replace("[", "");
422 enumAttributes = enumAttributes.replace("]", "");
423 enumAttributes = enumAttributes.replace(/ /g, '');
424 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
425 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
426 //enumKeyList.push(attribute);
427 return listemunerateValues;
433 function getBooleanList(){
434 var booleanList = [];
435 booleanList.push(true);
436 booleanList.push(false);
441 function isArray(arrayTest) {
442 return Object.prototype.toString.call(arrayTest) === '[object Array]';
446 function deconstructJSON(dataTest, level , name) {
449 var stringValue = "java.lang.String";
450 var intValue = "int";
451 var double = "double";
452 var boolean = "boolean";
453 var baseLevel = level;
455 if (name.length > 1){
456 label = label + name + '.';
459 for (key in dataTest) {
460 array = isArray(dataTest[key]);
461 console.log(key , dataTest[key]);
462 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
463 if (array==false && key!=="0"){
464 $scope.labelLayout(label, key, array );
467 if (array == true && key!=0){
471 if (lableList.length > 0){
475 var newKey = lableList.pop();
476 $scope.labelLayout(baseLevel, newKey, array );
478 label = baseLevel + newKey + '@0.';
480 label = baseLevel + newKey + '.';
483 deconstructJSON(dataTest[key] , label, key);
485 var attirbuteLabel = label;
487 var isRequired = false;
488 if (dataTest[key].includes('defaultValue-')){
489 defaultValue = dataTest[key].split('defaultValue-')[1];
494 attributekey = lableList.pop();
495 attirbuteLabel = baseLevel;
497 attributekey = key.split();
500 if (dataTest[key].includes('required-true')){
503 console.log("attirbuteLabel = " + attirbuteLabel);
504 switch (dataTest[key].split(splitcolon)[0]){
506 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
509 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
512 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
515 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
518 if (dataTest[key].includes('dictionary-')){
519 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
521 var list = getList(dataTest[key]);
523 if (list.length===0){
524 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
526 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
534 $scope.jsonLayout = function(dataTest){
535 deconstructJSON(dataTest , "", "");
539 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
540 $scope.temp.policy.ruleGridData.push(attibuteKey);
541 var br = document.createElement("BR");
543 var label = document.createElement("Label");
544 var labeltext = null;
545 var requiredLabName = "";
546 if (matching.includes(attibuteKey)){
547 labeltext = document.createTextNode(attibuteKey + "*!");
549 //var labeltext = document.createTextNode(refattributeLabel);
551 requiredLabName = attibuteKey + " *";
552 labeltext = document.createTextNode(requiredLabName);
554 labeltext = document.createTextNode(attibuteKey);
559 var divID = labelValue;
561 if (labelValue.length < 1){
562 divID = "DynamicTemplate";
563 }else if (labelValue.endsWith('.')){
564 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
567 label.appendChild(labeltext);
569 var textField = document.createElement("INPUT");
571 textField.setAttribute("class" , "form-control");
572 textField.setAttribute("type" , "text");
573 textField.setAttribute("style" , "width:300px;");
574 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
576 if(attributeManyKey){
577 checkKey = labelValue + attibuteKey+'@0';
578 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
579 var divTag = document.createElement("div");
580 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
581 var addButton = document.createElement("BUTTON");
582 var buttonaddLabel = document.createTextNode("+");
583 addButton.appendChild(buttonaddLabel);
584 addButton.setAttribute("id", labelValue + attibuteKey);
585 addButton.setAttribute("class", "btn btn-default");
586 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
587 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
588 var removeButton = document.createElement("BUTTON");
589 var buttonremoveLabel = document.createTextNode("-");
590 removeButton.appendChild(buttonremoveLabel);
591 removeButton.setAttribute("class", "btn btn-default");
592 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
593 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
594 document.getElementById(divID).appendChild(addButton);
595 document.getElementById(divID).appendChild(removeButton);
596 document.getElementById(divID).appendChild(label);
597 document.getElementById(divID).appendChild(textField);
598 document.getElementById(divID).appendChild(br);
599 document.getElementById(divID).appendChild(divTag);
601 checkKey = labelValue + attibuteKey;
602 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
603 if(requiredLabName.includes("*")){
604 textField.setAttribute("required", "true");
606 document.getElementById(divID).appendChild(label);
607 document.getElementById(divID).appendChild(textField);
608 document.getElementById(divID).appendChild(br);
612 if (defaultValue.length > 0){
613 if(defaultValue.includes(":")){
614 defaultValue = defaultValue.split(":")[0];
615 if(defaultValue === "NA") {
619 document.getElementById(checkKey).value = defaultValue;
622 if($scope.temp.policy.ruleData != null){
623 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
624 if (attributeManyKey){
625 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
626 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
629 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
633 $scope.addNewChoice(newCheckKey);
634 document.getElementById(newCheckKey+'@'+i).value = newValue;
640 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
643 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
646 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
647 var label = document.createElement("Label")
648 var divID = labelValue;
649 if (labelValue.endsWith('.')){
650 var workingLabel = labelValue.substring(0, labelValue.length-1);
652 var workingLabel = labelValue;
655 if (labelValue.length < 1){
656 divID = "DynamicTemplate";
657 } else if (labelValue.endsWith('.')){
658 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
661 var labeltext = document.createTextNode(lableName);
663 label.appendChild(labeltext);
666 var addButton = document.createElement("BUTTON");
667 var buttonLabel = document.createTextNode("+");
668 addButton.appendChild(buttonLabel);
669 addButton.setAttribute("class", "btn btn-default");
670 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
671 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
672 var removeButton = document.createElement("BUTTON");
673 var buttonremoveLabel = document.createTextNode("-");
674 removeButton.appendChild(buttonremoveLabel);
675 removeButton.setAttribute("class", "btn btn-default");
676 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
677 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
678 document.getElementById(divID).appendChild(addButton);
679 document.getElementById(divID).appendChild(removeButton);
680 document.getElementById(divID).appendChild(label);
681 var id = "div."+labelValue+lableName;
682 var divTag = document.createElement("div");
683 divTag.setAttribute("id", id);
684 document.getElementById(divID).appendChild(divTag);
686 var divTag = document.createElement("div");
687 divTag.setAttribute("id", id +'@0');
688 document.getElementById(id).appendChild(divTag);
690 var divTag = document.createElement("div");
691 divTag.setAttribute("id", "div."+labelValue+lableName);
692 document.getElementById(divID).appendChild(label);
693 document.getElementById(divID).appendChild(divTag);
697 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
698 var br = document.createElement("BR");
700 if (labelLevel.length < 1){
701 var divID = "DynamicTemplate";
702 } else if (labelLevel.endsWith('.')){
703 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
707 var label = document.createElement("Label")
708 if (matching.includes(attributeName)){
709 var labeltext = document.createTextNode(attributeName + "*!");
711 var labeltext = document.createTextNode(attributeName);
713 label.appendChild(labeltext);
715 var listField = document.createElement("SELECT");
716 listField.setAttribute("class" , "form-control");
717 listField.setAttribute("style" , "width:300px;");
718 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
720 for (i=0; i < listemunerateValues.length; i += 1) {
721 option = document.createElement('option');
722 option.setAttribute('value', listemunerateValues[i]);
723 option.appendChild(document.createTextNode(listemunerateValues[i]));
724 listField.appendChild(option);
726 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
728 enumKeyList.push(attributeName);
730 document.getElementById(divID).appendChild(label);
731 document.getElementById(divID).appendChild(br);
734 document.getElementById(divID).appendChild(listField).multiple = true;
735 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
737 document.getElementById(divID).appendChild(listField).multiple = false;
738 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
741 if($scope.temp.policy.ruleData != null){
743 document.getElementById(labelLevel +attributeName).options[0].selected = false;
744 for (i=0; i < listemunerateValues.length; i += 1) {
745 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
746 if (testValue === undefined){
747 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
749 var location = listemunerateValues.indexOf(testValue);
751 document.getElementById(labelLevel +attributeName).options[location].selected = true;
755 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
761 function onlyUnique(value, index, self) {
762 return self.indexOf(value) === index;
766 function checkDictionary(value){
767 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
768 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
774 $scope.savePolicy = function(policy){
775 if(policy.itemContent != undefined){
776 $scope.refreshCheck = true;
777 $scope.policyNavigator = policy.itemContent;
778 policy.itemContent = "";
780 $scope.savebutton = false;
784 if(plainAttributeKeys != null){
785 for(a = 0; a < plainAttributeKeys.length; a++){
786 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
787 console.log(splitPlainAttributeKey[1]);
788 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
789 var key = splitPlainAttributeKey[0];
790 if(searchElement == null){
791 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
792 key = splitPlainAttributeKey[0]+'@0';
793 }else if (searchElement.nodeName == 'BUTTON'){
794 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
795 key = splitPlainAttributeKey[0]+'@0';
797 if(searchElement != null){
798 var keySplit = key.split(dot);
799 var elumentLocation = keySplit.length;
801 if (elumentLocation > 1){
802 enumKey = keySplit[keySplit.length - 1];
804 var aWhiteSpace = " ";
805 if (enumKeyList.indexOf(enumKey) != -1){
806 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
808 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
809 multiSlect.push(searchElement.selectedOptions[i].value);
811 jsonPolicy[key]= multiSlect;
813 //set a space due to empty value caused JSON format error in PolicyRestAdapter and remove it in back-end.
814 if(searchElement.value == ""){
815 searchElement.value = aWhiteSpace;
817 console.log(" searchElement.value = > " + searchElement.value);
818 jsonPolicy[key]= searchElement.value;
821 if(searchElement.value != null){
822 //set a default value due to empty value caused JSON format error in PolicyRestAdapter
823 if(searchElement.value == ""){
824 searchElement.value = aWhiteSpace;
826 console.log(" searchElement.value = > " + searchElement.value);
827 jsonPolicy[key]= searchElement.value;
833 var uuu = "policycreation/save_policy";
834 var postData={policyData: policy, policyJSON : jsonPolicy};
839 contentType: 'application/json',
840 data: JSON.stringify(postData),
841 success : function(data){
842 $scope.$apply(function(){
843 $scope.data=data.policyData;
844 if($scope.data == 'success'){
845 $scope.temp.policy.readOnly = 'true';
846 $scope.safetyChecker = data.policyData.split("#")[2];
847 if ($scope.safetyChecker!=undefined) {
848 Notification.success($scope.safetyChecker);
850 $scope.pushStatus=data.policyData.split("&")[1];
851 if($scope.pushStatus=="successPush"){
852 Notification.success("Policy pushed successfully");
854 Notification.success("Policy Saved Successfully.");
855 }else if ($scope.data == 'PolicyExists'){
856 $scope.savebutton = true;
857 Notification.error("Policy Already Exists with Same Name in Scope.");
860 console.log($scope.data);
862 error : function(data){
863 Notification.error("Error Occured while saving Policy.");
868 $scope.validatePolicy = function(policy){
869 document.getElementById("validate").innerHTML = "";
873 if(plainAttributeKeys != null){
874 for(a = 0; a < plainAttributeKeys.length; a++){
875 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
876 console.log(splitPlainAttributeKey[1]);
877 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
878 var key = splitPlainAttributeKey[0];
879 if(searchElement == null){
880 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
881 key = splitPlainAttributeKey[0]+'@0';
882 }else if (searchElement.nodeName == 'BUTTON'){
883 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
884 key = splitPlainAttributeKey[0]+'@0';
886 if(searchElement != null){
887 if (enumKeyList.indexOf(key) != -1){
888 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
890 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
891 multiSlect.push(searchElement.selectedOptions[i].value);
893 jsonPolicy[key]= multiSlect;
895 jsonPolicy[key]= searchElement.value;
898 if(searchElement.value != null){
899 jsonPolicy[key]= searchElement.value;
900 if(searchElement.getAttribute("required")){
901 if(!searchElement.value){
910 var uuu = "policyController/validate_policy.htm";
911 var postData={policyData: policy, policyJSON : jsonPolicy};
916 contentType: 'application/json',
917 data: JSON.stringify(postData),
918 success : function(data){
919 $scope.$apply(function(){
920 $scope.validateData = data.data.replace(/\"/g, "");
921 $scope.data=data.data.substring(1,8);
922 var size = data.data.length;
923 if($scope.data == 'success'){
924 Notification.success("Validation Success.");
925 $scope.savebutton = false;
927 var displayWarning = data.data.substring(19,size - 1);
928 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
929 document.getElementById("validate").style.color = "white";
930 document.getElementById("validate").style.backgroundColor = "skyblue";
933 Notification.error("Validation Failed.");
934 document.getElementById("validate").innerHTML = $scope.validateData;
935 document.getElementById("validate").style.color = "white";
936 document.getElementById("validate").style.backgroundColor = "red";
937 $scope.savebutton = true;
941 console.log($scope.data);
943 error : function(data){
944 Notification.error("Validation Failed.");
945 $scope.savebutton = true;
950 function extend(obj, src) {
951 for (var key in src) {
952 if (src.hasOwnProperty(key)) obj[key] = src[key];