Improve test coverage
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / auditing / impl / distribution / AuditDistributionNotificationEventFactory.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.auditing.impl.distribution;
21
22 import org.openecomp.sdc.be.auditing.impl.AuditBaseEventFactory;
23 import org.openecomp.sdc.be.model.User;
24 import org.openecomp.sdc.be.resources.data.auditing.AuditingActionEnum;
25 import org.openecomp.sdc.be.resources.data.auditing.AuditingGenericEvent;
26 import org.openecomp.sdc.be.resources.data.auditing.DistributionNotificationEvent;
27 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
28 import org.openecomp.sdc.be.resources.data.auditing.model.OperationalEnvAuditData;
29 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceCommonInfo;
30 import org.openecomp.sdc.be.resources.data.auditing.model.ResourceVersionInfo;
31
32 public class AuditDistributionNotificationEventFactory extends AuditBaseEventFactory {
33
34     private static final String LOG_STR = "ACTION = \"%s\" RESOURCE_NAME = \"%s\" RESOURCE_TYPE = \"%s\" "
35         + "SERVICE_INSTANCE_ID = \"%s\" CURR_VERSION = \"%s\" MODIFIER = \"%s\" CURR_STATE = \"%s\" DID = \"%s\" "
36         + "TOPIC_NAME = \"%s\" STATUS = \"%s\" DESC = \"%s\" TENANT = \"%s\" VNF_WORKLOAD_CONTEXT = \"%s\" ENV_ID = \"%s\"";
37     private final DistributionNotificationEvent event;
38
39     public AuditDistributionNotificationEventFactory(CommonAuditData commonAuditData, ResourceCommonInfo resourceCommonInfo,
40                                                      ResourceVersionInfo resourceVersionInfo, String did, User modifier, String topicName,
41                                                      OperationalEnvAuditData opEnvFields) {
42         this(commonAuditData, resourceCommonInfo, resourceVersionInfo, did, AuditBaseEventFactory.buildUserName(modifier), topicName, opEnvFields);
43     }
44
45     private AuditDistributionNotificationEventFactory(CommonAuditData commonAuditData, ResourceCommonInfo resourceCommonInfo,
46                                                       ResourceVersionInfo resourceVersionInfo, String did, String modifier, String topicName,
47                                                       OperationalEnvAuditData opEnvFields) {
48         super(AuditingActionEnum.DISTRIBUTION_NOTIFY);
49         this.event = new DistributionNotificationEvent(getAction().getName(), commonAuditData, resourceCommonInfo, resourceVersionInfo, did, modifier,
50             topicName, opEnvFields);
51     }
52
53     @Override
54     public String getLogPattern() {
55         return LOG_STR;
56     }
57
58     @Override
59     public String[] getLogMessageParams() {
60         return new String[]{event.getAction(), event.getResourceName(), event.getResourceType(), event.getServiceInstanceId(), event.getCurrVersion(),
61             event.getModifier(), event.getCurrState(), event.getDid(), event.getTopicName(), event.getStatus(), event.getDesc(), event.getTenant(),
62             event.getVnfWorkloadContext(), event.getEnvId()};
63     }
64
65     @Override
66     public AuditingGenericEvent getDbEvent() {
67         return event;
68     }
69 }