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=========================================================
20 package org.openecomp.sdc.be.resources.data.auditing;
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;
33 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
34 import org.openecomp.sdc.be.resources.data.auditing.model.DistributionData;
35 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
36 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
37 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
40 * This class Represents the Audit for External API
44 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.EXTERNAL_API_EVENT_TYPE)
45 public class ExternalApiEvent extends AuditingGenericEvent {
48 protected UUID timebaseduuid;
50 protected Date timestamp1;
52 protected String action;
54 protected String status;
55 @Column(name = "description")
56 protected String desc;
57 @Column(name = "service_instance_id")
58 protected String serviceInstanceId;
59 @Column(name = "invariant_uuid")
60 protected String invariantUuid;
61 @Column(name = "prev_version")
62 protected String prevVersion;
63 @Column(name = "prev_state")
64 protected String prevState;
65 @Column(name = "curr_state")
66 protected String currState;
67 @Column(name = "consumer_id")
68 private String consumerId;
69 @Column(name = "resource_url")
70 private String resourceURL;
71 @Column(name = "resource_name")
72 private String resourceName;
73 @Column(name = "resource_type")
74 private String resourceType;
75 @Column(name = "modifier")
76 private String modifier;
77 @Column(name = "curr_version")
78 private String currVersion;
79 @Column(name = "prev_artifact_uuid")
80 private String prevArtifactUuid;
81 @Column(name = "curr_artifact_uuid")
82 private String currArtifactUuid;
83 @Column(name = "artifact_data")
84 private String artifactData;
86 //Required to be public as it is used by Cassandra driver on get operation
87 public ExternalApiEvent() {
88 timestamp1 = new Date();
89 timebaseduuid = UUIDs.timeBased();
92 public ExternalApiEvent(String action, CommonAuditData commonAuditData, ResourceCommonInfo resourceCommonInfo, DistributionData distributionData,
93 ResourceVersionInfo prevParams, ResourceVersionInfo currParams, String modifier, String invariantUuid,
94 String artifactData) {
97 this.status = commonAuditData.getStatus();
98 this.desc = commonAuditData.getDescription();
99 this.requestId = commonAuditData.getRequestId();
100 this.consumerId = distributionData.getConsumerId();
101 this.resourceURL = distributionData.getResourceUrl();
102 this.resourceName = resourceCommonInfo.getResourceName();
103 this.resourceType = resourceCommonInfo.getResourceType();
104 this.serviceInstanceId = commonAuditData.getServiceInstanceId();
105 this.invariantUuid = invariantUuid;
106 this.modifier = modifier;
107 this.prevVersion = prevParams.getVersion();
108 this.prevState = prevParams.getState();
109 this.prevArtifactUuid = prevParams.getArtifactUuid();
110 this.currVersion = currParams.getVersion();
111 this.currState = currParams.getState();
112 this.currArtifactUuid = currParams.getArtifactUuid();
113 this.artifactData = artifactData;
117 public void fillFields() {
118 fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
119 fields.put(AuditingFieldsKey.AUDIT_INVARIANT_UUID.getDisplayName(), getInvariantUuid());
120 fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
121 fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
122 fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
123 SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
124 simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
125 fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
126 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
127 fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), getResourceURL());
128 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_NAME.getDisplayName(), getResourceName());
129 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_TYPE.getDisplayName(), getResourceType());
130 fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
131 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_PREV_VERSION.getDisplayName(), getPrevVersion());
132 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_VERSION.getDisplayName(), getCurrVersion());
133 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_PREV_STATE.getDisplayName(), getPrevState());
134 fields.put(AuditingFieldsKey.AUDIT_RESOURCE_CURR_STATE.getDisplayName(), getCurrState());
135 fields.put(AuditingFieldsKey.AUDIT_PREV_ARTIFACT_UUID.getDisplayName(), getPrevArtifactUuid());
136 fields.put(AuditingFieldsKey.AUDIT_CURR_ARTIFACT_UUID.getDisplayName(), getCurrArtifactUuid());
137 fields.put(AuditingFieldsKey.AUDIT_ARTIFACT_DATA.getDisplayName(), getArtifactData());
141 public String toString() {
142 return "ExternalApiEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1 + ", action=" + action + ", status=" + status
143 + ", desc=" + desc + ", consumerId=" + consumerId + ", resourceURL=" + resourceURL + ", resourceName=" + resourceName + ", resourceType="
144 + resourceType + ", serviceInstanceId=" + serviceInstanceId + ", invariantUuid=" + invariantUuid + ", modifier=" + modifier
145 + ", prevVersion=" + prevVersion + ", currVersion=" + currVersion + ", prevState=" + prevState + ", currState=" + currState
146 + ", prevArtifactUuid=" + prevArtifactUuid + ", currArtifactUuid=" + currArtifactUuid + ", artifactData=" + artifactData + "]";