diff options
author | romaingimbert <romain.gimbert@orange.com> | 2018-08-22 10:00:22 +0200 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2018-08-22 10:00:22 +0200 |
commit | 8c4f868a5417629c1be17d7b98307fb5ed575211 (patch) | |
tree | 07e266da1c127d41a6df22084c014acbb61f67f0 /src/main/java | |
parent | 9feae3a717ad1fc69700e59f7b3181fa78337138 (diff) |
Help NBI user to get information
-add orderMessage 105 (service name already exists)
-add tests
Change-Id: I62ead9c22af49ee14d3a99eb97dddbf4fcd91e3c
Issue-ID: EXTAPI-116
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
Diffstat (limited to 'src/main/java')
5 files changed, 46 insertions, 20 deletions
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 393236f..d38d012 100644 --- a/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java +++ b/src/main/java/org/onap/nbi/apis/serviceinventory/ServiceInventoryService.java @@ -54,7 +54,7 @@ public class ServiceInventoryService { if (StringUtils.isEmpty(serviceSpecId) && StringUtils.isEmpty(serviceSpecName)) { throw new BackendFunctionalException(HttpStatus.NOT_FOUND, - "serviceSpecName or serviceSpecId must be provided"); + "serviceSpecName or serviceSpecId must be provided","serviceSpecName or serviceSpecId must be provided"); } String customerId = getCustomerId(clientId); @@ -68,7 +68,7 @@ public class ServiceInventoryService { addRelatedPartyId(customerId, serviceInventoryResponse); return serviceInventoryResponse; } else { - throw new BackendFunctionalException(HttpStatus.NOT_FOUND, "no catalog service found"); + throw new BackendFunctionalException(HttpStatus.NOT_FOUND, "no catalog service found","no catalog service found"); } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java index f9724f9..57cb6b5 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java @@ -77,7 +77,7 @@ public class SoClient { } catch (BackendFunctionalException e) { LOGGER.error("error on calling " + url + " ," + e); - return new ResponseEntity<>(e.getHttpStatus()); + return new ResponseEntity(e.getBodyResponse(),e.getHttpStatus()); } catch (ResourceAccessException e) { LOGGER.error("error on calling " + url + " ," + e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); @@ -101,7 +101,7 @@ public class SoClient { } catch (BackendFunctionalException e) { LOGGER.error("error on calling " + url + " ," + e); - return new ResponseEntity<>(e.getHttpStatus()); + return new ResponseEntity(e.getBodyResponse(),e.getHttpStatus()); } catch (ResourceAccessException e) { LOGGER.error("error on calling " + url + " ," + e); return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java index 3f9b556..7c954ff 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/SOTaskProcessor.java @@ -83,7 +83,7 @@ public class SOTaskProcessor { ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderInfo.getServiceOrderId()); ServiceOrderItem serviceOrderItem = getServiceOrderItem(executionTask, serviceOrder); boolean e2eService = E2EServiceUtils.isE2EService(serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId())); - + if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { if (e2eService) { ResponseEntity<CreateE2EServiceInstanceResponse> response = postE2EServiceOrderItem(serviceOrderInfo, @@ -104,7 +104,7 @@ public class SOTaskProcessor { pollE2ESoRequestStatus(serviceOrder, serviceOrderItem); else pollSoRequestStatus(serviceOrder, serviceOrderItem); - + if (serviceOrderItem.getState().equals(StateType.COMPLETED)) { updateSuccessTask(executionTask); } else { @@ -143,7 +143,7 @@ public class SOTaskProcessor { } return response; } - + private ServiceOrderItem getServiceOrderItem(ExecutionTask executionTask, ServiceOrder serviceOrder) { for (ServiceOrderItem item : serviceOrder.getOrderItem()) { if (item.getId().equals(executionTask.getOrderItemId())) { @@ -187,12 +187,26 @@ public class SOTaskProcessor { default: break; } - if(response!=null && response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) { - serviceOrderService.addOrderMessage(serviceOrder, "502"); - } + buildOrderMessageIfNeeded(serviceOrderItem, serviceOrder, response); return response; } + private void buildOrderMessageIfNeeded(ServiceOrderItem serviceOrderItem, ServiceOrder serviceOrder, + ResponseEntity<?> response) { + if(response!=null) + { + if(response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) { + serviceOrderService.addOrderMessage(serviceOrder, "502"); + } + if(response.getStatusCode()== HttpStatus.BAD_REQUEST) { + ResponseEntity<?> messageError=response; + if(messageError.getBody().toString().toLowerCase().contains("serviceinstance already exists")){ + serviceOrderService.addOrderItemMessage(serviceOrder, serviceOrderItem, "105"); + } + } + } + } + private ResponseEntity<CreateE2EServiceInstanceResponse> postE2ESORequest(ServiceOrderItem serviceOrderItem, ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder) { ServiceModel service = buildE2ESoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo(), serviceOrder); @@ -208,12 +222,10 @@ public class SOTaskProcessor { default: break; } - if(response!=null && response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) { - serviceOrderService.addOrderMessage(serviceOrder, "502"); - } + buildOrderMessageIfNeeded(serviceOrderItem, serviceOrder, response); return response; } - + private void updateServiceOrder(ServiceOrder serviceOrder) { boolean atLeastOneCompleted = false; boolean atLeastOneNotFinished = false; @@ -335,7 +347,7 @@ public class SOTaskProcessor { } } } - + /** * Build SO CREATE request from the ServiceOrder and catalog informations from SDC * @@ -388,7 +400,7 @@ public class SOTaskProcessor { return requestDetails; } - + /** * Build E2E SO CREATE request from the ServiceOrder and catalog informations from SDC * @@ -517,7 +529,7 @@ public class SOTaskProcessor { } } } - + /** * Update an executionTask in database when it's process with a success * diff --git a/src/main/java/org/onap/nbi/exceptions/BackendErrorHandler.java b/src/main/java/org/onap/nbi/exceptions/BackendErrorHandler.java index 56496b8..637cbdd 100644 --- a/src/main/java/org/onap/nbi/exceptions/BackendErrorHandler.java +++ b/src/main/java/org/onap/nbi/exceptions/BackendErrorHandler.java @@ -15,10 +15,12 @@ */ package org.onap.nbi.exceptions; +import java.io.IOException; +import java.nio.charset.StandardCharsets; +import org.apache.commons.io.IOUtils; import org.springframework.http.client.ClientHttpResponse; import org.springframework.web.client.DefaultResponseErrorHandler; import org.springframework.web.client.ResponseErrorHandler; -import java.io.IOException; public class BackendErrorHandler implements ResponseErrorHandler { @@ -32,7 +34,12 @@ public class BackendErrorHandler implements ResponseErrorHandler { @Override public void handleError(ClientHttpResponse response) throws IOException { if (response.getStatusCode() != null) { - throw new BackendFunctionalException(response.getStatusCode(), response.getStatusText()); + String body=null; + if(response.getBody()!=null) { + body = IOUtils.toString(response.getBody(), StandardCharsets.UTF_8.name()); + } + + throw new BackendFunctionalException(response.getStatusCode(), response.getStatusText(),body); } } } diff --git a/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java b/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java index e037987..43cb502 100644 --- a/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java +++ b/src/main/java/org/onap/nbi/exceptions/BackendFunctionalException.java @@ -21,13 +21,20 @@ public class BackendFunctionalException extends ApiException { private final HttpStatus httpStatus; - public BackendFunctionalException(HttpStatus httpStatus, String message) { + private final String bodyResponse; + + public BackendFunctionalException(HttpStatus httpStatus, String message, String bodyResponse) { super(message); this.httpStatus = httpStatus; + this.bodyResponse = bodyResponse; } public HttpStatus getHttpStatus() { return httpStatus; } + public String getBodyResponse() { + return bodyResponse; + } + } |