369fd555cab80d81c4f62bfdc7039029360d35f5
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / DistributionStatusEvent.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.DistributionData;
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_STATUS_EVENT_TYPE)
38 public class DistributionStatusEvent 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
61     private String did;
62
63     @Column(name = "consumer_id")
64     private String consumerId;
65
66     @Column(name = "topic_name")
67     private String topicName;
68
69     @Column(name = "resoure_url")
70     private String resoureURL;
71
72     @Column(name = "status_time")
73     private String statusTime;
74
75     //Required to be public as it is used by Cassandra driver on get operation
76     public DistributionStatusEvent() {
77         timestamp1 = new Date();
78         timebaseduuid = UUIDs.timeBased();
79
80     }
81
82     public DistributionStatusEvent(String action, CommonAuditData commonAuditData, DistributionData distributionData,
83                                    String did, String topicName, String statusTime) {
84         this();
85         this.action = action;
86         this.requestId = commonAuditData.getRequestId();
87         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
88         this.status = commonAuditData.getStatus();
89         this.desc = commonAuditData.getDescription();
90         this.did = did;
91         this.consumerId = distributionData.getConsumerId();
92         this.topicName = topicName;
93         this.resoureURL = distributionData.getResourceUrl();
94         this.statusTime = statusTime;
95     }
96
97     public void setTimestamp1(String timestamp) {
98         this.timestamp1 = parseDateFromString(timestamp);
99     }
100
101     @Override
102     public void fillFields() {
103         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
104
105         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
106         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
107         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
108         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
109         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
110
111         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ID.getDisplayName(), getDid());
112         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName(), getStatusTime());
113         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TOPIC_NAME.getDisplayName(), getTopicName());
114         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), getResoureURL());
115         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
116         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
117         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
118
119     }
120
121     public String getDid() {
122         return did;
123     }
124
125     public void setDid(String did) {
126         this.did = did;
127     }
128
129     public String getConsumerId() {
130         return consumerId;
131     }
132
133     public void setConsumerId(String consumerId) {
134         this.consumerId = consumerId;
135     }
136
137     public String getTopicName() {
138         return topicName;
139     }
140
141     public void setTopicName(String topicName) {
142         this.topicName = topicName;
143     }
144
145     public String getResoureURL() {
146         return resoureURL;
147     }
148
149     public void setResoureURL(String resoureURL) {
150         this.resoureURL = resoureURL;
151     }
152
153     public String getRequestId() {
154         return requestId;
155     }
156
157     public void setRequestId(String requestId) {
158         this.requestId = requestId;
159     }
160
161     public String getServiceInstanceId() {
162         return serviceInstanceId;
163     }
164
165     public void setServiceInstanceId(String serviceInstanceId) {
166         this.serviceInstanceId = serviceInstanceId;
167     }
168
169     public String getAction() {
170         return action;
171     }
172
173     public void setAction(String action) {
174         this.action = action;
175     }
176
177     public String getStatus() {
178         return status;
179     }
180
181     public void setStatus(String status) {
182         this.status = status;
183     }
184
185     public String getDesc() {
186         return desc;
187     }
188
189     public void setDesc(String desc) {
190         this.desc = desc;
191     }
192
193     public UUID getTimebaseduuid() {
194         return timebaseduuid;
195     }
196
197     public void setTimebaseduuid(UUID timebaseduuid) {
198         this.timebaseduuid = timebaseduuid;
199     }
200
201     public Date getTimestamp1() {
202         return timestamp1;
203     }
204
205     public void setTimestamp1(Date timestamp) {
206         this.timestamp1 = timestamp;
207     }
208
209     public String getStatusTime() {
210         return statusTime;
211     }
212
213     public void setStatusTime(String statusTime) {
214         this.statusTime = statusTime;
215     }
216
217      @Override
218     public String toString() {
219         return "DistributionStatusEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1 + ", requestId="
220                 + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action + ", status=" + status
221                 + ", desc=" + desc + ", did=" + did + ", consumerId=" + consumerId + ", topicName=" + topicName
222                 + ", resoureURL=" + resoureURL + ", statusTime=" + statusTime + "]";
223     }
224
225 }