re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / AuthEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.be.resources.data.auditing;
22
23 import com.datastax.driver.core.utils.UUIDs;
24 import com.datastax.driver.mapping.annotations.ClusteringColumn;
25 import com.datastax.driver.mapping.annotations.Column;
26 import com.datastax.driver.mapping.annotations.PartitionKey;
27 import com.datastax.driver.mapping.annotations.Table;
28 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
29 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
30
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.TimeZone;
34 import java.util.UUID;
35
36 @Table(keyspace = "sdcaudit", name = AuditingTypesConstants.AUTH_EVENT_TYPE)
37 public class AuthEvent extends AuditingGenericEvent {
38
39     @PartitionKey
40     protected UUID timebaseduuid;
41
42     @ClusteringColumn
43     protected Date timestamp1;
44
45     @Column
46     private String url;
47     @Column
48     private String user;
49
50     @Column(name = "auth_status")
51     private String authStatus;
52
53     @Column
54     private String realm;
55     @Column
56     protected String action;
57     @Column
58     protected String status;
59
60     @Column(name = "description")
61     protected String desc;
62
63     @Column(name = "request_id")
64     protected String requestId;
65
66     public AuthEvent(String action, CommonAuditData commonAuditData, String user, String authUrl, String realm, String authStatus) {
67         this();
68         this.action = action;
69         this.requestId = commonAuditData.getRequestId();
70         this.desc = commonAuditData.getDescription();
71         this.status = commonAuditData.getStatus();
72         this.authStatus = authStatus;
73         this.url = authUrl;
74         this.realm = realm;
75         this.user = user;
76     }
77
78     //Required to be public as it is used by Cassandra driver on get operation
79     public AuthEvent() {
80         timestamp1 = new Date();
81         timebaseduuid = UUIDs.timeBased();
82     }
83
84     public String getUrl() {
85         return url;
86     }
87
88     public void setUrl(String url) {
89         this.url = url;
90     }
91
92     public String getUser() {
93         return user;
94     }
95
96     public void setUser(String user) {
97         this.user = user;
98     }
99
100     public String getAuthStatus() {
101         return authStatus;
102     }
103
104     public void setAuthStatus(String authStatus) {
105         this.authStatus = authStatus;
106     }
107
108     public String getRealm() {
109         return realm;
110     }
111
112     public void setRealm(String realm) {
113         this.realm = realm;
114     }
115
116     public UUID getTimebaseduuid() {
117         return timebaseduuid;
118     }
119
120     public void setTimebaseduuid(UUID timebaseduuid) {
121         this.timebaseduuid = timebaseduuid;
122     }
123
124     public Date getTimestamp1() {
125         return timestamp1;
126     }
127
128     public void setTimestamp1(Date timestamp1) {
129         this.timestamp1 = timestamp1;
130     }
131
132     public String getAction() {
133         return action;
134     }
135
136     public void setAction(String action) {
137         this.action = action;
138     }
139
140     public String getStatus() {
141         return status;
142     }
143
144     public void setStatus(String status) {
145         this.status = status;
146     }
147
148     public String getDesc() {
149         return desc;
150     }
151
152     public void setDesc(String desc) {
153         this.desc = desc;
154     }
155
156     public String getRequestId() {
157         return requestId;
158     }
159
160     public void setRequestId(String requestId) {
161         this.requestId = requestId;
162     }
163
164     public void setTimestamp1(String timestamp) {
165         this.timestamp1 = parseDateFromString(timestamp);
166     }
167
168     @Override
169     public void fillFields() {
170         fields.put(AuditingFieldsKey.AUDIT_AUTH_URL.getDisplayName(), getUrl());
171
172         fields.put(AuditingFieldsKey.AUDIT_AUTH_USER.getDisplayName(), getUser());
173         fields.put(AuditingFieldsKey.AUDIT_AUTH_STATUS.getDisplayName(), getAuthStatus());
174         fields.put(AuditingFieldsKey.AUDIT_AUTH_REALM.getDisplayName(), getRealm());
175         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
176         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
177         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
178         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
179         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
180         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
181         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
182     }
183 }