Fix for Penetration test _ Session and cookie management
[vid.git] / vid-app-common / src / main / webapp / app / vid / scripts / controller / testEnvironmentsController.js
1 /*-
2  * ============LICENSE_START=======================================================
3  * VID
4  * ================================================================================
5  * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 (function () {
22     'use strict';
23
24     appDS2.controller("testEnvironmentsController", ["$uibModal", "TestEnvironmentsService", "$log", "$rootScope", "$scope", "COMPONENT", testEnvironmentsController]);
25
26     function testEnvironmentsController($uibModal, TestEnvironmentsService, $log, $rootScope, $scope, COMPONENT) {
27         var vm = this;
28
29         var toggleValue;
30
31         var init = function() {
32             vm.loadAAIestEnvironments();
33         };
34
35         vm.loadAAIestEnvironments = function() {
36             TestEnvironmentsService.loadAAIestEnvironments("VNF")
37                 .then(function(response) {
38                     vm.environments = response.operationalEnvironment;
39                     vm.connectError = false;
40                     if(!vm.environments.length) {
41                         vm.emptyData = true;
42                     }
43                 })
44                 .catch(function (error) {
45                     vm.connectError = error.message || "Unknown error";
46                     $log.error(error);
47                 });
48         };
49
50         function handleEnvActionComplete(result) {
51             if (result.isSuccessful) {
52                 vm.loadAAIestEnvironments();
53             }
54             $scope.popup.isVisible = false;
55         }
56
57         vm.onTestEnvActivateClick = function(testEnv) {
58             var modalInstance = $uibModal.open({
59                 templateUrl: 'app/vid/scripts/modals/attach-test-env-manifest/attach-test-env-manifest.html',
60                 controller: 'attachTestEnvManifestController',
61                 controllerAs: 'vm',
62                 resolve: {}
63             });
64
65             modalInstance.result.then(function (result) {
66                 if (result) {
67
68                     var relatedEcompEnv = _.find(testEnv.relationshipList.relationship, { relatedTo: "operational-environment" });
69
70                     var manifest = result;
71                     var envId = testEnv.operationalEnvironmentId;
72                     var relatedInstanceId =
73                         _.find(relatedEcompEnv.relationshipData, {"relationshipKey": "operational-environment.operational-environment-id"})
74                             .relationshipValue;
75                     var relatedInstanceName =
76                         _.find(relatedEcompEnv.relatedToProperty, {"propertyKey": "operational-environment.operational-environment-name"})
77                             .propertyValue;
78                     var workloadContext = testEnv.workloadContext;
79
80                     $rootScope.$broadcast(COMPONENT.MSO_ACTIVATE_ENVIRONMENT, {
81                         url: COMPONENT.MSO_ACTIVATE_ENVIRONMENT,
82                         envId: envId,
83                         relatedInstanceId: relatedInstanceId,
84                         relatedInstanceName: relatedInstanceName,
85                         workloadContext: workloadContext,
86                         manifest: manifest,
87                         callbackFunction: handleEnvActionComplete
88                     });
89
90                 }
91             });
92         };
93
94         vm.onTestEnvDeactivateClick = function(testEnv) {
95             var envId = testEnv.operationalEnvironmentId;
96             $rootScope.$broadcast(COMPONENT.MSO_DEACTIVATE_ENVIRONMENT, {
97                 url : COMPONENT.MSO_DEACTIVATE_ENVIRONMENT,
98                 envId : envId,
99                 callbackFunction: handleEnvActionComplete
100             });
101         };
102
103         vm.isEnvActive = function(testEnv) {
104             return testEnv.operationalEnvironmentStatus==='ACTIVE';
105         };
106
107         vm.getEnvStatus = function (testEnv) {
108             return testEnv.operationalEnvironmentStatus;
109         };
110
111         vm.createNewTestEnvironment = function() {
112             var modalInstance = $uibModal.open({
113                 templateUrl: 'app/vid/scripts/modals/new-test-environment/new-test-environment.html',
114                 controller: 'newTestEnvironmentModalController',
115                 controllerAs: 'vm',
116                 resolve: {}
117             });
118         };
119
120         init();
121     }
122 })();