[CPS] RI, Service: Code Refactoring 56/134356/3
authorraviteja.karumuri <raviteja.karumuri@est.tech>
Tue, 25 Apr 2023 18:41:29 +0000 (19:41 +0100)
committerRaviteja Karumuri <raviteja.karumuri@est.tech>
Wed, 26 Apr 2023 10:20:09 +0000 (10:20 +0000)
# Remove unused method "updateDataNodeAndDescendants"
# Remove unused production code

Issue-ID: CPS-1594
Signed-off-by: raviteja.karumuri <raviteja.karumuri@est.tech>
Change-Id: Id909e9da3e9181c181dfdfe62f051451d8e488a2

cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceIntegrationSpec.groovy
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceConcurrencySpec.groovy
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
cps-ri/src/test/groovy/org/onap/cps/spi/performance/CpsModuleReferenceRepositoryPerfTest.groovy
cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java

index 369e528..3d9105f 100644 (file)
@@ -493,21 +493,6 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         fragmentRepository.save(fragmentEntity);
     }
 
-    @Override
-    public void updateDataNodeAndDescendants(final String dataspaceName, final String anchorName,
-                                             final DataNode dataNode) {
-        final AnchorEntity anchorEntity = getAnchorEntity(dataspaceName, anchorName);
-        final FragmentEntity fragmentEntity = getFragmentEntity(anchorEntity, dataNode.getXpath());
-        updateFragmentEntityAndDescendantsWithDataNode(fragmentEntity, dataNode);
-        try {
-            fragmentRepository.save(fragmentEntity);
-        } catch (final StaleStateException staleStateException) {
-            throw new ConcurrencyException("Concurrent Transactions",
-                    String.format("dataspace :'%s', Anchor : '%s' and xpath: '%s' is updated by another transaction.",
-                            dataspaceName, anchorName, dataNode.getXpath()));
-        }
-    }
-
     @Override
     public void updateDataNodesAndDescendants(final String dataspaceName, final String anchorName,
                                               final Collection<DataNode> updatedDataNodes) {
index d25832b..8114f10 100755 (executable)
@@ -90,13 +90,6 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>,
     List<FragmentExtract> findByAnchorAndParentXpath(@Param("anchor") AnchorEntity anchorEntity,\r
                                                      @Param("parentXpath") String parentXpath);\r
 \r
-    @Query(value = "SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId,"\r
-            + " CAST(attributes AS TEXT) AS attributes"\r
-            + " FROM FRAGMENT WHERE "\r
-            + "( xpath = :parentXpath OR xpath LIKE CONCAT(:parentXpath,'/%') )",\r
-            nativeQuery = true)\r
-    List<FragmentExtract> findByParentXpath(@Param("parentXpath") String parentXpath);\r
-\r
     @Query(value = "SELECT id, anchor_id AS anchorId, xpath, parent_id AS parentId,"\r
         + " CAST(attributes AS TEXT) AS attributes"\r
         + " FROM FRAGMENT WHERE anchor_id = :anchorId"\r
index e60afa7..93d7662 100755 (executable)
@@ -23,7 +23,6 @@
 
 package org.onap.cps.spi.impl
 
-import com.fasterxml.jackson.databind.ObjectMapper
 import com.google.common.collect.ImmutableSet
 import org.onap.cps.spi.CpsDataPersistenceService
 import org.onap.cps.spi.entities.FragmentEntity
@@ -35,7 +34,6 @@ import org.onap.cps.spi.exceptions.DataNodeNotFoundException
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
 import org.onap.cps.spi.model.DataNode
 import org.onap.cps.spi.model.DataNodeBuilder
-import org.onap.cps.utils.JsonObjectMapper
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.jdbc.Sql
 
@@ -49,7 +47,6 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     @Autowired
     CpsDataPersistenceService objectUnderTest
 
-    static JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
     static DataNodeBuilder dataNodeBuilder = new DataNodeBuilder()
 
     static final String SET_DATA = '/data/fragment.sql'
@@ -353,11 +350,11 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
-    def 'Update data node and descendants by removing descendants.'() {
-        given: 'data node object with leaves updated, no children'
-            def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [])
+    def 'Update data nodes and descendants by removing descendants.'() {
+        given: 'data nodes with leaves updated, no children'
+            def submittedDataNodes = [buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [])]
         when: 'update data nodes and descendants is performed'
-            objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
+            objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes)
         then: 'leaves have been updated for selected data node'
             def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID)
             def updatedLeaves = getLeavesMap(updatedFragment)
@@ -370,13 +367,13 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
-    def 'Update data node and descendants with new descendants'() {
-        given: 'data node object with leaves updated, having child with old content'
-            def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+    def 'Update data nodes and descendants with new descendants'() {
+        given: 'data nodes with leaves updated, having child with old content'
+            def submittedDataNodes = [buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
                   buildDataNode('/parent-200/child-201/grand-child', ['leaf-value': 'original'], [])
-            ])
+            ])]
         when: 'update is performed including descendants'
-            objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
+            objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes)
         then: 'leaves have been updated for selected data node'
             def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID)
             def updatedLeaves = getLeavesMap(updatedFragment)
@@ -390,13 +387,13 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
-    def 'Update data node and descendants with same descendants but changed leaf value.'() {
-        given: 'data node object with leaves updated, having child with old content'
-            def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+    def 'Update data nodes and descendants with same descendants but changed leaf value.'() {
+        given: 'data nodes with leaves updated, having child with old content'
+            def submittedDataNodes = [buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
                     buildDataNode('/parent-200/child-201/grand-child', ['leaf-value': 'new'], [])
-            ])
+            ])]
         when: 'update is performed including descendants'
-            objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
+            objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes)
         then: 'leaves have been updated for selected data node'
             def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID)
             def updatedLeaves = getLeavesMap(updatedFragment)
@@ -410,13 +407,13 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
-    def 'Update data node and descendants with different descendants xpath'() {
-        given: 'data node object with leaves updated, having child with old content'
-            def submittedDataNode = buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
+    def 'Update data nodes and descendants with different descendants xpath'() {
+        given: 'data nodes with leaves updated, having child with old content'
+            def submittedDataNodes = [buildDataNode('/parent-200/child-201', ['leaf-value': 'new'], [
                     buildDataNode('/parent-200/child-201/grand-child-new', ['leaf-value': 'new'], [])
-            ])
+            ])]
         when: 'update is performed including descendants'
-            objectUnderTest.updateDataNodeAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNode)
+            objectUnderTest.updateDataNodesAndDescendants(DATASPACE_NAME, ANCHOR_FOR_DATA_NODES_WITH_LEAVES, submittedDataNodes)
         then: 'leaves have been updated for selected data node'
             def updatedFragment = fragmentRepository.getById(DATA_NODE_202_FRAGMENT_ID)
             def updatedLeaves = getLeavesMap(updatedFragment)
@@ -432,19 +429,17 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
-    def 'Update data node and descendants error scenario: #scenario.'() {
-        given: 'data node object'
-            def submittedDataNode = buildDataNode(xpath, ['leaf-name': 'leaf-value'], [])
+    def 'Update data nodes and descendants error scenario: #scenario.'() {
+        given: 'data nodes collection'
+            def submittedDataNodes = [buildDataNode(xpath, ['leaf-name': 'leaf-value'], [])]
         when: 'attempt to update data node for #scenario'
-            objectUnderTest.updateDataNodeAndDescendants(dataspaceName, anchorName, submittedDataNode)
+            objectUnderTest.updateDataNodesAndDescendants(dataspaceName, anchorName, submittedDataNodes)
         then: 'a #expectedException is thrown'
             thrown(expectedException)
         where: 'the following data is used'
             scenario                 | dataspaceName  | anchorName                        | xpath                 || expectedException
             'non-existing dataspace' | 'NO DATASPACE' | 'not relevant'                    | '/not relevant'       || DataspaceNotFoundException
             'non-existing anchor'    | DATASPACE_NAME | 'NO ANCHOR'                       | '/not relevant'       || AnchorNotFoundException
-            'non-existing xpath'     | DATASPACE_NAME | ANCHOR_FOR_DATA_NODES_WITH_LEAVES | '/NON-EXISTING-XPATH' || DataNodeNotFoundException
-            'invalid xpath'          | DATASPACE_NAME | ANCHOR_FOR_DATA_NODES_WITH_LEAVES | 'INVALID XPATH'       || CpsPathException
     }
 
     @Sql([CLEAR_DATA, SET_DATA])
@@ -699,7 +694,7 @@ class CpsDataPersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
         return dataNodeBuilder.withXpath(xpath).withLeaves(leaves).withChildDataNodes(childDataNodes).build()
     }
 
-    static Map<String, Object> getLeavesMap(FragmentEntity fragmentEntity) {
+    Map<String, Object> getLeavesMap(FragmentEntity fragmentEntity) {
         return jsonObjectMapper.convertJsonString(fragmentEntity.attributes, Map<String, Object>.class)
     }
 
index f02aa75..204b934 100644 (file)
@@ -77,24 +77,6 @@ class CpsDataPersistenceServiceSpec extends Specification {
             1 * objectUnderTest.storeDataNodes('dataspace1', 'anchor1', [dataNode])
     }
 
-    def 'Handling of StaleStateException (caused by concurrent updates) during update data node and descendants.'() {
-        given: 'the fragment repository returns a fragment entity'
-            mockFragmentRepository.getByAnchorAndXpath(*_) >> {
-                def fragmentEntity = new FragmentEntity()
-                fragmentEntity.setChildFragments([new FragmentEntity()] as Set<FragmentEntity>)
-                return fragmentEntity
-            }
-        and: 'a data node is concurrently updated by another transaction'
-            mockFragmentRepository.save(_) >> { throw new StaleStateException("concurrent updates") }
-        when: 'attempt to update data node with submitted data nodes'
-            objectUnderTest.updateDataNodeAndDescendants('some-dataspace', 'some-anchor', new DataNodeBuilder().withXpath('/some/xpath').build())
-        then: 'concurrency exception is thrown'
-            def concurrencyException = thrown(ConcurrencyException)
-            assert concurrencyException.getDetails().contains('some-dataspace')
-            assert concurrencyException.getDetails().contains('some-anchor')
-            assert concurrencyException.getDetails().contains('/some/xpath')
-    }
-
     def 'Handling of StaleStateException (caused by concurrent updates) during update data nodes and descendants.'() {
         given: 'the system can update one datanode and has two more datanodes that throw an exception while updating'
             def dataNodes = createDataNodesAndMockRepositoryMethodSupportingThem([
index 214fd69..65d63df 100644 (file)
@@ -1,6 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada.
+ *  Modifications Copyright (C) 2021-2023 Nordix Foundation.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the 'License');
  *  you may not use this file except in compliance with the License.
  */
 package org.onap.cps.spi.impl
 
-import com.fasterxml.jackson.databind.ObjectMapper
+
 import org.hibernate.exception.ConstraintViolationException
-import org.onap.cps.spi.CpsAdminPersistenceService
 import org.onap.cps.spi.CpsModulePersistenceService
 import org.onap.cps.spi.entities.DataspaceEntity
 import org.onap.cps.spi.exceptions.DuplicatedYangResourceException
 import org.onap.cps.spi.model.ModuleReference
-import org.onap.cps.spi.repository.AnchorRepository
 import org.onap.cps.spi.repository.DataspaceRepository
-import org.onap.cps.spi.repository.SchemaSetRepository
 import org.onap.cps.spi.repository.YangResourceRepository
-import org.onap.cps.utils.JsonObjectMapper
 import org.spockframework.spring.SpringBean
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.dao.DataIntegrityViolationException
@@ -43,24 +40,12 @@ class CpsModulePersistenceServiceConcurrencySpec extends CpsPersistenceSpecBase
     @Autowired
     CpsModulePersistenceService objectUnderTest
 
-    @Autowired
-    AnchorRepository anchorRepository
-
-    @Autowired
-    SchemaSetRepository schemaSetRepository
-
-    @Autowired
-    CpsAdminPersistenceService cpsAdminPersistenceService
-
     @SpringBean
     YangResourceRepository yangResourceRepositoryMock = Mock()
 
     @SpringBean
     DataspaceRepository dataspaceRepositoryMock = Mock()
 
-    @SpringBean
-    JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper())
-
     static final String DATASPACE_NAME = 'DATASPACE-001'
     static final String SCHEMA_SET_NAME_NEW = 'SCHEMA-SET-NEW'
     static final String NEW_RESOURCE_NAME = 'some new resource'
index 864b3e3..53f42f5 100644 (file)
@@ -30,31 +30,22 @@ import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
 import org.onap.cps.spi.model.ModuleDefinition
 import org.onap.cps.spi.model.ModuleReference
 import org.onap.cps.spi.model.SchemaSet
-import org.onap.cps.spi.repository.AnchorRepository
 import org.onap.cps.spi.repository.SchemaSetRepository
 import org.onap.cps.spi.repository.SchemaSetYangResourceRepositoryImpl
-import org.onap.cps.spi.repository.YangResourceRepository
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.jdbc.Sql
-import spock.lang.Ignore
 
 class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase {
 
     @Autowired
     CpsModulePersistenceService objectUnderTest
 
-    @Autowired
-    AnchorRepository anchorRepository
-
     @Autowired
     SchemaSetRepository schemaSetRepository
 
     @Autowired
     CpsAdminPersistenceService cpsAdminPersistenceService
 
-    @Autowired
-    YangResourceRepository yangResourceRepository
-
     final static String SET_DATA = '/data/schemaset.sql'
 
     def static EXISTING_SCHEMA_SET_NAME = SCHEMA_SET_NAME1
index 9b722cd..222a828 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  ============LICENSE_START=======================================================
- *  Copyright (C) 2022 Nordix Foundation
+ *  Copyright (C) 2022-2023 Nordix Foundation
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -24,7 +24,6 @@ import org.onap.cps.spi.CpsModulePersistenceService
 import org.onap.cps.spi.entities.SchemaSetEntity
 import org.onap.cps.spi.impl.CpsPersistenceSpecBase
 import org.onap.cps.spi.model.ModuleReference
-import org.onap.cps.spi.repository.DataspaceRepository
 import org.onap.cps.spi.repository.ModuleReferenceRepository
 import org.onap.cps.spi.repository.SchemaSetRepository
 import org.springframework.beans.factory.annotation.Autowired
@@ -52,9 +51,6 @@ class CpsModuleReferenceRepositoryPerfTest extends CpsPersistenceSpecBase {
     @Autowired
     CpsModulePersistenceService objectUnderTest
 
-    @Autowired
-    DataspaceRepository dataspaceRepository
-
     @Autowired
     SchemaSetRepository schemaSetRepository
 
index 5404019..949fbc2 100644 (file)
@@ -137,15 +137,6 @@ public interface CpsDataPersistenceService {
      */
     void updateDataLeaves(String dataspaceName, String anchorName, String xpath, Map<String, Serializable> leaves);
 
-    /**
-     * Replaces an existing data node's content including descendants.
-     *
-     * @param dataspaceName dataspace name
-     * @param anchorName    anchor name
-     * @param dataNode      data node
-     */
-    void updateDataNodeAndDescendants(String dataspaceName, String anchorName, DataNode dataNode);
-
     /**
      * Replaces multiple existing data nodes' content including descendants in a batch operation.
      *