2 * Copyright (c) 2018 Orange
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.nbi.apis.serviceorder.workflow;
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;
30 public class CreateAAIServiceTypeManager {
33 private MultiClient serviceOrderConsumerService;
36 public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) {
38 LinkedHashMap servicesInAaiForCustomer = serviceOrderConsumerService
39 .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
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);
55 private boolean serviceNameExistsInAAI(LinkedHashMap servicesInAaiForCustomer, String sdcServiceName) {
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)) {