bfda0b1495566b2c78a44b347619844e4cf18afe
[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.factory('generalValidationResultsSvc', [ function() {
20     var svc = [];
21     svc.getBlueprintLayers = function(wRobotNexusTestResults) {
22         var layers = [];
23         angular.forEach(wRobotNexusTestResults,
24                 function(wRobotNexusTestResult) {
25                     if (wRobotNexusTestResult.blueprintLayer !== undefined) {
26                         layers.push(wRobotNexusTestResult.blueprintLayer);
27                     }
28                 });
29         return layers;
30     };
31     svc.mapResult = function(validationNexusTestResult) {
32         if (!validationNexusTestResult.timestamp) {
33             return null;
34         }
35         if (!validationNexusTestResult.wRobotNexusTestResults) {
36             return null;
37         }
38         if (validationNexusTestResult.wRobotNexusTestResults.length === 0) {
39             return null;
40         }
41         var resultExistence = false;
42         angular.forEach(validationNexusTestResult.wRobotNexusTestResults,
43                 function(result) {
44                     if (result.robotTestResults
45                             && result.robotTestResults.length > 0) {
46                         resultExistence = true;
47                     }
48                 });
49         if (resultExistence) {
50             if (validationNexusTestResult.result === true) {
51                 return 'SUCCESS';
52             }
53             return 'FAILURE'
54         }
55         return null;
56     };
57     svc.filterWithLayer = function(validationNexusTestResults, filterLayer) {
58         if (filterLayer === undefined || filterLayer === '') {
59             return validationNexusTestResults;
60         }
61         var filteredResults = [];
62         angular.forEach(validationNexusTestResults, function(
63                 validationNexusTestResult) {
64             angular.forEach(validationNexusTestResult.wRobotNexusTestResults,
65                     function(wRobotNexusTestResult) {
66                         if (wRobotNexusTestResult.blueprintLayer.toLowerCase()
67                                 .includes(filterLayer.toLowerCase())) {
68                             filteredResults.push(validationNexusTestResult);
69                         }
70                     });
71         });
72         return filteredResults;
73     }
74     svc.filterWithResult = function(validationNexusTestResults, filterResult) {
75         if (filterResult === undefined || filterResult === '') {
76             return validationNexusTestResults;
77         }
78         var filteredResults = [];
79         angular.forEach(validationNexusTestResults, function(
80                 validationNexusTestResult) {
81             if (validationNexusTestResult.result === true
82                     && 'success'.includes(filterResult.toLowerCase())) {
83                 filteredResults.push(validationNexusTestResult);
84             } else if (validationNexusTestResult.result === false
85                     && 'failure'.includes(filterResult.toLowerCase())) {
86                 filteredResults.push(validationNexusTestResult);
87             }
88         });
89         return filteredResults;
90     }
91     svc.getLab = function(silo, silos) {
92         var lab = null;
93         angular.forEach(silos, function(siloData) {
94             if (silo === siloData.silo) {
95                 lab = siloData.lab.lab;
96             }
97         });
98         return lab;
99     }
100     return svc;
101 } ]);