2 * Copyright (c) 2018 Orange
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
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
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
15 package org.onap.nbi.apis.servicecatalog.jolt;
17 import com.bazaarvoice.jolt.Chainr;
18 import com.bazaarvoice.jolt.JsonUtils;
19 import com.bazaarvoice.jolt.exception.JoltException;
20 import java.util.LinkedHashMap;
21 import java.util.List;
22 import org.onap.nbi.exceptions.TechnicalException;
23 import org.slf4j.Logger;
24 import org.slf4j.LoggerFactory;
25 import org.springframework.stereotype.Service;
28 public class FindServiceSpecJsonTransformer {
30 private Chainr chainr;
32 private static final Logger LOGGER = LoggerFactory.getLogger(FindServiceSpecJsonTransformer.class);
34 public FindServiceSpecJsonTransformer() {
35 List<Object> specs = JsonUtils.classpathToList("/jolt/findServiceCatalog.json");
36 this.chainr = Chainr.fromSpec(specs);
39 public List<LinkedHashMap> transform(Object serviceSpec) {
41 return (List<LinkedHashMap>) chainr.transform(serviceSpec);
42 } catch (JoltException joE) {
43 LOGGER.error("Unable to transform SDC response with JOLT Transformer", joE);
44 throw new TechnicalException("Error while parsing ONAP response");