2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
5 * the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
10 * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
11 * specific language governing permissions and limitations under the License.
13 package org.onap.nbi.apis.serviceorder.workflow;
15 import java.util.Date;
17 import org.onap.nbi.apis.serviceorder.MultiClient;
18 import org.onap.nbi.apis.serviceorder.model.ActionType;
19 import org.onap.nbi.apis.serviceorder.model.ServiceOrder;
20 import org.onap.nbi.apis.serviceorder.model.ServiceOrderItem;
21 import org.onap.nbi.apis.serviceorder.model.StateType;
22 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderInfo;
23 import org.onap.nbi.apis.serviceorder.model.orchestrator.ServiceOrderItemInfo;
24 import org.onap.nbi.apis.serviceorder.repositories.ServiceOrderRepository;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.stereotype.Service;
29 import java.util.LinkedHashMap;
30 import java.util.List;
33 public class CreateAAIServiceTypeManager {
36 private MultiClient serviceOrderConsumerService;
39 ServiceOrderRepository serviceOrderRepository;
41 private static final Logger LOGGER = LoggerFactory.getLogger(CreateAAIServiceTypeManager.class);
43 public void createAAIServiceType(ServiceOrder serviceOrder, ServiceOrderInfo serviceOrderInfo) {
45 Map servicesInAaiForCustomer = serviceOrderConsumerService
46 .getServicesInAaiForCustomer(serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
48 for (ServiceOrderItem serviceOrderItem : serviceOrder.getOrderItem()) {
49 if (ActionType.ADD == serviceOrderItem.getAction()) {
50 ServiceOrderItemInfo serviceOrderItemInfo =
51 serviceOrderInfo.getServiceOrderItemInfos().get(serviceOrderItem.getId());
52 String sdcServiceName = (String) serviceOrderItemInfo.getCatalogResponse().get("name");
53 if (!serviceNameExistsInAAI(servicesInAaiForCustomer, sdcServiceName)) {
54 boolean serviceCreated = serviceOrderConsumerService.putServiceType(
55 serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId(), sdcServiceName);
56 if (!serviceCreated) {
57 serviceOrder.setState(StateType.REJECTED);
58 serviceOrder.setCompletionDateTime(new Date());
59 serviceOrderRepository.save(serviceOrder);
60 LOGGER.warn("serviceOrder {} rejected : cannot create service type {} for customer {}",
61 serviceOrder.getId(), sdcServiceName,
62 serviceOrderInfo.getSubscriberInfo().getGlobalSubscriberId());
70 private boolean serviceNameExistsInAAI(Map servicesInAaiForCustomer, String sdcServiceName) {
72 if (servicesInAaiForCustomer != null && servicesInAaiForCustomer.get("service-subscription") != null) {
73 List<LinkedHashMap> servicesInAAI =
74 (List<LinkedHashMap>) servicesInAaiForCustomer.get("service-subscription");
75 for (LinkedHashMap service : servicesInAAI) {
76 String serviceType = (String) service.get("service-type");
77 if (sdcServiceName.equalsIgnoreCase(serviceType)) {