Find service inventory
[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.ArrayList;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import org.apache.commons.collections.CollectionUtils;
22 import org.onap.nbi.apis.servicecatalog.jolt.FindServiceSpecJsonTransformer;
23 import org.onap.nbi.apis.servicecatalog.jolt.GetServiceSpecJsonTransformer;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26 import org.springframework.beans.factory.annotation.Autowired;
27 import org.springframework.stereotype.Service;
28 import org.springframework.util.MultiValueMap;
29
30 @Service
31 public class ServiceSpecificationService {
32
33     @Autowired
34     SdcClient sdcClient;
35
36     @Autowired
37     GetServiceSpecJsonTransformer getServiceSpecJsonTransformer;
38
39     @Autowired
40     FindServiceSpecJsonTransformer findServiceSpecJsonTransformer;
41
42     @Autowired
43     ToscaInfosProcessor toscaInfosProcessor;
44
45     private static final Logger LOGGER = LoggerFactory.getLogger(ServiceSpecificationService.class);
46
47
48     public LinkedHashMap get(String serviceSpecId) {
49         LinkedHashMap sdcResponse = sdcClient.callGet(serviceSpecId);
50         LinkedHashMap serviceCatalogResponse = (LinkedHashMap) getServiceSpecJsonTransformer.transform(sdcResponse);
51         LinkedHashMap toscaInfosTopologyTemplate = toscaInfosProcessor.getToscaInfos(serviceCatalogResponse);
52         if (toscaInfosTopologyTemplate != null) {
53             LOGGER.debug("tosca file found, retrieving informations");
54             toscaInfosProcessor.buildResponseWithToscaInfos(toscaInfosTopologyTemplate, serviceCatalogResponse);
55         } else {
56             LOGGER.debug("no tosca file found, partial response");
57         }
58         return serviceCatalogResponse;
59     }
60
61
62     public List<LinkedHashMap> find(MultiValueMap<String, String> parametersMap) {
63         List<LinkedHashMap> sdcResponse = sdcClient.callFind(parametersMap);
64         List<LinkedHashMap> serviceCatalogResponse = new ArrayList<>();
65         if(CollectionUtils.isNotEmpty(sdcResponse)){
66             serviceCatalogResponse =
67                 findServiceSpecJsonTransformer.transform(sdcResponse);
68         }
69         return serviceCatalogResponse;
70     }
71 }