Improve test coverage
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / auditing / DistributionStatusEvent.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.be.resources.data.auditing.model.DistributionData;
33 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
34
35 import java.text.SimpleDateFormat;
36 import java.util.Date;
37 import java.util.TimeZone;
38 import java.util.UUID;
39
40 @Getter
41 @Setter
42 @ToString
43 @Table(keyspace = AuditingTypesConstants.AUDIT_KEYSPACE, name = AuditingTypesConstants.DISTRIBUTION_STATUS_EVENT_TYPE)
44 public class DistributionStatusEvent extends AuditingGenericEvent {
45
46     @PartitionKey
47     protected UUID timebaseduuid;
48
49     @ClusteringColumn
50     protected Date timestamp1;
51
52     @Column(name = "request_id")
53     protected String requestId;
54
55     @Column(name = "service_instance_id")
56     protected String serviceInstanceId;
57
58     @Column
59     protected String action;
60     @Column
61     protected String status;
62
63     @Column(name = "description")
64     protected String desc;
65
66     @Column
67     private String did;
68
69     @Column(name = "consumer_id")
70     private String consumerId;
71
72     @Column(name = "topic_name")
73     private String topicName;
74
75     @Column(name = "resoure_url")
76     private String resoureURL;
77
78     @Column(name = "status_time")
79     private String statusTime;
80
81     //Required to be public as it is used by Cassandra driver on get operation
82     public DistributionStatusEvent() {
83         timestamp1 = new Date();
84         timebaseduuid = UUIDs.timeBased();
85
86     }
87
88     public DistributionStatusEvent(String action, CommonAuditData commonAuditData, DistributionData distributionData,
89                                    String did, String topicName, String statusTime) {
90         this();
91         this.action = action;
92         this.requestId = commonAuditData.getRequestId();
93         this.serviceInstanceId = commonAuditData.getServiceInstanceId();
94         this.status = commonAuditData.getStatus();
95         this.desc = commonAuditData.getDescription();
96         this.did = did;
97         this.consumerId = distributionData.getConsumerId();
98         this.topicName = topicName;
99         this.resoureURL = distributionData.getResourceUrl();
100         this.statusTime = statusTime;
101     }
102
103     public void setTimestamp1(String timestamp) {
104         this.timestamp1 = parseDateFromString(timestamp);
105     }
106
107     public void setTimestamp1(Date timestamp) {
108         this.timestamp1 = timestamp;
109     }
110
111     @Override
112     public void fillFields() {
113         fields.put(AuditingFieldsKey.AUDIT_REQUEST_ID.getDisplayName(), getRequestId());
114
115         fields.put(AuditingFieldsKey.AUDIT_SERVICE_INSTANCE_ID.getDisplayName(), getServiceInstanceId());
116         fields.put(AuditingFieldsKey.AUDIT_ACTION.getDisplayName(), getAction());
117         fields.put(AuditingFieldsKey.AUDIT_STATUS.getDisplayName(), getStatus());
118         fields.put(AuditingFieldsKey.AUDIT_DESC.getDisplayName(), getDesc());
119         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_CONSUMER_ID.getDisplayName(), getConsumerId());
120
121         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_ID.getDisplayName(), getDid());
122         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_STATUS_TIME.getDisplayName(), getStatusTime());
123         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_TOPIC_NAME.getDisplayName(), getTopicName());
124         fields.put(AuditingFieldsKey.AUDIT_DISTRIBUTION_RESOURCE_URL.getDisplayName(), getResoureURL());
125         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormatPattern);
126         simpleDateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
127         fields.put(AuditingFieldsKey.AUDIT_TIMESTAMP.getDisplayName(), simpleDateFormat.format(timestamp1));
128
129     }
130 }