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) {
45 return new YamlUtil().yamlToObject(new String(serviceTemplateContent), Map.class);
50 public List<Object> getImports() {
51 return Objects.isNull(this.readServiceTemplate.get("imports")) ? new ArrayList<>()
52 : (List<Object>) this.readServiceTemplate.get("imports");
56 public Map<String, Object> getPolicies() {
57 Map<String, Object> policiesAsMap = new HashMap<>();
58 if (!Objects.isNull(this.getTopologyTemplate()) && !Objects.isNull(
59 ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES))) {
60 policiesAsMap = (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES);
66 public Object getMetadata() {
67 return this.readServiceTemplate.get(metadata);
71 public Object getToscaVersion() {
72 return this.readServiceTemplate.get(definitionVersion);
76 public Map<String, Object> getNodeTypes() {
77 return Objects.isNull(this.readServiceTemplate.get(nodeTypes)) ? new HashMap<>()
78 : (Map<String, Object>) this.readServiceTemplate.get(nodeTypes);
82 public Object getTopologyTemplate() {
83 return this.readServiceTemplate.get(topologyTemplate);
87 public Map<String, Object> getNodeTemplates() {
88 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
89 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(nodeTemplates);
93 public Map<String, Object> getInputs() {
94 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
95 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(inputs);
99 public Map<String, Object> getOutputs() {
100 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
101 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(outputs);
105 public Map<String, Object> getSubstitutionMappings() {
106 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
107 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate())
108 .get(substitutionMappings);