Security/ Package Name changes
[portal.git] / ecomp-portal-FE-common / client / app / services / scheduler / scheduler.service.js
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 'use strict';
39
40 (function () {
41         class SchedulerService {
42                 constructor($q, $log, $http, conf, uuid, utilsService,$modal) {
43                         this.$q = $q;
44                         this.$log = $log;
45                         this.$http = $http;
46                         this.conf = conf;
47                         this.uuid = uuid;
48                         this.utilsService = utilsService;
49                         this.$modal = $modal;
50                         this.widgetInfo={
51                                         id:'',
52                                         data:'',
53                                         param:''
54                         }
55                 }
56
57                 /** get scheduler uuID **/
58                 getStatusSchedulerId(schedulerInfo) {
59                         let deferred = this.$q.defer();
60                         var url = this.conf.api.getSchedulerId
61                         this.$http({
62                                 url: url+'?r='+ Math.random(),
63                                 method: 'POST',
64                                 cache: false,
65                                 timeout: 60000,
66                                 data:schedulerInfo,
67                                 headers: {
68                                         'X-ECOMP-RequestID':this.uuid.generate()
69                                 }
70                         }).then(res => {
71                                 if (res == null || res.data == null || this.utilsService.isValidJSON(res.data)== false) {
72                                         deferred.reject('SchedulerService::getStatusSchedulerId Failed');
73                                 } else {
74                                         deferred.resolve(res.data);
75                                 }
76                         }).catch(status => {
77                                 deferred.reject(status);
78                         });
79                         return deferred.promise;
80                 }
81
82                 /** get time slots for Range scheduler **/
83                 getTimeslotsForScheduler(schedulerID) {
84                         let deferred = this.$q.defer();
85                         var url = this.conf.api.getTimeslotsForScheduler + '/' + schedulerID + '?r=' + Math.random();
86                         this.$http({
87                                 url: url,
88                                 method: 'GET',
89                                 timeout: 60000,
90                                 cache: false,
91                                 headers: {
92                                         'X-ECOMP-RequestID':this.uuid.generate()
93                                 },
94                         }).then(res => {
95                                 this.$log.debug('SchedulerService:: this.conf.api.portalAdmin: ' + JSON.stringify(res));
96                                 if (res == null || res.data == null || this.utilsService.isValidJSON(res.data)== false) {
97                                         deferred.reject('SchedulerService::getTimeslotsForScheduler Failed');
98                                 } else {
99                                         deferred.resolve(res.data);
100                                 }
101                         }).catch(errRes => {
102                                 deferred.reject(errRes);
103                         });
104                         return deferred.promise;
105                 }
106
107                 
108                 postSubmitForApprovedTimeslots(approvedTimeSlotsObj) {
109                         let deferred = this.$q.defer();
110                         let url = this.conf.api.postSubmitForApprovedTimeslots + '?r='+ Math.random();
111                         this.$http({
112                                 url: url,
113                                 method: 'POST',
114                                 timeout: 60000,
115                                 cache: false,
116                                 data: approvedTimeSlotsObj, 
117                                 headers: {
118                                         'X-ECOMP-RequestID':this.uuid.generate()
119                                 }
120                         }).then(res => {
121                                 if (res == null || res.data == null || this.utilsService.isValidJSON(res.data)== false) {
122                                         deferred.reject('SchedulerService::postSubmitForapprovedTimeslots');
123                                 } else {
124                                         deferred.resolve(res.data);
125                                 }
126                         }).catch(errRes => {
127                                 deferred.reject(errRes);
128                         });
129
130                         return deferred.promise;
131                 }
132
133                 /** Get policy information from BE **/
134                 getPolicyInfo() {
135                         let deferred = this.$q.defer();
136                         let url =  this.conf.api.getPolicy + '?r=' + Math.random();
137                         this.$http({
138                                 url: url,
139                                 method: 'GET',
140                                 timeout: 60000,
141                                 cache: false,
142                                 headers: {
143                                         'X-ECOMP-RequestID':this.uuid.generate()
144                                 }
145                         }).then(res => {
146                                 if (res == null || res.data == null || this.utilsService.isValidJSON(res.data)== false) {
147                                         deferred.reject('SchedulerService::getPolicyInfo');
148                                 } else {
149                                         deferred.resolve(res.data);
150                                 }
151                         }).catch(errRes => {
152                                 deferred.reject(errRes);
153                         });
154
155                         return deferred.promise;
156                 }
157
158                 /** get Scheduler UI constants from BE **/
159                 getSchedulerConstants() {
160                         let deferred = this.$q.defer();
161                         let url =  this.conf.api.getSchedulerConstants;       
162                         this.$http({
163                                 url: url,
164                                 method: 'GET',
165                                 timeout: 60000,
166                                 cache: false,
167                                 headers: {
168                                         'X-ECOMP-RequestID':this.uuid.generate()
169                                 }
170                         }).then(res => {
171                                 if (res == null || res.data == null || this.utilsService.isValidJSON(res.data)== false) {
172                                         deferred.reject('SchedulerService::getSchedulerConstant');
173                                 } else {
174                                         deferred.resolve(res.data);
175                                 }
176                         }).catch(errRes => {
177                                 deferred.reject(errRes);
178                         });
179                         return deferred.promise;
180                 }
181
182                 
183                 /**Opens up the popup for Scheduler UI**/
184                 showWidget(widgetId,widgetData,widgetParam) {
185                         let deferred = this.$q.defer();
186                         this.widgetInfo.id = widgetId;
187                         this.widgetInfo.data = widgetData;
188                         this.widgetInfo.param = widgetParam;    
189                         var modalInstance = this.$modal.open({
190                                 templateUrl: 'app/views/scheduler/scheduler.tpl.html',
191                                 controller: 'SchedulerCtrl',
192                                 sizeClass:'modal-large',
193                                 windowClass:"modal-docked",
194                                 resolve: {
195                                         message: function message() {
196                                                 var message = {
197                                                                 id: widgetId,
198                                                                 data: widgetData,
199                                                                 param: widgetParam
200                                                 };
201                                                 return message;
202                                         }
203                                 }
204                         });
205                         modalInstance.result.then(function () {
206                                 deferred.resolve();
207                         });  
208                         return deferred.promise;
209                 };
210
211                 getWidgetData(){
212                         return this.widgetInfo;
213                 }
214         }
215         SchedulerService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4', 'utilsService', '$modal'];
216         angular.module('ecompApp').service('schedulerService', SchedulerService)
217 })();