2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
13 package org.onap.nbi.apis.serviceorder.workflow;
15 import java.util.Date;
16 import org.onap.nbi.apis.serviceorder.MultiClient;
17 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
18 import org.onap.nbi.apis.serviceorder.model.StateType;
19 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
20 import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service;
27 public class CreateAAICustomerManager {
31 private MultiClient serviceOrderConsumerService;
34 ServiceOrderRepository serviceOrderRepository;
36 private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAICustomerManager.class);
38 public void createAAICustomer(ServiceOrder serviceOrder,
39 ServiceOrderInfo serviceOrderInfo) {
41 if (serviceOrderInfo.isUseServiceOrderCustomer() && serviceOrderInfo.isAllItemsInAdd()
42 && !serviceOrderConsumerService
43 .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId())) {
45 boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo());
46 if (!customerCreated) {
47 serviceOrder.setState(StateType.REJECTED);
48 serviceOrder.setCompletionDateTime(new Date());
49 serviceOrderRepository.save(serviceOrder);
50 LOGGER.error("serviceOrder {0} rejected : cannot create customer", serviceOrder.getId());