Improve test coverage
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / EcompOperationalEnvironmentEvent.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.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 lombok.Getter;
28 import lombok.Setter;
29 import lombok.ToString;
30 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
31
32 import java.text.SimpleDateFormat;
33 import java.util.Date;
34 import java.util.TimeZone;
35
36
37 @Getter
38 @Setter
39 @ToString
40 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.ECOMP_OPERATIONAL_ENV_EVENT_TYPE)
41 public class EcompOperationalEnvironmentEvent  extends AuditingGenericEvent {
42
43     @PartitionKey
44     @Column(name = "operational_environment_id")
45     protected String operationalEnvironmentId;
46
47     @ClusteringColumn
48     protected Date timestamp1;
49
50     @Column
51     protected String action;
52
53     @Column(name = "operational_environment_action")
54     protected String operationalEnvironmentAction;
55
56     @Column(name = "operational_environment_name")
57     protected String operationalEnvironmentName;
58
59     @Column(name = "operational_environment_type")
60     protected String operationalEnvironmentType;
61
62     @Column(name = "tenant_context")
63     protected String tenantContext;
64
65
66     //Required to be public as it is used by Cassandra driver on get operation
67     public EcompOperationalEnvironmentEvent() {
68         timestamp1 = new Date();
69     }
70
71     public EcompOperationalEnvironmentEvent(String action, String operationalEnvironmentId, String operationalEnvironmentName,
72                                             String operationalEnvironmentType, String operationalEnvironmentAction, String tenantContext) {
73         this();
74         this.action = action;
75         this.operationalEnvironmentId = operationalEnvironmentId;
76         this.operationalEnvironmentType = operationalEnvironmentType;
77         this.operationalEnvironmentName = operationalEnvironmentName;
78         this.operationalEnvironmentAction = operationalEnvironmentAction;
79         this.tenantContext = tenantContext;
80     }
81
82     @Override
83     public void fillFields() {
84         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
85         fields.put(AuditingFieldsKey.AUDIT_OPERATIONAL_ENVIRONMENT_ID.getDisplayName(), getOperationalEnvironmentId());
86         fields.put(AuditingFieldsKey.AUDIT_OPERATIONAL_ENVIRONMENT_NAME.getDisplayName(), getOperationalEnvironmentName());
87         fields.put(AuditingFieldsKey.AUDIT_OPERATIONAL_ENVIRONMENT_TYPE.getDisplayName(), getOperationalEnvironmentType());
88         fields.put(AuditingFieldsKey.AUDIT_OPERATIONAL_ENVIRONMENT_ACTION.getDisplayName(), getOperationalEnvironmentAction());
89         fields.put(AuditingFieldsKey.AUDIT_TENANT_CONTEXT.getDisplayName(), getTenantContext());
90         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
91         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
92         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
93     }
94 }