Reformat catalog-dao
[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 package org.openecomp.sdc.be.resources.data.auditing;
21
22 import com.datastax.driver.core.utils.UUIDs;
23 import com.datastax.driver.mapping.annotations.ClusteringColumn;
24 import com.datastax.driver.mapping.annotations.Column;
25 import com.datastax.driver.mapping.annotations.PartitionKey;
26 import com.datastax.driver.mapping.annotations.Table;
27 import java.text.SimpleDateFormat;
28 import java.util.Date;
29 import java.util.TimeZone;
30 import java.util.UUID;
31 import lombok.Getter;
32 import lombok.Setter;
33 import lombok.ToString;
34 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
35 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
36 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
37
38 @Getter
39 @Setter
40 @ToString
41 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_DOWNLOAD_EVENT_TYPE)
42 public class DistributionDownloadEvent extends AuditingGenericEvent {
43
44     @PartitionKey
45     protected UUID timebaseduuid;
46     @ClusteringColumn
47     protected Date timestamp1;
48     @Column(name = "request_id")
49     protected String requestId;
50     @Column(name = "service_instance_id")
51     protected String serviceInstanceId;
52     @Column
53     protected String action;
54     @Column
55     protected String status;
56     @Column(name = "description")
57     protected String desc;
58     @Column(name = "consumer_id")
59     private String consumerId;
60     @Column(name = "resource_url")
61     private String resourceUrl;
62
63     //Required to be public as it is used by Cassandra driver on get operation
64     public DistributionDownloadEvent() {
65         timestamp1 = new Date();
66         timebaseduuid = UUIDs.timeBased();
67     }
68
69     public DistributionDownloadEvent(String action, CommonAuditData commonAuditData, DistributionData distributionData) {
70         this();
71         this.action = action;
72         this.requestId = commonAuditData.getRequestId();
73         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
74         this.status = commonAuditData.getStatus();
75         this.desc = commonAuditData.getDescription();
76         this.consumerId = distributionData.getConsumerId();
77         this.resourceUrl = distributionData.getResourceUrl();
78     }
79
80     public void setTimestamp1(String timestamp) {
81         this.timestamp1 = parseDateFromString(timestamp);
82     }
83
84     public void setTimestamp1(Date timestamp1) {
85         this.timestamp1 = timestamp1;
86     }
87
88     @Override
89     public void fillFields() {
90         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
91         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
92         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
93         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
94         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
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 }