Add serviceOrder rest services
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / serviceorder / workflow / CreateAAIServiceTypeManager.java
1 package org.onap.nbi.apis.serviceorder.workflow;
2
3 import org.onap.nbi.apis.serviceorder.MultiClient;
4 import org.onap.nbi.apis.serviceorder.model.ActionType;
5 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
6 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
7 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
8 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderItemInfo;
9 import org.springframework.beans.factory.annotation.Autowired;
10 import org.springframework.stereotype.Service;
11 import java.util.LinkedHashMap;
12 import java.util.List;
13
14 @Service
15 public class CreateAAIServiceTypeManager {
16
17     @Autowired
18     private MultiClient serviceOrderConsumerService;
19
20
21     public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) {
22
23         LinkedHashMap servicesInAaiForCustomer = serviceOrderConsumerService
24                 .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
25
26         for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) {
27             if (ActionType.ADD == serviceOrderItem.getAction()) {
28                 ServiceOrderItemInfo serviceOrderItemInfo =
29                         serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId());
30                 String sdcServiceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name");
31                 if (!serviceNameExistsInAAI(servicesInAaiForCustomer, sdcServiceName)) {
32                     serviceOrderConsumerService.putServiceType(
33                             serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName);
34                 }
35             }
36         }
37
38     }
39
40     private boolean serviceNameExistsInAAI(LinkedHashMap servicesInAaiForCustomer, String sdcServiceName) {
41
42         if (servicesInAaiForCustomer != null && servicesInAaiForCustomer.get("service-subscription") != null) {
43             List<LinkedHashMap> servicesInAAI =
44                     (List<LinkedHashMap>) servicesInAaiForCustomer.get("service-subscription");
45             for (LinkedHashMap service : servicesInAAI) {
46                 String serviceType = (String) service.get("service-type");
47                 if (sdcServiceName.equalsIgnoreCase(serviceType)) {
48                     return true;
49                 }
50
51             }
52         }
53
54         return false;
55
56     }
57
58 }