2 * ============LICENSE_START=======================================================
3 * Modification Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.openecomp.core.impl.services;
23 import org.onap.sdc.tosca.services.YamlUtil;
24 import org.openecomp.core.converter.ServiceTemplateReaderService;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.List;
30 import java.util.Objects;
32 import static org.openecomp.core.converter.datatypes.Constants.*;
34 public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderService {
36 private Map<String, Object> readServiceTemplate = new HashMap<>();
38 public ServiceTemplateReaderServiceImpl(byte[] serviceTemplateContent){
39 this.readServiceTemplate = readServiceTemplate(serviceTemplateContent);
43 public Map<String, Object> readServiceTemplate(byte[] serviceTemplateContent) {
46 new YamlUtil().yamlToObject(new String(serviceTemplateContent), Map.class);
51 public List<Object> getImports(){
52 return Objects.isNull(this.readServiceTemplate.get("imports")) ?
53 new ArrayList<>() : (List<Object>) this.readServiceTemplate.get("imports");
57 public Object getMetadata(){
58 return this.readServiceTemplate.get(metadata);
62 public Object getToscaVersion(){
63 return this.readServiceTemplate.get(definitionVersion);
67 public Map<String, Object> getNodeTypes(){
68 return Objects.isNull(this.readServiceTemplate.get(nodeTypes)) ? new HashMap<>()
69 :(Map<String, Object>) this.readServiceTemplate.get(nodeTypes);
73 public Object getTopologyTemplate(){
74 return this.readServiceTemplate.get(topologyTemplate);
78 public Map<String, Object> getNodeTemplates(){
79 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
80 : (Map<String, Object>) ((Map<String, Object>)this.getTopologyTemplate()).get(nodeTemplates);
84 public Map<String, Object> getInputs(){
85 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
86 : (Map<String, Object>) ((Map<String, Object>)this.getTopologyTemplate()).get(inputs);
90 public Map<String, Object> getOutputs(){
91 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
92 : (Map<String, Object>) ((Map<String, Object>)this.getTopologyTemplate()).get(outputs);
96 public Map<String, Object> getSubstitutionMappings(){
97 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
98 : (Map<String, Object>) ((Map<String, Object>)this.getTopologyTemplate()).get(substitutionMappings);