e89960a69922443bb16c831697ccfe6ef9d850b6
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / ServiceSpecificationService.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
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
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.nbi.apis.servicecatalog;
17
18 import java.util.LinkedHashMap;
19 import java.util.List;
20 import org.onap.nbi.apis.servicecatalog.jolt.FindServiceSpecJsonTransformer;
21 import org.onap.nbi.apis.servicecatalog.jolt.GetServiceSpecJsonTransformer;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.stereotype.Service;
26 import org.springframework.util.MultiValueMap;
27
28 @Service
29 public class ServiceSpecificationService {
30
31     @Autowired
32     SdcClient sdcClient;
33
34     @Autowired
35     GetServiceSpecJsonTransformer getServiceSpecJsonTransformer;
36
37     @Autowired
38     FindServiceSpecJsonTransformer findServiceSpecJsonTransformer;
39
40     @Autowired
41     ToscaInfosProcessor toscaInfosProcessor;
42
43     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
44
45
46     public LinkedHashMap get(String serviceSpecId) {
47         LinkedHashMap sdcResponse = sdcClient.callGet(serviceSpecId);
48         LinkedHashMap serviceCatalogResponse = (LinkedHashMap) getServiceSpecJsonTransformer.transform(sdcResponse);
49         LinkedHashMap toscaInfosTopologyTemplate = toscaInfosProcessor.getToscaInfos(serviceCatalogResponse);
50         if (toscaInfosTopologyTemplate != null) {
51             LOGGER.debug("tosca file found, retrieving informations");
52             toscaInfosProcessor.buildResponseWithToscaInfos(toscaInfosTopologyTemplate, serviceCatalogResponse);
53         } else {
54             LOGGER.debug("no tosca file found, partial response");
55         }
56         return serviceCatalogResponse;
57     }
58
59
60     public List<LinkedHashMap> find(MultiValueMap<String, String> parametersMap) {
61         List<LinkedHashMap> sdcResponse = sdcClient.callFind(parametersMap);
62         List<LinkedHashMap> serviceCatalogResponse =
63                 (List<LinkedHashMap>) findServiceSpecJsonTransformer.transform(sdcResponse);
64         return serviceCatalogResponse;
65     }
66 }