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 if(!$scope.temp.policy.editPolicy && !$scope.temp.policy.readOnly){
29 $scope.temp.policy = {
30 policyType : "Config",
31 configPolicyType : "Micro Service"
35 $scope.refresh = function(){
36 if($scope.refreshCheck){
37 $scope.policyNavigator.refresh();
39 $scope.modal('createNewPolicy', true);
40 $scope.temp.policy = "";
43 $scope.modal = function(id, hide) {
44 return $('#' + id).modal(hide ? 'hide' : 'show');
47 $('#ttlDate').datepicker({
48 dateFormat: 'dd/mm/yy',
51 onSelect: function(date) {
52 angular.element($('#ttlDate')).triggerHandler('input');
56 if ($scope.temp.policy.editPolicy != undefined|| $scope.temp.policy.readOnly != undefined){
57 if ($scope.temp.policy.configName == undefined){
58 $scope.isCheck = false;
60 $scope.isCheck = true;
63 $scope.isCheck = false;
66 PolicyAppService.getData('getDictionary/get_OnapNameDataByName').then(function (data) {
68 $scope.data = JSON.parse(j.data);
69 console.log($scope.data);
70 $scope.onapNameDictionaryDatas = JSON.parse($scope.data.onapNameDictionaryDatas);
71 console.log($scope.onapNameDictionaryDatas);
73 console.log("failed");
76 PolicyAppService.getData('get_DCAEPriorityValues').then(function (data) {
78 $scope.data = JSON.parse(j.data);
79 console.log($scope.data);
80 $scope.priorityDatas = JSON.parse($scope.data.priorityDatas);
81 console.log($scope.priorityDatas);
83 console.log("failed");
86 PolicyAppService.getData('getDictionary/get_GroupPolicyScopeDataByName').then(function (data) {
88 $scope.data = JSON.parse(j.data);
89 console.log($scope.data);
90 $scope.groupPolicyScopeListDatas = JSON.parse($scope.data.groupPolicyScopeListDatas);
91 console.log($scope.groupPolicyScopeListDatas);
93 console.log("failed");
96 PolicyAppService.getData('getDictionary/get_MicroServiceConfigNameDataByName').then(function (data) {
98 $scope.data = JSON.parse(j.data);
99 console.log($scope.data);
100 $scope.microServiceCongigNameDictionaryDatas = JSON.parse($scope.data.microServiceCongigNameDictionaryDatas);
101 console.log($scope.microServiceCongigNameDictionaryDatas);
102 }, function (error) {
103 console.log("failed");
106 PolicyAppService.getData('getDictionary/get_MicroServiceLocationDataByName').then(function (data) {
108 $scope.data = JSON.parse(j.data);
109 console.log($scope.data);
110 $scope.microServiceLocationDictionaryDatas = JSON.parse($scope.data.microServiceLocationDictionaryDatas);
111 console.log($scope.microServiceLocationDictionaryDatas);
112 }, function (error) {
113 console.log("failed");
116 PolicyAppService.getData('getDictionary/get_MicroServiceModelsDataByName').then(function (data) {
118 $scope.data = JSON.parse(j.data);
119 console.log($scope.data);
120 var inputModelList = JSON.parse($scope.data.microServiceModelsDictionaryDatas);
123 for(var i = 0; i < inputModelList.length; i++){
124 if(typeof unique[inputModelList[i]] == "undefined"){
125 unique[inputModelList[i]] = "";
126 uniqueList.push(inputModelList[i]);
129 $scope.microServiceModelsDictionaryDatas = uniqueList;
130 console.log($scope.microServiceModelsDictionaryDatas);
131 }, function (error) {
132 console.log("failed");
135 PolicyAppService.getData('getDictionary/get_DCAEUUIDDataByName').then(function (data) {
137 $scope.data = JSON.parse(j.data);
138 console.log($scope.data);
139 $scope.dcaeUUIDDictionaryDatas = JSON.parse($scope.data.dcaeUUIDDictionaryDatas);
140 console.log($scope.dcaeUUIDDictionaryDatas);
141 }, function (error) {
142 console.log("failed");
145 PolicyAppService.getData('getDictionary/get_RiskTypeDataByName').then(function (data) {
147 $scope.data = JSON.parse(j.data);
148 console.log($scope.data);
149 $scope.riskTypeDictionaryDatas = JSON.parse($scope.data.riskTypeDictionaryDatas);
150 console.log($scope.riskTypeDictionaryDatas);
151 }, function (error) {
152 console.log("failed");
155 PolicyAppService.getData('getDictionary/get_MicroServiceAttributeData').then(function (data) {
157 $scope.data = JSON.parse(j.data);
158 console.log($scope.data);
159 $scope.microServiceAttributeDictionaryDatas = JSON.parse($scope.data.microServiceAttributeDictionaryDatas);
160 console.log($scope.microServiceAttributeDictionaryDatas);
161 }, function (error) {
162 console.log("failed");
167 $scope.attributeDatas = [{"attributes" : $scope.choices}];
169 $scope.addNewChoice = function(value) {
171 if(value != undefined){
172 if (value.startsWith('div.')){
173 value = value.replace('div.','');
175 var parentElement = document.getElementById("div."+value);
176 var div = document.getElementById(value+"@0");
178 var clone = div.cloneNode(true);
179 var addElement = parentElement.childElementCount + 1;
180 clone.id = ''+value+'@'+addElement;
182 clone.className += ' child_single'; //here cloned is single element
183 document.getElementById("div."+value).appendChild(clone);
184 plainAttributeKeys.push(''+value+'@'+addElement);
186 div = document.getElementById("div."+value+"@0");
188 div.className += ' children_group'; //here is div with a group of children.
190 var childElement = parentElement.firstElementChild;
191 var countParent = parentElement.childElementCount;
192 var childElementString = childElement.innerHTML;
193 var find = value+"@0";
194 var re = new RegExp(find, 'g');
195 childElementString = childElementString.replace(re,value+'@' + countParent);
196 var clone = childElement.cloneNode(true);
197 for (var ii = 0; ii < parentElement.childNodes.length; ii++){
198 var childId = parentElement.childNodes[ii].id;
199 if(ii = parentElement.childNodes.length){
200 var childnewId = childId.slice(0, -1);
201 var count = childId.slice(-1);
204 var countvalue = parseInt(count) + 1;
205 clone.id = childnewId+countvalue;
207 clone.innerHTML=childElementString;
208 document.getElementById("div."+value).appendChild(clone);
209 var selects = clone.getElementsByTagName("select");
210 var inputs = clone.getElementsByTagName("input");
211 var removeValues = [];
212 for(var i=0; i<inputs.length; i++){
213 if ($scope.temp.policy.ruleData!=undefined){
214 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
215 if (checkValue!=undefined){
216 if($scope.temp.policy.ruleData != null){
217 var checkValue = $scope.temp.policy.ruleData[inputs[i].id];
218 document.getElementById(inputs[i].id).value = $scope.temp.policy.ruleData[inputs[i].id];
219 plainAttributeKeys.push(inputs[i].id);
222 // removeValues.push(inputs[i].id);
223 plainAttributeKeys.push(inputs[i].id);
226 plainAttributeKeys.push(inputs[i].id);
230 for(var i=0; i<selects.length; i++){
231 if ($scope.temp.policy.ruleData!=undefined){
232 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
233 if (checkValue!=undefined){
234 if($scope.temp.policy.ruleData != null){
235 var checkValue = $scope.temp.policy.ruleData[selects[i].id];
236 document.getElementById(selects[i].id).value = $scope.temp.policy.ruleData[selects[i].id];
237 plainAttributeKeys.push(selects[i].id);
240 plainAttributeKeys.push(selects[i].id);
243 plainAttributeKeys.push(selects[i].id);
247 for (var k=0; k<removeValues.length; k++){
248 var elem = document.getElementById(removeValues[k]);
249 elem.parentNode.removeChild(elem);
251 var ele = angular.element(document.getElementById("div."+value));
252 $compile(ele.contents())($scope);
258 $scope.removeChoice = function(value) {
260 if(value != undefined){
261 document.getElementById("div."+value).removeChild(document.getElementById("div."+value).lastChild);
265 $scope.pullVersion = function(serviceName) {
266 console.log(serviceName);
267 if(serviceName != undefined){
268 var uuu = "policyController/getModelServiceVersioneData.htm";
269 var postData={policyData: serviceName};
274 contentType: 'application/json',
275 data: JSON.stringify(postData),
276 success : function(data){
277 $scope.$apply(function(){
278 $scope.microServiceModelsDictionaryVersionDatas = data[0].dcaeModelVersionData;
281 error : function(data){
282 alert("Error While Retriving the Template Layout Pattren.");
289 var splitEqual = '=';
290 var splitComma = ',';
291 var splitcolon = ':';
292 var splitsemicolon = ";";
293 var splitEnum = "],";
294 var plainAttributeKeys = [];
296 var enumKeyList = [];
297 var dictionaryList = [];
298 var dictionaryNameList = [];
299 $scope.addDataToFields = function(serviceName, version){
300 if(serviceName != null && version !=null){
301 var service=serviceName+"-v"+version;
302 var myNode = document.getElementById("DynamicTemplate");
303 myNode.innerHTML = '';
304 var uuu = "policyController/getDCAEMSTemplateData.htm";
305 var postData={policyData: service};
310 contentType: 'application/json',
311 data: JSON.stringify(postData),
312 success : function(data){
313 $scope.$apply(function(){
314 $scope.addNewChoice();
315 var plainAttributeKeys = [];
316 $scope.dcaeModelData = data[0].dcaeModelData;
317 $scope.dcaeJsonDate = data[0].jsonValue;
318 console.log("$scope.dcaeJsonDate: " + $scope.dcaeJsonDate);
319 var attributes = $scope.dcaeModelData.attributes;
320 var refAttributes = $scope.dcaeModelData.ref_attributes;
321 var subAttributes = $scope.dcaeModelData.sub_attributes;
322 console.log("subAttributes: " + subAttributes);
324 var enumAttributes = $scope.dcaeModelData.enumValues;
325 var annotation = $scope.dcaeModelData.annotation;
326 var dictionary = $scope.microServiceAttributeDictionaryDatas;
328 if (annotation == null || annotation.length<1){
329 $scope.isCheck = true;
331 $scope.isCheck = false;
332 var annoationList = annotation.split(splitComma);
333 for (k = 0; k < annoationList.length; k++){
334 var splitAnnotation = annoationList[k].split(splitEqual);
335 if (splitAnnotation[1].includes("matching-true")){
336 matching.push(splitAnnotation[0].trim());
342 if (dictionary!= null && dictionary.length>1){
343 for (m=0; m < dictionary.length; m += 1){
344 var keyCompare = dictionary[m].name;
345 var valueCompare = dictionary[m].value;
346 var valueModel = dictionary[m].modelName;
347 var conpairService = serviceName;
348 if (valueModel.includes('-v')){
349 conpairService = service;
351 if(valueModel.localeCompare(conpairService) == 0){
352 console.log(valueCompare);
353 dictionaryList.push(dictionary[m]);
354 if (!dictionaryNameList.includes(dictionary[m].name)){
355 dictionaryNameList.push(dictionary[m].name)
361 $scope.temp.policy.ruleGridData = [];
363 $scope.jsonLayout($scope.dcaeJsonDate);
366 if($scope.temp.policy.editPolicy || $scope.temp.policy.readOnly){
369 if($scope.temp.policy.ruleData != null){
370 var propNames = Object.getOwnPropertyNames($scope.temp.policy.ruleData);
371 propNames.forEach(function(name) {
374 for(a = 0; a < data.length; a++){
375 var splitPlainAttributeKey1 = data[a].split(".");
376 if(splitPlainAttributeKey1[0].indexOf("@") != -1){
377 var key = splitPlainAttributeKey1[0];
381 var unique = checkData.filter(onlyUnique);
382 for(i =0; i < unique.length; i++){
383 if(unique[i].indexOf("@0") == -1){
384 var finalkey = unique[i].split("@")[0];
385 $scope.addNewChoice(finalkey);
390 var ele = angular.element(document.getElementById("DynamicTemplate"));
391 $compile(ele.contents())($scope);
394 error : function(data){
395 alert("Error While Retriving the Template Layout Pattren.");
401 function getDictionary(attribute){
402 var dicName = attribute;
404 if(attribute.includes(":")){
405 dicName = attribute.split(":")[0];
408 var dictionaryRegExp = new RegExp(dicName);
409 listemunerateValues = [];
410 if (dictionaryRegExp.test(dictionaryNameList)) {
411 for (p=0; p < dictionaryList.length; p += 1) {
412 if (dicName == dictionaryList[p].name) {
413 listemunerateValues.push(dictionaryList[p].value);
417 return listemunerateValues;
420 function getList(attribute) {
421 var enumName = attribute;
422 console.log("In getList: attribute => " + attribute);
424 if(attribute.includes(":")){
425 enumName = attribute.split(":")[0];
428 var baseEnum = $scope.dcaeModelData.enumValues;
430 if(baseEnum != null){
431 enumList = baseEnum.split(splitEnum);
434 var patternTest = new RegExp(enumName);
435 for (k=0; k < enumList.length; k += 1){
436 if(patternTest.test(enumList[k]) == true){
437 enumAttributes = enumList[k].trim();
442 enumAttributes = enumAttributes.replace("[", "");
443 enumAttributes = enumAttributes.replace("]", "");
444 enumAttributes = enumAttributes.replace(/ /g, '');
445 var dropListAfterCommaSplit = enumAttributes.split(splitEqual);
446 listemunerateValues = dropListAfterCommaSplit[1].split(splitComma);
447 //enumKeyList.push(attribute);
448 return listemunerateValues;
454 function getBooleanList(){
455 var booleanList = [];
456 booleanList.push(true);
457 booleanList.push(false);
462 function isArray(arrayTest) {
463 return Object.prototype.toString.call(arrayTest) === '[object Array]';
466 function deconstructJSON(dataTest, level , name) {
469 var stringValue = "java.lang.String";
470 var string = "string";
471 var intValue = "int";
472 var double = "double";
473 var boolean = "boolean";
474 var baseLevel = level;
476 if (name.length > 1){
477 label = label + name + '.';
480 for (key in dataTest) {
481 array = isArray(dataTest[key]);
482 console.log(key , dataTest[key]);
484 if (!!dataTest[key] && typeof(dataTest[key])=="object") {
485 if (array==false && key!=="0"){
486 $scope.labelLayout(label, key, array );
489 if (array == true && key!=0){
493 if (lableList.length > 0){
497 var newKey = lableList.pop();
498 $scope.labelLayout(baseLevel, newKey, array );
500 label = baseLevel + newKey + '@0.';
502 label = baseLevel + newKey + '.';
505 deconstructJSON(dataTest[key] , label, key);
507 var attirbuteLabel = label;
509 var isRequired = false;
510 if (dataTest[key].includes('defaultValue-')){
511 defaultValue = dataTest[key].split('defaultValue-')[1];
516 attributekey = lableList.pop();
517 attirbuteLabel = baseLevel;
519 attributekey = key.split();
522 if (dataTest[key].includes('required-true')){
526 var subAttributes = $scope.dcaeModelData.sub_attributes;
529 var jsonObject = JSON.parse(subAttributes);
530 var allkeys = Object.keys(jsonObject);
532 for (var k = 0; k < allkeys.length; k++) {
533 var keyValue = allkeys[k];
534 console.log(" keyValue:jsonObject["+keyValue+ "]: " + jsonObject[keyValue]);
535 if(jsonObject[keyValue]){
536 var tempObject = jsonObject[keyValue];
537 if(tempObject && tempObject[key]){
538 if (tempObject[key].includes('required-true')){
547 switch (dataTest[key].split(splitcolon)[0]){
549 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
552 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
555 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
558 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
561 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], getBooleanList());
564 if (dataTest[key].includes('dictionary-')){
565 var list = getDictionary(dataTest[key].split('dictionary-')[1]);
567 var list = getList(dataTest[key]);
569 if (list.length===0){
570 $scope.attributeBox(attributekey, array, attirbuteLabel, defaultValue, isRequired);
572 $scope.dropBoxLayout(attirbuteLabel, attributekey, array, dataTest[key], list);
580 $scope.jsonLayout = function(dataTest){
581 deconstructJSON(dataTest , "", "");
585 $scope.attributeBox = function(attibuteKey, attributeManyKey, labelValue, defaultValue, isRequired){
586 $scope.temp.policy.ruleGridData.push(attibuteKey);
587 var br = document.createElement("BR");
589 var label = document.createElement("Label");
590 var labeltext = null;
591 var requiredLabName = "";
592 if (matching.includes(attibuteKey)){
593 labeltext = document.createTextNode(attibuteKey + "*!");
595 //var labeltext = document.createTextNode(refattributeLabel);
597 requiredLabName = attibuteKey + " *";
598 labeltext = document.createTextNode(requiredLabName);
600 labeltext = document.createTextNode(attibuteKey);
605 var divID = labelValue;
607 if (labelValue.length < 1){
608 divID = "DynamicTemplate";
609 }else if (labelValue.endsWith('.')){
610 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
613 label.appendChild(labeltext);
615 var textField = document.createElement("INPUT");
617 textField.setAttribute("class" , "form-control");
618 textField.setAttribute("type" , "text");
619 textField.setAttribute("style" , "width:300px;");
620 textField.setAttribute("ng-disabled" , "temp.policy.readOnly");
622 if(attributeManyKey){
623 checkKey = labelValue + attibuteKey+'@0';
624 textField.setAttribute("id" , ''+labelValue + attibuteKey+'@0'+'');
625 var divTag = document.createElement("div");
626 divTag.setAttribute("id", "div."+ labelValue +attibuteKey);
627 var addButton = document.createElement("BUTTON");
628 var buttonaddLabel = document.createTextNode("+");
629 addButton.appendChild(buttonaddLabel);
630 addButton.setAttribute("id", labelValue + attibuteKey);
631 addButton.setAttribute("class", "btn btn-add-remove");
632 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + attibuteKey+'");');
633 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
634 var removeButton = document.createElement("BUTTON");
635 var buttonremoveLabel = document.createTextNode("-");
636 removeButton.appendChild(buttonremoveLabel);
637 removeButton.setAttribute("class", "btn btn-add-remove");
638 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue + attibuteKey+'");');
639 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
640 document.getElementById(divID).appendChild(addButton);
641 document.getElementById(divID).appendChild(removeButton);
642 document.getElementById(divID).appendChild(label);
643 document.getElementById(divID).appendChild(textField);
644 document.getElementById(divID).appendChild(br);
645 document.getElementById(divID).appendChild(divTag);
648 checkKey = labelValue + attibuteKey;
649 textField.setAttribute("id" , ''+labelValue +attibuteKey+'');
650 if(requiredLabName.includes("*")){
651 textField.setAttribute("required", "true");
653 document.getElementById(divID).appendChild(label);
654 document.getElementById(divID).appendChild(textField);
655 document.getElementById(divID).appendChild(br);
659 if(divID.includes("@0") && divID.includes("div.")){
660 var firstChild_Id = divID.split("@0")[0];
661 var firstChild_element = document.getElementById(firstChild_Id);
662 if(firstChild_element){
663 firstChild_element.className += ' children_group'; //here is a div with a group of children.
666 console.log('firstChild_Id: ' + firstChild_Id);
667 console.log('divID: ' + divID);
669 if (defaultValue.length > 0){
670 if(defaultValue.includes(":")){
671 defaultValue = defaultValue.split(":")[0];
672 if(defaultValue === "NA") {
676 document.getElementById(checkKey).value = defaultValue;
679 if($scope.temp.policy.ruleData != null){
680 //document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
681 if (attributeManyKey){
682 var newCheckKey = checkKey.replace(attibuteKey + '@0',attibuteKey);
683 document.getElementById(newCheckKey +'@0').value = $scope.temp.policy.ruleData[newCheckKey +'@0'];
686 var newValue = $scope.temp.policy.ruleData[newCheckKey+'@'+i];
690 $scope.addNewChoice(newCheckKey);
691 document.getElementById(newCheckKey+'@'+i).value = newValue;
697 document.getElementById(checkKey).value = $scope.temp.policy.ruleData[checkKey];
700 plainAttributeKeys.push(labelValue + attibuteKey+'*'+attributeManyKey);
703 $scope.labelLayout = function(labelValue, lableName, labelManyKey ){
704 var label = document.createElement("Label")
705 var divID = labelValue;
706 if (labelValue.endsWith('.')){
707 var workingLabel = labelValue.substring(0, labelValue.length-1);
709 var workingLabel = labelValue;
712 if (labelValue.length < 1){
713 divID = "DynamicTemplate";
714 } else if (labelValue.endsWith('.')){
715 var divID = 'div.'+ labelValue.substring(0, labelValue.length-1);
718 var labeltext = document.createTextNode(lableName);
720 label.appendChild(labeltext);
722 var subAttributes = $scope.dcaeModelData.sub_attributes;
725 var addButton = document.createElement("BUTTON");
726 var buttonLabel = document.createTextNode("+");
727 addButton.appendChild(buttonLabel);
728 addButton.setAttribute("class", "btn btn-add-remove");
729 addButton.setAttribute("ng-click" , 'addNewChoice("'+labelValue + lableName+'");');
730 addButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
731 var removeButton = document.createElement("BUTTON");
732 var buttonremoveLabel = document.createTextNode("-");
733 removeButton.appendChild(buttonremoveLabel);
734 removeButton.setAttribute("class", "btn btn-add-remove");
735 removeButton.setAttribute("ng-click" , 'removeChoice("'+labelValue +lableName+'");');
736 removeButton.setAttribute("ng-disabled" , "temp.policy.readOnly");
737 document.getElementById(divID).appendChild(addButton);
738 document.getElementById(divID).appendChild(removeButton);
739 document.getElementById(divID).appendChild(label);
740 var id = "div."+labelValue+lableName;
741 var divTag = document.createElement("div");
742 divTag.setAttribute("id", id);
743 document.getElementById(divID).appendChild(divTag);
745 var divTag = document.createElement("div");
746 divTag.setAttribute("id", id +'@0');
748 divTag.className += ' children_group'; //here is div with a group of children.
750 document.getElementById(id).appendChild(divTag);
752 var divTag = document.createElement("div");
753 divTag.setAttribute("id", "div."+labelValue+lableName);
754 divTag.className += ' children_group'; //here is div with a group of children.
755 document.getElementById(divID).appendChild(label);
756 document.getElementById(divID).appendChild(divTag);
760 $scope.dropBoxLayout = function(labelLevel, attributeName, many , refValue, listemunerateValues){
761 var br = document.createElement("BR");
763 if (labelLevel.length < 1){
764 var divID = "DynamicTemplate";
765 } else if (labelLevel.endsWith('.')){
766 var divID = 'div.'+ labelLevel.substring(0, labelLevel.length-1);
770 var label = document.createElement("Label")
771 if (matching.includes(attributeName)){
772 var labeltext = document.createTextNode(attributeName + "*!");
774 var labeltext = document.createTextNode(attributeName);
776 label.appendChild(labeltext);
778 var listField = document.createElement("SELECT");
779 listField.setAttribute("class" , "form-control");
780 listField.setAttribute("style" , "width:300px;");
781 listField.setAttribute("ng-disabled" , "temp.policy.readOnly");
783 for (i=0; i < listemunerateValues.length; i += 1) {
784 option = document.createElement('option');
785 option.setAttribute('value', listemunerateValues[i]);
786 option.appendChild(document.createTextNode(listemunerateValues[i]));
787 listField.appendChild(option);
789 listField.setAttribute("id" , ''+ labelLevel + attributeName + '');
791 enumKeyList.push(attributeName);
793 document.getElementById(divID).appendChild(label);
794 document.getElementById(divID).appendChild(br);
797 document.getElementById(divID).appendChild(listField).multiple = true;
798 plainAttributeKeys.push(labelLevel + attributeName+'*'+true);
800 document.getElementById(divID).appendChild(listField).multiple = false;
801 plainAttributeKeys.push(labelLevel + attributeName+'*'+false);
804 if($scope.temp.policy.ruleData != null){
806 document.getElementById(labelLevel +attributeName).options[0].selected = false;
807 for (i=0; i < listemunerateValues.length; i += 1) {
808 var testValue = $scope.temp.policy.ruleData[labelLevel +attributeName+'@' + i];
809 if (testValue === undefined){
810 testValue = $scope.temp.policy.ruleData[labelLevel +attributeName];
812 var location = listemunerateValues.indexOf(testValue);
814 document.getElementById(labelLevel +attributeName).options[location].selected = true;
818 document.getElementById(labelLevel + attributeName).value = $scope.temp.policy.ruleData[labelLevel + attributeName];
824 function onlyUnique(value, index, self) {
825 return self.indexOf(value) === index;
829 function checkDictionary(value){
830 for (i = 0; i < $scope.microServiceAttributeDictionaryDatas.length; i++) {
831 if ($scope.microServiceAttributeDictionaryDatas[i].name.localeCompare(value)){
837 $scope.savePolicy = function(policy){
838 if(policy.itemContent != undefined){
839 $scope.refreshCheck = true;
840 $scope.policyNavigator = policy.itemContent;
841 policy.itemContent = "";
843 $scope.savebutton = false;
847 if(plainAttributeKeys != null){
848 for(a = 0; a < plainAttributeKeys.length; a++){
849 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
850 console.log(splitPlainAttributeKey[1]);
851 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
852 var key = splitPlainAttributeKey[0];
853 if(searchElement == null){
854 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
855 key = splitPlainAttributeKey[0]+'@0';
856 }else if (searchElement.nodeName == 'BUTTON'){
857 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
858 key = splitPlainAttributeKey[0]+'@0';
860 if(searchElement != null){
861 var keySplit = key.split(dot);
862 var elumentLocation = keySplit.length;
864 if (elumentLocation > 1){
865 enumKey = keySplit[keySplit.length - 1];
867 if (enumKeyList.indexOf(enumKey) != -1){
868 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
870 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
871 multiSlect.push(searchElement.selectedOptions[i].value);
873 jsonPolicy[key]= multiSlect;
875 console.log(" searchElement.value = > " + searchElement.value);
876 jsonPolicy[key]= searchElement.value;
879 if(searchElement.value != null){
880 console.log(" searchElement.value = > " + searchElement.value);
881 jsonPolicy[key]= searchElement.value;
887 var uuu = "policycreation/save_policy";
888 var postData={policyData: policy, policyJSON : jsonPolicy};
893 contentType: 'application/json',
894 data: JSON.stringify(postData),
895 success : function(data){
896 $scope.$apply(function(){
897 $scope.data=data.policyData;
898 if($scope.data == 'success'){
899 $scope.temp.policy.readOnly = 'true';
900 $scope.safetyChecker = data.policyData.split("#")[2];
901 if ($scope.safetyChecker!=undefined) {
902 Notification.success($scope.safetyChecker);
904 $scope.pushStatus=data.policyData.split("&")[1];
905 if($scope.pushStatus=="successPush"){
906 Notification.success("Policy pushed successfully");
908 Notification.success("Policy Saved Successfully.");
909 }else if ($scope.data == 'PolicyExists'){
910 $scope.savebutton = true;
911 Notification.error("Policy Already Exists with Same Name in Scope.");
914 console.log($scope.data);
916 error : function(data){
917 Notification.error("Error Occured while saving Policy.");
922 $scope.validatePolicy = function(policy){
923 document.getElementById("validate").innerHTML = "";
927 if(plainAttributeKeys != null){
928 for(a = 0; a < plainAttributeKeys.length; a++){
929 var splitPlainAttributeKey = plainAttributeKeys[a].split(splitAt);
930 console.log(splitPlainAttributeKey[1]);
931 var searchElement = document.getElementById(splitPlainAttributeKey[0]);
932 var key = splitPlainAttributeKey[0];
933 if(searchElement == null){
934 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
935 key = splitPlainAttributeKey[0]+'@0';
936 }else if (searchElement.nodeName == 'BUTTON'){
937 searchElement = document.getElementById(splitPlainAttributeKey[0]+'@0');
938 key = splitPlainAttributeKey[0]+'@0';
940 if(searchElement != null){
941 if (enumKeyList.indexOf(key) != -1){
942 if (splitPlainAttributeKey[1].indexOf("true") !== -1){
944 for ( var i = 0; i < searchElement.selectedOptions.length; i++) {
945 multiSlect.push(searchElement.selectedOptions[i].value);
947 jsonPolicy[key]= multiSlect;
949 jsonPolicy[key]= searchElement.value;
952 if(searchElement.value != null){
953 jsonPolicy[key]= searchElement.value;
954 if(searchElement.getAttribute("required")){
955 if(!searchElement.value){
964 var uuu = "policyController/validate_policy.htm";
965 var postData={policyData: policy, policyJSON : jsonPolicy};
970 contentType: 'application/json',
971 data: JSON.stringify(postData),
972 success : function(data){
973 $scope.$apply(function(){
974 $scope.validateData = data.data.replace(/\"/g, "");
975 $scope.data=data.data.substring(1,8);
976 var size = data.data.length;
977 if($scope.data == 'success'){
978 Notification.success("Validation Success.");
979 $scope.savebutton = false;
981 var displayWarning = data.data.substring(19,size - 1);
982 document.getElementById("validate").innerHTML = "Safe Policy Warning Message : "+displayWarning;
983 document.getElementById("validate").style.color = "white";
984 document.getElementById("validate").style.backgroundColor = "skyblue";
987 Notification.error("Validation Failed.");
988 document.getElementById("validate").innerHTML = $scope.validateData;
989 document.getElementById("validate").style.color = "white";
990 document.getElementById("validate").style.backgroundColor = "red";
991 $scope.savebutton = true;
995 console.log($scope.data);
997 error : function(data){
998 Notification.error("Validation Failed.");
999 $scope.savebutton = true;
1004 function extend(obj, src) {
1005 for (var key in src) {
1006 if (src.hasOwnProperty(key)) obj[key] = src[key];