b7513ff46817472051432840a603917cd72233eb
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / DistributionEngineEvent.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.be.resources.data.auditing.model.DistributionTopicData;
30 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
31
32 import java.text.SimpleDateFormat;
33 import java.util.Date;
34 import java.util.TimeZone;
35 import java.util.UUID;
36
37 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_ENGINE_EVENT_TYPE)
38 public class DistributionEngineEvent extends AuditingGenericEvent {
39
40     @PartitionKey
41     protected UUID timebaseduuid;
42
43     @ClusteringColumn
44     protected Date timestamp1;
45
46     @Column(name = "request_id")
47     protected String requestId;
48
49     @Column(name = "service_instance_id")
50     protected String serviceInstanceId;
51
52     @Column
53     protected String action;
54     @Column
55     protected String status;
56
57     @Column(name = "description")
58     protected String desc;
59
60     @Column(name = "consumer_id")
61     private String consumerId;
62
63     @Column(name = "DSTATUS_TOPIC")
64     private String dstatusTopic;
65
66     @Column(name = "DNOTIF_TOPIC")
67     private String dnotifTopic;
68
69     @Column(name = "d_env")
70     private String environmentName;
71
72     @Column
73     private String role;
74
75     @Column(name = "api_key")
76     private String apiKey;
77
78     //Required to be public as it is used by Cassandra driver on get operation
79     public DistributionEngineEvent() {
80         timestamp1 = new Date();
81         timebaseduuid = UUIDs.timeBased();
82     }
83
84     public DistributionEngineEvent(String action, CommonAuditData commonAuditData, String consumerId, DistributionTopicData distributionTopicData,
85                                     String apiKey, String envName, String role) {
86         this();
87         this.action = action;
88         this.requestId = commonAuditData.getRequestId();
89         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
90         this.status = commonAuditData.getStatus();
91         //if no desc, keep distr desc
92         this.desc = commonAuditData.getDescription();
93         this.consumerId = consumerId;
94         this.dstatusTopic = distributionTopicData.getStatusTopic();
95         this.dnotifTopic = distributionTopicData.getNotificationTopic();
96         this.apiKey = apiKey;
97         this.environmentName = envName;
98         this.role = role;
99     }
100
101     public void setTimestamp1(String timestamp) {
102         this.timestamp1 = parseDateFromString(timestamp);
103     }
104
105     @Override
106     public void fillFields() {
107         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
108
109         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
110         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
111         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
112         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
113
114         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
115         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_API_KEY.getDisplayName(), getApiKey());
116         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME.getDisplayName(), getEnvironmentName());
117         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ROLE.getDisplayName(), getRole());
118         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TOPIC_NAME.getDisplayName(), getDstatusTopic());
119         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_NOTIFICATION_TOPIC_NAME.getDisplayName(),
120                 getDnotifTopic());
121         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
122         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
123         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
124     }
125
126     public String getDstatusTopic() {
127         return dstatusTopic;
128     }
129
130     public void setDstatusTopic(String dstatusTopic) {
131         this.dstatusTopic = dstatusTopic;
132     }
133
134     public String getDnotifTopic() {
135         return dnotifTopic;
136     }
137
138     public void setDnotifTopic(String dnotifTopic) {
139         this.dnotifTopic = dnotifTopic;
140     }
141
142     public String getEnvironmentName() {
143         return environmentName;
144     }
145
146     public void setEnvironmentName(String environmentName) {
147         this.environmentName = environmentName;
148     }
149
150     public String getRole() {
151         return role;
152     }
153
154     public void setRole(String role) {
155         this.role = role;
156     }
157
158     public String getApiKey() {
159         return apiKey;
160     }
161
162     public void setApiKey(String apiKey) {
163         this.apiKey = apiKey;
164     }
165
166     public UUID getTimebaseduuid() {
167         return timebaseduuid;
168     }
169
170     public void setTimebaseduuid(UUID timebaseduuid) {
171         this.timebaseduuid = timebaseduuid;
172     }
173
174     public Date getTimestamp1() {
175         return timestamp1;
176     }
177
178     public void setTimestamp1(Date timestamp1) {
179         this.timestamp1 = timestamp1;
180     }
181
182     public String getRequestId() {
183         return requestId;
184     }
185
186     public void setRequestId(String requestId) {
187         this.requestId = requestId;
188     }
189
190     public String getServiceInstanceId() {
191         return serviceInstanceId;
192     }
193
194     public void setServiceInstanceId(String serviceInstanceId) {
195         this.serviceInstanceId = serviceInstanceId;
196     }
197
198     public String getAction() {
199         return action;
200     }
201
202     public void setAction(String action) {
203         this.action = action;
204     }
205
206     public String getStatus() {
207         return status;
208     }
209
210     public void setStatus(String status) {
211         this.status = status;
212     }
213
214     public String getDesc() {
215         return desc;
216     }
217
218     public void setDesc(String desc) {
219         this.desc = desc;
220     }
221
222     public String getConsumerId() {
223         return consumerId;
224     }
225
226     public void setConsumerId(String consumerId) {
227         this.consumerId = consumerId;
228     }
229
230     @Override
231     public String toString() {
232         return "DistributionEngineEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1 + ", requestId="
233                 + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action + ", status=" + status
234                 + ", desc=" + desc + ", consumerId=" + consumerId + ", dstatusTopic=" + dstatusTopic + ", dnotifTopic="
235                 + dnotifTopic + ", environmentName=" + environmentName + ", role=" + role + ", apiKey=" + apiKey + "]";
236     }
237
238 }