Find service inventory
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / jolt / FindServiceSpecJsonTransformer.java
1 /**
2  * Copyright (c) 2018 Orange
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package org.onap.nbi.apis.servicecatalog.jolt;
15
16 import com.bazaarvoice.jolt.Chainr;
17 import com.bazaarvoice.jolt.JsonUtils;
18 import com.bazaarvoice.jolt.exception.JoltException;
19 import java.util.LinkedHashMap;
20 import java.util.List;
21 import org.onap.nbi.exceptions.TechnicalException;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.springframework.stereotype.Service;
25
26 @Service
27 public class FindServiceSpecJsonTransformer {
28
29     private Chainr chainr;
30
31     private static final Logger LOGGER = LoggerFactory.getLogger(FindServiceSpecJsonTransformer.class);
32
33     public FindServiceSpecJsonTransformer() {
34         List<Object> specs = JsonUtils.classpathToList("/jolt/findServiceCatalog.json");
35         this.chainr = Chainr.fromSpec(specs);
36     }
37
38     public List<LinkedHashMap> transform(Object serviceSpec) {
39         try {
40             return (List<LinkedHashMap>)chainr.transform(serviceSpec);
41         } catch (JoltException joE) {
42             LOGGER.error("Unable to transform SDC response with JOLT Transformer", joE);
43             throw new TechnicalException("Error while parsing ONAP response");
44         }
45     }
46
47 }