Remove 'All rights reserved.' on apache 2 license
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceorder / workflow / CreateAAIServiceTypeManager.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 package org.onap.nbi.apis.serviceorder.workflow;
17
18 import org.onap.nbi.apis.serviceorder.MultiClient;
19 import org.onap.nbi.apis.serviceorder.model.ActionType;
20 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
21 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
22 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
23 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderItemInfo;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service;
26 import java.util.LinkedHashMap;
27 import java.util.List;
28
29 @Service
30 public class CreateAAIServiceTypeManager {
31
32     @Autowired
33     private MultiClient serviceOrderConsumerService;
34
35
36     public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) {
37
38         LinkedHashMap servicesInAaiForCustomer = serviceOrderConsumerService
39                 .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
40
41         for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) {
42             if (ActionType.ADD == serviceOrderItem.getAction()) {
43                 ServiceOrderItemInfo serviceOrderItemInfo =
44                         serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId());
45                 String sdcServiceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name");
46                 if (!serviceNameExistsInAAI(servicesInAaiForCustomer, sdcServiceName)) {
47                     serviceOrderConsumerService.putServiceType(
48                             serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName);
49                 }
50             }
51         }
52
53     }
54
55     private boolean serviceNameExistsInAAI(LinkedHashMap servicesInAaiForCustomer, String sdcServiceName) {
56
57         if (servicesInAaiForCustomer != null && servicesInAaiForCustomer.get("service-subscription") != null) {
58             List<LinkedHashMap> servicesInAAI =
59                     (List<LinkedHashMap>) servicesInAaiForCustomer.get("service-subscription");
60             for (LinkedHashMap service : servicesInAAI) {
61                 String serviceType = (String) service.get("service-type");
62                 if (sdcServiceName.equalsIgnoreCase(serviceType)) {
63                     return true;
64                 }
65
66             }
67         }
68
69         return false;
70
71     }
72
73 }