d3710a9b22c22fa262a72191c3ae08e98f8e33eb
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceorder / workflow / CreateAAICustomerManager.java
1 /**
2  * Copyright (c) 2018 Orange
3  *
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
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
12  */
13 package org.onap.nbi.apis.serviceorder.workflow;
14
15 import org.onap.nbi.apis.serviceorder.MultiClient;
16 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
17 import org.onap.nbi.apis.serviceorder.model.StateType;
18 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
19 import org.onap.nbi.apis.serviceorder.service.ServiceOrderService;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.stereotype.Service;
24
25 @Service
26 public class CreateAAICustomerManager {
27
28
29     @Autowired
30     private MultiClient serviceOrderConsumerService;
31
32     @Autowired
33     ServiceOrderService serviceOrderService;
34
35     private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAICustomerManager.class);
36
37
38
39     public void createAAICustomer(ServiceOrder serviceOrder,
40         ServiceOrderInfo serviceOrderInfo) {
41
42         if (serviceOrderInfo.isUseServiceOrderCustomer() && serviceOrderInfo.isAllItemsInAdd()
43             && !serviceOrderConsumerService
44             .isCustomerPresentInAAI(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), serviceOrder)) {
45
46             boolean customerCreated = serviceOrderConsumerService.putCustomer(serviceOrderInfo.getSubscriberInfo(), serviceOrder);
47             if (!customerCreated) {
48                 serviceOrderService.updateOrderState(serviceOrder,StateType.REJECTED);
49                 LOGGER.warn("serviceOrder {} rejected : cannot create customer", serviceOrder.getId());
50                 serviceOrderService.addOrderMessage(serviceOrder, "501");
51             }
52         }
53     }
54
55
56 }
57
58