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.servicecatalog;
18 import java.util.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
22 import org.apache.commons.collections.CollectionUtils;
23 import org.onap.nbi.apis.servicecatalog.jolt.FindServiceSpecJsonTransformer;
24 import org.onap.nbi.apis.servicecatalog.jolt.GetServiceSpecJsonTransformer;
25 import org.onap.nbi.apis.serviceorder.ServiceCatalogUrl;
26 import org.slf4j.Logger;
27 import org.slf4j.LoggerFactory;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.stereotype.Service;
30 import org.springframework.util.MultiValueMap;
33 public class ServiceSpecificationService {
39 GetServiceSpecJsonTransformer getServiceSpecJsonTransformer;
42 FindServiceSpecJsonTransformer findServiceSpecJsonTransformer;
45 ToscaInfosProcessor toscaInfosProcessor;
48 private ServiceCatalogUrl serviceCatalogUrl;
51 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
54 public Map get(String serviceSpecId) {
55 Map sdcResponse = sdcClient.callGet(serviceSpecId);
56 LinkedHashMap serviceCatalogResponse = (LinkedHashMap) getServiceSpecJsonTransformer.transform(sdcResponse);
57 Map toscaInfosTopologyTemplate = toscaInfosProcessor.getToscaInfos(serviceCatalogResponse);
58 if (toscaInfosTopologyTemplate != null) {
59 LOGGER.debug("tosca file found, retrieving informations");
60 toscaInfosProcessor.buildResponseWithToscaInfos(toscaInfosTopologyTemplate, serviceCatalogResponse);
62 LOGGER.debug("no tosca file found, partial response");
64 return serviceCatalogResponse;
67 public List<LinkedHashMap> find(MultiValueMap<String, String> parametersMap) {
68 List<LinkedHashMap> sdcResponse = sdcClient.callFind(parametersMap);
69 List<LinkedHashMap> serviceCatalogResponse = new ArrayList<>();
70 if(CollectionUtils.isNotEmpty(sdcResponse)){
71 serviceCatalogResponse =
72 findServiceSpecJsonTransformer.transform(sdcResponse);
74 return serviceCatalogResponse;