diff options
author | grabinsk <maciej.grabinski@nokia.com> | 2019-06-21 09:10:03 +0200 |
---|---|---|
committer | grabinsk <maciej.grabinski@nokia.com> | 2019-06-21 09:10:03 +0200 |
commit | 5763275d59e628eabcc08eae2aa1d32120d4c072 (patch) | |
tree | a0519e11dde5f99f95c83355a267168413e69880 /prh-app-server/src | |
parent | ffe51aaf7b04f7f8be60b3b4c2e9cedb011439fe (diff) |
Skip putting non-primitive values from CBS config into PRH app environment
Non-primitive properties are currently not used by app and cause serialization failure on 'actuator/env' endpoint.
The serialization issue is caused by fact, that swagger enforces switch to jackson and there are no proper gson's JsonObject serializers registered.
Change-Id: Id5cfb743282aeec7db88434f06815ae5cc9057a6
Issue-ID: DCAEGEN2-1544
Signed-off-by: grabinsk <maciej.grabinski@nokia.com>
Diffstat (limited to 'prh-app-server/src')
2 files changed, 19 insertions, 27 deletions
diff --git a/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverter.java b/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverter.java index bf4077b9..79bf4656 100644 --- a/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverter.java +++ b/prh-app-server/src/main/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverter.java @@ -20,12 +20,12 @@ package org.onap.dcaegen2.services.bootstrap; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import java.util.Map; -import java.util.stream.Collectors; + +import static java.util.stream.Collectors.toMap; class CbsJsonToPropertyMapConverter { @@ -34,8 +34,9 @@ class CbsJsonToPropertyMapConverter { Map<String, Object> convertToMap(JsonObject jsonObject) { verifyExpectedCbsJsonFormat(jsonObject); JsonObject config = jsonObject.getAsJsonObject(CBS_CONFIG_ROOT_PROPERTY); - return config.entrySet().stream().collect( - Collectors.toMap(Map.Entry::getKey, entry -> unpack(entry.getValue()))); + return config.entrySet().stream() + .filter(entry -> entry.getValue().isJsonPrimitive()) + .collect(toMap(Map.Entry::getKey, entry -> unpack(entry.getValue().getAsJsonPrimitive()))); } private static void verifyExpectedCbsJsonFormat(JsonObject jsonObject) { @@ -45,20 +46,17 @@ class CbsJsonToPropertyMapConverter { } } - private Object unpack(JsonElement value) { - if (value.isJsonPrimitive()) { - JsonPrimitive primitiveValue = value.getAsJsonPrimitive(); - if (primitiveValue.isString()) { - return primitiveValue.getAsString(); - } - if (primitiveValue.isBoolean()) { - return primitiveValue.getAsBoolean(); - } - if (primitiveValue.isNumber()) { - return primitiveValue.getAsLong(); - } + private Object unpack(JsonPrimitive value) { + if (value.isString()) { + return value.getAsString(); + } + if (value.isBoolean()) { + return value.getAsBoolean(); + } + if (value.isNumber()) { + return value.getAsLong(); } - return value; + throw new IllegalArgumentException("Unexpected JsonPrimitive type found in configuration form CBS: " + value); } } diff --git a/prh-app-server/src/test/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverterTest.java b/prh-app-server/src/test/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverterTest.java index da9a0008..55e1b014 100644 --- a/prh-app-server/src/test/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverterTest.java +++ b/prh-app-server/src/test/java/org/onap/dcaegen2/services/bootstrap/CbsJsonToPropertyMapConverterTest.java @@ -22,7 +22,6 @@ package org.onap.dcaegen2.services.bootstrap; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import org.assertj.core.api.Condition; import org.junit.jupiter.api.Test; import java.util.Map; @@ -38,6 +37,7 @@ class CbsJsonToPropertyMapConverterTest { " \"someStringProp\": \"foo\",\n" + " \"someNumericalProp\": 123,\n" + " \"someBooleanProp\": true,\n" + + " \"someArrayProp\": [],\n" + " \"someObjectProp\": {\n" + " \"bar\": \"baz\"\n" + " }\n" + @@ -58,10 +58,11 @@ class CbsJsonToPropertyMapConverterTest { } @Test - void shouldLeaveComplexPropertiesAsJsonTypes() { + void shouldSkipComplexProperties() { Map<String, Object> map = cbsJsonToPropertyMapConverter.convertToMap(SOME_JSON_FROM_CBS); - assertThat(map).hasEntrySatisfying("someObjectProp", hasClass(JsonObject.class)); + assertThat(map).doesNotContainKeys("someObjectProp"); + assertThat(map).doesNotContainKeys("someArrayProp"); } @Test @@ -76,11 +77,4 @@ class CbsJsonToPropertyMapConverterTest { return new JsonParser().parse(jsonString).getAsJsonObject(); } - private static Condition<Object> hasClass(Class clazz) { - return new Condition<Object>(clazz.getCanonicalName()){ - public boolean matches(Object value) { - return value.getClass().equals(clazz); - } - }; - } }
\ No newline at end of file |