174dea663da9f06fd4f53f864b4973ff46baef86
[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.be.resources.data.auditing.model.OperationalEnvAuditData;
33 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
34 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
35 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
36
37 import java.text.SimpleDateFormat;
38 import java.util.Date;
39 import java.util.TimeZone;
40 import java.util.UUID;
41
42 @Getter
43 @Setter
44 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_NOTIFICATION_EVENT_TYPE)
45 public class DistributionNotificationEvent extends AuditingGenericEvent {
46
47     @PartitionKey
48     protected UUID timebaseduuid;
49
50     @ClusteringColumn
51     @Setter(AccessLevel.NONE)protected Date timestamp1;
52
53     @Column(name = "request_id")
54     protected String requestId;
55
56     @Column(name = "service_instance_id")
57     protected String serviceInstanceId;
58     @Column
59     protected String action;
60     @Column
61     protected String status;
62
63     @Column(name = "description")
64     protected String desc;
65
66     @Column(name = "resource_name")
67     private String resourceName;
68
69     @Column(name = "resource_type")
70     private String resourceType;
71
72     @Column(name = "curr_version")
73     private String currVersion;
74
75     @Column
76     private String modifier;
77
78     @Column(name = "curr_state")
79     private String currState;
80
81     @Column(name = "topic_name")
82     private String topicName;
83
84     @Column
85     private String did;
86
87     @Column(name = "env_id")
88     private String envId;
89
90     @Column(name = "vnf_workload_context")
91     private String vnfWorkloadContext;
92
93     @Column(name = "tenant")
94     private String tenant;
95
96     public DistributionNotificationEvent() {
97         timestamp1 = new Date();
98         timebaseduuid = UUIDs.timeBased();
99     }
100
101     public DistributionNotificationEvent(String action, CommonAuditData commonAuditData, ResourceCommonInfo resourceCommonInfo,
102                                          ResourceVersionInfo resourceVersionInfo,
103                                          String did, String modifier, String topicName,
104                                          OperationalEnvAuditData opEnvFields) {
105         this();
106         this.action = action;
107         this.requestId = commonAuditData.getRequestId();
108         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
109         this.status = commonAuditData.getStatus();
110         this.desc = commonAuditData.getDescription();
111         this.did = did;
112         this.modifier = modifier;
113         this.currState = resourceVersionInfo.getState();
114         this.currVersion = resourceVersionInfo.getVersion();
115         this.resourceName = resourceCommonInfo.getResourceName();
116         this.resourceType = resourceCommonInfo.getResourceType();
117         this.topicName = topicName;
118         this.envId = opEnvFields.getEnvId();
119         this.vnfWorkloadContext = opEnvFields.getVnfWorkloadContext();
120         this.tenant = opEnvFields.getTenant();
121
122     }
123
124     public void setTimestamp1(String timestamp) {
125         this.timestamp1 = parseDateFromString(timestamp);
126     }
127
128     public void setTimestamp1(Date timestamp) {
129         this.timestamp1 = timestamp;
130     }
131
132     @Override
133     public void fillFields() {
134         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
135
136         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
137         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
138         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
139         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
140         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ENVIRONMENT_ID.getDisplayName(), getEnvId());
141         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_VNF_WORKLOAD_CONTEXT.getDisplayName(), getVnfWorkloadContext());
142         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TENANT.getDisplayName(), getTenant());
143
144         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ID.getDisplayName(), getDid());
145         fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
146         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_STATE.getDisplayName(), getCurrState());
147         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_VERSION.getDisplayName(), getCurrVersion());
148         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_NAME.getDisplayName(), getResourceName());
149         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_TYPE.getDisplayName(), getResourceType());
150         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TOPIC_NAME.getDisplayName(), getTopicName());
151         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
152         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
153         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
154     }
155
156     @Override
157     public String toString() {
158         return "DistributionNotificationEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1
159                 + ", requestId=" + requestId + ", serviceInstanceId=" + serviceInstanceId + ", action=" + action
160                 + ", status=" + status + ", desc=" + desc + ", resourceName=" + resourceName + ", resourceType="
161                 + resourceType + ", currVersion=" + currVersion + ", modifier=" + modifier + ", currState=" + currState
162                 + ", topicName=" + topicName + ", did=" + did
163                 + ", envId=" + envId + ", vnfWorkloadContext=" + vnfWorkloadContext + ", tenant=" + tenant + "]";
164     }
165
166 }