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_OnapNameDataByName').then(function (data) {
52 $scope.data = JSON.parse(j.data);
53 console.log($scope.data);
54 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
55 console.log($scope.onapNameDictionaryDatas);
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 clone.className += ' child_single'; //here cloned is single element
167 document.getElementById("div."+value).appendChild(clone);
168 plainAttributeKeys.push(''+value+'@'+addElement);
170 div = document.getElementById("div."+value+"@0");
172 div.className += ' children_group'; //here is div with a group of children.
174 var childElement = parentElement.firstElementChild;
175 var countParent = parentElement.childElementCount;
176 var childElementString = childElement.innerHTML;
177 var find = value+"@0";
178 var re = new RegExp(find, 'g');
179 childElementString = childElementString.replace(re,value+'@' + countParent);
180 var clone = childElement.cloneNode(true);
181 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
182 var childId = parentElement.childNodes[ii].id;
183 if(ii = parentElement.childNodes.length){
184 var childnewId = childId.slice(0, -1);
185 var count = childId.slice(-1);
188 var countvalue = parseInt(count) + 1;
189 clone.id = childnewId+countvalue;
191 clone.innerHTML=childElementString;
192 document.getElementById("div."+value).appendChild(clone);
193 var selects = clone.getElementsByTagName("select");
194 var inputs = clone.getElementsByTagName("input");
195 var removeValues = [];
196 for(var i=0; i<inputs.length; i++){
197 if ($scope.temp.policy.ruleData!=undefined){
198 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
199 if (checkValue!=undefined){
200 if($scope.temp.policy.ruleData != null){
201 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
202 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
203 plainAttributeKeys.push(inputs[i].id);
206 // removeValues.push(inputs[i].id);
207 plainAttributeKeys.push(inputs[i].id);
210 plainAttributeKeys.push(inputs[i].id);
214 for(var i=0; i<selects.length; i++){
215 if ($scope.temp.policy.ruleData!=undefined){
216 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
217 if (checkValue!=undefined){
218 if($scope.temp.policy.ruleData != null){
219 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
220 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
221 plainAttributeKeys.push(selects[i].id);
224 plainAttributeKeys.push(selects[i].id);
227 plainAttributeKeys.push(selects[i].id);
231 for (var k=0; k<removeValues.length; k++){
232 var elem = document.getElementById(removeValues[k]);
233 elem.parentNode.removeChild(elem);
235 var ele = angular.element(document.getElementById("div."+value));
236 $compile(ele.contents())($scope);
242 $scope.removeChoice = function(value) {
244 if(value != undefined){
245 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
249 $scope.pullVersion = function(serviceName) {
250 console.log(serviceName);
251 if(serviceName != undefined){
252 var uuu = "policyController/getModelServiceVersioneData.htm";
253 var postData={policyData: serviceName};
258 contentType: 'application/json',
259 data: JSON.stringify(postData),
260 success : function(data){
261 $scope.$apply(function(){
262 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
265 error : function(data){
266 alert("Error While Retriving the Template Layout Pattren.");
273 var splitEqual = '=';
274 var splitComma = ',';
275 var splitcolon = ':';
276 var splitsemicolon = ";";
277 var splitEnum = "],";
278 var plainAttributeKeys = [];
280 var enumKeyList = [];
281 var dictionaryList = [];
282 var dictionaryNameList = [];
283 $scope.addDataToFields = function(serviceName, version){
284 if(serviceName != null && version !=null){
285 var service=serviceName+"-v"+version;
286 var myNode = document.getElementById("DynamicTemplate");
287 myNode.innerHTML = '';
288 var uuu = "policyController/getDCAEMSTemplateData.htm";
289 var postData={policyData: service};
294 contentType: 'application/json',
295 data: JSON.stringify(postData),
296 success : function(data){
297 $scope.$apply(function(){
298 $scope.addNewChoice();
299 var plainAttributeKeys = [];
300 $scope.dcaeModelData = data[0].dcaeModelData;
301 $scope.dcaeJsonDate = data[0].jsonValue;
302 console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
303 var attributes = $scope.dcaeModelData.attributes;
304 var refAttributes = $scope.dcaeModelData.ref_attributes;
305 var subAttributes = $scope.dcaeModelData.sub_attributes;
306 console.log("subAttributes: " + subAttributes);
308 var enumAttributes = $scope.dcaeModelData.enumValues;
309 var annotation = $scope.dcaeModelData.annotation;
310 var dictionary = $scope.microServiceAttributeDictionaryDatas;
312 if (annotation == null || annotation.length<1){
313 $scope.isCheck = true;
315 $scope.isCheck = false;
316 var annoationList = annotation.split(splitComma);
317 for (k = 0; k < annoationList.length; k++){
318 var splitAnnotation = annoationList[k].split(splitEqual);
319 if (splitAnnotation[1].includes("matching-true")){
320 matching.push(splitAnnotation[0].trim());
326 if (dictionary!= null || dictionary>1){
327 if (dictionary!= null || dictionary.length>1){
328 for (m=0; m < dictionary.length; m += 1){
329 var keyCompare = dictionary[m].name;
330 var valueCompare = dictionary[m].value;
331 var valueModel = dictionary[m].modelName;
332 var conpairService = serviceName;
333 if (valueModel.includes('-v')){
334 conpairService = service;
336 if(valueModel.localeCompare(conpairService) == 0){
337 console.log(valueCompare);
338 dictionaryList.push(dictionary[m]);
339 if (!dictionaryNameList.includes(dictionary[m].name)){
340 dictionaryNameList.push(dictionary[m].name)
347 $scope.temp.policy.ruleGridData = [];
349 $scope.jsonLayout($scope.dcaeJsonDate);
352 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
355 if($scope.temp.policy.ruleData != null){
356 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
357 propNames.forEach(function(name) {
360 for(a = 0; a < data.length; a++){
361 var splitPlainAttributeKey1 = data[a].split(".");
362 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
363 var key = splitPlainAttributeKey1[0];
367 var unique = checkData.filter(onlyUnique);
368 for(i =0; i < unique.length; i++){
369 if(unique[i].indexOf("@0") == -1){
370 var finalkey = unique[i].split("@")[0];
371 $scope.addNewChoice(finalkey);
376 var ele = angular.element(document.getElementById("DynamicTemplate"));
377 $compile(ele.contents())($scope);
380 error : function(data){
381 alert("Error While Retriving the Template Layout Pattren.");
387 function getDictionary(attribute){
388 var dicName = attribute;
390 if(attribute.includes(":")){
391 dicName = attribute.split(":")[0];
394 var dictionaryRegExp = new RegExp(dicName);
395 listemunerateValues = [];
396 if (dictionaryRegExp.test(dictionaryNameList)) {
397 for (p=0; p < dictionaryList.length; p += 1) {
398 if (dicName == dictionaryList[p].name) {
399 listemunerateValues.push(dictionaryList[p].value);
403 return listemunerateValues;
406 function getList(attribute) {
407 var enumName = attribute;
408 console.log("In getList: attribute => " + attribute);
410 if(attribute.includes(":")){
411 enumName = attribute.split(":")[0];
414 var baseEnum = $scope.dcaeModelData.enumValues;
416 if(baseEnum != null){
417 enumList = baseEnum.split(splitEnum);
420 var patternTest = new RegExp(enumName);
421 for (k=0; k < enumList.length; k += 1){
422 if(patternTest.test(enumList[k]) == true){
423 enumAttributes = enumList[k].trim();
428 enumAttributes = enumAttributes.replace("[", "");
429 enumAttributes = enumAttributes.replace("]", "");
430 enumAttributes = enumAttributes.replace(/ /g, '');
431 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
432 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
433 //enumKeyList.push(attribute);
434 return listemunerateValues;
440 function getBooleanList(){
441 var booleanList = [];
442 booleanList.push(true);
443 booleanList.push(false);
448 function isArray(arrayTest) {
449 return Object.prototype.toString.call(arrayTest) === '[object Array]';
452 function deconstructJSON(dataTest, level , name) {
455 var stringValue = "java.lang.String";
456 var string = "string";
457 var intValue = "int";
458 var double = "double";
459 var boolean = "boolean";
460 var baseLevel = level;
462 if (name.length > 1){
463 label = label + name + '.';
466 for (key in dataTest) {
467 array = isArray(dataTest[key]);
468 console.log(key , dataTest[key]);
470 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
471 if (array==false && key!=="0"){
472 $scope.labelLayout(label, key, array );
475 if (array == true && key!=0){
479 if (lableList.length > 0){
483 var newKey = lableList.pop();
484 $scope.labelLayout(baseLevel, newKey, array );
486 label = baseLevel + newKey + '@0.';
488 label = baseLevel + newKey + '.';
491 deconstructJSON(dataTest[key] , label, key);
493 var attirbuteLabel = label;
495 var isRequired = false;
496 if (dataTest[key].includes('defaultValue-')){
497 defaultValue = dataTest[key].split('defaultValue-')[1];
502 attributekey = lableList.pop();
503 attirbuteLabel = baseLevel;
505 attributekey = key.split();
508 if (dataTest[key].includes('required-true')){
512 var subAttributes = $scope.dcaeModelData.sub_attributes;
515 var jsonObject = JSON.parse(subAttributes);
516 var allkeys = Object.keys(jsonObject);
518 for (var k = 0; k < allkeys.length; k++) {
519 var keyValue = allkeys[k];
520 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
521 if(jsonObject[keyValue]){
522 var tempObject = jsonObject[keyValue];
523 if(tempObject && tempObject[key]){
524 if (tempObject[key].includes('required-true')){
533 switch (dataTest[key].split(splitcolon)[0]){
535 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
538 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
541 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
544 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
547 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
550 if (dataTest[key].includes('dictionary-')){
551 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
553 var list = getList(dataTest[key]);
555 if (list.length===0){
556 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
558 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
566 $scope.jsonLayout = function(dataTest){
567 deconstructJSON(dataTest , "", "");
571 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
572 $scope.temp.policy.ruleGridData.push(attibuteKey);
573 var br = document.createElement("BR");
575 var label = document.createElement("Label");
576 var labeltext = null;
577 var requiredLabName = "";
578 if (matching.includes(attibuteKey)){
579 labeltext = document.createTextNode(attibuteKey + "*!");
581 //var labeltext = document.createTextNode(refattributeLabel);
583 requiredLabName = attibuteKey + " *";
584 labeltext = document.createTextNode(requiredLabName);
586 labeltext = document.createTextNode(attibuteKey);
591 var divID = labelValue;
593 if (labelValue.length < 1){
594 divID = "DynamicTemplate";
595 }else if (labelValue.endsWith('.')){
596 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
599 label.appendChild(labeltext);
601 var textField = document.createElement("INPUT");
603 textField.setAttribute("class" , "form-control");
604 textField.setAttribute("type" , "text");
605 textField.setAttribute("style" , "width:300px;");
606 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
608 if(attributeManyKey){
609 checkKey = labelValue + attibuteKey+'@0';
610 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
611 var divTag = document.createElement("div");
612 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
613 var addButton = document.createElement("BUTTON");
614 var buttonaddLabel = document.createTextNode("+");
615 addButton.appendChild(buttonaddLabel);
616 addButton.setAttribute("id", labelValue + attibuteKey);
617 addButton.setAttribute("class", "btn btn-add-remove");
618 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
619 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
620 var removeButton = document.createElement("BUTTON");
621 var buttonremoveLabel = document.createTextNode("-");
622 removeButton.appendChild(buttonremoveLabel);
623 removeButton.setAttribute("class", "btn btn-add-remove");
624 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
625 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
626 document.getElementById(divID).appendChild(addButton);
627 document.getElementById(divID).appendChild(removeButton);
628 document.getElementById(divID).appendChild(label);
629 document.getElementById(divID).appendChild(textField);
630 document.getElementById(divID).appendChild(br);
631 document.getElementById(divID).appendChild(divTag);
634 checkKey = labelValue + attibuteKey;
635 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
636 if(requiredLabName.includes("*")){
637 textField.setAttribute("required", "true");
639 document.getElementById(divID).appendChild(label);
640 document.getElementById(divID).appendChild(textField);
641 document.getElementById(divID).appendChild(br);
645 if(divID.includes("@0") && divID.includes("div.")){
646 var firstChild_Id = divID.split("@0")[0];
647 var firstChild_element = document.getElementById(firstChild_Id);
648 if(firstChild_element){
649 firstChild_element.className += ' children_group'; //here is a div with a group of children.
652 console.log('firstChild_Id: ' + firstChild_Id);
653 console.log('divID: ' + divID);
655 if (defaultValue.length > 0){
656 if(defaultValue.includes(":")){
657 defaultValue = defaultValue.split(":")[0];
658 if(defaultValue === "NA") {
662 document.getElementById(checkKey).value = defaultValue;
665 if($scope.temp.policy.ruleData != null){
666 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
667 if (attributeManyKey){
668 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
669 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
672 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
676 $scope.addNewChoice(newCheckKey);
677 document.getElementById(newCheckKey+'@'+i).value = newValue;
683 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
686 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
689 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
690 var label = document.createElement("Label")
691 var divID = labelValue;
692 if (labelValue.endsWith('.')){
693 var workingLabel = labelValue.substring(0, labelValue.length-1);
695 var workingLabel = labelValue;
698 if (labelValue.length < 1){
699 divID = "DynamicTemplate";
700 } else if (labelValue.endsWith('.')){
701 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
704 var labeltext = document.createTextNode(lableName);
706 label.appendChild(labeltext);
708 var subAttributes = $scope.dcaeModelData.sub_attributes;
711 var addButton = document.createElement("BUTTON");
712 var buttonLabel = document.createTextNode("+");
713 addButton.appendChild(buttonLabel);
714 addButton.setAttribute("class", "btn btn-add-remove");
715 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
716 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
717 var removeButton = document.createElement("BUTTON");
718 var buttonremoveLabel = document.createTextNode("-");
719 removeButton.appendChild(buttonremoveLabel);
720 removeButton.setAttribute("class", "btn btn-add-remove");
721 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
722 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
723 document.getElementById(divID).appendChild(addButton);
724 document.getElementById(divID).appendChild(removeButton);
725 document.getElementById(divID).appendChild(label);
726 var id = "div."+labelValue+lableName;
727 var divTag = document.createElement("div");
728 divTag.setAttribute("id", id);
729 document.getElementById(divID).appendChild(divTag);
731 var divTag = document.createElement("div");
732 divTag.setAttribute("id", id +'@0');
734 divTag.className += ' children_group'; //here is div with a group of children.
736 document.getElementById(id).appendChild(divTag);
738 var divTag = document.createElement("div");
739 divTag.setAttribute("id", "div."+labelValue+lableName);
740 divTag.className += ' children_group'; //here is div with a group of children.
741 document.getElementById(divID).appendChild(label);
742 document.getElementById(divID).appendChild(divTag);
746 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
747 var br = document.createElement("BR");
749 if (labelLevel.length < 1){
750 var divID = "DynamicTemplate";
751 } else if (labelLevel.endsWith('.')){
752 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
756 var label = document.createElement("Label")
757 if (matching.includes(attributeName)){
758 var labeltext = document.createTextNode(attributeName + "*!");
760 var labeltext = document.createTextNode(attributeName);
762 label.appendChild(labeltext);
764 var listField = document.createElement("SELECT");
765 listField.setAttribute("class" , "form-control");
766 listField.setAttribute("style" , "width:300px;");
767 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
769 for (i=0; i < listemunerateValues.length; i += 1) {
770 option = document.createElement('option');
771 option.setAttribute('value', listemunerateValues[i]);
772 option.appendChild(document.createTextNode(listemunerateValues[i]));
773 listField.appendChild(option);
775 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
777 enumKeyList.push(attributeName);
779 document.getElementById(divID).appendChild(label);
780 document.getElementById(divID).appendChild(br);
783 document.getElementById(divID).appendChild(listField).multiple = true;
784 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
786 document.getElementById(divID).appendChild(listField).multiple = false;
787 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
790 if($scope.temp.policy.ruleData != null){
792 document.getElementById(labelLevel +attributeName).options[0].selected = false;
793 for (i=0; i < listemunerateValues.length; i += 1) {
794 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
795 if (testValue === undefined){
796 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
798 var location = listemunerateValues.indexOf(testValue);
800 document.getElementById(labelLevel +attributeName).options[location].selected = true;
804 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
810 function onlyUnique(value, index, self) {
811 return self.indexOf(value) === index;
815 function checkDictionary(value){
816 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
817 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
823 $scope.savePolicy = function(policy){
824 if(policy.itemContent != undefined){
825 $scope.refreshCheck = true;
826 $scope.policyNavigator = policy.itemContent;
827 policy.itemContent = "";
829 $scope.savebutton = false;
833 if(plainAttributeKeys != null){
834 for(a = 0; a < plainAttributeKeys.length; a++){
835 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
836 console.log(splitPlainAttributeKey[1]);
837 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
838 var key = splitPlainAttributeKey[0];
839 if(searchElement == null){
840 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
841 key = splitPlainAttributeKey[0]+'@0';
842 }else if (searchElement.nodeName == 'BUTTON'){
843 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
844 key = splitPlainAttributeKey[0]+'@0';
846 if(searchElement != null){
847 var keySplit = key.split(dot);
848 var elumentLocation = keySplit.length;
850 if (elumentLocation > 1){
851 enumKey = keySplit[keySplit.length - 1];
853 if (enumKeyList.indexOf(enumKey) != -1){
854 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
856 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
857 multiSlect.push(searchElement.selectedOptions[i].value);
859 jsonPolicy[key]= multiSlect;
861 console.log(" searchElement.value = > " + searchElement.value);
862 jsonPolicy[key]= searchElement.value;
865 if(searchElement.value != null){
866 console.log(" searchElement.value = > " + searchElement.value);
867 jsonPolicy[key]= searchElement.value;
873 var uuu = "policycreation/save_policy";
874 var postData={policyData: policy, policyJSON : jsonPolicy};
879 contentType: 'application/json',
880 data: JSON.stringify(postData),
881 success : function(data){
882 $scope.$apply(function(){
883 $scope.data=data.policyData;
884 if($scope.data == 'success'){
885 $scope.temp.policy.readOnly = 'true';
886 $scope.safetyChecker = data.policyData.split("#")[2];
887 if ($scope.safetyChecker!=undefined) {
888 Notification.success($scope.safetyChecker);
890 $scope.pushStatus=data.policyData.split("&")[1];
891 if($scope.pushStatus=="successPush"){
892 Notification.success("Policy pushed successfully");
894 Notification.success("Policy Saved Successfully.");
895 }else if ($scope.data == 'PolicyExists'){
896 $scope.savebutton = true;
897 Notification.error("Policy Already Exists with Same Name in Scope.");
900 console.log($scope.data);
902 error : function(data){
903 Notification.error("Error Occured while saving Policy.");
908 $scope.validatePolicy = function(policy){
909 document.getElementById("validate").innerHTML = "";
913 if(plainAttributeKeys != null){
914 for(a = 0; a < plainAttributeKeys.length; a++){
915 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
916 console.log(splitPlainAttributeKey[1]);
917 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
918 var key = splitPlainAttributeKey[0];
919 if(searchElement == null){
920 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
921 key = splitPlainAttributeKey[0]+'@0';
922 }else if (searchElement.nodeName == 'BUTTON'){
923 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
924 key = splitPlainAttributeKey[0]+'@0';
926 if(searchElement != null){
927 if (enumKeyList.indexOf(key) != -1){
928 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
930 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
931 multiSlect.push(searchElement.selectedOptions[i].value);
933 jsonPolicy[key]= multiSlect;
935 jsonPolicy[key]= searchElement.value;
938 if(searchElement.value != null){
939 jsonPolicy[key]= searchElement.value;
940 if(searchElement.getAttribute("required")){
941 if(!searchElement.value){
950 var uuu = "policyController/validate_policy.htm";
951 var postData={policyData: policy, policyJSON : jsonPolicy};
956 contentType: 'application/json',
957 data: JSON.stringify(postData),
958 success : function(data){
959 $scope.$apply(function(){
960 $scope.validateData = data.data.replace(/\"/g, "");
961 $scope.data=data.data.substring(1,8);
962 var size = data.data.length;
963 if($scope.data == 'success'){
964 Notification.success("Validation Success.");
965 $scope.savebutton = false;
967 var displayWarning = data.data.substring(19,size - 1);
968 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
969 document.getElementById("validate").style.color = "white";
970 document.getElementById("validate").style.backgroundColor = "skyblue";
973 Notification.error("Validation Failed.");
974 document.getElementById("validate").innerHTML = $scope.validateData;
975 document.getElementById("validate").style.color = "white";
976 document.getElementById("validate").style.backgroundColor = "red";
977 $scope.savebutton = true;
981 console.log($scope.data);
983 error : function(data){
984 Notification.error("Validation Failed.");
985 $scope.savebutton = true;
990 function extend(obj, src) {
991 for (var key in src) {
992 if (src.hasOwnProperty(key)) obj[key] = src[key];