2  * ============LICENSE_START=======================================================
 
   4  * ================================================================================
 
   5  * Copyright (C) 2020 Samsung. 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=========================================================
 
  21 package org.onap.so.adapters.vevnfm.service;
 
  23 import org.apache.logging.log4j.util.Strings;
 
  24 import org.onap.so.adapters.etsisol003adapter.lcm.lcn.model.VnfLcmOperationOccurrenceNotification;
 
  25 import org.onap.so.adapters.vevnfm.aai.AaiConnection;
 
  26 import org.onap.so.adapters.vevnfm.configuration.ConfigProperties;
 
  27 import org.onap.so.adapters.vevnfm.constant.NotificationVnfFilterType;
 
  28 import org.slf4j.Logger;
 
  29 import org.slf4j.LoggerFactory;
 
  30 import org.springframework.stereotype.Service;
 
  33 public class DmaapConditionalSender {
 
  35     private static final Logger logger = LoggerFactory.getLogger(DmaapConditionalSender.class);
 
  37     private final NotificationVnfFilterType notificationVnfFilterType;
 
  38     private final AaiConnection aaiConnection;
 
  39     private final DmaapService dmaapService;
 
  41     public DmaapConditionalSender(final ConfigProperties configProperties, final AaiConnection aaiConnection,
 
  42             final DmaapService dmaapService) {
 
  43         this.notificationVnfFilterType = configProperties.getNotificationVnfFilterType();
 
  44         this.aaiConnection = aaiConnection;
 
  45         this.dmaapService = dmaapService;
 
  48     public void send(final VnfLcmOperationOccurrenceNotification notification) {
 
  49         final String href = notification.getLinks().getVnfInstance().getHref();
 
  50         boolean logSent = false;
 
  52         switch (notificationVnfFilterType) {
 
  54                 dmaapService.send(notification, aaiConnection.receiveGenericVnfId(href));
 
  58                 final String genericId = aaiConnection.receiveGenericVnfId(href);
 
  59                 if (Strings.isNotBlank(genericId)) {
 
  60                     dmaapService.send(notification, genericId);
 
  67                 throw new IllegalArgumentException(
 
  68                         "The value of VnfNotificationFilterType is not supported: " + notificationVnfFilterType);
 
  71         final String vnfInstanceId = notification.getVnfInstanceId();
 
  72         final String not = logSent ? "" : "not ";
 
  73         logger.info("The info with the VNF id '{}' is " + not + "sent to DMaaP", vnfInstanceId);