CPS-265 - updating cps path to support include-descendants option.
[cps.git] / cps-ri / src / main / java / org / onap / cps / spi / impl / CpsDataPersistenceServiceImpl.java
index fd4e768..0c61c99 100644 (file)
@@ -38,6 +38,7 @@ import org.onap.cps.spi.entities.DataspaceEntity;
 import org.onap.cps.spi.entities.FragmentEntity;
 import org.onap.cps.spi.model.DataNode;
 import org.onap.cps.spi.model.DataNodeBuilder;
+import org.onap.cps.spi.query.CpsPathQuery;
 import org.onap.cps.spi.repository.AnchorRepository;
 import org.onap.cps.spi.repository.DataspaceRepository;
 import org.onap.cps.spi.repository.FragmentRepository;
@@ -124,6 +125,20 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, xpath);
     }
 
+    @Override
+    public List<DataNode> queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath,
+        final FetchDescendantsOption fetchDescendantsOption) {
+        final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+        final AnchorEntity anchorEntity = anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName);
+        final CpsPathQuery cpsPathQuery = CpsPathQuery.createFrom(cpsPath);
+        final List<FragmentEntity> fragmentEntities = fragmentRepository
+            .getByAnchorAndXpathAndLeafAttributes(anchorEntity.getId(), cpsPathQuery
+                .getXpathPrefix(), cpsPathQuery.getLeafName(), cpsPathQuery.getLeafValue());
+        return fragmentEntities.stream()
+            .map(fragmentEntity -> toDataNode(fragmentEntity, fetchDescendantsOption))
+            .collect(Collectors.toUnmodifiableList());
+    }
+
     private static DataNode toDataNode(final FragmentEntity fragmentEntity,
         final FetchDescendantsOption fetchDescendantsOption) {
         final Map<String, Object> leaves = GSON.fromJson(fragmentEntity.getAttributes(), Map.class);