aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorandre.schmid <andre.schmid@est.tech>2019-09-03 13:45:28 +0000
committerAvi Gaffa <avi.gaffa@amdocs.com>2019-09-03 15:39:43 +0000
commit7de4f3e788ff2b71936ae43be7dfbdf48740f9be (patch)
treea7419656377e146ec1095d6eaf82dbbffd717b41 /common
parentccc1f364baea63733e93c6f4eb26ea97eeb77960 (diff)
Implement PNFD Model driven conversion
Change-Id: I7427e82353cac17817457294d78953f867d2d6e8 Issue-ID: SDC-2509 Signed-off-by: andre.schmid <andre.schmid@est.tech>
Diffstat (limited to 'common')
-rw-r--r--common/onap-tosca-datatype/pom.xml5
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java36
2 files changed, 41 insertions, 0 deletions
diff --git a/common/onap-tosca-datatype/pom.xml b/common/onap-tosca-datatype/pom.xml
index c388652d81..f63bfa63d6 100644
--- a/common/onap-tosca-datatype/pom.xml
+++ b/common/onap-tosca-datatype/pom.xml
@@ -70,5 +70,10 @@
<artifactId>lombok</artifactId>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>${slf4j.version}</version>
+ </dependency>
</dependencies>
</project>
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java
index 4030d3acd1..4ac60d40e4 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java
@@ -16,6 +16,10 @@
package org.onap.sdc.tosca.services;
+import java.util.List;
+import java.util.Optional;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.TypeDescription;
import org.yaml.snakeyaml.Yaml;
@@ -29,6 +33,7 @@ import org.yaml.snakeyaml.nodes.Tag;
import org.yaml.snakeyaml.parser.ParserException;
import org.yaml.snakeyaml.representer.Representer;
+
import java.beans.IntrospectionException;
import java.io.IOException;
import java.io.InputStream;
@@ -43,6 +48,7 @@ import java.util.Set;
*/
@SuppressWarnings("unchecked")
public class YamlUtil {
+ private static final Logger LOGGER = LoggerFactory.getLogger(YamlUtil.class.getName());
private static final String DEFAULT = "default";
private static final String DEFAULT_STR = "_default";
@@ -140,6 +146,36 @@ public class YamlUtil {
return (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent);
}
+
+ /**
+ * Parse a YAML file to List
+ *
+ * @param yamlFileInputStream the YAML file input stream
+ * @return The YAML casted as a list
+ */
+ public static Optional<List<Object>> yamlToList(final InputStream yamlFileInputStream) {
+ List<Object> yamlList = null;
+ try {
+ yamlList = (List<Object>) read(yamlFileInputStream);
+ } catch (final ClassCastException ex) {
+ if (LOGGER.isWarnEnabled()) {
+ LOGGER.warn("Could not parse YAML to List.", ex);
+ }
+ }
+ return Optional.ofNullable(yamlList);
+ }
+
+ /**
+ * Parse a YAML file to Object
+ *
+ * @param yamlFileInputStream the YAML file input stream
+ * @return The YAML Object
+ */
+ public static Object read(final InputStream yamlFileInputStream) {
+ final Yaml yaml = new Yaml();
+ return yaml.load(yamlFileInputStream);
+ }
+
/**
* Object to yaml string.
* @param obj the obj