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