2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2021 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=========================================================
21 import {GlobalExtConstants} from 'utils/GlobalExtConstants.js';
23 let OXM = GlobalExtConstants.OXM;
25 var scrollTo = function(id) {
26 setTimeout(function () {
27 document.getElementById("main-app-container").scrollTop = document.getElementById(id).offsetTop;
30 var populatePathDSL = function(tree, isInit, onLoad, enableRealTime){
31 console.log('populatePathDSL>>>>>>> pathFIlter****',tree);
34 var treeArrayLength = 0;
39 treeArray = tree.children;
40 treeArrayLength = tree.children.length;
42 for(var k = 0; treeArray && k < treeArrayLength; k++){
43 if(k === 0 && treeArrayLength > 1){
52 var nodeData=(onLoad)?node:node.data;
54 console.log('***************',JSON.stringify(nodeData));
56 DSL += '(>'+nodeData.name;
63 var tempAttributeString = '';
64 var selectedAttributeCount = 0;
65 for (var key in nodeData.details.attrDetails){
66 if(nodeData.details.attrDetails[key].filterValue && nodeData.details.attrDetails[key].filterValue[0] !==''){
67 DSL += '(\'' + nodeData.details.attrDetails[key].attributeName + '\',';
69 for(var indx=0; indx<nodeData.details.attrDetails[key].filterValue.length; indx++){
70 dslValues=(indx>0) ? dslValues+',':dslValues;
71 if(enableRealTime && nodeData.details.attrDetails[key].filterType && nodeData.details.attrDetails[key].filterType[indx]){
72 dslValues += nodeData.details.attrDetails[key].filterType[indx]+'(\''+ nodeData.details.attrDetails[key].filterValue[indx] + '\')';
74 dslValues +='\''+nodeData.details.attrDetails[key].filterValue[indx] + '\'';
76 if(nodeData.details.attrDetails[key].filterValue.length-1 === indx){
85 if(node.children && node.children.length>0){
86 DSL+= '>' + populatePathDSL(node,false,onLoad,enableRealTime);
88 if(k !== treeArrayLength - 1){
91 if(k === treeArrayLength - 1 && treeArrayLength > 1){
100 var getFilteringOptions = function(nodeType){
101 var propertiesDsl = [];
102 var result = JSON.parse(OXM);
103 var arrayOfTypes = result['xml-bindings']['java-types'][0]['java-type'];
104 //console.dir(arrayOfTypes);
106 var searchParam = nodeType;
108 if (nodeType.toUpperCase() === 'LINESOFBUSINESS') {
109 searchParam = 'lineOfBusiness';
111 //console.log('searchParam:' + searchParam);
112 for (var i = 0; i < arrayOfTypes.length && foundIndex === -1; i++) {
113 if (arrayOfTypes[i]['xml-root-element'][0]['$']['name'] === camelToDash(searchParam)) {
117 if(foundIndex && arrayOfTypes[foundIndex]){
118 //build the filter list
119 for (var j = 0; j < arrayOfTypes[foundIndex]['java-attributes'][0]['xml-element'].length; j++) {
120 let property = arrayOfTypes[foundIndex]['java-attributes'][0]['xml-element'][j]['$']['name'];
121 let type = arrayOfTypes[foundIndex]['java-attributes'][0]['xml-element'][j]['$']['type'];
122 if(property !== 'length'){
123 if (type === 'java.lang.String' || type === 'java.lang.Boolean' || type === 'java.lang.Long' || type === 'java.lang.Integer') {
124 propertiesDsl[property] = {};
125 propertiesDsl[property].isSelected = false;
126 propertiesDsl[property].attributeName = property;
127 propertiesDsl[property].filterValue = [''];
128 propertiesDsl[property].filterType = [''];
129 propertiesDsl[property].dslPath = [];
130 propertiesDsl[property].dslPathTree = [];
134 let sortedPropertiesDsl = propertiesDsl.sort(function (filter1, filter2) {
135 if (filter1.attributeName < filter2.attributeName) {
137 } else if (filter1.attributeName > filter2.attributeName) {
143 //console.log('FilterList' + JSON.stringify(sortedPropertiesDsl));
144 return sortedPropertiesDsl;
149 var getNodeTypes = function(){
150 var result = JSON.parse(OXM);
151 var arrayOfTypes = result['xml-bindings']['java-types'][0]['java-type'];
152 var nodeTypeArray = [];
153 for(var j = 0; j < arrayOfTypes.length; j++){
154 if(arrayOfTypes[j]['xml-root-element'] && arrayOfTypes[j]['xml-root-element'][0]
155 && arrayOfTypes[j]['xml-root-element'][0]['$'] && arrayOfTypes[j]['xml-root-element'][0]['$']['name']){
156 nodeTypeArray.push((arrayOfTypes[j]['xml-root-element'][0]['$']['name']).toLowerCase());
159 return nodeTypeArray;
161 var populateContainer = function(nodeType){
162 var result = JSON.parse(OXM);
163 var arrayOfTypes = result['xml-bindings']['java-types'][0]['java-type'];
166 for (var i = 0; i < arrayOfTypes.length && !isFound; i++) {
167 if(arrayOfTypes[i]['xml-root-element'][0]['$']['name'] === nodeType
168 && arrayOfTypes[i]['xml-properties']
169 && arrayOfTypes[i]['xml-properties'][0]
170 && arrayOfTypes[i]['xml-properties'][0]['xml-property']){
172 for(var k = 0; k < arrayOfTypes[i]['xml-properties'][0]['xml-property'].length; k++){
173 if(arrayOfTypes[i]['xml-properties'][0]['xml-property'][k]['$']['name'] === 'container'){
174 container = arrayOfTypes[i]['xml-properties'][0]['xml-property'][k]['$']['value'];
181 var getEditableAttributes = function(nodeType){
182 //get this from the oxm field
183 var result = JSON.parse(OXM);
184 var arrayOfTypes = result['xml-bindings']['java-types'][0]['java-type'];
186 var uiEditableProps = [];
187 for (var i = 0; i < arrayOfTypes.length && !isFound; i++) {
188 if(arrayOfTypes[i]['xml-root-element'][0]['$']['name'] === nodeType
189 && arrayOfTypes[i]['xml-properties']
190 && arrayOfTypes[i]['xml-properties'][0]
191 && arrayOfTypes[i]['xml-properties'][0]['xml-property']){
193 for(var k = 0; k < arrayOfTypes[i]['xml-properties'][0]['xml-property'].length; k++){
194 if(arrayOfTypes[i]['xml-properties'][0]['xml-property'][k]['$']['name'] === 'uiEditableProps'){
195 uiEditableProps = ((arrayOfTypes[i]['xml-properties'][0]['xml-property'][k]['$']['value']).replace(/\s/g,"")).split(',');
200 return uiEditableProps;
202 var populateEdgeRules = function(nodeType,edgeRules){
203 var nodeDetails = [];
205 console.log('populateEdgeRules.nodeType: ' + nodeType);
206 var id = generateID();
207 for (var i = 0; i < edgeRules.length; i++) {
208 var ruleObj = edgeRules[i];
209 if (ruleObj.from === nodeType && !nodeDetails[ruleObj.to + id]) {
210 node = ruleObj.to + id;
211 if(!nodeDetails[node]){
212 nodeDetails[node] = {};
213 nodeDetails[node].nodeType = ruleObj.to;
214 nodeDetails[node].isSelected = false;
215 nodeDetails[node].attrDetails = GeneralCommonFunctions.getFilteringOptions(ruleObj.to);
216 nodeDetails[node].parentContainer = GeneralCommonFunctions.populateContainer(ruleObj.to);
219 if (ruleObj.to === nodeType && !nodeDetails[ruleObj.from + id]) {
220 node = ruleObj.from + id;
221 if(!nodeDetails[node]){
222 nodeDetails[node] = {};
223 nodeDetails[node].nodeType = ruleObj.from;
224 nodeDetails[node].isSelected = false;
225 nodeDetails[node].attrDetails = GeneralCommonFunctions.getFilteringOptions(ruleObj.from);
226 nodeDetails[node].parentContainer = GeneralCommonFunctions.populateContainer(ruleObj.from);
230 let nodesSorted = nodeDetails.sort(function (filter1, filter2) {
231 if (filter1.nodeType < filter2.nodeType) {
233 } else if (filter1.nodeType > filter2.nodeType) {
239 console.log('EdgeRulesList' + JSON.stringify(nodesSorted));
240 nodeDetails = nodesSorted;
243 var camelToDash = function(str){
244 return (str.replace(/\W+/g, '-')
245 .replace(/([a-z\d])([A-Z])/g, '$1-$2')).toLowerCase();
247 var generateID = function(){
248 return Math.random().toString().replace('0.', '');
250 var extractNodeDetails = function(node, isRoot, errorFunction, isAperture){
251 let nodeType = node['node-type'];
258 nodeData.details.includeInOutput = node.store;
259 nodeData.details.isSelected = true;
260 nodeData.details.isRootNode = isRoot;
261 nodeData.details.nodeType = nodeType;
262 var attributes = GeneralCommonFunctions.getFilteringOptions(nodeType);
263 nodeData.details.attrDetails = attributes;
264 nodeData.details.parentContainer = GeneralCommonFunctions.populateContainer(nodeType);
265 if(node.store && !node['requested-props']){
266 for(var key in nodeData.details.attrDetails){
267 nodeData.details.attrDetails[key].isSelected = true;
269 }else if (node.store && node['requested-props']){
270 for(var key in node['requested-props']){
271 nodeData.details.attrDetails[key].isSelected = true;
275 for (var x in node['node-filter']){
277 for (var y in node['node-filter'][x]) {
279 var attrKey = node['node-filter'][x][y]['key'];
280 var filter = node['node-filter'][x][y]['filter'];
281 //If aperture is not turned on and query loaded uses anything besides EQ throw error
282 //when merged with calls from builder use condition to enable this
283 /*if(!isAperture && filter !== 'EQ'){
284 errorFunction(null, "invalidQuery");
287 if(!nodeData.details.attrDetails[attrKey]){
288 nodeData.details.attrDetails[attrKey] = {};
290 if(nodeData.details.attrDetails[attrKey].filterType.length > 0 && nodeData.details.attrDetails[attrKey].filterType[0] === ''){
291 nodeData.details.attrDetails[attrKey].filterType = [];
293 if(nodeData.details.attrDetails[attrKey].filterValue.length > 0 && nodeData.details.attrDetails[attrKey].filterValue[0] === ''){
294 nodeData.details.attrDetails[attrKey].filterValue = [];
297 if(node['node-filter'][x][y]['value'][0]){
298 for (var i in node['node-filter'][x][y]['value']){
299 nodeData.details.attrDetails[attrKey].filterType.push(filter);
300 nodeData.details.attrDetails[attrKey].filterValue.push(node['node-filter'][x][y]['value'][i]);
302 if(!nodeData.details.attrDetails[attrKey].attributeName){
303 nodeData.details.attrDetails[attrKey].attributeName = attrKey;
306 //if a filter had no values associated to it do nothing
307 //when merged with calls from builder use condition to enable this
308 /* errorFunction(null, "invalidQuery");
315 var initWhereNode = null;
316 if(node['where-filter'].length > 0){
317 for(var index in node['where-filter']){
318 initWhereNode = GeneralCommonFunctions.extractNodeDetails(node['where-filter'][index].children[0], true);
322 nodeData.details.dslPath=[];
323 nodeData.details.dslPathTree=[];
324 nodeData.details.dslPathTree.push(initWhereNode);
326 if(node.children.length > 0){
327 for(var i = 0; i < node.children.length; i++){
328 nodeData.children[i] = GeneralCommonFunctions.extractNodeDetails(node.children[i], false);
333 export const GeneralCommonFunctions = {
335 populatePathDSL: populatePathDSL,
336 getFilteringOptions: getFilteringOptions,
337 getNodeTypes: getNodeTypes,
338 populateContainer: populateContainer,
339 populateEdgeRules: populateEdgeRules,
340 camelToDash: camelToDash,
341 generateID: generateID,
342 extractNodeDetails: extractNodeDetails,
343 getEditableAttributes: getEditableAttributes