8cdd37d43f67d134659d5559daad21cf8c745036
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
22 package org.onap.so.adapters.tasks.audit;
23
24 import org.onap.so.objects.audit.AAIObjectAudit;
25 import org.onap.so.objects.audit.AAIObjectAuditList;
26 import org.onap.so.utils.ExternalTaskUtils;
27 import org.onap.so.utils.RetrySequenceLevel;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.core.env.Environment;
32 import org.springframework.stereotype.Component;
33
34 @Component
35 public abstract class AbstractAuditService extends ExternalTaskUtils {
36
37     private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
38
39     protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
40             "Unable to find all VServers and L-Interaces in A&AI";
41
42     protected static final String UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK = "Unable to find VServers in Openstack";
43
44     @Autowired
45     public Environment env;
46
47     public AbstractAuditService() {
48         super(RetrySequenceLevel.LONG);
49     }
50
51     /**
52      * @param auditList
53      * @return
54      */
55     protected boolean didCreateAuditFail(AAIObjectAuditList auditList) {
56         if (isAuditListNotNullAndNotEmpty(auditList)) {
57             if (logger.isInfoEnabled()) {
58                 logger.info("Audit Results: {}", auditList.toString());
59             }
60             return auditList.getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist()).findFirst()
61                     .map(v -> true).orElse(false);
62         } else {
63             return false;
64         }
65     }
66
67     /**
68      * @param auditList
69      * @return
70      */
71     protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
72         if (isAuditListNotNullAndNotEmpty(auditList)) {
73             if (logger.isInfoEnabled()) {
74                 logger.info("Audit Results: {}", auditList.toString());
75             }
76             return auditList.getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
77                     .map(v -> true).orElse(false);
78         } else {
79             return false;
80         }
81     }
82
83     private boolean isAuditListNotNullAndNotEmpty(AAIObjectAuditList auditList) {
84         return auditList != null && auditList.getAuditList() != null && !auditList.getAuditList().isEmpty();
85     }
86
87 }