546b71070d5ee900753159fccc03fdcf6c298a34
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / ConsumerEvent.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
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 org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
29 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
30
31 import java.text.SimpleDateFormat;
32 import java.util.Date;
33 import java.util.TimeZone;
34 import java.util.UUID;
35
36 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.CONSUMER_EVENT_TYPE)
37 public class ConsumerEvent extends AuditingGenericEvent {
38
39     @PartitionKey
40     protected UUID timebaseduuid;
41
42     @ClusteringColumn
43     protected Date timestamp1;
44
45     @Column(name = "request_id")
46     protected String requestId;
47     @Column
48     protected String action;
49     @Column
50     protected String status;
51
52     @Column(name = "description")
53     protected String desc;
54
55     @Column
56     private String modifier;
57
58     @Column(name = "ecomp_user")
59     private String ecompUser;
60
61     public ConsumerEvent(String action, CommonAuditData commonAuditData, String ecompUser, String modifier) {
62         this();
63         this.action = action;
64         this.requestId = commonAuditData.getRequestId();
65         this.status = commonAuditData.getStatus();
66         this.desc = commonAuditData.getDescription();
67         this.modifier = modifier;
68         this.ecompUser = ecompUser;
69     }
70
71     //Required to be public as it is used by Cassandra driver on get operation
72     public ConsumerEvent() {
73         timestamp1 = new Date();
74         timebaseduuid = UUIDs.timeBased();
75     }
76
77     public void setTimestamp1(String timestamp) {
78         this.timestamp1 = parseDateFromString(timestamp);
79     }
80
81     @Override
82     public void fillFields() {
83         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
84
85         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
86         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
87         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
88         fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
89         fields.put(AuditingFieldsKey.AUDIT_ECOMP_USER.getDisplayName(), getEcompUser());
90         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
91         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
92         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
93     }
94
95     public String getModifier() {
96         return modifier;
97     }
98
99     public void setModifier(String modifier) {
100         this.modifier = modifier;
101     }
102
103     public String getEcompUser() {
104         return ecompUser;
105     }
106
107     public void setEcompUser(String ecompUser) {
108         this.ecompUser = ecompUser;
109     }
110
111     public UUID getTimebaseduuid() {
112         return timebaseduuid;
113     }
114
115     public void setTimebaseduuid(UUID timebaseduuid) {
116         this.timebaseduuid = timebaseduuid;
117     }
118
119     public Date getTimestamp1() {
120         return timestamp1;
121     }
122
123     public void setTimestamp1(Date timestamp1) {
124         this.timestamp1 = timestamp1;
125     }
126
127     public String getRequestId() {
128         return requestId;
129     }
130
131     public void setRequestId(String requestId) {
132         this.requestId = requestId;
133     }
134
135     public String getAction() {
136         return action;
137     }
138
139     public void setAction(String action) {
140         this.action = action;
141     }
142
143     public String getStatus() {
144         return status;
145     }
146
147     public void setStatus(String status) {
148         this.status = status;
149     }
150
151     public String getDesc() {
152         return desc;
153     }
154
155     public void setDesc(String desc) {
156         this.desc = desc;
157     }
158
159     @Override
160     public String toString() {
161         return "ConsumerEvent [timebaseduuid=" + timebaseduuid + ", timestamp1=" + timestamp1 + ", requestId="
162                 + requestId + ", action=" + action + ", status=" + status + ", desc=" + desc + ", modifier=" + modifier
163                 + ", ecompUser=" + ecompUser + "]";
164     }
165
166 }