summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorromaingimbert <romain.gimbert@orange.com>2018-04-26 10:56:56 +0200
committerromaingimbert <romain.gimbert@orange.com>2018-04-26 10:58:04 +0200
commit29d157e1fa499b2f9ab134a627bf7543e7dd3409 (patch)
treecb36017a91824712ddb13071516f1ead7fcb3ff3 /src/main
parent2aff8bb6713a6975af2b232dd5bc92175e3ab0f6 (diff)
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 <romain.gimbert@orange.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceinventory/AaiClient.java13
-rw-r--r--src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java12
2 files changed, 19 insertions, 6 deletions
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<Object> response = callApiGet(callUrlFormated, buildRequestHeaderForAAI());
- return (LinkedHashMap) response.getBody();
+ try{
+ ResponseEntity<Object> 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<LinkedHashMap> serviceInstancesForServiceType =
(List<LinkedHashMap>) 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);
+
}