[UI] Ignore malformed results
[validation.git] / ui / src / main / webapp / app / BluvalUI / ValidationResults / ValidationResults.Services.js
1 /*
2  * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *        http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var app = angular.module('ValidationResults');
18
19 app
20         .factory(
21                 'generalValidationResultsSvc',
22                 [ function() {
23                     var svc = [];
24                     svc.getBlueprintLayers = function(wrobotDbTestResults) {
25                         if (!wrobotDbTestResults
26                                 || wrobotDbTestResults.length === 0) {
27                             return null;
28                         }
29                         var layers = [];
30                         angular
31                                 .forEach(
32                                         angular.fromJson(wrobotDbTestResults),
33                                         function(wrobotDbTestResult) {
34                                             if (wrobotDbTestResult.layer !== undefined) {
35                                                 layers
36                                                         .push(wrobotDbTestResult.layer);
37                                             }
38                                         });
39                         return layers;
40                     };
41                     svc.mapResult = function(validationDbTestResult) {
42                         if (validationDbTestResult
43                                 && validationDbTestResult.dateStorage) {
44                             if (validationDbTestResult.result === true) {
45                                 return 'SUCCESS';
46                             }
47                             return 'FAILURE'
48                         }
49                         return null;
50                     };
51                     svc.filterWithLayer = function(validationDbTestResults,
52                             filterLayer) {
53                         if (filterLayer === undefined || filterLayer === '') {
54                             return validationDbTestResults;
55                         }
56                         var filteredResults = [];
57                         angular
58                                 .forEach(
59                                         validationDbTestResults,
60                                         function(validationDbTestResult) {
61                                             angular
62                                                     .forEach(
63                                                             angular
64                                                                     .fromJson(validationDbTestResult.wrobotDbTestResults),
65                                                             function(
66                                                                     wrobotDbTestResult) {
67                                                                 if (wrobotDbTestResult.layer
68                                                                         .toLowerCase()
69                                                                         .includes(
70                                                                                 filterLayer
71                                                                                         .toLowerCase())) {
72                                                                     filteredResults
73                                                                             .push(validationDbTestResult);
74                                                                 }
75                                                             });
76                                         });
77                         return filteredResults;
78                     }
79                     svc.filterWithResult = function(validationDbTestResults,
80                             filterResult) {
81                         var validationDbTestResultsWithNoErrors = [];
82                         angular
83                                 .forEach(
84                                         validationDbTestResults,
85                                         function(validationDbTestResult) {
86                                             if (validationDbTestResult.submission || (validationDbTestResult.wrobotDbTestResults && validationDbTestResult.wrobotDbTestResults.length > 0)) {
87                                                 validationDbTestResultsWithNoErrors.push(validationDbTestResult);
88                                             }
89                                         });
90                         if (filterResult === undefined || filterResult === '') {
91                             return validationDbTestResultsWithNoErrors;
92                         }
93                         var filteredResults = [];
94                         angular.forEach(validationDbTestResultsWithNoErrors, function(
95                                 validationDbTestResult) {
96                             if (validationDbTestResult.result === true
97                                     && 'success'.includes(filterResult
98                                             .toLowerCase())) {
99                                 filteredResults.push(validationDbTestResult);
100                             } else if (validationDbTestResult.result === false
101                                     && 'failure'.includes(filterResult
102                                             .toLowerCase())) {
103                                 filteredResults.push(validationDbTestResult);
104                             }
105                         });
106                         return filteredResults;
107                     }
108                     svc.filterWithTimestamp = function(validationDbTestResults,
109                             filterTimestamp) {
110                         if (filterTimestamp === undefined
111                                 || filterTimestamp === '') {
112                             return validationDbTestResults;
113                         }
114                         var filteredResults = [];
115                         angular.forEach(validationDbTestResults, function(
116                                 validationDbTestResult) {
117                             if (validationDbTestResult.timestamp
118                                     && validationDbTestResult.timestamp
119                                             .toLowerCase().includes(
120                                                     filterTimestamp
121                                                             .toLowerCase())) {
122                                 filteredResults.push(validationDbTestResult);
123                             }
124                         });
125                         return filteredResults;
126                     }
127                     return svc;
128                 } ]);