re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / DistributionNotificationEvent.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.OperationalEnvAuditData;
30 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
31 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
32 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
33
34 import java.text.SimpleDateFormat;
35 import java.util.Date;
36 import java.util.TimeZone;
37 import java.util.UUID;
38
39 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE)
40 public class DistributionNotificationEvent extends AuditingGenericEvent {
41
42     @PartitionKey
43     protected UUID timebaseduuid;
44
45     @ClusteringColumn
46     protected Date timestamp1;
47
48     @Column(name = "request_id")
49     protected String requestId;
50
51     @Column(name = "service_instance_id")
52     protected String serviceInstanceId;
53     @Column
54     protected String action;
55     @Column
56     protected String status;
57
58     @Column(name = "description")
59     protected String desc;
60
61     @Column(name = "resource_name")
62     private String resourceName;
63
64     @Column(name = "resource_type")
65     private String resourceType;
66
67     @Column(name = "curr_version")
68     private String currVersion;
69
70     @Column
71     private String modifier;
72
73     @Column(name = "curr_state")
74     private String currState;
75
76     @Column(name = "topic_name")
77     private String topicName;
78
79     @Column
80     private String did;
81
82     @Column(name = "env_id")
83     private String envId;
84
85     @Column(name = "vnf_workload_context")
86     private String vnfWorkloadContext;
87
88     @Column(name = "tenant")
89     private String tenant;
90
91     public DistributionNotificationEvent() {
92         timestamp1 = new Date();
93         timebaseduuid = UUIDs.timeBased();
94     }
95
96     public DistributionNotificationEvent(String action, CommonAuditData commonAuditData, ResourceCommonInfo resourceCommonInfo,
97                                          ResourceVersionInfo resourceVersionInfo,
98                                          String did, String modifier, String topicName,
99                                          OperationalEnvAuditData opEnvFields) {
100         this();
101         this.action = action;
102         this.requestId = commonAuditData.getRequestId();
103         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
104         this.status = commonAuditData.getStatus();
105         this.desc = commonAuditData.getDescription();
106         this.did = did;
107         this.modifier = modifier;
108         this.currState = resourceVersionInfo.getState();
109         this.currVersion = resourceVersionInfo.getVersion();
110         this.resourceName = resourceCommonInfo.getResourceName();
111         this.resourceType = resourceCommonInfo.getResourceType();
112         this.topicName = topicName;
113         this.envId = opEnvFields.getEnvId();
114         this.vnfWorkloadContext = opEnvFields.getVnfWorkloadContext();
115         this.tenant = opEnvFields.getTenant();
116
117     }
118
119     public void setTimestamp1(String timestamp) {
120         this.timestamp1 = parseDateFromString(timestamp);
121     }
122
123     @Override
124     public void fillFields() {
125         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
126
127         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
128         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
129         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
130         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
131         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ENVIRONMENT_ID.getDisplayName(), getEnvId());
132         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_VNF_WORKLOAD_CONTEXT.getDisplayName(), getVnfWorkloadContext());
133         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TENANT.getDisplayName(), getTenant());
134
135         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ID.getDisplayName(), getDid());
136         fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
137         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_STATE.getDisplayName(), getCurrState());
138         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_VERSION.getDisplayName(), getCurrVersion());
139         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_NAME.getDisplayName(), getResourceName());
140         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_TYPE.getDisplayName(), getResourceType());
141         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TOPIC_NAME.getDisplayName(), getTopicName());
142         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
143         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
144         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
145     }
146
147     public String getResourceName() {
148         return resourceName;
149     }
150
151     public void setResourceName(String resourceName) {
152         this.resourceName = resourceName;
153     }
154
155     public String getResourceType() {
156         return resourceType;
157     }
158
159     public void setResourceType(String resourceType) {
160         this.resourceType = resourceType;
161     }
162
163     public String getCurrVersion() {
164         return currVersion;
165     }
166
167     public void setCurrVersion(String currVersion) {
168         this.currVersion = currVersion;
169     }
170
171     public String getCurrState() {
172         return currState;
173     }
174
175     public void setCurrState(String currState) {
176         this.currState = currState;
177     }
178
179     public String getTopicName() {
180         return topicName;
181     }
182
183     public void setTopicName(String topicName) {
184         this.topicName = topicName;
185     }
186
187     public UUID getTimebaseduuid() {
188         return timebaseduuid;
189     }
190
191     public void setTimebaseduuid(UUID timebaseduuid) {
192         this.timebaseduuid = timebaseduuid;
193     }
194
195     public Date getTimestamp1() {
196         return timestamp1;
197     }
198
199     public void setTimestamp1(Date timestamp1) {
200         this.timestamp1 = timestamp1;
201     }
202
203     public String getRequestId() {
204         return requestId;
205     }
206
207     public void setRequestId(String requestId) {
208         this.requestId = requestId;
209     }
210
211     public String getServiceInstanceId() {
212         return serviceInstanceId;
213     }
214
215     public void setServiceInstanceId(String serviceInstanceId) {
216         this.serviceInstanceId = serviceInstanceId;
217     }
218
219     public String getAction() {
220         return action;
221     }
222
223     public void setAction(String action) {
224         this.action = action;
225     }
226
227     public String getStatus() {
228         return status;
229     }
230
231     public void setStatus(String status) {
232         this.status = status;
233     }
234
235     public String getDesc() {
236         return desc;
237     }
238
239     public void setDesc(String desc) {
240         this.desc = desc;
241     }
242
243     public String getModifier() {
244         return modifier;
245     }
246
247     public void setModifier(String modifier) {
248         this.modifier = modifier;
249     }
250
251     public String getDid() {
252         return did;
253     }
254
255     public void setDid(String did) {
256         this.did = did;
257     }
258
259     public String getVnfWorkloadContext() {
260         return vnfWorkloadContext;
261     }
262
263     public void setVnfWorkloadContext(String vnfWorkloadContext) {
264         this.vnfWorkloadContext = vnfWorkloadContext;
265     }
266
267     public String getEnvId() {
268         return envId;
269     }
270
271     public void setEnvId(String envId) {
272         this.envId = envId;
273     }
274
275     public String getTenant() {
276         return tenant;
277     }
278
279     public void setTenant(String tenant) {
280         this.tenant = tenant;
281     }
282
283     @Override
284     public String toString() {
285         return "DistributionNotificationEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1
286                 + ", requestId=" + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action
287                 + ", status=" + status + ", desc=" + desc + ", resourceName=" + resourceName + ", resourceType="
288                 + resourceType + ", currVersion=" + currVersion + ", modifier=" + modifier + ", currState=" + currState
289                 + ", topicName=" + topicName + ", did=" + did
290                 + ", envId=" + envId + ", vnfWorkloadContext=" + vnfWorkloadContext + ", tenant=" + tenant + "]";
291     }
292
293 }