package org.onap.cps.spi.impl;
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.ImmutableSet.Builder;
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;
return fragmentRepository.getByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, xpath);
}
+ @Override
+ public List<DataNode> queryDataNodes(final String dataspaceName, final String anchorName, final String cpsPath) {
+ 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, OMIT_DESCENDANTS))
+ .collect(Collectors.toUnmodifiableList());
+ }
+
private static DataNode toDataNode(final FragmentEntity fragmentEntity,
final FetchDescendantsOption fetchDescendantsOption) {
final Map<String, Object> leaves = GSON.fromJson(fragmentEntity.getAttributes(), Map.class);