2  * ============LICENSE_START=======================================================
 
   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
 
  11  *      http://www.apache.org/licenses/LICENSE-2.0
 
  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=========================================================
 
  22 package org.onap.so.adapters.tasks.audit;
 
  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 import java.util.Optional;
 
  36 public abstract class AbstractAuditService extends ExternalTaskUtils {
 
  38     private static final Logger logger = LoggerFactory.getLogger(AbstractAuditService.class);
 
  40     protected static final String UNABLE_TO_FIND_ALL_V_SERVERS_AND_L_INTERACES_IN_A_AI =
 
  41             "Unable to find all VServers and L-Interaces in A&AI";
 
  43     protected static final String UNABLE_TO_FIND_V_SERVERS_IN_OPENSTACK = "Unable to find VServers in Openstack";
 
  46     public Environment env;
 
  48     public AbstractAuditService() {
 
  49         super(RetrySequenceLevel.LONG);
 
  56     protected boolean didCreateAuditFail(Optional<AAIObjectAuditList> auditList) {
 
  57         if (auditList.isPresent() && isAuditListNotNullAndNotEmpty(auditList.get())) {
 
  58             if (logger.isInfoEnabled()) {
 
  59                 logger.info("Audit Results: {}", auditList.get().toString());
 
  61             return auditList.get().getAuditList().stream().filter(auditObject -> !auditObject.isDoesObjectExist())
 
  62                     .findFirst().map(v -> true).orElse(false);
 
  72     protected boolean didDeleteAuditFail(AAIObjectAuditList auditList) {
 
  73         if (isAuditListNotNullAndNotEmpty(auditList)) {
 
  74             if (logger.isInfoEnabled()) {
 
  75                 logger.info("Audit Results: {}", auditList.toString());
 
  77             return auditList.getAuditList().stream().filter(AAIObjectAudit::isDoesObjectExist).findFirst()
 
  78                     .map(v -> true).orElse(false);
 
  84     private boolean isAuditListNotNullAndNotEmpty(AAIObjectAuditList auditList) {
 
  85         return auditList != null && auditList.getAuditList() != null && !auditList.getAuditList().isEmpty();