3 * Copyright (c) 2017 Orange. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onap.nbi.apis.serviceorder.workflow;
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;
31 public class CreateAAIServiceTypeManager {
34 private MultiClient serviceOrderConsumerService;
37 public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) {
39 LinkedHashMap servicesInAaiForCustomer = serviceOrderConsumerService
40 .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
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);
56 private boolean serviceNameExistsInAAI(LinkedHashMap servicesInAaiForCustomer, String sdcServiceName) {
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)) {