[UI] Common class for results
[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(validationDbTestResult) {
25                         if (!validationDbTestResult) {
26                             return null;
27                         }
28                         if (validationDbTestResult.allLayers) {
29                             return "all";
30                         }
31                         var layers = [];
32                         angular.forEach(
33                                 validationDbTestResult.wrobotDbTestResults,
34                                 function(result) {
35                                     layers.push(result.layer);
36                                 });
37                         return layers;
38                     };
39                     svc.getResultUrl = function(submission) {
40                         if (submission.submissionStatus !== "Completed") {
41                             return null;
42                         }
43                         if (!submission.validationDbTestResult) {
44                             return null;
45                         }
46                         if (!submission.validationDbTestResult.wrobotDbTestResults) {
47                             return null;
48                         }
49                         if (submission.validationDbTestResult.wrobotDbTestResults.length === 0) {
50                             return null;
51                         }
52                         if (submission.validationDbTestResult.dateStorage) {
53                             return "https://nexus.akraino.org/content/sites/logs/"
54                                     + submission.timeslot.labInfo.silo
55                                     + "/"
56                                     + submission.validationDbTestResult.blueprintInstance.blueprint.blueprintName
57                                     + "/"
58                                     + submission.validationDbTestResult.blueprintInstance.version
59                                     + "/"
60                                     + submission.validationDbTestResult.timestamp
61                                     + "/";
62                         }
63                         return null;
64                     };
65                     svc.mapResult = function(validationDbTestResult) {
66                         if (validationDbTestResult
67                                 && validationDbTestResult.dateStorage) {
68                             if (validationDbTestResult.result === true) {
69                                 return 'SUCCESS';
70                             }
71                             return 'FAILURE'
72                         }
73                         return null;
74                     };
75                     return svc;
76                 } ]);