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.length>1){
327 for (m=0; m < dictionary.length; m += 1){
328 var keyCompare = dictionary[m].name;
329 var valueCompare = dictionary[m].value;
330 var valueModel = dictionary[m].modelName;
331 var conpairService = serviceName;
332 if (valueModel.includes('-v')){
333 conpairService = service;
335 if(valueModel.localeCompare(conpairService) == 0){
336 console.log(valueCompare);
337 dictionaryList.push(dictionary[m]);
338 if (!dictionaryNameList.includes(dictionary[m].name)){
339 dictionaryNameList.push(dictionary[m].name)
345 $scope.temp.policy.ruleGridData = [];
347 $scope.jsonLayout($scope.dcaeJsonDate);
350 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
353 if($scope.temp.policy.ruleData != null){
354 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
355 propNames.forEach(function(name) {
358 for(a = 0; a < data.length; a++){
359 var splitPlainAttributeKey1 = data[a].split(".");
360 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
361 var key = splitPlainAttributeKey1[0];
365 var unique = checkData.filter(onlyUnique);
366 for(i =0; i < unique.length; i++){
367 if(unique[i].indexOf("@0") == -1){
368 var finalkey = unique[i].split("@")[0];
369 $scope.addNewChoice(finalkey);
374 var ele = angular.element(document.getElementById("DynamicTemplate"));
375 $compile(ele.contents())($scope);
378 error : function(data){
379 alert("Error While Retriving the Template Layout Pattren.");
385 function getDictionary(attribute){
386 var dicName = attribute;
388 if(attribute.includes(":")){
389 dicName = attribute.split(":")[0];
392 var dictionaryRegExp = new RegExp(dicName);
393 listemunerateValues = [];
394 if (dictionaryRegExp.test(dictionaryNameList)) {
395 for (p=0; p < dictionaryList.length; p += 1) {
396 if (dicName == dictionaryList[p].name) {
397 listemunerateValues.push(dictionaryList[p].value);
401 return listemunerateValues;
404 function getList(attribute) {
405 var enumName = attribute;
406 console.log("In getList: attribute => " + attribute);
408 if(attribute.includes(":")){
409 enumName = attribute.split(":")[0];
412 var baseEnum = $scope.dcaeModelData.enumValues;
414 if(baseEnum != null){
415 enumList = baseEnum.split(splitEnum);
418 var patternTest = new RegExp(enumName);
419 for (k=0; k < enumList.length; k += 1){
420 if(patternTest.test(enumList[k]) == true){
421 enumAttributes = enumList[k].trim();
426 enumAttributes = enumAttributes.replace("[", "");
427 enumAttributes = enumAttributes.replace("]", "");
428 enumAttributes = enumAttributes.replace(/ /g, '');
429 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
430 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
431 //enumKeyList.push(attribute);
432 return listemunerateValues;
438 function getBooleanList(){
439 var booleanList = [];
440 booleanList.push(true);
441 booleanList.push(false);
446 function isArray(arrayTest) {
447 return Object.prototype.toString.call(arrayTest) === '[object Array]';
450 function deconstructJSON(dataTest, level , name) {
453 var stringValue = "java.lang.String";
454 var string = "string";
455 var intValue = "int";
456 var double = "double";
457 var boolean = "boolean";
458 var baseLevel = level;
460 if (name.length > 1){
461 label = label + name + '.';
464 for (key in dataTest) {
465 array = isArray(dataTest[key]);
466 console.log(key , dataTest[key]);
468 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
469 if (array==false && key!=="0"){
470 $scope.labelLayout(label, key, array );
473 if (array == true && key!=0){
477 if (lableList.length > 0){
481 var newKey = lableList.pop();
482 $scope.labelLayout(baseLevel, newKey, array );
484 label = baseLevel + newKey + '@0.';
486 label = baseLevel + newKey + '.';
489 deconstructJSON(dataTest[key] , label, key);
491 var attirbuteLabel = label;
493 var isRequired = false;
494 if (dataTest[key].includes('defaultValue-')){
495 defaultValue = dataTest[key].split('defaultValue-')[1];
500 attributekey = lableList.pop();
501 attirbuteLabel = baseLevel;
503 attributekey = key.split();
506 if (dataTest[key].includes('required-true')){
510 var subAttributes = $scope.dcaeModelData.sub_attributes;
513 var jsonObject = JSON.parse(subAttributes);
514 var allkeys = Object.keys(jsonObject);
516 for (var k = 0; k < allkeys.length; k++) {
517 var keyValue = allkeys[k];
518 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
519 if(jsonObject[keyValue]){
520 var tempObject = jsonObject[keyValue];
521 if(tempObject && tempObject[key]){
522 if (tempObject[key].includes('required-true')){
531 switch (dataTest[key].split(splitcolon)[0]){
533 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
536 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
539 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
542 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
545 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
548 if (dataTest[key].includes('dictionary-')){
549 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
551 var list = getList(dataTest[key]);
553 if (list.length===0){
554 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
556 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
564 $scope.jsonLayout = function(dataTest){
565 deconstructJSON(dataTest , "", "");
569 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
570 $scope.temp.policy.ruleGridData.push(attibuteKey);
571 var br = document.createElement("BR");
573 var label = document.createElement("Label");
574 var labeltext = null;
575 var requiredLabName = "";
576 if (matching.includes(attibuteKey)){
577 labeltext = document.createTextNode(attibuteKey + "*!");
579 //var labeltext = document.createTextNode(refattributeLabel);
581 requiredLabName = attibuteKey + " *";
582 labeltext = document.createTextNode(requiredLabName);
584 labeltext = document.createTextNode(attibuteKey);
589 var divID = labelValue;
591 if (labelValue.length < 1){
592 divID = "DynamicTemplate";
593 }else if (labelValue.endsWith('.')){
594 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
597 label.appendChild(labeltext);
599 var textField = document.createElement("INPUT");
601 textField.setAttribute("class" , "form-control");
602 textField.setAttribute("type" , "text");
603 textField.setAttribute("style" , "width:300px;");
604 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
606 if(attributeManyKey){
607 checkKey = labelValue + attibuteKey+'@0';
608 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
609 var divTag = document.createElement("div");
610 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
611 var addButton = document.createElement("BUTTON");
612 var buttonaddLabel = document.createTextNode("+");
613 addButton.appendChild(buttonaddLabel);
614 addButton.setAttribute("id", labelValue + attibuteKey);
615 addButton.setAttribute("class", "btn btn-add-remove");
616 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
617 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
618 var removeButton = document.createElement("BUTTON");
619 var buttonremoveLabel = document.createTextNode("-");
620 removeButton.appendChild(buttonremoveLabel);
621 removeButton.setAttribute("class", "btn btn-add-remove");
622 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
623 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
624 document.getElementById(divID).appendChild(addButton);
625 document.getElementById(divID).appendChild(removeButton);
626 document.getElementById(divID).appendChild(label);
627 document.getElementById(divID).appendChild(textField);
628 document.getElementById(divID).appendChild(br);
629 document.getElementById(divID).appendChild(divTag);
632 checkKey = labelValue + attibuteKey;
633 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
634 if(requiredLabName.includes("*")){
635 textField.setAttribute("required", "true");
637 document.getElementById(divID).appendChild(label);
638 document.getElementById(divID).appendChild(textField);
639 document.getElementById(divID).appendChild(br);
643 if(divID.includes("@0") && divID.includes("div.")){
644 var firstChild_Id = divID.split("@0")[0];
645 var firstChild_element = document.getElementById(firstChild_Id);
646 if(firstChild_element){
647 firstChild_element.className += ' children_group'; //here is a div with a group of children.
650 console.log('firstChild_Id: ' + firstChild_Id);
651 console.log('divID: ' + divID);
653 if (defaultValue.length > 0){
654 if(defaultValue.includes(":")){
655 defaultValue = defaultValue.split(":")[0];
656 if(defaultValue === "NA") {
660 document.getElementById(checkKey).value = defaultValue;
663 if($scope.temp.policy.ruleData != null){
664 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
665 if (attributeManyKey){
666 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
667 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
670 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
674 $scope.addNewChoice(newCheckKey);
675 document.getElementById(newCheckKey+'@'+i).value = newValue;
681 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
684 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
687 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
688 var label = document.createElement("Label")
689 var divID = labelValue;
690 if (labelValue.endsWith('.')){
691 var workingLabel = labelValue.substring(0, labelValue.length-1);
693 var workingLabel = labelValue;
696 if (labelValue.length < 1){
697 divID = "DynamicTemplate";
698 } else if (labelValue.endsWith('.')){
699 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
702 var labeltext = document.createTextNode(lableName);
704 label.appendChild(labeltext);
706 var subAttributes = $scope.dcaeModelData.sub_attributes;
709 var addButton = document.createElement("BUTTON");
710 var buttonLabel = document.createTextNode("+");
711 addButton.appendChild(buttonLabel);
712 addButton.setAttribute("class", "btn btn-add-remove");
713 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
714 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
715 var removeButton = document.createElement("BUTTON");
716 var buttonremoveLabel = document.createTextNode("-");
717 removeButton.appendChild(buttonremoveLabel);
718 removeButton.setAttribute("class", "btn btn-add-remove");
719 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
720 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
721 document.getElementById(divID).appendChild(addButton);
722 document.getElementById(divID).appendChild(removeButton);
723 document.getElementById(divID).appendChild(label);
724 var id = "div."+labelValue+lableName;
725 var divTag = document.createElement("div");
726 divTag.setAttribute("id", id);
727 document.getElementById(divID).appendChild(divTag);
729 var divTag = document.createElement("div");
730 divTag.setAttribute("id", id +'@0');
732 divTag.className += ' children_group'; //here is div with a group of children.
734 document.getElementById(id).appendChild(divTag);
736 var divTag = document.createElement("div");
737 divTag.setAttribute("id", "div."+labelValue+lableName);
738 divTag.className += ' children_group'; //here is div with a group of children.
739 document.getElementById(divID).appendChild(label);
740 document.getElementById(divID).appendChild(divTag);
744 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
745 var br = document.createElement("BR");
747 if (labelLevel.length < 1){
748 var divID = "DynamicTemplate";
749 } else if (labelLevel.endsWith('.')){
750 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
754 var label = document.createElement("Label")
755 if (matching.includes(attributeName)){
756 var labeltext = document.createTextNode(attributeName + "*!");
758 var labeltext = document.createTextNode(attributeName);
760 label.appendChild(labeltext);
762 var listField = document.createElement("SELECT");
763 listField.setAttribute("class" , "form-control");
764 listField.setAttribute("style" , "width:300px;");
765 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
767 for (i=0; i < listemunerateValues.length; i += 1) {
768 option = document.createElement('option');
769 option.setAttribute('value', listemunerateValues[i]);
770 option.appendChild(document.createTextNode(listemunerateValues[i]));
771 listField.appendChild(option);
773 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
775 enumKeyList.push(attributeName);
777 document.getElementById(divID).appendChild(label);
778 document.getElementById(divID).appendChild(br);
781 document.getElementById(divID).appendChild(listField).multiple = true;
782 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
784 document.getElementById(divID).appendChild(listField).multiple = false;
785 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
788 if($scope.temp.policy.ruleData != null){
790 document.getElementById(labelLevel +attributeName).options[0].selected = false;
791 for (i=0; i < listemunerateValues.length; i += 1) {
792 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
793 if (testValue === undefined){
794 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
796 var location = listemunerateValues.indexOf(testValue);
798 document.getElementById(labelLevel +attributeName).options[location].selected = true;
802 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
808 function onlyUnique(value, index, self) {
809 return self.indexOf(value) === index;
813 function checkDictionary(value){
814 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
815 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
821 $scope.savePolicy = function(policy){
822 if(policy.itemContent != undefined){
823 $scope.refreshCheck = true;
824 $scope.policyNavigator = policy.itemContent;
825 policy.itemContent = "";
827 $scope.savebutton = false;
831 if(plainAttributeKeys != null){
832 for(a = 0; a < plainAttributeKeys.length; a++){
833 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
834 console.log(splitPlainAttributeKey[1]);
835 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
836 var key = splitPlainAttributeKey[0];
837 if(searchElement == null){
838 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
839 key = splitPlainAttributeKey[0]+'@0';
840 }else if (searchElement.nodeName == 'BUTTON'){
841 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
842 key = splitPlainAttributeKey[0]+'@0';
844 if(searchElement != null){
845 var keySplit = key.split(dot);
846 var elumentLocation = keySplit.length;
848 if (elumentLocation > 1){
849 enumKey = keySplit[keySplit.length - 1];
851 if (enumKeyList.indexOf(enumKey) != -1){
852 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
854 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
855 multiSlect.push(searchElement.selectedOptions[i].value);
857 jsonPolicy[key]= multiSlect;
859 console.log(" searchElement.value = > " + searchElement.value);
860 jsonPolicy[key]= searchElement.value;
863 if(searchElement.value != null){
864 console.log(" searchElement.value = > " + searchElement.value);
865 jsonPolicy[key]= searchElement.value;
871 var uuu = "policycreation/save_policy";
872 var postData={policyData: policy, policyJSON : jsonPolicy};
877 contentType: 'application/json',
878 data: JSON.stringify(postData),
879 success : function(data){
880 $scope.$apply(function(){
881 $scope.data=data.policyData;
882 if($scope.data == 'success'){
883 $scope.temp.policy.readOnly = 'true';
884 $scope.safetyChecker = data.policyData.split("#")[2];
885 if ($scope.safetyChecker!=undefined) {
886 Notification.success($scope.safetyChecker);
888 $scope.pushStatus=data.policyData.split("&")[1];
889 if($scope.pushStatus=="successPush"){
890 Notification.success("Policy pushed successfully");
892 Notification.success("Policy Saved Successfully.");
893 }else if ($scope.data == 'PolicyExists'){
894 $scope.savebutton = true;
895 Notification.error("Policy Already Exists with Same Name in Scope.");
898 console.log($scope.data);
900 error : function(data){
901 Notification.error("Error Occured while saving Policy.");
906 $scope.validatePolicy = function(policy){
907 document.getElementById("validate").innerHTML = "";
911 if(plainAttributeKeys != null){
912 for(a = 0; a < plainAttributeKeys.length; a++){
913 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
914 console.log(splitPlainAttributeKey[1]);
915 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
916 var key = splitPlainAttributeKey[0];
917 if(searchElement == null){
918 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
919 key = splitPlainAttributeKey[0]+'@0';
920 }else if (searchElement.nodeName == 'BUTTON'){
921 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
922 key = splitPlainAttributeKey[0]+'@0';
924 if(searchElement != null){
925 if (enumKeyList.indexOf(key) != -1){
926 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
928 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
929 multiSlect.push(searchElement.selectedOptions[i].value);
931 jsonPolicy[key]= multiSlect;
933 jsonPolicy[key]= searchElement.value;
936 if(searchElement.value != null){
937 jsonPolicy[key]= searchElement.value;
938 if(searchElement.getAttribute("required")){
939 if(!searchElement.value){
948 var uuu = "policyController/validate_policy.htm";
949 var postData={policyData: policy, policyJSON : jsonPolicy};
954 contentType: 'application/json',
955 data: JSON.stringify(postData),
956 success : function(data){
957 $scope.$apply(function(){
958 $scope.validateData = data.data.replace(/\"/g, "");
959 $scope.data=data.data.substring(1,8);
960 var size = data.data.length;
961 if($scope.data == 'success'){
962 Notification.success("Validation Success.");
963 $scope.savebutton = false;
965 var displayWarning = data.data.substring(19,size - 1);
966 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
967 document.getElementById("validate").style.color = "white";
968 document.getElementById("validate").style.backgroundColor = "skyblue";
971 Notification.error("Validation Failed.");
972 document.getElementById("validate").innerHTML = $scope.validateData;
973 document.getElementById("validate").style.color = "white";
974 document.getElementById("validate").style.backgroundColor = "red";
975 $scope.savebutton = true;
979 console.log($scope.data);
981 error : function(data){
982 Notification.error("Validation Failed.");
983 $scope.savebutton = true;
988 function extend(obj, src) {
989 for (var key in src) {
990 if (src.hasOwnProperty(key)) obj[key] = src[key];