[PORTAL-7] Rebase
[portal.git] / ecomp-portal-FE-common / client / app / services / audit-log / audit-log.service.js
1 /*-\r
2  * ================================================================================\r
3  * ECOMP Portal\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ================================================================================\r
19  */\r
20 /**\r
21  * Created by robertlo on 11/18/2016.\r
22  */\r
23 'use strict';\r
24 \r
25 (function () {\r
26     class AuditLogService {\r
27         constructor($q, $log, $http, conf, uuid) {\r
28             this.$q = $q;\r
29             this.$log = $log;\r
30             this.$http = $http;\r
31             this.conf = conf;\r
32           \r
33             this.uuid = uuid;\r
34         }\r
35         storeAudit(affectedAppId) {\r
36             // this.$log.error('ecomp::storeAudit storeAudit',affectedAppId);\r
37                 let deferred = this.$q.defer();\r
38                 this.$http({\r
39                     method: "GET",\r
40                     url: this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId +"&type=''&comment=''",\r
41                     cache: false,\r
42                     headers: {\r
43                         'X-ECOMP-RequestID':this.uuid.generate()\r
44                     }\r
45             })\r
46                 return deferred.promise;\r
47         }\r
48         \r
49         storeAudit(affectedAppId,type) {\r
50             // this.$log.error('ecomp::storeAudit storeAudit',affectedAppId + " " +type);\r
51                 let deferred = this.$q.defer();\r
52                 this.$http({\r
53                     method: "GET",\r
54                     url: this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId + '&type='+type+"&comment=''",\r
55                     cache: false,\r
56                     headers: {\r
57                         'X-ECOMP-RequestID':this.uuid.generate()\r
58                     }\r
59             })\r
60                 return deferred.promise;\r
61         }\r
62         storeAudit(affectedAppId,type,comment) {\r
63                 comment = filterDummyValue(comment);\r
64                 let deferred = this.$q.defer();\r
65                 var url =this.conf.api.storeAuditLog+'?affectedAppId=' + affectedAppId;\r
66                 if(type!=''){\r
67                         url= url+'&type='+type;\r
68                 }\r
69                 if(comment!=''){\r
70                         url= url+'&comment='+comment;\r
71                 }\r
72                 this.$http({\r
73                     method: "GET",\r
74                     url: url,\r
75                     cache: false,\r
76                     headers: {\r
77                         'X-ECOMP-RequestID':this.uuid.generate()\r
78                     }\r
79             })\r
80                 return deferred.promise;\r
81         }\r
82     }  \r
83     AuditLogService.$inject = ['$q', '$log', '$http', 'conf', 'uuid4'];\r
84     angular.module('ecompApp').service('auditLogService', AuditLogService)\r
85 })();\r
86 \r
87 function filterDummyValue(comment){\r
88         var n = comment.indexOf("?dummyVar");\r
89         if(n!=-1)\r
90                 comment = comment.substring(0, n);\r
91         return comment;\r
92 }\r