diff options
author | Niamh Core <niamh.core@est.tech> | 2021-09-03 15:37:52 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-09-03 15:37:52 +0000 |
commit | 1ce718a31547f9345286154170f230b9e89e5ee3 (patch) | |
tree | d5c2920d8c5a54b898874916cb996e37d14de1db /cps-ri/src/main/java | |
parent | cd048075b11eef88501619da0068d5eb6dd330f7 (diff) | |
parent | 008abaee59bb542d5a60e89fa7f4231cecf7bdf5 (diff) |
Merge "Ensure Leaf value retains Integer type"
Diffstat (limited to 'cps-ri/src/main/java')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java | 23 |
1 files changed, 20 insertions, 3 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java index af010f4fcd..7b3b726284 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java @@ -24,12 +24,15 @@ package org.onap.cps.spi.impl; import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableSet; import com.google.common.collect.ImmutableSet.Builder; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -50,6 +53,7 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedException; import org.onap.cps.spi.exceptions.ConcurrencyException; import org.onap.cps.spi.exceptions.CpsPathException; import org.onap.cps.spi.exceptions.DataNodeNotFoundException; +import org.onap.cps.spi.exceptions.DataValidationException; import org.onap.cps.spi.model.DataNode; import org.onap.cps.spi.model.DataNodeBuilder; import org.onap.cps.spi.repository.AnchorRepository; @@ -68,6 +72,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService private FragmentRepository fragmentRepository; + private final ObjectMapper objectMapper; + /** * Constructor. * @@ -80,6 +86,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService this.dataspaceRepository = dataspaceRepository; this.anchorRepository = anchorRepository; this.fragmentRepository = fragmentRepository; + this.objectMapper = new ObjectMapper(); } private static final Gson GSON = new GsonBuilder().create(); @@ -236,17 +243,27 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService return ancestorXpath; } - private static DataNode toDataNode(final FragmentEntity fragmentEntity, + private DataNode toDataNode(final FragmentEntity fragmentEntity, final FetchDescendantsOption fetchDescendantsOption) { - final Map<String, Object> leaves = GSON.fromJson(fragmentEntity.getAttributes(), Map.class); final List<DataNode> childDataNodes = getChildDataNodes(fragmentEntity, fetchDescendantsOption); + Map<String, Object> leaves = new HashMap<>(); + if (fragmentEntity.getAttributes() != null) { + try { + leaves = objectMapper.readValue(fragmentEntity.getAttributes(), Map.class); + } catch (final JsonProcessingException jsonProcessingException) { + final String message = "Parsing error occurred while processing fragmentEntity attributes."; + log.error(message); + throw new DataValidationException(message, + jsonProcessingException.getMessage(), jsonProcessingException); + } + } return new DataNodeBuilder() .withXpath(fragmentEntity.getXpath()) .withLeaves(leaves) .withChildDataNodes(childDataNodes).build(); } - private static List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity, + private List<DataNode> getChildDataNodes(final FragmentEntity fragmentEntity, final FetchDescendantsOption fetchDescendantsOption) { if (fetchDescendantsOption == INCLUDE_ALL_DESCENDANTS) { return fragmentEntity.getChildFragments().stream() |