re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / CategoryEvent.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.CATEGORY_EVENT_TYPE)
37 public class CategoryEvent extends AuditingGenericEvent {
38
39     @PartitionKey
40     protected UUID timebaseduuid;
41
42     @ClusteringColumn
43     protected Date timestamp1;
44
45     @Column
46     String action;
47     @Column
48     String status;
49     @Column(name = "description")
50     String desc;
51
52     @Column(name = "category_name")
53     String categoryName;
54
55     @Column(name = "sub_category_name")
56     String subCategoryName;
57
58     @Column(name = "grouping_name")
59     String groupingName;
60
61     @Column
62     String modifier;
63
64     @Column(name = "service_instance_id")
65     String serviceInstanceId;
66
67     @Column(name = "resource_type")
68     String resourceType;
69
70     @Column(name = "request_id")
71     String requestId;
72
73     public CategoryEvent(String action, CommonAuditData commonAuditData, String modifier, String categoryName, String subCategoryName,
74                          String groupingName, String resourceType) {
75         this();
76         this.action = action;
77         this.requestId = commonAuditData.getRequestId();
78         this.status = commonAuditData.getStatus();
79         this.desc = commonAuditData.getDescription();
80         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
81         this.resourceType = resourceType;
82         this.modifier = modifier;
83         this.categoryName = categoryName;
84         this.subCategoryName = subCategoryName;
85         this.groupingName = groupingName;
86     }
87
88     //Required to be public as it is used by Cassandra driver on get operation
89     public CategoryEvent() {
90         timestamp1 = new Date();
91         timebaseduuid = UUIDs.timeBased();
92     }
93
94     public void setTimestamp1(String timestamp) {
95         this.timestamp1 = parseDateFromString(timestamp);
96     }
97
98     @Override
99     public void fillFields() {
100
101         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
102         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
103         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
104         fields.put(AuditingFieldsKey.AUDIT_CATEGORY_NAME.getDisplayName(), getCategoryName());
105         fields.put(AuditingFieldsKey.AUDIT_SUB_CATEGORY_NAME.getDisplayName(), getSubCategoryName());
106         fields.put(AuditingFieldsKey.AUDIT_GROUPING_NAME.getDisplayName(), getGroupingName());
107         fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
108         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
109         fields.put(AuditingFieldsKey.AUDIT_RESOURCE_TYPE.getDisplayName(), getResourceType());
110         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
111         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
112         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
113         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
114
115     }
116
117     public UUID getTimebaseduuid() {
118         return timebaseduuid;
119     }
120
121     public void setTimebaseduuid(UUID timebaseduuid) {
122         this.timebaseduuid = timebaseduuid;
123     }
124
125     public String getAction() {
126         return action;
127     }
128
129     public void setAction(String action) {
130         this.action = action;
131     }
132
133     public String getStatus() {
134         return status;
135     }
136
137     public void setStatus(String status) {
138         this.status = status;
139     }
140
141     public String getDesc() {
142         return desc;
143     }
144
145     public void setDesc(String desc) {
146         this.desc = desc;
147     }
148
149     public String getCategoryName() {
150         return categoryName;
151     }
152
153     public void setCategoryName(String categoryName) {
154         this.categoryName = categoryName;
155     }
156
157     public String getSubCategoryName() {
158         return subCategoryName;
159     }
160
161     public void setSubCategoryName(String subCategoryName) {
162         this.subCategoryName = subCategoryName;
163     }
164
165     public String getGroupingName() {
166         return groupingName;
167     }
168
169     public void setGroupingName(String groupingName) {
170         this.groupingName = groupingName;
171     }
172
173     public Date getTimestamp1() {
174         return timestamp1;
175     }
176
177     public void setTimestamp1(Date timestamp1) {
178         this.timestamp1 = timestamp1;
179     }
180
181     public String getModifier() {
182         return modifier;
183     }
184
185     public void setModifier(String modifier) {
186         this.modifier = modifier;
187     }
188
189     public String getServiceInstanceId() {
190         return serviceInstanceId;
191     }
192
193     public void setServiceInstanceId(String serviceInstanceId) {
194         this.serviceInstanceId = serviceInstanceId;
195     }
196
197     public String getResourceType() {
198         return resourceType;
199     }
200
201     public void setResourceType(String resourceType) {
202         this.resourceType = resourceType;
203     }
204
205     public String getRequestId() {
206         return requestId;
207     }
208
209     public void setRequestId(String requestId) {
210         this.requestId = requestId;
211     }
212
213 }