d4e1c37c58eed187a8d52d1219c9065085a0a2dd
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / auditing / impl / category / AuditCategoryEventFactory.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.category;
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.CategoryEvent;
27 import org.openecomp.sdc.be.resources.data.auditing.model.CommonAuditData;
28
29 public class AuditCategoryEventFactory extends AuditBaseEventFactory {
30
31     private static final String LOG_STR = "ACTION = \"%s\" MODIFIER = \"%s\" CATEGORY_NAME = \"%s\" SUB_CATEGORY_NAME = \"%s\""
32         + " GROUPING_NAME = \"%s\" RESOURCE_TYPE = \"%s\" STATUS = \"%s\" DESC = \"%s\"";
33     private final CategoryEvent event;
34
35     private AuditCategoryEventFactory(AuditingActionEnum action, CommonAuditData commonFields, String modifier, String categoryName,
36                                       String subCategoryName, String groupingName, String resourceType) {
37         super(action);
38         event = new CategoryEvent(getAction().getName(), commonFields, modifier, categoryName, subCategoryName, groupingName, resourceType);
39     }
40
41     public AuditCategoryEventFactory(AuditingActionEnum action, CommonAuditData commonFields, User modifier, String categoryName,
42                                      String subCategoryName, String groupingName, String resourceType) {
43         this(action, commonFields, buildUserName(modifier), categoryName, subCategoryName, groupingName, resourceType);
44     }
45
46     public AuditCategoryEventFactory(AuditingActionEnum action, CommonAuditData commonFields, String modifier, String categoryName,
47                                      String subCategoryName, String groupingName, String resourceType, String timestamp) {
48         this(action, commonFields, modifier, categoryName, subCategoryName, groupingName, resourceType);
49         event.setTimestamp1(timestamp);
50     }
51
52     @Override
53     public String getLogPattern() {
54         return LOG_STR;
55     }
56
57     @Override
58     public String[] getLogMessageParams() {
59         return new String[]{event.getAction(), event.getModifier(), event.getCategoryName(), event.getSubCategoryName(), event.getGroupingName(),
60             event.getResourceType(), event.getStatus(), event.getDesc()};
61     }
62
63     @Override
64     public AuditingGenericEvent getDbEvent() {
65         return event;
66     }
67 }