diff options
author | romaingimbert <romain.gimbert@orange.com> | 2018-06-22 10:10:20 +0200 |
---|---|---|
committer | romaingimbert <romain.gimbert@orange.com> | 2018-06-22 10:10:20 +0200 |
commit | ac8e5b3b6667eec54f357cda4489044ea04acec7 (patch) | |
tree | 8d9348cdffb515b18ecc0fcee797614a49161900 | |
parent | a42cd685193bd9156a25fe0708ba8c4a30664137 (diff) |
add serviceorder service
- change code to have in the service all the update state
Change-Id: I01a409224984ae831da0f07edcda5bb34dc537dc
Issue-ID: EXTAPI-106
Signed-off-by: romaingimbert <romain.gimbert@orange.com>
6 files changed, 153 insertions, 78 deletions
diff --git a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java index 04a8329..12ee889 100644 --- a/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java +++ b/src/main/java/org/onap/nbi/apis/serviceorder/ServiceOrderResource.java @@ -15,14 +15,12 @@ */ package org.onap.nbi.apis.serviceorder; -import java.util.Date; import java.util.List; import javax.validation.Valid; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; -import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; -import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.onap.nbi.apis.serviceorder.workflow.CheckOrderConsistenceManager; import org.onap.nbi.apis.serviceorder.workflow.CreateAAICustomerManager; import org.onap.nbi.apis.serviceorder.workflow.CreateAAIServiceTypeManager; @@ -54,8 +52,10 @@ import org.springframework.web.bind.annotation.RestController; @EnableScheduling public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { + + @Autowired - ServiceOrderRepository serviceOrderRepository; + ServiceOrderService serviceOrderService; @Autowired CheckOrderConsistenceManager checkOrderConsistenceManager; @@ -80,7 +80,7 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { public ResponseEntity<Object> getServiceOrder(@PathVariable String serviceOrderId, @RequestParam MultiValueMap<String, String> params) { - ServiceOrder serviceOrder = serviceOrderRepository.findOne(serviceOrderId); + ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderId); if (serviceOrder == null) { return ResponseEntity.notFound().build(); } @@ -95,7 +95,7 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { Query query = multiCriteriaRequestBuilder.buildRequest(params); List<ServiceOrder> serviceOrders = mongoTemplate.find(query, ServiceOrder.class); JsonRepresentation filter = new JsonRepresentation(params); - long totalCount = serviceOrderRepository.count(); + long totalCount = serviceOrderService.countServiceOrder(); HttpHeaders headers = new HttpHeaders(); headers.add("X-Total-Count", String.valueOf(totalCount)); headers.add("X-Result-Count", String.valueOf(serviceOrders.size())); @@ -107,7 +107,7 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { @DeleteMapping(value = "/{serviceOrderId}") public ResponseEntity<Object> deleteServiceOrder(@PathVariable String serviceOrderId) { - serviceOrderRepository.delete(serviceOrderId); + serviceOrderService.deleteServiceOrder(serviceOrderId); return this.deleteResponse(); @@ -122,15 +122,8 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { throw new ValidationException(errors.getAllErrors()); } - serviceOrder.setState(StateType.ACKNOWLEDGED); - serviceOrder.setOrderDate(new Date()); - for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) { - serviceOrderItem.setState(StateType.ACKNOWLEDGED); - } - - ServiceOrder serviceOrderSaved = serviceOrderRepository.save(serviceOrder); - serviceOrderSaved.setHref("serviceOrder/" + serviceOrderSaved.getId()); - serviceOrderRepository.save(serviceOrderSaved); + ServiceOrder serviceOrderSaved =serviceOrderService.updateOrderAndItemStateToAcknowledged(serviceOrder); + serviceOrderService.updateOrderHref(serviceOrderSaved); JsonRepresentation filter = new JsonRepresentation(params); return this.createResponse(serviceOrderSaved, filter); @@ -138,15 +131,14 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { @Scheduled(fixedDelay = 5000) public void scheduleCheckServiceOrders() { - List<ServiceOrder> acknowledgedOrders = serviceOrderRepository.findByState(StateType.ACKNOWLEDGED); + List<ServiceOrder> acknowledgedOrders = serviceOrderService.findServiceOrdersByState(StateType.ACKNOWLEDGED); for (ServiceOrder serviceOrder : acknowledgedOrders) { ServiceOrderInfo serviceOrderInfo = checkOrderConsistenceManager.checkServiceOrder(serviceOrder); if (serviceOrderInfo.isServiceOrderRejected()) { - changeServiceOrderState(serviceOrder, StateType.REJECTED); + serviceOrderService.updateOrderFinalState(serviceOrder, StateType.REJECTED); } else if (serviceOrderInfo.isAllItemsCompleted()) { - changeServiceOrderState(serviceOrder, StateType.COMPLETED); + serviceOrderService.updateOrderFinalState(serviceOrder, StateType.COMPLETED); } else { - serviceOrderRepository.save(serviceOrder); createAAICustomer.createAAICustomer(serviceOrder,serviceOrderInfo); if(StateType.ACKNOWLEDGED==serviceOrder.getState()) { createAAIServiceType.createAAIServiceType(serviceOrder, serviceOrderInfo); @@ -159,15 +151,4 @@ public class ServiceOrderResource extends ResourceManagement<ServiceOrder> { } } - /** - * - * @param serviceOrder - * @param stateType - */ - private void changeServiceOrderState(ServiceOrder serviceOrder, StateType stateType) { - serviceOrder.setState(stateType); - serviceOrder.setCompletionDateTime(new Date()); - serviceOrderRepository.save(serviceOrder); - } - } 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 new file mode 100644 index 0000000..8f9cff1 --- /dev/null +++ b/src/main/java/org/onap/nbi/apis/serviceorder/service/ServiceOrderService.java @@ -0,0 +1,81 @@ +/** + * 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. + */ +package org.onap.nbi.apis.serviceorder.service; + +import java.util.Date; +import java.util.List; +import org.onap.nbi.apis.serviceorder.model.ServiceOrder; +import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; +import org.onap.nbi.apis.serviceorder.model.StateType; +import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +@Service +public class ServiceOrderService { + + @Autowired + ServiceOrderRepository serviceOrderRepository; + + public ServiceOrder findServiceOrderById(String serviceOrderId){ + return serviceOrderRepository.findOne(serviceOrderId); + } + + public List<ServiceOrder> findServiceOrdersByState(StateType state){ + return serviceOrderRepository.findByState(state); + } + + public void updateOrderState(ServiceOrder serviceOrder,StateType state){ + serviceOrder.setState(state); + serviceOrderRepository.save(serviceOrder); + } + + public void updateOrderFinalState(ServiceOrder serviceOrder,StateType state){ + serviceOrder.setState(state); + serviceOrder.setCompletionDateTime(new Date()); + serviceOrderRepository.save(serviceOrder); + } + + public void updateOrderItemState(ServiceOrder serviceOrder,ServiceOrderItem serviceOrderItem, StateType state){ + serviceOrderItem.setState(state); + serviceOrderRepository.save(serviceOrder); + } + + public ServiceOrder updateOrderAndItemStateToAcknowledged(ServiceOrder serviceOrder){ + serviceOrder.setState(StateType.ACKNOWLEDGED); + serviceOrder.setOrderDate(new Date()); + for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) { + serviceOrderItem.setState(StateType.ACKNOWLEDGED); + } + return serviceOrderRepository.save(serviceOrder); + } + + public void updateOrderHref(ServiceOrder serviceOrder){ + serviceOrder.setHref("serviceOrder/" + serviceOrder.getId()); + serviceOrderRepository.save(serviceOrder); + } + + + public void deleteServiceOrder(String serviceOrderId){ + serviceOrderRepository.delete(serviceOrderId); + } + + public long countServiceOrder(){ + return serviceOrderRepository.count(); + } + + +} 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 580a606..7ee3a0e 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 @@ -17,6 +17,7 @@ import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderItemInfo; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -32,6 +33,9 @@ public class CheckOrderConsistenceManager { @Autowired private MultiClient serviceOrderConsumerService; + @Autowired + private ServiceOrderService serviceOrderService; + private static final Logger LOGGER = LoggerFactory.getLogger(CheckOrderConsistenceManager.class); public ServiceOrderInfo checkServiceOrder(ServiceOrder serviceOrder) { @@ -45,7 +49,7 @@ public class CheckOrderConsistenceManager { handleServiceFromCatalog(serviceOrderItem, serviceOrderItemInfo); if (!existServiceInCatalog(serviceOrderItemInfo)) { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderItem.setState(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(), @@ -53,15 +57,15 @@ public class CheckOrderConsistenceManager { } else { switch (serviceOrderItem.getAction()) { case ADD: - handleServiceOrderItemInAdd(serviceOrderInfo, serviceOrderItem, serviceOrderItemInfo); + handleServiceOrderItemInAdd(serviceOrderInfo,serviceOrder, serviceOrderItem, serviceOrderItemInfo); break; case MODIFY: case DELETE: - handleServiceOrderItemInChange(serviceOrderInfo, serviceOrderItem, serviceOrderItemInfo); + handleServiceOrderItemInChange(serviceOrderInfo,serviceOrder, serviceOrderItem, serviceOrderItemInfo); break; case NOCHANGE: serviceOrderInfo.setAllItemsInAdd(false); - serviceOrderItem.setState(StateType.COMPLETED); + serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.COMPLETED); nbItemsCompleted++; break; } @@ -79,7 +83,8 @@ public class CheckOrderConsistenceManager { } - private void handleServiceOrderItemInChange(ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem, + private void handleServiceOrderItemInChange(ServiceOrderInfo serviceOrderInfo, + ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, ServiceOrderItemInfo serviceOrderItemInfo) { serviceOrderInfo.setAllItemsInAdd(false); if (shouldAcceptServiceOrderItemToChange(serviceOrderInfo, serviceOrderItem, @@ -87,17 +92,18 @@ public class CheckOrderConsistenceManager { serviceOrderInfo.addServiceOrderItemInfos(serviceOrderItem.getId(), serviceOrderItemInfo); } else { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderItem.setState(StateType.REJECTED); + serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.REJECTED); } } - private void handleServiceOrderItemInAdd(ServiceOrderInfo serviceOrderInfo, ServiceOrderItem serviceOrderItem, + private void handleServiceOrderItemInAdd(ServiceOrderInfo serviceOrderInfo, + ServiceOrder serviceOrder, ServiceOrderItem serviceOrderItem, ServiceOrderItemInfo serviceOrderItemInfo) { if (shouldAcceptServiceOrderItemToAdd(serviceOrderItem, serviceOrderInfo.getServiceOrderId())) { serviceOrderInfo.addServiceOrderItemInfos(serviceOrderItem.getId(), serviceOrderItemInfo); } else { serviceOrderInfo.setIsServiceOrderRejected(true); - serviceOrderItem.setState(StateType.REJECTED); + serviceOrderService.updateOrderItemState(serviceOrder,serviceOrderItem,StateType.REJECTED); } } 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 f3c77d6..69bbd83 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 @@ -12,12 +12,11 @@ */ package org.onap.nbi.apis.serviceorder.workflow; -import java.util.Date; import org.onap.nbi.apis.serviceorder.MultiClient; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; -import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -31,7 +30,7 @@ public class CreateAAICustomerManager { private MultiClient serviceOrderConsumerService; @Autowired - ServiceOrderRepository serviceOrderRepository; + ServiceOrderService serviceOrderService; private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAICustomerManager.class); @@ -46,9 +45,7 @@ public class CreateAAICustomerManager { boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo()); if (!customerCreated) { - serviceOrder.setState(StateType.REJECTED); - serviceOrder.setCompletionDateTime(new Date()); - serviceOrderRepository.save(serviceOrder); + serviceOrderService.updateOrderFinalState(serviceOrder,StateType.REJECTED); LOGGER.warn("serviceOrder {} rejected : cannot create customer", serviceOrder.getId()); } } 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 9ae0550..7f150fe 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 @@ -12,7 +12,8 @@ */ package org.onap.nbi.apis.serviceorder.workflow; -import java.util.Date; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import org.onap.nbi.apis.serviceorder.MultiClient; import org.onap.nbi.apis.serviceorder.model.ActionType; @@ -21,13 +22,11 @@ import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; import org.onap.nbi.apis.serviceorder.model.StateType; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderItemInfo; -import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; +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.stereotype.Service; -import java.util.LinkedHashMap; -import java.util.List; @Service public class CreateAAIServiceTypeManager { @@ -36,7 +35,7 @@ public class CreateAAIServiceTypeManager { private MultiClient serviceOrderConsumerService; @Autowired - ServiceOrderRepository serviceOrderRepository; + ServiceOrderService serviceOrderService; private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAIServiceTypeManager.class); @@ -54,9 +53,7 @@ public class CreateAAIServiceTypeManager { boolean serviceCreated = serviceOrderConsumerService.putServiceType( serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName); if (!serviceCreated) { - serviceOrder.setState(StateType.REJECTED); - serviceOrder.setCompletionDateTime(new Date()); - serviceOrderRepository.save(serviceOrder); + serviceOrderService.updateOrderFinalState(serviceOrder,StateType.REJECTED); LOGGER.warn("serviceOrder {} rejected : cannot create service type {} for customer {}", serviceOrder.getId(), sdcServiceName, serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId()); 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 24e137b..67c9b93 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 @@ -12,30 +12,42 @@ */ package org.onap.nbi.apis.serviceorder.workflow; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Date; +import java.util.List; +import java.util.Map; import org.onap.nbi.apis.serviceorder.SoClient; import org.onap.nbi.apis.serviceorder.model.ServiceCharacteristic; import org.onap.nbi.apis.serviceorder.model.ServiceOrder; import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem; import org.onap.nbi.apis.serviceorder.model.StateType; -import org.onap.nbi.apis.serviceorder.model.consumer.*; +import org.onap.nbi.apis.serviceorder.model.consumer.CloudConfiguration; +import org.onap.nbi.apis.serviceorder.model.consumer.CreateServiceInstanceResponse; +import org.onap.nbi.apis.serviceorder.model.consumer.GetRequestStatusResponse; +import org.onap.nbi.apis.serviceorder.model.consumer.MSOPayload; +import org.onap.nbi.apis.serviceorder.model.consumer.ModelInfo; +import org.onap.nbi.apis.serviceorder.model.consumer.RequestDetails; +import org.onap.nbi.apis.serviceorder.model.consumer.RequestInfo; +import org.onap.nbi.apis.serviceorder.model.consumer.RequestParameters; +import org.onap.nbi.apis.serviceorder.model.consumer.RequestState; +import org.onap.nbi.apis.serviceorder.model.consumer.SubscriberInfo; +import org.onap.nbi.apis.serviceorder.model.consumer.UserParams; import org.onap.nbi.apis.serviceorder.model.orchestrator.ExecutionTask; import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo; import org.onap.nbi.apis.serviceorder.repositories.ExecutionTaskRepository; -import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository; +import org.onap.nbi.apis.serviceorder.service.ServiceOrderService; import org.onap.nbi.apis.serviceorder.utils.JsonEntityConverter; import org.onap.nbi.exceptions.TechnicalException; 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; -import java.io.IOException; -import java.util.*; - @Service public class SOTaskProcessor { @@ -48,8 +60,9 @@ public class SOTaskProcessor { @Value("${onap.tenantId}") private String tenantId; + @Autowired - private ServiceOrderRepository serviceOrderRepository; + private ServiceOrderService serviceOrderService; @Autowired private ExecutionTaskRepository executionTaskRepository; @@ -69,7 +82,7 @@ public class SOTaskProcessor { ServiceOrderInfo serviceOrderInfo = getServiceOrderInfo(executionTask); - ServiceOrder serviceOrder = serviceOrderRepository.findOne(serviceOrderInfo.getServiceOrderId()); + ServiceOrder serviceOrder = serviceOrderService.findServiceOrderById(serviceOrderInfo.getServiceOrderId()); ServiceOrderItem serviceOrderItem = getServiceOrderItem(executionTask, serviceOrder); if (StateType.ACKNOWLEDGED == serviceOrderItem.getState()) { @@ -82,7 +95,7 @@ public class SOTaskProcessor { if (executionTask.getNbRetries() > 0 && StateType.FAILED != serviceOrderItem.getState() ) { // TODO lancer en asynchrone - pollSoRequestStatus(serviceOrderItem); + pollSoRequestStatus(serviceOrder,serviceOrderItem); if (serviceOrderItem.getState().equals(StateType.COMPLETED)) { updateSuccessTask(executionTask); } else { @@ -180,27 +193,28 @@ public class SOTaskProcessor { } if (atLeastOneNotFinished) { - serviceOrder.setState(StateType.INPROGRESS); + serviceOrderService.updateOrderState(serviceOrder,StateType.INPROGRESS); } else { - serviceOrder.setCompletionDateTime(new Date()); + StateType finalState; if (atLeastOneFailed) { if (!atLeastOneCompleted) { - serviceOrder.setState(StateType.FAILED); + finalState=StateType.FAILED; } else { - serviceOrder.setState(StateType.PARTIAL); + finalState=StateType.PARTIAL; } } else { - serviceOrder.setState(StateType.COMPLETED); + finalState=StateType.COMPLETED; } + serviceOrderService.updateOrderFinalState(serviceOrder,finalState); } - serviceOrderRepository.save(serviceOrder); } /** * * @param orderItem */ - private void pollSoRequestStatus(ServiceOrderItem orderItem) throws InterruptedException { + private void pollSoRequestStatus(ServiceOrder serviceOrder, + ServiceOrderItem orderItem) throws InterruptedException { boolean stopPolling = false; String requestId = orderItem.getRequestId(); GetRequestStatusResponse response = null; @@ -211,20 +225,20 @@ public class SOTaskProcessor { if (response != null) { if (response.getRequest().getRequestStatus().getPercentProgress() != 100) { nbRetries++; - orderItem.setState(StateType.INPROGRESS); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.INPROGRESS); Thread.sleep(1000); LOGGER.debug("orderitem id {} still in progress from so",orderItem.getId()); } else if (RequestState.COMPLETE != response.getRequest().getRequestStatus().getRequestState()) { - orderItem.setState(StateType.FAILED); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.FAILED); stopPolling = true; LOGGER.debug("orderitem id {} failed, response from request status {}",orderItem.getId(),response.getRequest().getRequestStatus().getRequestState()); } else { - orderItem.setState(StateType.COMPLETED); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.COMPLETED); stopPolling = true; LOGGER.debug("orderitem id {} completed"); } } else { - orderItem.setState(StateType.INPROGRESS); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.INPROGRESS); stopPolling = true; LOGGER.debug("orderitem id {} still in progress from so",orderItem.getId()); } @@ -307,7 +321,7 @@ public class SOTaskProcessor { if (response == null) { LOGGER.warn("response=null for serviceOrderItem.id=" + orderItem.getId()); - orderItem.setState(StateType.FAILED); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.FAILED); } else { CreateServiceInstanceResponse createServiceInstanceResponse = response.getBody(); @@ -318,13 +332,12 @@ public class SOTaskProcessor { if (!response.getStatusCode().is2xxSuccessful() || response.getBody() == null || response.getBody().getRequestReferences() == null) { - orderItem.setState(StateType.FAILED); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.FAILED); LOGGER.warn("order item {} failed , status {} , response {}",orderItem.getId(),response.getStatusCode(),response.getBody()); } else { - orderItem.setState(StateType.INPROGRESS); + serviceOrderService.updateOrderItemState(serviceOrder,orderItem,StateType.INPROGRESS); } } - serviceOrderRepository.save(serviceOrder); } /** @@ -351,7 +364,7 @@ public class SOTaskProcessor { for (ServiceOrderItem item : serviceOrder.getOrderItem()) { for (ExecutionTask taskToDelete : executionTasksToDelete) { if (taskToDelete.getOrderItemId().equals(item.getId())) { - item.setState(StateType.FAILED); + serviceOrderService.updateOrderItemState(serviceOrder,item,StateType.FAILED); LOGGER.warn("task {} with orderitem id {} to failed cause orderitem id {} failed ",taskToDelete.getInternalId(),taskToDelete.getOrderItemId(),executionTask.getOrderItemId()); } |