dd4f699a11169686da8ff67c37bf469bde5a90c0
[validation.git] / ui / src / main / webapp / app / BluvalUI / CommittedSubmissions / CommittedSubmissions.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('CommittedSubmissions');
18
19 app
20         .factory(
21                 'committedSubmissionsSvc',
22                 [ function() {
23                     var svc = [];
24                     svc.getLayer = function(validationNexusTestResult) {
25                         if (validationNexusTestResult.allLayers) {
26                             return "all";
27                         }
28                         var layers = [];
29                         angular
30                                 .forEach(
31                                         validationNexusTestResult.wRobotNexusTestResults,
32                                         function(result) {
33                                             layers.push(result.blueprintLayer);
34                                         });
35                         return layers;
36                     };
37                     svc.getResultUrl = function(submissionData) {
38                         if (submissionData.status !== "Completed") {
39                             return null;
40                         }
41                         if (!submissionData.validationNexusTestResult.wRobotNexusTestResults) {
42                             return null;
43                         }
44                         if (submissionData.validationNexusTestResult.wRobotNexusTestResults.length === 0) {
45                             return null;
46                         }
47                         var resultExistence = false;
48                         angular
49                                 .forEach(
50                                         submissionData.validationNexusTestResult.wRobotNexusTestResults,
51                                         function(result) {
52                                             if (result.robotTestResults
53                                                     && result.robotTestResults.length > 0) {
54                                                 resultExistence = true;
55                                             }
56                                         });
57                         if (resultExistence) {
58                             return "https://nexus.akraino.org/content/sites/logs/"
59                                     + submissionData.validationNexusTestResult.silo
60                                     + "/"
61                                     + submissionData.validationNexusTestResult.blueprintName
62                                     + "/"
63                                     + submissionData.validationNexusTestResult.version
64                                     + "/"
65                                     + submissionData.validationNexusTestResult.timestamp
66                                     + "/";
67                         }
68                         return null;
69                     };
70                     svc.mapResult = function(validationNexusTestResult) {
71                         if (!validationNexusTestResult.timestamp) {
72                             return null;
73                         }
74                         if (!validationNexusTestResult.wRobotNexusTestResults) {
75                             return null;
76                         }
77                         if (validationNexusTestResult.wRobotNexusTestResults.length === 0) {
78                             return null;
79                         }
80                         var resultExistence = false;
81                         angular
82                                 .forEach(
83                                         validationNexusTestResult.wRobotNexusTestResults,
84                                         function(result) {
85                                             if (result.robotTestResults
86                                                     && result.robotTestResults.length > 0) {
87                                                 resultExistence = true;
88                                             }
89                                         });
90                         if (resultExistence) {
91                             if (validationNexusTestResult.result === true) {
92                                 return 'SUCCESS';
93                             }
94                             return 'FAILURE'
95                         }
96                         return null;
97                     };
98                     return svc;
99                 } ]);