2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
24 app.controller("ServiceModelController", function ($scope, $http, $location, COMPONENT, DataService, vidService,
28 var re = /.*?:\/\/.*?:.*?\/(.*?)\//g;
29 var baseEndpoint = re.exec($location.absUrl())[1];
31 $scope.getServiceModels = function() {
32 $scope.status = "Fetching service catalog from ASDC. Please wait.";
33 $http.get('/' + baseEndpoint + '/rest/models/services?distributionStatus=DISTRIBUTED')
34 .then(function(response) {
36 if (angular.isArray(response.data)) {
37 $scope.services = response.data;
38 $scope.viewPerPage=10;
39 $scope.totalPage=$scope.services.length/$scope.viewPerPage;
41 $scope.scrollViewPerPage=2;
43 $scope.searchCategory;
44 $scope.searchString="";
45 $scope.currentPageNum=1;
46 $scope.isSpinnerVisible = false;
47 $scope.isProgressVisible = false;
49 $scope.status = "Failed to get service models from ASDC.";
51 $scope.isSpinnerVisible = false;
53 }, function (response) {
54 console.log("Error: " + response);
57 $scope.init = function() {
58 // takes a default value, retrieves the prop value from the file system and sets it
59 var msecs = PropertyService.retrieveMsoMaxPollingIntervalMsec(1000);
60 PropertyService.setMsoMaxPollingIntervalMsec(msecs);
62 // takes a default value, retrieves the prop value from the file system and sets it
63 var polls = PropertyService.retrieveMsoMaxPolls(7);
64 PropertyService.setMsoMaxPolls(polls);
66 //PropertyService.setMsoBaseUrl("testmso");
67 PropertyService.setServerResponseTimeoutMsec(10000);
70 $scope.prevPage = function() {
74 $scope.nextPage = function() {
78 $scope.deployService = function(service) {
80 console.log("Instantiating ASDC service " + service.uuid);
82 $http.get('/' + baseEndpoint + '/rest/models/services/' + service.uuid)
83 .then(function successCallback(getServiceResponse) {
85 var serviceModel = getServiceResponse.data;
86 DataService.setServiceName(serviceModel.service.name);
88 DataService.setModelInfo(COMPONENT.SERVICE, {
89 "modelInvariantId": serviceModel.service.invariantUuid,
90 "modelVersion": serviceModel.service.version,
91 "modelNameVersionId": serviceModel.service.uuid,
92 "modelName": serviceModel.service.name,
93 "description": serviceModel.service.description,
94 "category":serviceModel.service.category
97 $scope.$broadcast("createComponent", {
98 componentId : COMPONENT.SERVICE,
99 callbackFunction : function(response) {
100 if (response.isSuccessful) {
101 vidService.setModel(serviceModel);
103 var subscriberId = "Not Found";
104 var serviceType = "Not Found";
106 var serviceInstanceId = response.instanceId;
108 for (var i = 0; i < response.control.length; i++) {
109 if (response.control[i].id == "subscriberName") {
110 subscriberId = response.control[i].value;
111 } else if (response.control[i].id == "serviceType") {
112 serviceType = response.control[i].value;
117 $scope.refreshSubs(subscriberId,serviceType,serviceInstanceId);
123 }, function errorCallback(response) {
124 console.log("Error: " + response);
128 $scope.refreshSubs = function(subscriberId, serviceType, serviceInstanceId) {
129 $scope.status = "Fetching subscriber list from A&AI...";
131 $http.get( PropertyService.getAaiBaseUrl() + "/aai_refresh_full_subscribers", {
134 timeout: $scope.responseTimeoutMsec
135 }).then(function(response){
137 if (response.data.status < 200 || response.data.status > 202) {
138 $scope.showError("MSO failure - see log below for details")
142 $scope.customer = response.data.customer; // get data from json
144 $scope.customerList = [];
146 $scope.serviceInstanceToCustomer = [];
148 angular.forEach($scope.customer, function(subVal, subKey) {
149 var cust = { "globalCustomerId": subVal["global-customer-id"], "subscriberName": subVal["subscriber-name"] };
150 $scope.customerList.push(cust);
151 if (subVal["service-subscriptions"] != null) {
152 angular.forEach(subVal["service-subscriptions"]["service-subscription"], function(serviceSubscription, key) {
153 $scope.serviceInstanceId = [];
154 if (serviceSubscription["service-type"] != null) {
155 $scope.serviceType = serviceSubscription["service-type"];
157 $scope.serviceType = "No Service Subscription Found";
159 if (serviceSubscription["service-instances"] != null) {
160 angular.forEach(serviceSubscription["service-instances"]["service-instance"], function(instValue, instKey) {
161 var foo = { "serviceInstanceId": instValue["service-instance-id"],
162 "globalCustomerId": subVal["global-customer-id"],
163 "subscriberName": subVal["subscriber-name"] };
164 $scope.serviceInstanceToCustomer.push(foo);
170 DataService.setServiceInstanceToCustomer($scope.serviceInstanceToCustomer);
171 var serviceIdList = [];
172 $http.get(PropertyService.getAaiBaseUrl() + "/aai_get_services", {
174 timeout: $scope.responseTimeoutMsec
175 }).then(function(response) {
176 angular.forEach(response.data, function(value, key) {
177 angular.forEach(value, function(subVal, key) {
178 var newVal = { "id" : subVal["service-id"], "description" : subVal["service-description"] };
179 serviceIdList.push(newVal);
180 DataService.setServiceIdList(serviceIdList);
183 "subscriberId": subscriberId,
184 "serviceType": serviceType,
185 "serviceInstanceId": serviceInstanceId
188 $location.path("/instantiate");
193 ["catch"]($scope.handleServerError);