27cb6c8b3b8fdb858b90d001c4d10ffdc5fe0912
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceorder / workflow / CreateAAIOwningEntityManager.java
1 /**
2  * Copyright (c) 2019 Orange
3  * <p>
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  * <p>
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * <p>
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.beans.factory.annotation.Value;
24 import org.springframework.stereotype.Service;
25
26 @Service
27 public class CreateAAIOwningEntityManager {
28
29
30     @Autowired
31     private MultiClient serviceOrderConsumerService;
32
33     @Autowired
34     ServiceOrderService serviceOrderService;
35
36     @Value("${so.owning.entity.id}")
37     private String owningEntityId;
38
39
40     private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAIOwningEntityManager.class);
41
42
43     public void createAAIOwningEntity(ServiceOrder serviceOrder,
44         ServiceOrderInfo serviceOrderInfo) {
45
46         String owningEntityIdToSo=serviceOrderConsumerService.getOwningEntityIdInAAI(serviceOrder);
47         if (owningEntityIdToSo==null) {
48             owningEntityIdToSo=owningEntityId;
49             boolean owningEntity = serviceOrderConsumerService.putOwningEntity(serviceOrder);
50             if (!owningEntity) {
51                 serviceOrderService.updateOrderState(serviceOrder, StateType.REJECTED);
52                 LOGGER.warn("serviceOrder {} rejected : cannot create owning entity ", serviceOrder.getId());
53                 serviceOrderService.addOrderMessage(serviceOrder, "501");
54             }
55         }
56         serviceOrderInfo.setOwningEntityId(owningEntityIdToSo);
57     }
58
59
60 }
61
62