From 8bbefa2ea43f8d2beedeb347bb831b82009417a3 Mon Sep 17 00:00:00 2001 From: romaingimbert Date: Fri, 10 Aug 2018 14:29:31 +0200 Subject: Help NBI user to get information -add orderMessage to order and orderItem -add tests Change-Id: Ibb9e54ec03f8b8f736390501fc16c9b96c0f987a Issue-ID: EXTAPI-116 Signed-off-by: romaingimbert --- .../onap/nbi/apis/serviceorder/MultiClient.java | 90 +++++--- .../org/onap/nbi/apis/serviceorder/SoClient.java | 60 +++--- .../nbi/apis/serviceorder/model/OrderMessage.java | 227 +++++++++++++++++++++ .../nbi/apis/serviceorder/model/ServiceOrder.java | 50 ++++- .../apis/serviceorder/model/ServiceOrderItem.java | 53 ++++- .../apis/serviceorder/model/SeverityMessage.java | 78 +++++++ .../serviceorder/service/ServiceOrderService.java | 73 +++++++ .../workflow/CheckOrderConsistenceManager.java | 69 ++++--- .../workflow/CreateAAICustomerManager.java | 5 +- .../workflow/CreateAAIServiceTypeManager.java | 7 +- .../serviceorder/workflow/SOTaskProcessor.java | 18 +- 11 files changed, 630 insertions(+), 100 deletions(-) create mode 100755 src/main/java/org/onap/nbi/apis/serviceorder/model/OrderMessage.java create mode 100755 src/main/java/org/onap/nbi/apis/serviceorder/model/SeverityMessage.java (limited to 'src/main/java') diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java index 4884485..2bc654b 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/MultiClient.java @@ -22,7 +22,10 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.onap.nbi.OnapComponentsUrlPaths; +import org.onap.nbi.apis.serviceorder.model.ServiceOrder; +import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.onap.nbi.exceptions.BackendFunctionalException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,6 +75,9 @@ public class MultiClient { @Autowired private ServiceInventoryUrl serviceInventoryUrl; + @Autowired + private ServiceOrderService serviceOrderService; + private static final String HEADER_AUTHORIZATION = "Authorization"; private static final String X_FROM_APP_ID = "X-FromAppId"; @@ -79,19 +85,34 @@ public class MultiClient { private static final Logger LOGGER = LoggerFactory.getLogger(MultiClient.class); - public ResponseEntity getServiceCatalog(String id) { + public Map getServiceCatalog(String id,ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem){ StringBuilder callURL = new StringBuilder().append(serviceCatalogUrl.getServiceCatalogUrl()).append(id); - return callApiGet(callURL.toString(), new HttpHeaders(), null); + ResponseEntity response = callApiGet(callURL.toString(), new HttpHeaders(), null); + + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "500"); + LOGGER.warn("unable to retrieve catalog information for service {}", + serviceOrderItem.getService().getServiceSpecification().getId()); + } + if (response.getStatusCode().is2xxSuccessful()) { + return (LinkedHashMap) response.getBody(); + } + return null; + } - public boolean doesServiceExistInServiceInventory(String id, String serviceName, String globalSubscriberId) { + public boolean doesServiceExistInServiceInventory(String id, String serviceName, String globalSubscriberId, ServiceOrder serviceOrder) { StringBuilder callURL = new StringBuilder().append(serviceInventoryUrl.getServiceInventoryUrl()).append(id); Map param = new HashMap<>(); param.put("serviceSpecification.name", serviceName); param.put("relatedParty.id", globalSubscriberId); ResponseEntity response = callApiGet(callURL.toString(), new HttpHeaders(), param); - return response != null && response.getStatusCode().equals(HttpStatus.OK); + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + return false; + } + return response.getStatusCode().equals(HttpStatus.OK); } @@ -107,13 +128,13 @@ public class MultiClient { } - public boolean isTenantIdPresentInAAI() { + public boolean isTenantIdPresentInAAI(ServiceOrder serviceOrder) { StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_TENANTS_PATH); String callUrlFormated = callURL.toString().replace("$onap.lcpCloudRegionId", lcpCloudRegionId); callUrlFormated = callUrlFormated.replace("$onap.cloudOwner", cloudOwner); ResponseEntity response = callApiGet(callUrlFormated, buildRequestHeaderForAAI(), null); - if (response != null) { + if (response.getStatusCode().is2xxSuccessful()) { LinkedHashMap body = (LinkedHashMap) response.getBody(); List tenants = (List) body.get("tenant"); for (LinkedHashMap tenant : tenants) { @@ -121,19 +142,27 @@ public class MultiClient { return true; } } + } else { + serviceOrderService.addOrderMessage(serviceOrder, "501"); } return false; } - public boolean isCustomerPresentInAAI(String customerId) { + public boolean isCustomerPresentInAAI(String customerId, + ServiceOrder serviceOrder) { StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH) .append(customerId); ResponseEntity response = callApiGet(callURL.toString(), buildRequestHeaderForAAI(), null); - return(response != null && response.getStatusCode().equals(HttpStatus.OK)); + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + return false; + } + return response.getStatusCode().equals(HttpStatus.OK); } - public boolean putCustomer(SubscriberInfo subscriberInfo) { + public boolean putCustomer(SubscriberInfo subscriberInfo, + ServiceOrder serviceOrder) { Map param = new HashMap<>(); param.put("global-customer-id", subscriberInfo.getGlobalSubscriberId()); param.put("subscriber-name", subscriberInfo.getSubscriberName()); @@ -142,29 +171,42 @@ public class MultiClient { aaiHost + OnapComponentsUrlPaths.AAI_GET_CUSTOMER_PATH + subscriberInfo.getGlobalSubscriberId(); ResponseEntity response = putRequest(param, callURL, buildRequestHeaderForAAI()); - return response != null && response.getStatusCode().equals(HttpStatus.CREATED); + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + return false; + } + return response.getStatusCode().equals(HttpStatus.CREATED); } - public Map getServicesInAaiForCustomer(String customerId) { + public Map getServicesInAaiForCustomer(String customerId, + ServiceOrder serviceOrder) { StringBuilder callURL = new StringBuilder().append(aaiHost).append(OnapComponentsUrlPaths.AAI_GET_SERVICES_FOR_CUSTOMER_PATH); String callUrlFormated = callURL.toString().replace("$customerId", customerId); ResponseEntity response = callApiGet(callUrlFormated, buildRequestHeaderForAAI(), null); - if (response != null && response.getStatusCode().equals(HttpStatus.OK)) { + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + return null; + } + else if (response.getStatusCode().is2xxSuccessful()) { return (LinkedHashMap) response.getBody(); } return null; } - public boolean putServiceType(String globalSubscriberId, String serviceName) { + public boolean putServiceType(String globalSubscriberId, String serviceName, + ServiceOrder serviceOrder) { Map param = new HashMap<>(); param.put("service-type", serviceName); String callURL = aaiHost + OnapComponentsUrlPaths.AAI_PUT_SERVICE_FOR_CUSTOMER_PATH + serviceName; String callUrlFormated = callURL.replace("$customerId", globalSubscriberId); ResponseEntity response = putRequest(param, callUrlFormated, buildRequestHeaderForAAI()); - return response != null && response.getStatusCode().equals(HttpStatus.CREATED); + if(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)) { + serviceOrderService.addOrderMessage(serviceOrder, "501"); + } + return response.getStatusCode().is2xxSuccessful(); } @@ -177,17 +219,17 @@ public class MultiClient { LOGGER.warn("HTTP call on {} returns {} , {}", callUrl , response.getStatusCodeValue(), response.getBody().toString()); } return response; - } catch (BackendFunctionalException|ResourceAccessException e) { + } catch (BackendFunctionalException e) { LOGGER.error("error on calling " + callUrl + " ," + e); - return null; + return new ResponseEntity<>("problem calling onap services", e.getHttpStatus()); + }catch (ResourceAccessException e) { + LOGGER.error("error on calling " + callUrl + " ," + e); + return new ResponseEntity<>("unable to reach onap services", HttpStatus.INTERNAL_SERVER_ERROR); } } private ResponseEntity callApiGet(String callURL, HttpHeaders httpHeaders, Map param) { - - try { - UriComponentsBuilder builder = UriComponentsBuilder.fromUriString(callURL); if (param != null) { for (Entry stringEntry : param.entrySet()) { @@ -196,8 +238,6 @@ public class MultiClient { } } URI uri = builder.build().encode().toUri(); - - ResponseEntity response = restTemplate.exchange(uri, HttpMethod.GET, new HttpEntity<>(httpHeaders), Object.class); if(LOGGER.isDebugEnabled()){ @@ -210,10 +250,14 @@ public class MultiClient { } return response; - } catch (BackendFunctionalException|ResourceAccessException e) { + } catch (BackendFunctionalException e) { LOGGER.error("error on calling " + callURL + " ," + e); - return null; + return new ResponseEntity<>("problem calling onap services", e.getHttpStatus()); + }catch (ResourceAccessException e) { + LOGGER.error("error on calling " + callURL + " ," + e); + return new ResponseEntity<>("unable to reach onap services", HttpStatus.INTERNAL_SERVER_ERROR); } + } 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 e2b10ab..5dda00a 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/SoClient.java @@ -1,17 +1,14 @@ /** - * Copyright (c) 2018 Orange + * Copyright (c) 2018 Orange * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the + * specific language governing permissions and limitations under the License. */ package org.onap.nbi.apis.serviceorder; @@ -67,19 +64,21 @@ public class SoClient { try { ResponseEntity response = restTemplate.exchange(url, HttpMethod.POST, - new HttpEntity<>(msoPayload, buildRequestHeader()), CreateServiceInstanceResponse.class); + new HttpEntity<>(msoPayload, buildRequestHeader()), CreateServiceInstanceResponse.class); logResponsePost(url, response); return response; - } catch (BackendFunctionalException|ResourceAccessException e) { - LOGGER.error(ERROR_ON_CALLING + url + " ," + e); - return null; + } catch (BackendFunctionalException e) { + LOGGER.error("error on calling " + url + " ," + e); + return new ResponseEntity<>(e.getHttpStatus()); + } catch (ResourceAccessException e) { + LOGGER.error("error on calling " + url + " ," + e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } - public ResponseEntity callDeleteServiceInstance(MSOPayload msoPayload, - String serviceId) { + public ResponseEntity callDeleteServiceInstance(MSOPayload msoPayload, String serviceId) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Calling SO DeleteServiceInstance with msoPayload : " + msoPayload.toString()); @@ -89,26 +88,30 @@ public class SoClient { try { ResponseEntity response = restTemplate.exchange(url, HttpMethod.DELETE, - new HttpEntity<>(msoPayload, buildRequestHeader()), CreateServiceInstanceResponse.class); + new HttpEntity<>(msoPayload, buildRequestHeader()), CreateServiceInstanceResponse.class); logResponsePost(url, response); return response; - } catch (BackendFunctionalException|ResourceAccessException e) { - LOGGER.error(ERROR_ON_CALLING + url + " ," + e); - return null; + } catch (BackendFunctionalException e) { + LOGGER.error("error on calling " + url + " ," + e); + return new ResponseEntity<>(e.getHttpStatus()); + } catch (ResourceAccessException e) { + LOGGER.error("error on calling " + url + " ," + e); + return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } private void logResponsePost(String url, ResponseEntity response) { LOGGER.info(RESPONSE_STATUS + response.getStatusCodeValue()); - if(LOGGER.isDebugEnabled()){ + if (LOGGER.isDebugEnabled()) { LOGGER.debug("response body : {}", response.getBody().toString()); } if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.CREATED)) { - LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString()); + LOGGER.warn("HTTP call SO on {} returns {} , {}", url, response.getStatusCodeValue(), + response.getBody().toString()); } } @@ -119,27 +122,28 @@ public class SoClient { try { ResponseEntity response = restTemplate.exchange(url, HttpMethod.GET, - new HttpEntity<>(buildRequestHeader()), GetRequestStatusResponse.class); + new HttpEntity<>(buildRequestHeader()), GetRequestStatusResponse.class); logResponseGet(url, response); return response.getBody(); - } catch (BackendFunctionalException|ResourceAccessException e) { + } catch (BackendFunctionalException | ResourceAccessException e) { LOGGER.error(ERROR_ON_CALLING + url + " ," + e); return null; } } private void logResponseGet(String url, ResponseEntity response) { - if(response!=null){ - if(LOGGER.isDebugEnabled()){ + if (response != null) { + if (LOGGER.isDebugEnabled()) { LOGGER.debug("response body : {}", response.getBody().toString()); } LOGGER.info("response status : {}", response.getStatusCodeValue()); if (LOGGER.isWarnEnabled() && !response.getStatusCode().equals(HttpStatus.OK)) { - LOGGER.warn("HTTP call SO on {} returns {} , {}",url ,response.getStatusCodeValue(), response.getBody().toString()); + LOGGER.warn("HTTP call SO on {} returns {} , {}", url, response.getStatusCodeValue(), + response.getBody().toString()); } } else { - LOGGER.info("no response calling url {}",url); + LOGGER.info("no response calling url {}", url); } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/OrderMessage.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/OrderMessage.java new file mode 100755 index 0000000..0e9204b --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/OrderMessage.java @@ -0,0 +1,227 @@ +/** + * Copyright (c) 2018 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * API ServiceOrder serviceOrder API designed for ONAP Beijing Release. This API is build from TMF + * open API16.5 + applied TMF guideline 3.0 + * + * OpenAPI spec version: 0.1.1_inProgress + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ + + +package org.onap.nbi.apis.serviceorder.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import java.util.Objects; +import javax.validation.constraints.NotNull; + +/** + * An optional array of messages associated with the Order + */ +@ApiModel(description = "An optional array of messages associated with the Order") +@javax.annotation.Generated(value = "io.swagger.codegen.languages.JavaJerseyServerCodegen", + date = "2018-07-12T11:46:30.345Z") +public class OrderMessage { + + + @JsonProperty("code") + private String code = null; + + @JsonProperty("field") + private String field = null; + + @JsonProperty("messageInformation") + private String messageInformation = null; + + @JsonProperty("severity") + private SeverityMessage severity = null; + + @JsonProperty("correctionRequired") + private boolean correctionRequired; + + + + + /** + * A code associated to this message + * + * @return code + **/ + @JsonProperty("code") + @ApiModelProperty(value = "A code associated to this message") + public String getCode() { + return code; + } + + public void setCode(String code) { + this.code = code; + } + + public OrderMessage code(String code) { + this.code = code; + return this; + } + + + /** + * Service Order attribute related to this error message + * + * @return field + **/ + @JsonProperty("field") + @ApiModelProperty(value = "Service Order attribute related to this error message") + public String getField() { + return field; + } + + public void setField(String field) { + this.field = field; + } + + public OrderMessage field(String field) { + this.field = field; + return this; + } + + + /** + * Message related to this order + * + * @return messageInformation + **/ + @JsonProperty("messageInformation") + @ApiModelProperty(value = "Message related to this order") + public String getMessageInformation() { + return messageInformation; + } + + public void setMessageInformation(String messageInformation) { + this.messageInformation = messageInformation; + } + + public OrderMessage messageInformation(String messageInformation) { + this.messageInformation = messageInformation; + return this; + } + + + /** + * Gravity of this message + * + * @return severity + **/ + @JsonProperty("severity") + @ApiModelProperty(required = true,value = "Gravity of this message") + @NotNull + public SeverityMessage getSeverity() { + return severity; + } + + public void setSeverity(SeverityMessage severity) { + this.severity = severity; + } + + public OrderMessage severity(SeverityMessage severity) { + this.severity = severity; + return this; + } + + + /** + * Indicator that an action is required to allow service order fullfilment to follow up + * + * @return correctionRequired + **/ + @JsonProperty("correctionRequired") + @ApiModelProperty(required = true,value = "Indicator that an action is required to allow service order fullfilment to follow up") + @NotNull + public boolean getCorrectionRequired() { + return correctionRequired; + } + + public void setCorrectionRequired(boolean correctionRequired) { + this.correctionRequired = correctionRequired; + } + + public OrderMessage severity(boolean correctionRequired) { + this.correctionRequired = correctionRequired; + return this; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + OrderMessage orderMessage = (OrderMessage) o; + return Objects.equals(this.code, orderMessage.code) + && Objects.equals(this.field, orderMessage.field) + && Objects.equals(this.messageInformation, orderMessage.messageInformation) + && Objects.equals(this.severity, orderMessage.severity) + && Objects.equals(this.correctionRequired, orderMessage.correctionRequired); + } + + + @Override + public int hashCode() { + return Objects.hash(code, field, messageInformation,severity); + } + + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class OrderMessage {\n"); + sb.append(" code: ").append(toIndentedString(code)).append("\n"); + sb.append(" field: ").append(toIndentedString(field)).append("\n"); + sb.append(" messageInformation: ").append(toIndentedString(messageInformation)).append("\n"); + sb.append(" severity: ").append(toIndentedString(severity)).append("\n"); + sb.append(" correctionRequired: ").append(toIndentedString(correctionRequired)).append("\n"); + sb.append("}"); + return sb.toString(); + } + + /** + * Convert the given object to string with each line indented by 4 spaces (except the first + * line). + */ + private String toIndentedString(Object o) { + if (o == null) { + return "null"; + } + return o.toString().replace("\n", "\n "); + } +} + diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrder.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrder.java index e8d1e97..bd86f35 100755 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrder.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrder.java @@ -121,6 +121,9 @@ public class ServiceOrder implements Resource { @JsonProperty("orderItem") private List orderItem = null; + @JsonProperty("orderMessage") + private List orderMessage = null; + public ServiceOrder id(String id) { this.id = id; return this; @@ -526,6 +529,46 @@ public class ServiceOrder implements Resource { } + public ServiceOrder orderMessage(List orderMessage) { + this.orderMessage = orderMessage; + return this; + } + + public ServiceOrder addOrderMessageItem(OrderMessage orderMessageItem) { + if (this.orderMessage == null) { + this.orderMessage = new ArrayList(); + } + boolean mesageAlreadyExist=false; + for (OrderMessage message : this.orderMessage) { + if(message.getCode().equals(orderMessageItem.getCode())){ + mesageAlreadyExist=true; + + } + } + if(!mesageAlreadyExist) { + this.orderMessage.add(orderMessageItem); + } + return this; + } + + /** + * + * @return orderMessage + **/ + @JsonProperty("orderMessage") + @ApiModelProperty(value = "") + public List getOrderMessage() { + return orderMessage; + } + + public void setOrderMessage(List orderMessage) { + this.orderMessage = orderMessage; + } + + + + + @Override public boolean equals(java.lang.Object o) { if (this == o) { @@ -551,14 +594,16 @@ public class ServiceOrder implements Resource { && Objects.equals(this.schemaLocation, serviceOrder.schemaLocation) && Objects.equals(this.relatedParty, serviceOrder.relatedParty) && Objects.equals(this.orderRelationship, serviceOrder.orderRelationship) - && Objects.equals(this.orderItem, serviceOrder.orderItem); + && Objects.equals(this.orderItem, serviceOrder.orderItem) + && Objects.equals(this.orderMessage, serviceOrder.orderMessage); } + @Override public int hashCode() { return Objects.hash(id, href, externalId, priority, description, category, state, orderDate, completionDateTime, expectedCompletionDate, requestedStartDate, requestedCompletionDate, startDate, baseType, type, - schemaLocation, relatedParty, orderRelationship, orderItem); + schemaLocation, relatedParty, orderRelationship, orderItem, orderMessage); } @@ -586,6 +631,7 @@ public class ServiceOrder implements Resource { sb.append(" relatedParty: ").append(toIndentedString(relatedParty)).append("\n"); sb.append(" orderRelationship: ").append(toIndentedString(orderRelationship)).append("\n"); sb.append(" orderItem: ").append(toIndentedString(orderItem)).append("\n"); + sb.append(" orderMessage: ").append(toIndentedString(orderMessage)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrderItem.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrderItem.java index e03713e..812e42b 100755 --- a/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrderItem.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/ServiceOrderItem.java @@ -80,6 +80,11 @@ public class ServiceOrderItem { @JsonProperty("service") private Service service = null; + + @JsonProperty("orderMessage") + private List orderItemMessage = new ArrayList<>(); + + public ServiceOrderItem id(String id) { this.id = id; return this; @@ -257,6 +262,46 @@ public class ServiceOrderItem { this.requestId = requestId; } + + public ServiceOrderItem orderItemMessage(List orderItemMessage) { + this.orderItemMessage = orderItemMessage; + return this; + } + + public ServiceOrderItem addOrderItemMessageItem(OrderMessage orderItemMessageItem) { + if (this.orderItemMessage == null) { + this.orderItemMessage = new ArrayList(); + } + boolean mesageAlreadyExist=false; + for (OrderMessage message : this.orderItemMessage) { + if(message.getCode().equals(orderItemMessageItem.getCode())){ + mesageAlreadyExist=true; + + } + } + if(!mesageAlreadyExist) { + this.orderItemMessage.add(orderItemMessageItem); + } + return this; + } + + /** + * + * @return orderItemMessage + **/ + @JsonProperty("orderItemMessage") + @ApiModelProperty(value = "") + public List getOrderItemMessage() { + return orderItemMessage; + } + + public void setOrderMessage(List orderItemMessage) { + this.orderItemMessage = orderItemMessage; + } + + + + @Override public boolean equals(java.lang.Object o) { if (this == o) { @@ -273,13 +318,15 @@ public class ServiceOrderItem { && Objects.equals(this.baseType, serviceOrderItem.baseType) && Objects.equals(this.orderItemRelationship, serviceOrderItem.orderItemRelationship) && Objects.equals(this.service, serviceOrderItem.service) - && Objects.equals(this.requestId, serviceOrderItem.requestId); + && Objects.equals(this.requestId, serviceOrderItem.requestId) + && Objects.equals(this.orderItemMessage, serviceOrderItem.orderItemMessage); + } @Override public int hashCode() { return Objects.hash(id, action, state, type, schemaLocation, baseType, orderItemRelationship, service, - requestId); + requestId,orderItemMessage); } @@ -287,7 +334,6 @@ public class ServiceOrderItem { public String toString() { StringBuilder sb = new StringBuilder(); sb.append("class ServiceOrderItem {\n"); - sb.append(" id: ").append(toIndentedString(id)).append("\n"); sb.append(" action: ").append(toIndentedString(action)).append("\n"); sb.append(" state: ").append(toIndentedString(state)).append("\n"); @@ -297,6 +343,7 @@ public class ServiceOrderItem { sb.append(" orderItemRelationship: ").append(toIndentedString(orderItemRelationship)).append("\n"); sb.append(" requestId: ").append(toIndentedString(requestId)).append("\n"); sb.append(" service: ").append(toIndentedString(service)).append("\n"); + sb.append(" service: ").append(toIndentedString(orderItemMessage)).append("\n"); sb.append("}"); return sb.toString(); } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/model/SeverityMessage.java b/src/main/java/org/onap/nbi/apis/serviceorder/model/SeverityMessage.java new file mode 100755 index 0000000..be6836f --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/model/SeverityMessage.java @@ -0,0 +1,78 @@ +/** + * Copyright (c) 2018 Orange + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +/* + * API ServiceOrder serviceOrder API designed for ONAP Beijing Release. This API is build from TMF + * open API16.5 + applied TMF guideline 3.0 + * + * OpenAPI spec version: 0.1.1_inProgress + * + * + * NOTE: This class is auto generated by the swagger code generator program. + * https://github.com/swagger-api/swagger-codegen.git Do not edit the class manually. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software distributed under the License + * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express + * or implied. See the License for the specific language governing permissions and limitations under + * the License. + */ +package org.onap.nbi.apis.serviceorder.model; + + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +/** + * + */ +public enum SeverityMessage { + + INFORMATION("information"), + + ERROR("error"); + + private String value; + + SeverityMessage(String value) { + this.value = value; + } + + @Override + public String toString() { + return String.valueOf(value); + } + + @JsonCreator + public static SeverityMessage fromValue(String text) { + for (SeverityMessage b : SeverityMessage.values()) { + if (String.valueOf(b.value).equals(text)) { + return b; + } + } + return null; + } + + @JsonValue + public String value() { + return this.value; + } + +} + diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java index bc8b854..f20c89d 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java @@ -15,8 +15,10 @@ */ package org.onap.nbi.apis.serviceorder.service; +import org.onap.nbi.apis.serviceorder.model.OrderMessage; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; +import org.onap.nbi.apis.serviceorder.model.SeverityMessage; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; import org.springframework.beans.factory.annotation.Autowired; @@ -72,4 +74,75 @@ public class ServiceOrderService { } + + public void addOrderMessage(ServiceOrder serviceOrder, String code) { + OrderMessage orderMessage = new OrderMessage(); + orderMessage.setCode(code); + orderMessage.setSeverity(SeverityMessage.ERROR); + orderMessage.setCorrectionRequired(true); + + if ("104".equalsIgnoreCase(code)) { + orderMessage.setField("relatedParty.id"); + orderMessage.setMessageInformation("Referred customer did not exist in ONAP"); + serviceOrder.addOrderMessageItem(orderMessage); + } + if ("500".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("Problem with SDC API"); + serviceOrder.addOrderMessageItem(orderMessage); + } + if ("501".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("Problem with AAI API"); + serviceOrder.addOrderMessageItem(orderMessage); + } + if ("502".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("Problem with SO API"); + serviceOrder.addOrderMessageItem(orderMessage); + } + if ("503".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("tenantId not found in AAI"); + serviceOrder.addOrderMessageItem(orderMessage); + } + serviceOrderRepository.save(serviceOrder); + } + + public void addOrderItemMessage(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, String code) { + OrderMessage orderMessage = new OrderMessage(); + orderMessage.setCode(code); + orderMessage.setSeverity(SeverityMessage.ERROR); + orderMessage.setCorrectionRequired(true); + + if ("101".equalsIgnoreCase(code)) { + orderMessage.setField("service.id"); + orderMessage.setMessageInformation("Missing Information - orderItem.service.id must be provided"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + if ("102".equalsIgnoreCase(code)) { + orderMessage.setField("serviceSpecification.id"); + orderMessage + .setMessageInformation("Incorrect serviceSpecification.id provided – not found in Catalog (SDC"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + if ("103".equalsIgnoreCase(code)) { + orderMessage.setField("service.id"); + orderMessage.setMessageInformation( + "Inconsistence information provided. service.id must not be provided for add action"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + if ("105".equalsIgnoreCase(code)) { + orderMessage.setField("service.name"); + orderMessage.setMessageInformation("ServiceName already exist in AAI"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + if ("106".equalsIgnoreCase(code)) { + orderMessage.setField("service.id"); + orderMessage.setMessageInformation("Incorrect service.id provided – not found in Inventory (AAI)"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + if ("107".equalsIgnoreCase(code)) { + orderMessage.setMessageInformation("tenantId not found in AAI"); + serviceOrderItem.addOrderItemMessageItem(orderMessage); + } + serviceOrderRepository.save(serviceOrder); + } + } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java index 7ee3a0e..e868bc6 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CheckOrderConsistenceManager.java @@ -8,7 +8,7 @@ */ package org.onap.nbi.apis.serviceorder.workflow; -import java.util.LinkedHashMap; +import java.util.Map; import org.onap.nbi.apis.serviceorder.MultiClient; import org.onap.nbi.apis.serviceorder.model.RelatedParty; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; @@ -21,8 +21,6 @@ import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.StringUtils; @@ -36,6 +34,7 @@ public class CheckOrderConsistenceManager { @Autowired private ServiceOrderService serviceOrderService; + private static final Logger LOGGER = LoggerFactory.getLogger(CheckOrderConsistenceManager.class); public ServiceOrderInfo checkServiceOrder(ServiceOrder serviceOrder) { @@ -46,26 +45,29 @@ public class CheckOrderConsistenceManager { for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) { ServiceOrderItemInfo serviceOrderItemInfo = new ServiceOrderItemInfo(); - handleServiceFromCatalog(serviceOrderItem, serviceOrderItemInfo); + handleServiceFromCatalog(serviceOrderItem,serviceOrder, serviceOrderItemInfo); if (!existServiceInCatalog(serviceOrderItemInfo)) { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.REJECTED); + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.REJECTED); LOGGER.warn( "service order item {} of service order {} rejected cause no service catalog found for id {}", serviceOrderItem.getId(), serviceOrder.getId(), serviceOrderItem.getService().getServiceSpecification().getId()); + serviceOrderService.addOrderItemMessage(serviceOrder,serviceOrderItem, "102"); } else { switch (serviceOrderItem.getAction()) { case ADD: - handleServiceOrderItemInAdd(serviceOrderInfo,serviceOrder, serviceOrderItem, serviceOrderItemInfo); + handleServiceOrderItemInAdd(serviceOrderInfo, serviceOrder, serviceOrderItem, + serviceOrderItemInfo); break; case MODIFY: case DELETE: - handleServiceOrderItemInChange(serviceOrderInfo,serviceOrder, serviceOrderItem, serviceOrderItemInfo); + handleServiceOrderItemInChange(serviceOrderInfo, serviceOrder, serviceOrderItem, + serviceOrderItemInfo); break; case NOCHANGE: serviceOrderInfo.setAllItemsInAdd(false); - serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.COMPLETED); + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.COMPLETED); nbItemsCompleted++; break; } @@ -87,61 +89,67 @@ public class CheckOrderConsistenceManager { ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, ServiceOrderItemInfo serviceOrderItemInfo) { serviceOrderInfo.setAllItemsInAdd(false); - if (shouldAcceptServiceOrderItemToChange(serviceOrderInfo, serviceOrderItem, + if (shouldAcceptServiceOrderItemToChange(serviceOrderInfo, serviceOrder, serviceOrderItem, serviceOrderItemInfo)) { serviceOrderInfo.addServiceOrderItemInfos(serviceOrderItem.getId(), serviceOrderItemInfo); } else { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.REJECTED); + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.REJECTED); } } private void handleServiceOrderItemInAdd(ServiceOrderInfo serviceOrderInfo, ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, ServiceOrderItemInfo serviceOrderItemInfo) { - if (shouldAcceptServiceOrderItemToAdd(serviceOrderItem, serviceOrderInfo.getServiceOrderId())) { + if (shouldAcceptServiceOrderItemToAdd(serviceOrderItem, serviceOrder, serviceOrderInfo.getServiceOrderId())) { serviceOrderInfo.addServiceOrderItemInfos(serviceOrderItem.getId(), serviceOrderItemInfo); } else { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.REJECTED); + serviceOrderService.updateOrderItemState(serviceOrder, serviceOrderItem, StateType.REJECTED); } } private boolean shouldAcceptServiceOrderItemToAdd(ServiceOrderItem serviceOrderItem, - String serviceOrderId) { + ServiceOrder serviceOrder, String serviceOrderId) { if (!StringUtils.isEmpty(serviceOrderItem.getService().getId())) { LOGGER .warn("serviceOrderItem {} for serviceorder {} rejected cause service.id must be empty in add action", serviceOrderItem.getId(), serviceOrderId); + serviceOrderService.addOrderItemMessage(serviceOrder,serviceOrderItem, "103"); return false; - } else if (!serviceOrderConsumerService.isTenantIdPresentInAAI()) { + } else if (!serviceOrderConsumerService.isTenantIdPresentInAAI(serviceOrder)) { LOGGER.warn("serviceOrderItem {} for serviceOrder {} rejected cause tenantId not found in AAI", serviceOrderItem.getId(), serviceOrderId); + serviceOrderService.addOrderItemMessage(serviceOrder,serviceOrderItem, "107"); + return false; } return true; } private boolean shouldAcceptServiceOrderItemToChange(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem, + ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, ServiceOrderItemInfo serviceOrderItemInfo) { if (StringUtils.isEmpty(serviceOrderItem.getService().getId())) { LOGGER.warn( "serviceOrderItem {} for serviceOrder {} rejected cause service.id is mandatory in delete/change action", serviceOrderItem.getId(), serviceOrderInfo.getServiceOrderId()); + serviceOrderService.addOrderItemMessage(serviceOrder,serviceOrderItem, "101"); return false; - } else if (!isCustomerFromServiceOrderPresentInInventory(serviceOrderInfo)) { + } else if (!isCustomerFromServiceOrderPresentInInventory(serviceOrderInfo,serviceOrder)) { LOGGER .warn("serviceOrderItem {} for serviceOrder {} rejected cause customer not found in inventory", serviceOrderItem.getId(), serviceOrderInfo.getServiceOrderId()); + serviceOrderService.addOrderMessage(serviceOrder, "104"); return false; - } else if (!existServiceInInventory(serviceOrderItem, serviceOrderItemInfo, + } else if (!existServiceInInventory(serviceOrderItem, serviceOrder, serviceOrderItemInfo, serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId())) { LOGGER .warn("serviceOrderItem {} for serviceOrder {} rejected cause service id {} not found in inventory", serviceOrderItem.getId(), serviceOrderInfo.getServiceOrderId(), serviceOrderItem.getService().getId()); + serviceOrderService.addOrderItemMessage(serviceOrder,serviceOrderItem, "106"); return false; } return true; @@ -175,20 +183,22 @@ public class CheckOrderConsistenceManager { return null; } - private boolean isCustomerFromServiceOrderPresentInInventory(ServiceOrderInfo serviceOrderInfo) { + private boolean isCustomerFromServiceOrderPresentInInventory(ServiceOrderInfo serviceOrderInfo, + ServiceOrder serviceOrder) { if (serviceOrderInfo.isUseServiceOrderCustomer()) { return serviceOrderConsumerService - .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId()); + .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(),serviceOrder); } return true; } private boolean existServiceInInventory(ServiceOrderItem serviceOrderItem, - ServiceOrderItemInfo serviceOrderItemInfo, String globalSubscriberId) { + ServiceOrder serviceOrder, ServiceOrderItemInfo serviceOrderItemInfo, + String globalSubscriberId) { String serviceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name"); return serviceOrderConsumerService.doesServiceExistInServiceInventory( - serviceOrderItem.getService().getId(), serviceName, globalSubscriberId); + serviceOrderItem.getService().getId(), serviceName, globalSubscriberId,serviceOrder); } private boolean existServiceInCatalog(ServiceOrderItemInfo serviceOrderItemInfo) { @@ -196,18 +206,11 @@ public class CheckOrderConsistenceManager { } private void handleServiceFromCatalog(ServiceOrderItem serviceOrderItem, - ServiceOrderItemInfo serviceOrderItemInfo) { - ResponseEntity response = serviceOrderConsumerService - .getServiceCatalog(serviceOrderItem.getService().getServiceSpecification().getId()); - if (response != null && (response.getStatusCode().equals(HttpStatus.OK) - || response.getStatusCode().equals(HttpStatus.PARTIAL_CONTENT))) { - LinkedHashMap body = (LinkedHashMap) response.getBody(); - serviceOrderItemInfo.setCatalogResponse(body); - } else { - LOGGER.warn("unable to retrieve catalog information for service {}", - serviceOrderItem.getService().getServiceSpecification().getId()); - } - } + ServiceOrder serviceOrder, ServiceOrderItemInfo serviceOrderItemInfo) { + Map body = serviceOrderConsumerService + .getServiceCatalog(serviceOrderItem.getService().getServiceSpecification().getId(),serviceOrder,serviceOrderItem); + serviceOrderItemInfo.setCatalogResponse(body); + } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java index aacf48c..d3710a9 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAICustomerManager.java @@ -41,12 +41,13 @@ public class CreateAAICustomerManager { if (serviceOrderInfo.isUseServiceOrderCustomer() && serviceOrderInfo.isAllItemsInAdd() && !serviceOrderConsumerService - .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId())) { + .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), serviceOrder)) { - boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo()); + boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo(), serviceOrder); if (!customerCreated) { serviceOrderService.updateOrderState(serviceOrder,StateType.REJECTED); LOGGER.warn("serviceOrder {} rejected : cannot create customer", serviceOrder.getId()); + serviceOrderService.addOrderMessage(serviceOrder, "501"); } } } diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java index 0da0355..baf7e7f 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/workflow/CreateAAIServiceTypeManager.java @@ -38,12 +38,13 @@ public class CreateAAIServiceTypeManager { @Autowired ServiceOrderService serviceOrderService; + private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAIServiceTypeManager.class); public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) { Map servicesInAaiForCustomer = serviceOrderConsumerService - .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId()); + .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), serviceOrder); for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) { if (ActionType.ADD == serviceOrderItem.getAction()) { @@ -52,12 +53,14 @@ public class CreateAAIServiceTypeManager { String sdcServiceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name"); if (!serviceNameExistsInAAI(servicesInAaiForCustomer, sdcServiceName)) { boolean serviceCreated = serviceOrderConsumerService.putServiceType( - serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName); + serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName, serviceOrder); if (!serviceCreated) { serviceOrderService.updateOrderState(serviceOrder,StateType.REJECTED); LOGGER.warn("serviceOrder {} rejected : cannot create service type {} for customer {}", serviceOrder.getId(), sdcServiceName, serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId()); + serviceOrderService.addOrderMessage(serviceOrder, "501"); + } } } 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 1957e5b..a11863c 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 @@ -28,6 +28,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; @@ -83,7 +84,7 @@ public class SOTaskProcessor { if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { - ResponseEntity response = postServiceOrderItem(serviceOrderInfo, + ResponseEntity response = postServiceOrderItem(serviceOrderInfo,serviceOrder, serviceOrderItem); updateServiceOrderItem(response, serviceOrderItem,serviceOrder); } @@ -108,10 +109,10 @@ public class SOTaskProcessor { } private ResponseEntity postServiceOrderItem(ServiceOrderInfo serviceOrderInfo, - ServiceOrderItem serviceOrderItem) { + ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem) { ResponseEntity response = null; try { - response = postSORequest(serviceOrderItem, serviceOrderInfo); + response = postSORequest(serviceOrderItem,serviceOrder, serviceOrderInfo); } catch (NullPointerException e) { LOGGER.error("Unable to create service instance for serviceOrderItem.id=" + serviceOrderItem.getId(), e); response = null; @@ -145,7 +146,7 @@ public class SOTaskProcessor { } private ResponseEntity postSORequest(ServiceOrderItem serviceOrderItem, - ServiceOrderInfo serviceOrderInfo) { + ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) { RequestDetails requestDetails = buildSoRequest(serviceOrderItem, serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId()).getCatalogResponse(), serviceOrderInfo.getSubscriberInfo()); @@ -157,11 +158,14 @@ public class SOTaskProcessor { response = soClient.callCreateServiceInstance(msoPayload); break; case DELETE: - response = soClient.callDeleteServiceInstance(msoPayload, serviceOrderItem.getService().getId()); + response = soClient.callDeleteServiceInstance(msoPayload,serviceOrderItem.getService().getId()); break; default: break; } + if(response!=null && response.getStatusCode()== HttpStatus.INTERNAL_SERVER_ERROR) { + serviceOrderService.addOrderMessage(serviceOrder, "502"); + } return response; } @@ -326,8 +330,8 @@ public class SOTaskProcessor { private void updateServiceOrderItem(ResponseEntity response, ServiceOrderItem orderItem, ServiceOrder serviceOrder) { - if (response == null) { - LOGGER.warn("response=null for serviceOrderItem.id=" + orderItem.getId()); + if (response==null || !response.getStatusCode().is2xxSuccessful()) { + LOGGER.warn("response ko for serviceOrderItem.id=" + orderItem.getId()); serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.FAILED); } else { -- cgit 1.2.3-korg