aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib
diff options
context:
space:
mode:
authorAvi Ziv <avi.ziv@amdocs.com>2017-07-18 19:45:38 +0300
committerAvi Ziv <avi.ziv@amdocs.com>2017-07-18 19:45:38 +0300
commitb8e2faf476202b6ffe61bc3a9a37df1304881d40 (patch)
treef78b8c0517d8e16c5ae610bf8b49f68ea8a312a1 /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib
parent75aacbbe1acf78fa53378f07f0a8c7769449a17e (diff)
[SDC] Onboarding 1710 rebase.
Change-Id: If3b6b81d221fde13908f1e8160db6f7d9433c535 Signed-off-by: Avi Ziv <avi.ziv@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib')
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml7
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml.versionsBackup83
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java4
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java12
-rw-r--r--openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/yaml/YamlUtil.java292
5 files changed, 99 insertions, 299 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
index f7f6ea65f6..76d6ff6b74 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml
@@ -14,6 +14,11 @@
<dependencies>
<dependency>
+ <groupId>org.openecomp.sdc.common</groupId>
+ <artifactId>openecomp-tosca-datatype</artifactId>
+ <version>${openecomp.sdc.common.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>${snakeyaml.version}</version>
@@ -42,7 +47,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
- <version>4.11</version>
+ <version>${junit.version}</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml.versionsBackup b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml.versionsBackup
new file mode 100644
index 0000000000..1e448f5a61
--- /dev/null
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/pom.xml.versionsBackup
@@ -0,0 +1,83 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <name>openecomp-utilities-lib</name>
+ <artifactId>openecomp-utilities-lib</artifactId>
+
+
+ <parent>
+ <artifactId>openecomp-core-lib</artifactId>
+ <groupId>org.openecomp.core</groupId>
+ <version>1.0-SNAPSHOT</version>
+ </parent>
+
+
+
+ <dependencies>
+ <dependency>
+ <groupId>org.yaml</groupId>
+ <artifactId>snakeyaml</artifactId>
+ <version>1.17</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-lang3</artifactId>
+ <version>3.4</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.commons</groupId>
+ <artifactId>commons-collections4</artifactId>
+ <version>4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ <dependency>
+ <groupId>commons-codec</groupId>
+ <artifactId>commons-codec</artifactId>
+ <version>${commons.codec.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ <version>4.11</version>
+ </dependency>
+ <dependency>
+ <groupId>org.codehaus.jackson</groupId>
+ <artifactId>jackson-mapper-asl</artifactId>
+ <version>1.9.13</version>
+ </dependency>
+ <dependency>
+ <groupId>org.everit.json</groupId>
+ <artifactId>org.everit.json.schema</artifactId>
+ <version>1.3.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <scope>test</scope>
+ <version>6.8.5</version>
+ <exclusions>
+ <exclusion>
+ <artifactId>snakeyaml</artifactId>
+ <groupId>org.yaml</groupId>
+ </exclusion>
+ </exclusions>
+ </dependency>
+ <dependency>
+ <groupId>org.openecomp.sdc</groupId>
+ <artifactId>openecomp-sdc-logging-api</artifactId>
+ <version>1.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ <version>2.3.1</version>
+ </dependency>
+ </dependencies>
+
+</project> \ No newline at end of file
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
index c828505932..8de222e688 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileContentHandler.java
@@ -62,6 +62,10 @@ public class FileContentHandler {
return files;
}
+ public void setFiles(Map<String, byte[]> files) {
+ this.files = files;
+ }
+
public void setFiles(FileContentHandler extFiles) {
extFiles.getFileList().stream()
.forEach(fileName -> this.addFile(fileName, extFiles.getFileContent(fileName)));
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
index 664ccb68c6..08d9bd8a41 100644
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
+++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/file/FileUtils.java
@@ -20,14 +20,14 @@
package org.openecomp.core.utilities.file;
-import org.apache.commons.collections4.CollectionUtils;
import org.openecomp.core.utilities.json.JsonUtil;
-import org.openecomp.core.utilities.yaml.YamlUtil;
-import org.openecomp.sdc.logging.types.LoggerConstants;
-import org.openecomp.sdc.logging.types.LoggerErrorDescription;
-import org.slf4j.MDC;
+import org.openecomp.sdc.tosca.services.YamlUtil;
-import java.io.*;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/yaml/YamlUtil.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/yaml/YamlUtil.java
deleted file mode 100644
index d38bf484e4..0000000000
--- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/main/java/org/openecomp/core/utilities/yaml/YamlUtil.java
+++ /dev/null
@@ -1,292 +0,0 @@
-/*-
- * ============LICENSE_START=======================================================
- * SDC
- * ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ============LICENSE_END=========================================================
- */
-
-package org.openecomp.core.utilities.yaml;
-
-import org.openecomp.sdc.logging.api.Logger;
-import org.openecomp.sdc.logging.api.LoggerFactory;
-import org.openecomp.core.utilities.CommonMethods;
-import org.yaml.snakeyaml.DumperOptions;
-import org.yaml.snakeyaml.TypeDescription;
-import org.yaml.snakeyaml.Yaml;
-import org.yaml.snakeyaml.constructor.Constructor;
-import org.yaml.snakeyaml.introspector.BeanAccess;
-import org.yaml.snakeyaml.introspector.Property;
-import org.yaml.snakeyaml.introspector.PropertyUtils;
-import org.yaml.snakeyaml.nodes.MappingNode;
-import org.yaml.snakeyaml.nodes.NodeTuple;
-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;
-import java.util.AbstractMap;
-import java.util.LinkedHashMap;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-
-/**
- * The type Yaml util.
- */
-public class YamlUtil {
-
- private static Logger logger = (Logger) LoggerFactory.getLogger(YamlUtil.class);
-
- /**
- * Yaml to object t.
- *
- * @param <T> the type parameter
- * @param yamlContent the yaml content
- * @param typClass the t class
- * @return the t
- */
- public <T> T yamlToObject(String yamlContent, Class<T> typClass) {
- Constructor constructor = getConstructor(typClass);
- constructor.setPropertyUtils(getPropertyUtils());
- TypeDescription yamlFileDescription = new TypeDescription(typClass);
- constructor.addTypeDescription(yamlFileDescription);
- Yaml yaml = new Yaml(constructor);
- T yamlObj = (T) yaml.load(yamlContent);
- yamlObj.toString();
- return yamlObj;
- }
-
- /**
- * Yaml to object t.
- *
- * @param <T> the type parameter
- * @param yamlContent the yaml content
- * @param typClass the t class
- * @return the t
- */
- public <T> T yamlToObject(InputStream yamlContent, Class<T> typClass) {
- try {
- Constructor constructor = getConstructor(typClass);
- constructor.setPropertyUtils(getPropertyUtils());
- TypeDescription yamlFileDescription = new TypeDescription(typClass);
- constructor.addTypeDescription(yamlFileDescription);
- Yaml yaml = new Yaml(constructor);
- T yamlObj = (T) yaml.load(yamlContent);
- if (yamlObj != null) {
- yamlObj.toString();
- return yamlObj;
- } else {
- throw new RuntimeException();
- }
- } catch (Exception exception) {
- logger.error("Error will trying to convert yaml to object:" + exception.getMessage());
- throw new RuntimeException(exception);
- } finally {
- try {
- if (yamlContent != null) {
- yamlContent.close();
- }
- } catch (IOException ignore) {
- //do nothing
- }
- }
- }
-
-
- /**
- * Gets constructor.
- *
- * @param <T> the type parameter
- * @param typClass the t class
- * @return the constructor
- */
- public <T> Constructor getConstructor(Class<T> typClass) {
- return new StrictMapAppenderConstructor(typClass);
- }
-
- /**
- * Gets property utils.
- *
- * @return the property utils
- */
- protected PropertyUtils getPropertyUtils() {
- return new MyPropertyUtils();
- }
-
-
- /**
- * Yaml to map map.
- *
- * @param yamlContent the yaml content
- * @return the map
- */
- public Map<String, LinkedHashMap<String, Object>> yamlToMap(InputStream yamlContent) {
- Yaml yaml = new Yaml();
- Map<String, LinkedHashMap<String, Object>> yamlData =
- (Map<String, LinkedHashMap<String, Object>>) yaml.load(yamlContent);
- return yamlData;
- }
-
- /**
- * Object to yaml string.
- *
- * @param <T> the type parameter
- * @param obj the obj
- * @return the string
- */
- public <T> String objectToYaml(Object obj) {
- DumperOptions options = new DumperOptions();
- options.setPrettyFlow(true);
- options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
- Representer representer = new CustomRepresenter();
- representer.addClassTag(obj.getClass(), Tag.MAP);
- representer.setPropertyUtils(new MyPropertyUtils());
-
- Yaml yaml = new Yaml(representer, options);
- return yaml.dump(obj);
- }
-
- /**
- * Load yaml file is input stream.
- *
- * @param yamlFullFileName the yaml full file name
- * @return the input stream
- */
- public InputStream loadYamlFileIs(String yamlFullFileName) {
- return CommonMethods.class.getResourceAsStream(yamlFullFileName);
- }
-
- /**
- * Is yaml file content valid boolean.
- *
- * @param yamlFullFileName the yaml full file name
- * @return the boolean
- */
- public boolean isYamlFileContentValid(String yamlFullFileName) {
- Yaml yaml = new Yaml();
- try {
- Object loadResult = yaml.load(yamlFullFileName);
- if (loadResult == null) {
- return false;
- }
- return true;
- } catch (Exception exception) {
- return false;
- }
- }
-
-
- private class CustomRepresenter extends Representer {
- @Override
- protected MappingNode representJavaBean(Set<Property> properties, Object javaBean) {
- //remove the bean type from the output yaml (!! ...)
- if (!classTags.containsKey(javaBean.getClass())) {
- addClassTag(javaBean.getClass(), Tag.MAP);
- }
-
- return super.representJavaBean(properties, javaBean);
- }
-
- @Override
- protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
- Object propertyValue, Tag customTag) {
- if (propertyValue == null) {
- return null;
- } else {
- NodeTuple defaultNode =
- super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
-
- return property.getName().equals("_default")
- ? new NodeTuple(representData("default"), defaultNode.getValueNode())
- : defaultNode;
- }
- }
- }
-
-
- /**
- * The type My property utils.
- */
- public class MyPropertyUtils extends PropertyUtils {
- //Unsorted properties
- @Override
- protected Set<Property> createPropertySet(Class<? extends Object> type, BeanAccess bnAccess)
- throws IntrospectionException {
- return new LinkedHashSet<Property>(getPropertiesMap(type,
- BeanAccess.FIELD).values());
- }
-
- @Override
- public Property getProperty(Class<?> type, String name) throws IntrospectionException {
- if (name.equals("default")) {
- name = "_default";
- }
- return super.getProperty(type, name);
- }
-
- }
-
- /**
- * The type Strict map appender constructor.
- */
- protected class StrictMapAppenderConstructor extends Constructor {
-
- /**
- * Instantiates a new Strict map appender constructor.
- *
- * @param theRoot the the root
- */
- public StrictMapAppenderConstructor(Class<?> theRoot) {
- super(theRoot);
- }
-
- @Override
- protected Map<Object, Object> createDefaultMap() {
- final Map<Object, Object> delegate = super.createDefaultMap();
- return new AbstractMap<Object, Object>() {
- @Override
- public Object put(Object key, Object value) {
- if (delegate.containsKey(key)) {
- throw new IllegalStateException("duplicate key: " + key);
- }
- return delegate.put(key, value);
- }
-
- @Override
- public Set<Entry<Object, Object>> entrySet() {
- return delegate.entrySet();
- }
- };
- }
-
- @Override
- protected Map<Object, Object> constructMapping(MappingNode node) {
- try {
- return super.constructMapping(node);
- } catch (IllegalStateException exception) {
- throw new ParserException("while parsing MappingNode",
- node.getStartMark(), exception.getMessage(),
- node.getEndMark());
- }
- }
- }
-}
-
-
-