Implement PNFD Model driven conversion
[sdc.git] / openecomp-be / lib / openecomp-tosca-converter-lib / openecomp-tosca-converter-core / src / main / java / org / openecomp / core / converter / impl / pnfd / parser / ParameterDefinitionYamlParser.java
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.Map;
23 import org.onap.sdc.tosca.datatypes.model.EntrySchema;
24 import org.onap.sdc.tosca.datatypes.model.ParameterDefinition;
25 import org.onap.sdc.tosca.datatypes.model.Status;
26
27 /**
28  * Handles YAML from/to {@link ParameterDefinition} conversions
29  */
30 public class ParameterDefinitionYamlParser {
31
32     private ParameterDefinitionYamlParser() {
33     }
34
35     /**
36      * Parses the given a YAML object to a {@link ParameterDefinition} instance.
37      * @param parameterDefinitionYaml    the YAML object representing a TOSCA Parameter Definition
38      * @return
39      *  A new instance of {@link ParameterDefinition}.
40      */
41     public static ParameterDefinition parse(final Map<String, Object> parameterDefinitionYaml) {
42         final ParameterDefinition parameterDefinition = new ParameterDefinition();
43         parameterDefinition.set_default(parameterDefinitionYaml.get("default"));
44         parameterDefinition.setDescription((String) parameterDefinitionYaml.get("description"));
45         final Map<String, Object> entrySchemaYaml = (Map<String, Object>) parameterDefinitionYaml.get("entry_schema");
46         if (entrySchemaYaml != null) {
47             final EntrySchema entrySchema = new EntrySchema();
48             entrySchema.setType((String) entrySchemaYaml.get("type"));
49             parameterDefinition.setEntry_schema(entrySchema);
50         }
51         parameterDefinition.setRequired((Boolean) parameterDefinitionYaml.get("required"));
52         parameterDefinition.setType((String) parameterDefinitionYaml.get("type"));
53         parameterDefinition.setStatus((Status) parameterDefinitionYaml.get("status"));
54
55         return parameterDefinition;
56     }
57 }