diff options
author | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-22 12:50:19 +0000 |
---|---|---|
committer | danielhanrahan <daniel.hanrahan@est.tech> | 2024-11-26 11:45:32 +0000 |
commit | 05e97441ad192b69051fbb67263284eb99ee1c41 (patch) | |
tree | 947c2bb52fc266da64e202ebab446713fa98eddf | |
parent | e50b36d17de45bc64eebb305a80dc62ac4ee0928 (diff) |
Don't handle root xpath in getFragmentEntity
getFragmentEntity is an internal method only used for resovling
parent xpaths. The root xpath handling is never reachable.
- Remove root xpath handling in getFragmentEntity
- Clean up unneeded FragmentRepository code
Issue-ID: CPS-2511
Signed-off-by: danielhanrahan <daniel.hanrahan@est.tech>
Change-Id: I910065bdb2e7c5fbb7c67af87f3f68af6c0fd4e0
3 files changed, 5 insertions, 18 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java index b7e50815e6..bdbdc7cf36 100644 --- a/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/CpsDataPersistenceServiceImpl.java @@ -543,12 +543,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService } private FragmentEntity getFragmentEntity(final AnchorEntity anchorEntity, final String xpath) { - final FragmentEntity fragmentEntity; - if (isRootXpath(xpath)) { - fragmentEntity = fragmentRepository.findOneByAnchorId(anchorEntity.getId()).orElse(null); - } else { - fragmentEntity = fragmentRepository.getByAnchorAndXpath(anchorEntity, getNormalizedXpath(xpath)); - } + final FragmentEntity fragmentEntity = + fragmentRepository.findByAnchorIdAndXpath(anchorEntity.getId(), getNormalizedXpath(xpath)); if (fragmentEntity == null) { throw new DataNodeNotFoundException(anchorEntity.getDataspace().getName(), anchorEntity.getName(), xpath); } diff --git a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java index 9598230cdb..a8c1fd2d4e 100755 --- a/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/ri/repository/FragmentRepository.java @@ -25,12 +25,10 @@ package org.onap.cps.ri.repository; import java.util.Collection; import java.util.List; -import java.util.Optional; import org.onap.cps.ri.models.AnchorEntity; import org.onap.cps.ri.models.DataspaceEntity; import org.onap.cps.ri.models.FragmentEntity; import org.onap.cps.ri.utils.EscapeUtils; -import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -41,12 +39,8 @@ import org.springframework.stereotype.Repository; public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>, FragmentRepositoryCpsPathQuery, FragmentPrefetchRepository { - Optional<FragmentEntity> findByAnchorAndXpath(AnchorEntity anchorEntity, String xpath); - - default FragmentEntity getByAnchorAndXpath(final AnchorEntity anchorEntity, final String xpath) { - return findByAnchorAndXpath(anchorEntity, xpath).orElseThrow(() -> - new DataNodeNotFoundException(anchorEntity.getDataspace().getName(), anchorEntity.getName(), xpath)); - } + @Query(value = "SELECT * FROM fragment WHERE anchor_id = :anchorId AND xpath = :xpath", nativeQuery = true) + FragmentEntity findByAnchorIdAndXpath(@Param("anchorId") long anchorId, @Param("xpath") String xpath); @Query(value = "SELECT * FROM fragment WHERE anchor_id = :anchorId AND xpath IN (:xpaths)", nativeQuery = true) @@ -84,9 +78,6 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long>, List<FragmentEntity> findByAnchorIdsAndXpathIn(@Param("anchorIds") Collection<Long> anchorIds, @Param("xpaths") Collection<String> xpaths); - @Query(value = "SELECT * FROM fragment WHERE anchor_id = :anchorId LIMIT 1", nativeQuery = true) - Optional<FragmentEntity> findOneByAnchorId(@Param("anchorId") long anchorId); - @Modifying @Query(value = "DELETE FROM fragment WHERE anchor_id IN (:anchorIds)", nativeQuery = true) void deleteByAnchorIdIn(@Param("anchorIds") Collection<Long> anchorIds); diff --git a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy index 36bf55e2db..500fe76a90 100644 --- a/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy +++ b/cps-ri/src/test/groovy/org/onap/cps/ri/CpsDataPersistenceServiceImplSpec.groovy @@ -246,7 +246,7 @@ class CpsDataPersistenceServiceImplSpec extends Specification { def createDataNodeAndMockRepositoryMethodSupportingIt(xpath, scenario) { def dataNode = new DataNodeBuilder().withXpath(xpath).build() def fragmentEntity = new FragmentEntity(xpath: xpath, childFragments: []) - mockFragmentRepository.getByAnchorAndXpath(_, xpath) >> fragmentEntity + mockFragmentRepository.findByAnchorIdAndXpath(_, xpath) >> fragmentEntity if ('EXCEPTION' == scenario) { mockFragmentRepository.save(fragmentEntity) >> { throw new StaleStateException("concurrent updates") } } |