Initial coomit for AAI-UI(sparky-fe)
[aai/sparky-fe.git] / src / app / networking / NetworkUtil.js
1 /*
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25
26 import {
27   AUDIT_SEARCH_DATE_FORMAT,
28   AUDIT_SEARCH_DATE_TIME_ZONE
29 } from './NetworkConstants.js';
30
31 export function getTableDateQueryString(requestObject) {
32   return {
33     'queryParameters': {
34       'startDate': requestObject.dateRange.startDate.format(
35         AUDIT_SEARCH_DATE_FORMAT),
36       'endDate': requestObject.dateRange.endDate.format(
37         AUDIT_SEARCH_DATE_FORMAT),
38       'time_zone': requestObject.dateRange.startDate.format(
39         AUDIT_SEARCH_DATE_TIME_ZONE),
40       'typeData': {
41         'type': 'pagination',
42         'from': requestObject.startIndex,
43         'size': requestObject.resultCount
44       }
45     }
46   };
47 }
48
49 export function getTSUIElasticSearchQueryString(query) {
50   // Create the query request
51   let posFirstEqualSign = query.indexOf('=');
52   let newQuery = query.substring(posFirstEqualSign + 1);  // remove the first
53                                                           // 'attrName=' from
54                                                           //'attrName=attrValue'
55   newQuery = newQuery.replace(/\,[^\=]+\=/gi, ' ');  // remove all ', attrName='
56   newQuery = newQuery.trim(); // remove whitespace at both ends, if any
57
58   return {
59     'maxResults': '10',
60     'queryStr': newQuery
61   };
62 }
63 export function getSeverityVisualizationQueryString(requestObject) {
64   return {
65     'queryParameters': {
66       'startDate': requestObject.dateRange.startDate.format(
67         AUDIT_SEARCH_DATE_FORMAT),
68       'endDate': requestObject.dateRange.endDate.format(
69         AUDIT_SEARCH_DATE_FORMAT),
70       'time_zone': requestObject.dateRange.startDate.format(
71         AUDIT_SEARCH_DATE_TIME_ZONE),
72       'typeData': {
73         'type': 'groupBy',
74         'groupByField': 'severity'
75       }
76     }
77   };
78 }
79
80 export function getStatusVisualizationQueryString(requestObject) {
81   return {
82     'queryParameters': {
83       'startDate': requestObject.dateRange.startDate.format(
84         AUDIT_SEARCH_DATE_FORMAT),
85       'endDate': requestObject.dateRange.endDate.format(
86         AUDIT_SEARCH_DATE_FORMAT),
87       'time_zone': requestObject.dateRange.startDate.format(
88         AUDIT_SEARCH_DATE_TIME_ZONE),
89       'typeData': {
90         'type': 'groupBy',
91         'groupByField': 'category'
92       }
93     }
94   };
95 }
96
97 export function getEntityTypeVisualizationQueryString(requestObject) {
98   return {
99     'queryParameters': {
100       'startDate': requestObject.dateRange.startDate.format(
101         AUDIT_SEARCH_DATE_FORMAT),
102       'endDate': requestObject.dateRange.endDate.format(
103         AUDIT_SEARCH_DATE_FORMAT),
104       'time_zone': requestObject.dateRange.startDate.format(
105         AUDIT_SEARCH_DATE_TIME_ZONE),
106       'typeData': {
107         'type': 'groupBy',
108         'groupByField': 'entityType'
109       }
110     }
111   };
112 }
113
114 export function getDateVisualizationQueryString(requestObject) {
115   return {
116     'queryParameters': {
117       'startDate': requestObject.dateRange.startDate.format(
118         AUDIT_SEARCH_DATE_FORMAT),
119       'endDate': requestObject.dateRange.endDate.format(
120         AUDIT_SEARCH_DATE_FORMAT),
121       'time_zone': requestObject.dateRange.startDate.format(
122         AUDIT_SEARCH_DATE_TIME_ZONE),
123       'typeData': {
124         'type': 'dateHistogram'
125       }
126     }
127   };
128 }
129
130 export function getVnfOrchStatusQueryString(requestObject) {
131   return {
132     'hashId': requestObject,
133     'groupby': 'orchestration-status'
134   };
135 }
136 export function getVnfProvStatusQueryString(requestObject) {
137   return {
138     'hashId': requestObject,
139     'groupby': 'prov-status'
140   };
141 }
142 export function getVnfCountQueryString(requestObject) {
143   return {
144     'hashId': requestObject
145   };
146 }
147
148
149
150
151