From 29d157e1fa499b2f9ab134a627bf7543e7dd3409 Mon Sep 17 00:00:00 2001 From: romaingimbert Date: Thu, 26 Apr 2018 10:56:56 +0200 Subject: service inventory empty when no service - fix code when a service type has no service-instance Change-Id: I6035a459bdf90b724377acb76bb99be747bf03fb Issue-ID: EXTAPI-78 Signed-off-by: romaingimbert --- .../java/org/onap/nbi/apis/serviceinventory/AaiClient.java | 13 +++++++++++-- .../nbi/apis/serviceinventory/ServiceInventoryService.java | 12 ++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/onap/nbi/apis/serviceinventory/AaiClient.java b/src/main/java/org/onap/nbi/apis/serviceinventory/AaiClient.java index 8fd3002..698981b 100644 --- a/src/main/java/org/onap/nbi/apis/serviceinventory/AaiClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceinventory/AaiClient.java @@ -17,6 +17,9 @@ package org.onap.nbi.apis.serviceinventory; import java.util.LinkedHashMap; import org.onap.nbi.OnapComponentsUrlPaths; +import org.onap.nbi.exceptions.BackendFunctionalException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -39,6 +42,7 @@ public class AaiClient extends BaseClient { private static final String HEADER_AUTHORIZATION = "Authorization"; private static final String X_FROM_APP_ID = "X-FromAppId"; + private static final Logger LOGGER = LoggerFactory.getLogger(AaiClient.class); private HttpHeaders buildRequestHeaderForAAI() { @@ -91,7 +95,12 @@ public class AaiClient extends BaseClient { String callUrlFormated = callURL.toString().replace(CUSTOMER_ID, customerId); callUrlFormated = callUrlFormated.replace("$serviceSpecName", serviceType); - ResponseEntity response = callApiGet(callUrlFormated, buildRequestHeaderForAAI()); - return (LinkedHashMap) response.getBody(); + try{ + ResponseEntity response = callApiGet(callUrlFormated, buildRequestHeaderForAAI()); + return (LinkedHashMap) response.getBody(); + } catch (BackendFunctionalException e) { + LOGGER.error("error on calling {0} , {1}" , callUrlFormated, e); + return null; + } } } diff --git a/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java b/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java index a4347d4..3208de4 100644 --- a/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java +++ b/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java @@ -24,6 +24,7 @@ import org.onap.nbi.exceptions.BackendFunctionalException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; +import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; @@ -156,11 +157,14 @@ public class ServiceInventoryService { List serviceInstancesForServiceType = (List) serviceInstancesInAaiForCustomer.get("service-instance"); - // add service type for jolt - for (LinkedHashMap serviceInstanceForServiceType : serviceInstancesForServiceType) { - serviceInstanceForServiceType.put("service-type", serviceType); + if(!CollectionUtils.isEmpty(serviceInstancesForServiceType)){ + // add service type for jolt + for (LinkedHashMap serviceInstanceForServiceType : serviceInstancesForServiceType) { + serviceInstanceForServiceType.put("service-type", serviceType); + } + serviceInstances.addAll(serviceInstancesForServiceType); } - serviceInstances.addAll(serviceInstancesForServiceType); + } -- cgit 1.2.3-korg