2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.resources.data.auditing;
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;
30 import lombok.ToString;
31 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
32 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionTopicData;
33 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
35 import java.text.SimpleDateFormat;
36 import java.util.Date;
37 import java.util.TimeZone;
38 import java.util.UUID;
43 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_ENGINE_EVENT_TYPE)
44 public class DistributionEngineEvent extends AuditingGenericEvent {
47 protected UUID timebaseduuid;
50 protected Date timestamp1;
52 @Column(name = "request_id")
53 protected String requestId;
55 @Column(name = "service_instance_id")
56 protected String serviceInstanceId;
59 protected String action;
61 protected String status;
63 @Column(name = "description")
64 protected String desc;
66 @Column(name = "consumer_id")
67 private String consumerId;
69 @Column(name = "DSTATUS_TOPIC")
70 private String dstatusTopic;
72 @Column(name = "DNOTIF_TOPIC")
73 private String dnotifTopic;
75 @Column(name = "d_env")
76 private String environmentName;
81 @Column(name = "api_key")
82 private String apiKey;
84 //Required to be public as it is used by Cassandra driver on get operation
85 public DistributionEngineEvent() {
86 timestamp1 = new Date();
87 timebaseduuid = UUIDs.timeBased();
90 public DistributionEngineEvent(String action, CommonAuditData commonAuditData, String consumerId, DistributionTopicData distributionTopicData,
91 String apiKey, String envName, String role) {
94 this.requestId = commonAuditData.getRequestId();
95 this.serviceInstanceId = commonAuditData.getServiceInstanceId();
96 this.status = commonAuditData.getStatus();
97 //if no desc, keep distr desc
98 this.desc = commonAuditData.getDescription();
99 this.consumerId = consumerId;
100 this.dstatusTopic = distributionTopicData.getStatusTopic();
101 this.dnotifTopic = distributionTopicData.getNotificationTopic();
102 this.apiKey = apiKey;
103 this.environmentName = envName;
107 public void setTimestamp1(String timestamp) {
108 this.timestamp1 = parseDateFromString(timestamp);
111 public void setTimestamp1(Date timestamp1) {
112 this.timestamp1 = timestamp1;
116 public void fillFields() {
117 fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
119 fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
120 fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
121 fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
122 fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
124 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
125 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_API_KEY.getDisplayName(), getApiKey());
126 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ENVRIONMENT_NAME.getDisplayName(), getEnvironmentName());
127 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ROLE.getDisplayName(), getRole());
128 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TOPIC_NAME.getDisplayName(), getDstatusTopic());
129 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_NOTIFICATION_TOPIC_NAME.getDisplayName(),
131 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
132 simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
133 fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));