aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java/org/onap
diff options
context:
space:
mode:
authorLathish <lathishbabu.ganesan@est.tech>2022-03-31 17:29:22 +0100
committerLathish <lathishbabu.ganesan@est.tech>2022-04-25 18:33:28 +0100
commit2f09266fd3231529e41ce97b02577bc5b82a8c03 (patch)
treed3c2dc83eadd5904775ecfa2621152d9d0e73da8 /cps-ri/src/main/java/org/onap
parent3a13b2e965569304822fe4d56838a4fee4e7ad44 (diff)
Fix Absolute Path to list with Integer/String key
- Introduced normalizedXpath to normalize the xpath and cpspath - Introduced normalizedAncestorpath to normalize the ancestor path in xpath and cpspath - Added new condition in the ANTLR Grammar to capture the invalid path in the xpath - Introduced PathParsingException to replace the IllegalStateException Issue-ID: CPS-961 Change-Id: Ie10f5c6cfc466387e79eec184b933297d1d79587 Signed-off-by: Lathish <lathishbabu.ganesan@est.tech>
Diffstat (limited to 'cps-ri/src/main/java/org/onap')
-rw-r--r--cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java22
1 files changed, 16 insertions, 6 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 bb3c2d07d..847a1d129 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
@@ -41,6 +41,8 @@ import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.StaleStateException;
import org.onap.cps.cpspath.parser.CpsPathQuery;
+import org.onap.cps.cpspath.parser.CpsPathUtil;
+import org.onap.cps.cpspath.parser.PathParsingException;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.entities.AnchorEntity;
@@ -174,8 +176,14 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
if (isRootXpath(xpath)) {
return fragmentRepository.findFirstRootByDataspaceAndAnchor(dataspaceEntity, anchorEntity);
} else {
+ final String normalizedXpath;
+ try {
+ normalizedXpath = CpsPathUtil.getNormalizedXpath(xpath);
+ } catch (final PathParsingException e) {
+ throw new CpsPathException(e.getMessage());
+ }
return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity,
- xpath);
+ normalizedXpath);
}
}
@@ -186,8 +194,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
final CpsPathQuery cpsPathQuery;
try {
- cpsPathQuery = CpsPathQuery.createFrom(cpsPath);
- } catch (final IllegalStateException e) {
+ cpsPathQuery = CpsPathUtil.getCpsPathQuery(cpsPath);
+ } catch (final PathParsingException e) {
throw new CpsPathException(e.getMessage());
}
List<FragmentEntity> fragmentEntities =
@@ -378,12 +386,13 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private boolean deleteDataNode(final FragmentEntity parentFragmentEntity, final String targetXpath) {
- if (parentFragmentEntity.getXpath().equals(targetXpath)) {
+ final String normalizedTargetXpath = CpsPathUtil.getNormalizedXpath(targetXpath);
+ if (parentFragmentEntity.getXpath().equals(normalizedTargetXpath)) {
fragmentRepository.delete(parentFragmentEntity);
return true;
}
if (parentFragmentEntity.getChildFragments()
- .removeIf(fragment -> fragment.getXpath().equals(targetXpath))) {
+ .removeIf(fragment -> fragment.getXpath().equals(normalizedTargetXpath))) {
fragmentRepository.save(parentFragmentEntity);
return true;
}
@@ -391,7 +400,8 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
}
private boolean deleteAllListElements(final FragmentEntity parentFragmentEntity, final String listXpath) {
- final String deleteTargetXpathPrefix = listXpath + "[";
+ final String normalizedListXpath = CpsPathUtil.getNormalizedXpath(listXpath);
+ final String deleteTargetXpathPrefix = normalizedListXpath + "[";
if (parentFragmentEntity.getChildFragments()
.removeIf(fragment -> fragment.getXpath().startsWith(deleteTargetXpathPrefix))) {
fragmentRepository.save(parentFragmentEntity);