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;
31 import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
33 import static org.openecomp.core.converter.datatypes.Constants.*;
35 public class ServiceTemplateReaderServiceImpl implements ServiceTemplateReaderService {
37 private Map<String, Object> readServiceTemplate = new HashMap<>();
39 public ServiceTemplateReaderServiceImpl(byte[] serviceTemplateContent) {
40 this.readServiceTemplate = readServiceTemplate(serviceTemplateContent);
44 public Map<String, Object> readServiceTemplate(byte[] serviceTemplateContent) {
46 return new YamlUtil().yamlToObject(new String(serviceTemplateContent), Map.class);
51 public List<Object> getImports() {
52 return Objects.isNull(this.readServiceTemplate.get("imports")) ? new ArrayList<>()
53 : (List<Object>) this.readServiceTemplate.get("imports");
57 public Map<String, Object> getPolicies() {
58 Map<String, Object> policiesAsMap = new HashMap<>();
59 if (!Objects.isNull(this.getTopologyTemplate()) && !Objects.isNull(
60 ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES))) {
61 policiesAsMap = (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(POLICIES);
67 public Object getMetadata() {
68 return this.readServiceTemplate.get(metadata);
72 public Object getToscaVersion() {
73 return this.readServiceTemplate.get(ToscaTagNamesEnum.TOSCA_VERSION.getElementName());
77 public Map<String, Object> getNodeTypes() {
78 return Objects.isNull(this.readServiceTemplate.get(nodeTypes)) ? new HashMap<>()
79 : (Map<String, Object>) this.readServiceTemplate.get(nodeTypes);
83 public Object getTopologyTemplate() {
84 return this.readServiceTemplate.get(topologyTemplate);
88 public Map<String, Object> getNodeTemplates() {
89 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
90 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(nodeTemplates);
94 public Map<String, Object> getInputs() {
95 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
96 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(inputs);
100 public Map<String, Object> getOutputs() {
101 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
102 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate()).get(outputs);
106 public Map<String, Object> getSubstitutionMappings() {
107 return Objects.isNull(this.getTopologyTemplate()) ? new HashMap<>()
108 : (Map<String, Object>) ((Map<String, Object>) this.getTopologyTemplate())
109 .get(substitutionMappings);