d3ffd33074e84ba08c1621468ea03c6740fecf66
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / DistributionDownloadEvent.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_DOWNLOAD_EVENT_TYPE)
38 public class DistributionDownloadEvent 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 = "resource_url")
64     private String resourceUrl;
65
66     //Required to be public as it is used by Cassandra driver on get operation
67     public DistributionDownloadEvent() {
68         timestamp1 = new Date();
69         timebaseduuid = UUIDs.timeBased();
70     }
71
72     public DistributionDownloadEvent(String action, CommonAuditData commonAuditData, DistributionData distributionData) {
73         this();
74         this.action = action;
75         this.requestId = commonAuditData.getRequestId();
76         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
77         this.status = commonAuditData.getStatus();
78         this.desc = commonAuditData.getDescription();
79         this.consumerId = distributionData.getConsumerId();
80         this.resourceUrl = distributionData.getResourceUrl();
81     }
82
83     public void setTimestamp1(String timestamp) {
84         this.timestamp1 = parseDateFromString(timestamp);
85     }
86
87     @Override
88     public void fillFields() {
89         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
90         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
91         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
92         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
93         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
94
95         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
96         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), getResourceUrl());
97         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
98         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
99         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
100     }
101
102     public String getConsumerId() {
103         return consumerId;
104     }
105
106     public void setConsumerId(String consumerId) {
107         this.consumerId = consumerId;
108     }
109
110     public String getResourceUrl() {
111         return resourceUrl;
112     }
113
114     public void setResourceUrl(String resourceUrl) {
115         this.resourceUrl = resourceUrl;
116     }
117
118     public UUID getTimebaseduuid() {
119         return timebaseduuid;
120     }
121
122     public void setTimebaseduuid(UUID timebaseduuid) {
123         this.timebaseduuid = timebaseduuid;
124     }
125
126     public Date getTimestamp1() {
127         return timestamp1;
128     }
129
130     public void setTimestamp1(Date timestamp1) {
131         this.timestamp1 = timestamp1;
132     }
133
134     public String getRequestId() {
135         return requestId;
136     }
137
138     public void setRequestId(String requestId) {
139         this.requestId = requestId;
140     }
141
142     public String getServiceInstanceId() {
143         return serviceInstanceId;
144     }
145
146     public void setServiceInstanceId(String serviceInstanceId) {
147         this.serviceInstanceId = serviceInstanceId;
148     }
149
150     public String getAction() {
151         return action;
152     }
153
154     public void setAction(String action) {
155         this.action = action;
156     }
157
158     public String getStatus() {
159         return status;
160     }
161
162     public void setStatus(String status) {
163         this.status = status;
164     }
165
166     public String getDesc() {
167         return desc;
168     }
169
170     @Override
171     public void setDesc(String desc) {
172         this.desc = desc;
173     }
174
175    @Override
176     public String toString() {
177         return "DistributionDownloadEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1
178                 + ", requestId=" + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action
179                 + ", status=" + status + ", desc=" + desc + ", consumerId=" + consumerId + ", resourceUrl="    + resourceUrl + "]";
180     }
181
182 }