[PORTAL-16 PORTAL-18] Widget ms; staging
[portal.git] / ecomp-portal-FE-common / client / app / services / audit-log / audit-log.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 /**
21  * Created by robertlo on 11/18/2016.
22  */
23 'use strict';
24
25 (function () {
26     class AuditLogService {
27         constructor($q, $log, $http, conf, uuid) {
28             this.$q = $q;
29             this.$log = $log;
30             this.$http = $http;
31             this.conf = conf;
32           
33             this.uuid = uuid;
34         }
35         storeAudit(affectedAppId) {
36             // this.$log.error('ecomp::storeAudit storeAudit',affectedAppId);
37                 let deferred = this.$q.defer();
38                 this.$http({
39                     method: "GET",
40                     url: this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId +"&type=''&comment=''",
41                     cache: false,
42                     headers: {
43                         'X-ECOMP-RequestID':this.uuid.generate()
44                     }
45             })
46                 return deferred.promise;
47         }
48         
49         storeAudit(affectedAppId,type) {
50             // this.$log.error('ecomp::storeAudit storeAudit',affectedAppId + " " +type);
51                 let deferred = this.$q.defer();
52                 this.$http({
53                     method: "GET",
54                     url: this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId + '&type='+type+"&comment=''",
55                     cache: false,
56                     headers: {
57                         'X-ECOMP-RequestID':this.uuid.generate()
58                     }
59             })
60                 return deferred.promise;
61         }
62         storeAudit(affectedAppId,type,comment) {
63                 comment = filterDummyValue(comment);
64                 let deferred = this.$q.defer();
65                 var url =this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId;
66                 if(type!=''){
67                         url= url+'&type='+type;
68                 }
69                 if(comment!=''){
70                         url= url+'&comment='+comment;
71                 }
72                 this.$http({
73                     method: "GET",
74                     url: url,
75                     cache: false,
76                     headers: {
77                         'X-ECOMP-RequestID':this.uuid.generate()
78                     }
79             })
80                 return deferred.promise;
81         }
82     }  
83     AuditLogService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];
84     angular.module('ecompApp').service('auditLogService', AuditLogService)
85 })();
86
87 function filterDummyValue(comment){
88         var n = comment.indexOf("?dummyVar");
89         if(n!=-1)
90                 comment = comment.substring(0, n);
91         return comment;
92 }