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