17a794691dfbeff0a7895b8172dbcf7af57b3b3b
[sdc.git] /
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 lombok.AccessLevel;
29 import lombok.Getter;
30 import lombok.Setter;
31 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
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 @Getter
40 @Setter
41 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_GET_UEB_CLUSTER_EVENT_TYPE)
42 public class AuditingGetUebClusterEvent extends AuditingGenericEvent {
43
44     @PartitionKey
45     protected UUID timebaseduuid;
46
47     @ClusteringColumn
48     @Setter(AccessLevel.NONE)protected Date timestamp1;
49
50     @Column(name = "request_id")
51     protected String requestId;
52
53     @Column(name = "service_instance_id")
54     protected String serviceInstanceId;
55     @Column
56     protected String action;
57     @Column
58     protected String status;
59
60     @Column(name = "description")
61     protected String desc;
62
63     @Column(name = "consumer_id")
64     private String consumerId;
65
66     //Required to be public as it is used by Cassandra driver on get operation
67     public AuditingGetUebClusterEvent() {
68         timestamp1 = new Date();
69         timebaseduuid = UUIDs.timeBased();
70     }
71
72     public AuditingGetUebClusterEvent(String action, CommonAuditData commonAuditData, String consumerId) {
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 = consumerId;
80     }
81
82     public void setTimestamp1(String timestamp) {
83         this.timestamp1 = parseDateFromString(timestamp);
84     }
85     public void setTimestamp1(Date timestamp) {
86         this.timestamp1 = timestamp;
87     }
88
89     @Override
90     public void fillFields() {
91         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
92
93         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
94         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
95         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
96         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
97         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
98         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
99         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
100         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
101
102     }
103
104     @Override
105     public String toString() {
106         return "AuditingGetUebClusterEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1
107                 + ", requestId=" + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action
108                 + ", status=" + status + ", desc=" + desc + ", consumerId=" + consumerId + "]";
109     }
110
111 }