summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorvasraz <vasyl.razinkov@est.tech>2022-12-15 10:12:06 +0000
committerVasyl Razinkov <vasyl.razinkov@est.tech>2022-12-15 18:44:43 +0000
commita64c4b2e9ede88f2448bde3c80a36f3b5770ca57 (patch)
tree6a3a0b564bf22e1428b61b5c8901d44092e4bd6f /common
parentd1e9af11f6c846d97713d64dd8b5f7e15cd1af95 (diff)
Fix 'Tosca List Entry Schema failed to be recoginized with creating VSP'-bug
Signed-off-by: Vasyl Razinkov <vasyl.razinkov@est.tech> Change-Id: Id33f7eff96b06a1cfb5e3e5d967b4e17da14a9a8 Issue-ID: SDC-2851
Diffstat (limited to 'common')
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/CommonUtil.java23
-rw-r--r--common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/YamlUtil.java2
-rw-r--r--common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/CommonUtilTest.java17
3 files changed, 27 insertions, 15 deletions
diff --git a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/CommonUtil.java b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/CommonUtil.java
index d6ff22c501..66fac9338a 100644
--- a/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/CommonUtil.java
+++ b/common/onap-tosca-datatype/src/main/java/org/onap/sdc/tosca/services/CommonUtil.java
@@ -19,7 +19,6 @@
package org.onap.sdc.tosca.services;
import com.fasterxml.jackson.databind.ObjectMapper;
-import com.google.common.collect.ImmutableSet;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
@@ -30,13 +29,15 @@ import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import org.apache.commons.beanutils.BeanUtils;
+import org.onap.sdc.tosca.datatypes.model.EntrySchema;
public class CommonUtil {
public static final String DEFAULT = "default";
public static final String UNDERSCORE_DEFAULT = "_default";
- private static ImmutableSet<Class<?>> complexClassType = ImmutableSet
- .of(Map.class, String.class, Integer.class, Float.class, Double.class, Set.class, Object.class, List.class);
+ private static final String ENTRY_SCHEMA = "entry_schema";
+ private static final Set<Class<?>> complexClassType =
+ Set.of(Map.class, String.class, Integer.class, Float.class, Double.class, Set.class, Object.class, List.class);
private CommonUtil() {
throw new IllegalStateException("Utility class");
@@ -49,10 +50,22 @@ public class CommonUtil {
Map<String, Object> objectAsMap = getObjectAsMap(objectCandidate);
Field[] declaredFields = classToCreate.getDeclaredFields();
createSubObjectsUsingSetters(objectAsMap, declaredFields);
+ handleEntrySchema(objectAsMap);
T result = populateBean(objectAsMap, classToCreate);
return Optional.of(result);
}
+ private static void handleEntrySchema(final Map<String, Object> objectAsMap) {
+ if (objectAsMap.containsKey(ENTRY_SCHEMA)) {
+ final Object entrySchema = objectAsMap.get(ENTRY_SCHEMA);
+ if (entrySchema instanceof Map) {
+ objectAsMap.remove(ENTRY_SCHEMA);
+ final Map<String, String> map = (Map<String, String>) entrySchema;
+ objectAsMap.put(ENTRY_SCHEMA, new EntrySchema(map.get("type")));
+ }
+ }
+ }
+
public static void createSubObjectsUsingSetters(Map<String, Object> objectAsMap, Field[] declaredFields) throws Exception {
for (Field field : declaredFields) {
if (isComplexClass(field)) {
@@ -66,8 +79,8 @@ public class CommonUtil {
}
public static <T> T populateBean(Map<String, Object> propertiesMap, Class<T> classToCreate)
- throws IllegalAccessException, InstantiationException, InvocationTargetException {
- T result = classToCreate.newInstance();
+ throws IllegalAccessException, InstantiationException, InvocationTargetException, NoSuchMethodException {
+ T result = classToCreate.getDeclaredConstructor().newInstance();
BeanUtils.populate(result, propertiesMap);
return result;
}
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 d8e592d353..45409c3439 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
@@ -88,7 +88,7 @@ public class YamlUtil {
TypeDescription yamlFileDescription = new TypeDescription(typClass);
constructor.addTypeDescription(yamlFileDescription);
T yamlObj = new Yaml(constructor, new Representer(), new DumperOptions(), getLoaderOptions()).load(yamlContent);
- ;
+
//noinspection ResultOfMethodCallIgnored
yamlObj.toString();
return yamlObj;
diff --git a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/CommonUtilTest.java b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/CommonUtilTest.java
index d9d7f69157..74dd40c638 100644
--- a/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/CommonUtilTest.java
+++ b/common/onap-tosca-datatype/src/test/java/org/onap/sdc/tosca/services/CommonUtilTest.java
@@ -19,13 +19,13 @@
*/
package org.onap.sdc.tosca.services;
-import java.lang.reflect.InvocationTargetException;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
import java.util.HashMap;
import java.util.Map;
-import org.junit.Assert;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
-public class CommonUtilTest {
+class CommonUtilTest {
private static final String INT_FIELD_KEY = "field1";
private static final Integer INT_FIELD_VALUE = 1;
@@ -33,13 +33,12 @@ public class CommonUtilTest {
private static final String STRING_FIELD_VALUE = "abc";
@Test
- public void testPopulateBeanMethod()
- throws InstantiationException, IllegalAccessException, InvocationTargetException {
+ void testPopulateBeanMethod() throws Exception {
Map<String, Object> props = new HashMap<>();
props.put(INT_FIELD_KEY, INT_FIELD_VALUE);
props.put(STRING_FIELD_KEY, STRING_FIELD_VALUE);
TestModel testModel = CommonUtil.populateBean(props, TestModel.class);
- Assert.assertEquals(testModel.getField1(), INT_FIELD_VALUE);
- Assert.assertEquals(testModel.getField2(), STRING_FIELD_VALUE);
+ assertEquals(testModel.getField1(), INT_FIELD_VALUE);
+ assertEquals(testModel.getField2(), STRING_FIELD_VALUE);
}
-} \ No newline at end of file
+}