diff options
author | romaingimbert <romain.gimbert@orange.com> | 2018-04-26 10:56:56 +0200 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2018-04-26 10:58:04 +0200 |
commit | 29d157e1fa499b2f9ab134a627bf7543e7dd3409 (patch) | |
tree | cb36017a91824712ddb13071516f1ead7fcb3ff3 /src | |
parent | 2aff8bb6713a6975af2b232dd5bc92175e3ab0f6 (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')
3 files changed, 32 insertions, 7 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); + } diff --git a/src/test/resources/mappings/aai_get_6490_service-subscriptions.json b/src/test/resources/mappings/aai_get_6490_service-subscriptions.json index 5582990..4995025 100644 --- a/src/test/resources/mappings/aai_get_6490_service-subscriptions.json +++ b/src/test/resources/mappings/aai_get_6490_service-subscriptions.json @@ -13,7 +13,19 @@ }, { "service-type": "vFW", - "resource-version": "1519660513613" + "resource-version": "1519660513613", + "service-instances": { + "service-instance": [ + { + "service-instance-id": "39ff3f9d-f210-4566-9d19-fa37edf1697d", + "service-instance-name": "vPCRF", + "model-invariant-id": "a09e799f-58eb-4c00-bfcc-4fa371a557e3", + "model-version-id": "4c393977-09ea-42c2-bcd9-f50302ebba48", + "resource-version": "1524672125232" + } + ] + } + } ] }, |