Improve test coverage
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / UserAdminEvent.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 lombok.Getter;
29 import lombok.Setter;
30 import lombok.ToString;
31 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
32 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
33
34 import java.text.SimpleDateFormat;
35 import java.util.Date;
36 import java.util.TimeZone;
37 import java.util.UUID;
38
39 @Getter
40 @Setter
41 @ToString
42 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.USER_ADMIN_EVENT_TYPE)
43 public class UserAdminEvent extends AuditingGenericEvent {
44
45     @PartitionKey
46     protected UUID timebaseduuid;
47
48     @ClusteringColumn
49     protected Date timestamp1;
50
51     @Column(name = "REQUEST_ID")
52     protected String requestId;
53
54     @Column(name = "SERVICE_INSTANCE_ID")
55     protected String serviceInstanceId;
56
57     @Column(name = "ACTION")
58     protected String action;
59     @Column
60     protected String status;
61
62     @Column(name = "description")
63     protected String desc;
64
65     @Column
66     private String modifier;
67
68     @Column(name = "user_before")
69     private String userBefore;
70
71     @Column(name = "user_after")
72     private String userAfter;
73
74     //Required to be public as it is used by Cassandra driver on get operation
75     public UserAdminEvent() {
76         timestamp1 = new Date();
77         timebaseduuid = UUIDs.timeBased();
78     }
79
80     public UserAdminEvent(String action, CommonAuditData commonAuditData, String modifier, String userBefore, String userAfter) {
81         this();
82         this.action = action;
83         this.requestId = commonAuditData.getRequestId();
84         this.status = commonAuditData.getStatus();
85         this.modifier = modifier;
86         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
87         this.desc = commonAuditData.getDescription();
88         this.userBefore = userBefore;
89         this.userAfter = userAfter;
90     }
91
92     public void setTimestamp1(String timestamp) {
93         this.timestamp1 = parseDateFromString(timestamp);
94     }
95
96     public void setTimestamp1(Date timestamp) {
97         this.timestamp1 = timestamp;
98     }
99
100     @Override
101     public void fillFields() {
102         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
103
104         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
105         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
106         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
107         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
108         fields.put(AuditingFieldsKey.AUDIT_USER_BEFORE.getDisplayName(), getUserBefore());
109         fields.put(AuditingFieldsKey.AUDIT_USER_AFTER.getDisplayName(), getUserAfter());
110         fields.put(AuditingFieldsKey.AUDIT_MODIFIER_UID.getDisplayName(), getModifier());
111         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
112         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
113         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
114     }
115 }