b0b52e0c406395eca1c44b647604340b9a3f47f2
[sdc.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  *  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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  *
16  *  SPDX-License-Identifier: Apache-2.0
17  *  ============LICENSE_END=========================================================
18  */
19
20 package org.openecomp.core.converter.impl.pnfd.parser;
21
22 import java.util.List;
23 import java.util.Map;
24 import org.onap.sdc.tosca.datatypes.model.ArtifactDefinition;
25 import org.onap.sdc.tosca.datatypes.model.AttributeDefinition;
26 import org.onap.sdc.tosca.datatypes.model.CapabilityDefinition;
27 import org.onap.sdc.tosca.datatypes.model.NodeType;
28 import org.onap.sdc.tosca.datatypes.model.PropertyDefinition;
29 import org.onap.sdc.tosca.datatypes.model.RequirementDefinition;
30 import org.openecomp.sdc.be.utils.TypeUtils.ToscaTagNamesEnum;
31
32 /**
33  * Handles YAML from/to {@link NodeType} conversions
34  */
35 public class NodeTypeYamlParser {
36
37     private NodeTypeYamlParser() {
38     }
39
40     /**
41      * Parses the given a YAML object to a {@link NodeType} instance.
42      * @param nodeTypeYaml the YAML object representing a TOSCA Node Type
43      * @return A new instance of {@link NodeType}.
44      */
45     @SuppressWarnings("unchecked")
46     public static NodeType parse(final Map<String, Object> nodeTypeYaml) {
47         final NodeType nodeType = new NodeType();
48         nodeType.setDerived_from((String) nodeTypeYaml.get(ToscaTagNamesEnum.DERIVED_FROM.getElementName()));
49         nodeType.setDescription((String) nodeTypeYaml.get(ToscaTagNamesEnum.DESCRIPTION.getElementName()));
50         nodeType.setVersion((String) nodeTypeYaml.get("version"));
51         nodeType.setProperties(
52             (Map<String, PropertyDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.PROPERTIES.getElementName()));
53         nodeType.setArtifacts((Map<String, ArtifactDefinition>) nodeTypeYaml.get("artifacts"));
54         nodeType.setMetadata((Map<String, String>) nodeTypeYaml.get("metadata"));
55         nodeType.setInterfaces(
56             (Map<String, Object>) nodeTypeYaml.get(ToscaTagNamesEnum.INTERFACES.getElementName()));
57         nodeType.setRequirements(
58             (List<Map<String, RequirementDefinition>>) nodeTypeYaml.get(ToscaTagNamesEnum.REQUIREMENTS.getElementName()));
59         nodeType.setCapabilities(
60             (Map<String, CapabilityDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.CAPABILITIES.getElementName()));
61         nodeType.setAttributes(
62             (Map<String, AttributeDefinition>) nodeTypeYaml.get(ToscaTagNamesEnum.ATTRIBUTES.getElementName()));
63
64         return nodeType;
65     }
66
67 }