Merge "Use PollingConditions to improve intermittent test failure"
[cps.git] / cps-service / src / main / java / org / onap / cps / api / impl / CpsDataServiceImpl.java
old mode 100755 (executable)
new mode 100644 (file)
index a1bae6a..b3f4227
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2021-2023 Nordix Foundation
+ *  Copyright (C) 2021-2024 Nordix Foundation
  *  Modifications Copyright (C) 2020-2022 Bell Canada.
  *  Modifications Copyright (C) 2021 Pantheon.tech
  *  Modifications Copyright (C) 2022-2023 TechMahindra Ltd.
@@ -48,9 +48,8 @@ import org.onap.cps.spi.model.DataNodeBuilder;
 import org.onap.cps.spi.model.DeltaReport;
 import org.onap.cps.spi.utils.CpsValidator;
 import org.onap.cps.utils.ContentType;
-import org.onap.cps.utils.TimedYangParser;
+import org.onap.cps.utils.YangParser;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.springframework.stereotype.Service;
 
 @Service
@@ -63,9 +62,8 @@ public class CpsDataServiceImpl implements CpsDataService {
 
     private final CpsDataPersistenceService cpsDataPersistenceService;
     private final CpsAnchorService cpsAnchorService;
-    private final YangTextSchemaSourceSetCache yangTextSchemaSourceSetCache;
     private final CpsValidator cpsValidator;
-    private final TimedYangParser timedYangParser;
+    private final YangParser yangParser;
     private final CpsDeltaService cpsDeltaService;
 
     @Override
@@ -105,9 +103,9 @@ public class CpsDataServiceImpl implements CpsDataService {
 
     @Override
     @Timed(value = "cps.data.service.list.element.save",
-        description = "Time taken to save a list element")
-    public void saveListElements(final String dataspaceName, final String anchorName,
-        final String parentNodeXpath, final String jsonData, final OffsetDateTime observedTimestamp) {
+        description = "Time taken to save list elements")
+    public void saveListElements(final String dataspaceName, final String anchorName, final String parentNodeXpath,
+                                 final String jsonData, final OffsetDateTime observedTimestamp) {
         cpsValidator.validateNameCharacters(dataspaceName, anchorName);
         final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
         final Collection<DataNode> listElementDataNodeCollection =
@@ -120,19 +118,6 @@ public class CpsDataServiceImpl implements CpsDataService {
         }
     }
 
-    @Override
-    @Timed(value = "cps.data.service.list.element.batch.save",
-        description = "Time taken to save a batch of list elements")
-    public void saveListElementsBatch(final String dataspaceName, final String anchorName, final String parentNodeXpath,
-            final Collection<String> jsonDataList, final OffsetDateTime observedTimestamp) {
-        cpsValidator.validateNameCharacters(dataspaceName, anchorName);
-        final Anchor anchor = cpsAnchorService.getAnchor(dataspaceName, anchorName);
-        final Collection<Collection<DataNode>> listElementDataNodeCollections =
-                buildDataNodes(anchor, parentNodeXpath, jsonDataList, ContentType.JSON);
-        cpsDataPersistenceService.addMultipleLists(dataspaceName, anchorName, parentNodeXpath,
-                listElementDataNodeCollections);
-    }
-
     @Override
     @Timed(value = "cps.data.service.datanode.get",
             description = "Time taken to get data nodes for an xpath")
@@ -322,10 +307,9 @@ public class CpsDataServiceImpl implements CpsDataService {
 
     private Collection<DataNode> buildDataNodes(final Anchor anchor, final String parentNodeXpath,
                                                 final String nodeData, final ContentType contentType) {
-        final SchemaContext schemaContext = getSchemaContext(anchor);
 
         if (ROOT_NODE_XPATH.equals(parentNodeXpath)) {
-            final ContainerNode containerNode = timedYangParser.parseData(contentType, nodeData, schemaContext);
+            final ContainerNode containerNode = yangParser.parseData(contentType, nodeData, anchor, "");
             final Collection<DataNode> dataNodes = new DataNodeBuilder()
                     .withContainerNode(containerNode)
                     .buildCollection();
@@ -336,7 +320,7 @@ public class CpsDataServiceImpl implements CpsDataService {
         }
         final String normalizedParentNodeXpath = CpsPathUtil.getNormalizedXpath(parentNodeXpath);
         final ContainerNode containerNode =
-            timedYangParser.parseData(contentType, nodeData, schemaContext, normalizedParentNodeXpath);
+            yangParser.parseData(contentType, nodeData, anchor, normalizedParentNodeXpath);
         final Collection<DataNode> dataNodes = new DataNodeBuilder()
             .withParentNodeXpath(normalizedParentNodeXpath)
             .withContainerNode(containerNode)
@@ -347,18 +331,6 @@ public class CpsDataServiceImpl implements CpsDataService {
         return dataNodes;
     }
 
-    private Collection<Collection<DataNode>> buildDataNodes(final Anchor anchor, final String parentNodeXpath,
-                                                            final Collection<String> nodeDataList,
-                                                            final ContentType contentType) {
-        return nodeDataList.stream()
-            .map(nodeData -> buildDataNodes(anchor, parentNodeXpath, nodeData, contentType))
-            .collect(Collectors.toList());
-    }
-
-    private SchemaContext getSchemaContext(final Anchor anchor) {
-        return yangTextSchemaSourceSetCache
-            .get(anchor.getDataspaceName(), anchor.getSchemaSetName()).getSchemaContext();
-    }
 
     private static boolean isRootNodeXpath(final String xpath) {
         return ROOT_NODE_XPATH.equals(xpath);