74c85f6ea9fc59910071390de373f00a0d801437
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / UserAccessEvent.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 = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.USER_ACCESS_EVENT_TYPE)
37 public class UserAccessEvent extends AuditingGenericEvent {
38
39     @PartitionKey
40     protected UUID timebaseduuid;
41
42     @ClusteringColumn
43     protected Date timestamp1;
44
45     @Column(name = "REQUEST_ID")
46     protected String requestId;
47
48     @Column(name = "USER")
49     private String userUid;
50
51     @Column
52     private String status;
53
54     @Column(name = "DESCRIPTION")
55     private String desc;
56
57     @Column
58     private String action;
59
60     @Column(name = "service_instance_id")
61     private String serviceInstanceId;
62
63     //Required to be public as it is used by Cassandra driver on get operation
64     public UserAccessEvent() {
65         timestamp1 = new Date();
66         timebaseduuid = UUIDs.timeBased();
67     }
68
69     public UserAccessEvent(String action, CommonAuditData commonAuditData, String user) {
70         this();
71         this.action = action;
72         this.requestId = commonAuditData.getRequestId();
73         this.userUid = user;
74         this.status = commonAuditData.getStatus();
75         this.desc = commonAuditData.getDescription();
76         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
77     }
78
79     public void setTimestamp1(String timestamp) {
80         this.timestamp1 = parseDateFromString(timestamp);
81     }
82
83     @Override
84     public void fillFields() {
85         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
86
87         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
88         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
89         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
90         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
91         fields.put(AuditingFieldsKey.AUDIT_USER_UID.getDisplayName(), getUserUid());
92         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
93         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
94         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
95     }
96
97     public String getUserUid() {
98         return userUid;
99     }
100
101     public void setUserUid(String userUid) {
102         this.userUid = userUid;
103     }
104
105     public UUID getTimebaseduuid() {
106         return timebaseduuid;
107     }
108
109     public void setTimebaseduuid(UUID timebaseduuid) {
110         this.timebaseduuid = timebaseduuid;
111     }
112
113     public String getRequestId() {
114         return requestId;
115     }
116
117     public void setRequestId(String requestId) {
118         this.requestId = requestId;
119     }
120
121     @Override
122     public String getServiceInstanceId() { return serviceInstanceId; }
123
124     @Override
125     public void setServiceInstanceId(String serviceInstanceId) {
126         this.serviceInstanceId = serviceInstanceId;
127     }
128
129     public String getStatus() {
130         return status;
131     }
132
133     public void setStatus(String status) {
134         this.status = status;
135     }
136
137     public String getDesc() {
138         return desc;
139     }
140
141     public void setDesc(String desc) {
142         this.desc = desc;
143     }
144
145     public String getAction() {
146         return action;
147     }
148
149     public void setAction(String action) {
150         this.action = action;
151     }
152
153     public Date getTimestamp1() {
154         return timestamp1;
155     }
156
157     public void setTimestamp1(Date timestamp) {
158         this.timestamp1 = timestamp;
159     }
160
161     @Override
162     public String toString() {
163         return "UserAccessEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1 + ", requestId="
164                 + requestId + ", userUid=" + userUid + ", status=" + status + ", desc=" + desc + ", action=" + action
165                 + ", serviceInstanceId=" + serviceInstanceId + "]";
166     }
167
168 }