Transformation of request/response payloads for SDC Integration for POST /serviceSpec...
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / servicecatalog / jolt / PostServiceSpecJsonTransformer.java
1 /*
2  * ============LICENSE_START=============================================================================================================
3  * Copyright (c) 2020 NikhilMohan
4  * ===================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 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 is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
10  * OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
11  * ============LICENSE_END===============================================================================================================
12  * 
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 org.onap.nbi.exceptions.TechnicalException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.stereotype.Service;
23
24 import java.util.List;
25
26 @Service
27 public class PostServiceSpecJsonTransformer {
28     private Chainr chainr;
29
30     private static final Logger LOGGER = LoggerFactory.getLogger(PostServiceSpecJsonTransformer.class);
31
32     public PostServiceSpecJsonTransformer() {
33         List<Object> specs = JsonUtils.classpathToList("/jolt/postServiceCatalog.json");
34         this.chainr = Chainr.fromSpec(specs);
35     }
36
37     public Object transform(Object serviceSpec) {
38         Object output = null;
39         try {
40             output = 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         return output;
46     }
47
48 }