nexus site path corrected
[portal.git] / ecomp-portal-FE / client / app / services / catalog / catalog.service.js
1 /*-
2  * ================================================================================
3  * eCOMP Portal
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property
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  * ================================================================================
19  */
20 'use strict';
21
22 (function () {
23     class CatalogService {
24         
25         constructor($q, $log, $http, conf, uuid) {
26             this.$q = $q;
27             this.$log = $log;
28             this.$http = $http;
29             this.conf = conf;
30             this.uuid = uuid;
31         }
32
33         getAppCatalog() {
34             let deferred = this.$q.defer();
35             this.$http(
36                 {
37                         method: "GET",
38                         url: this.conf.api.appCatalog,
39                     cache: false,
40                     headers: {
41                         'X-ECOMP-RequestID':this.uuid.generate()
42                     }
43                 })
44                 .then( res => {
45                     // Detect non-JSON
46                     if (res == null || res.data == null) {
47                         deferred.reject("CatalogService::getAppCatalog Failed");
48                     } else {
49                         deferred.resolve(res.data);
50                     }
51                 })
52                 .catch( status => {
53                         this.$log.error('CatalogService:getAppCatalog failed: ' + status);
54                     deferred.reject(status);
55                 });
56             return deferred.promise;
57         }
58         
59         // Expects an object with fields matching model class AppCatalogSelection:
60         // appId (number), select (boolean), pending (boolean).
61         updateAppCatalog(appData) {
62             let deferred = this.$q.defer();
63             // Validate the request, maybe this is overkill
64             if (appData == null || appData.appId == null || appData.select == null) {
65                 var msg = 'CatalogService::updateAppCatalog: field appId and/or select not found';
66                 this.$log.error(msg);
67                 return deferred.reject(msg);
68             }
69             this.$http({
70                 method: "PUT",
71                 url: this.conf.api.appCatalog,
72                 data: appData,
73                 headers: {
74                     'X-ECOMP-RequestID':this.uuid.generate()
75                 }
76             }).then( res => {
77                     // Detect non-JSON
78                     if (res == null || res.data == null) {
79                         deferred.reject("CatalogService::updateAppCatalog Failed");
80                     } else {
81                         deferred.resolve(res.data);
82                     }
83                 })
84                 .catch( status => {
85                         this.$log.error('CatalogService:updateAppCatalog failed: ' + status);
86                     deferred.reject(status);
87                 });
88             return deferred.promise;
89         }
90
91     }
92     
93     CatalogService.$inject = ['$q', '$log', '$http', 'conf','uuid4'];
94     angular.module('ecompApp').service('catalogService', CatalogService)
95 })();