3 * * ============LICENSE_START=======================================================
5 * * ================================================================================
6 * * Copyright (c) 2020 AT&T Intellectual Property. All rights reserved.
7 * * ================================================================================
8 * * Licensed under the Apache License, Version 2.0 (the "License");
9 * * you may not use this file except in compliance with the License.
10 * * You may obtain a copy of the License at
12 * * http://www.apache.org/licenses/LICENSE-2.0
14 * * Unless required by applicable law or agreed to in writing, software
15 * * distributed under the License is distributed on an "AS IS" BASIS,
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * * See the License for the specific language governing permissions and
18 * * limitations under the License.
19 * * ============LICENSE_END=========================================================
24 package org.onap.blueprintgenerator.service.common;
26 import java.io.IOException;
27 import org.onap.blueprintgenerator.exception.ComponentSpecException;
28 import org.onap.blueprintgenerator.model.componentspec.OnapComponentSpec;
29 import com.fasterxml.jackson.databind.ObjectMapper;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Qualifier;
32 import org.springframework.stereotype.Service;
37 * @author : Ravi Mantena
38 * @date 10/16/2020 Application: ONAP - Blueprint Generator Common ONAP Service used by ONAP and
39 * DMAAP Blueprint to create Component Spec from File
41 @Service("onapComponentSpecService")
42 public class ComponentSpecService {
44 @Qualifier("objectMapper")
46 private ObjectMapper componentMapper;
48 @Qualifier("yamlObjectMapper")
50 private ObjectMapper yamlComponentMapper;
53 * Creates ComponentSpec from given file path and validates if the input is json file or not
55 * @param componentSpecPath Path of Component Spec File Location
58 public OnapComponentSpec createComponentSpecFromFile(String componentSpecPath) {
59 OnapComponentSpec componentSpec;
61 if (!componentSpecPath.endsWith(".json")) {
62 componentSpec = yamlComponentMapper.readValue(new File(componentSpecPath), OnapComponentSpec.class);
64 componentSpec = componentMapper.readValue(new File(componentSpecPath), OnapComponentSpec.class);
66 } catch (Exception ex) {
67 throw new ComponentSpecException(
68 "Unable to create ONAP Component Spec from the input file: " + componentSpecPath,
75 * Creates the component spec from string.
76 * This method is used by RuntimeAPI
77 * @param specString the spec string of Component Spec
80 public OnapComponentSpec createComponentSpecFromString(String specString) {
81 OnapComponentSpec componentSpec;
83 componentSpec = componentMapper.readValue(specString, OnapComponentSpec.class);
84 } catch (Exception ex) {
85 throw new ComponentSpecException(
86 "Unable to create ONAP Component Spec from the input string: " + specString,