From 59fa1bffe797d2e03212f6037aee732b51e1cb92 Mon Sep 17 00:00:00 2001 From: danielhanrahan Date: Wed, 4 Dec 2024 23:17:36 +0000 Subject: Simple implementation of attribute-axis This minimally implements attribute-axis using existing queryDataNodes API. Acceptance tests are un-ignored now. Issue-ID: CPS-2416 Signed-off-by: danielhanrahan Change-Id: Ia06be3dd85dfce261d9d78529784d54d84b71bcd --- .../main/java/org/onap/cps/impl/CpsQueryServiceImpl.java | 4 ++-- .../java/org/onap/cps/spi/CpsDataPersistenceService.java | 14 +++++++++++++- .../org/onap/cps/impl/CpsQueryServiceImplSpec.groovy | 5 ++--- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'cps-service/src') diff --git a/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java b/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java index 2687d8faee..508a1b2449 100644 --- a/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/impl/CpsQueryServiceImpl.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2024 Nordix Foundation + * Copyright (C) 2021-2025 Nordix Foundation * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -54,7 +54,7 @@ public class CpsQueryServiceImpl implements CpsQueryService { public Set queryDataLeaf(final String dataspaceName, final String anchorName, final String cpsPath, final Class targetClass) { cpsValidator.validateNameCharacters(dataspaceName, anchorName); - throw new UnsupportedOperationException("Query by attribute-axis not implemented yet!"); + return cpsDataPersistenceService.queryDataLeaf(dataspaceName, anchorName, cpsPath, targetClass); } @Override diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java index 5be5b1e2e0..a4f05cdb53 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsDataPersistenceService.java @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2020-2024 Nordix Foundation. + * Copyright (C) 2020-2025 Nordix Foundation. * Modifications Copyright (C) 2021 Pantheon.tech * Modifications Copyright (C) 2022 Bell Canada * Modifications Copyright (C) 2022-2023 TechMahindra Ltd. @@ -27,6 +27,7 @@ import java.io.Serializable; import java.util.Collection; import java.util.List; import java.util.Map; +import java.util.Set; import org.onap.cps.api.model.DataNode; import org.onap.cps.api.parameters.FetchDescendantsOption; import org.onap.cps.api.parameters.PaginationOption; @@ -184,6 +185,17 @@ public interface CpsDataPersistenceService { List queryDataNodes(String dataspaceName, String anchorName, String cpsPath, FetchDescendantsOption fetchDescendantsOption); + /** + * Get data leaf for the given dataspace and anchor by cps path. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @param cpsPath cps path + * @param targetClass class of the expected data type + * @return a collection of data objects of expected type + */ + Set queryDataLeaf(String dataspaceName, String anchorName, String cpsPath, Class targetClass); + /** * Get a datanode by dataspace name and cps path across all anchors. * diff --git a/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy index 237e4e4592..b15ee72370 100644 --- a/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/impl/CpsQueryServiceImplSpec.groovy @@ -1,6 +1,6 @@ /* * ============LICENSE_START======================================================= - * Copyright (C) 2021-2023 Nordix Foundation + * Copyright (C) 2021-2025 Nordix Foundation * Modifications Copyright (C) 2023 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -73,11 +73,10 @@ class CpsQueryServiceImplSpec extends Specification { 1 * mockCpsDataPersistenceService.countAnchorsForDataspaceAndCpsPath("some-dataspace", "/cps-path") } - // TODO will be implemented in CPS-2416 def 'Query data leaf.'() { when: 'a query for a specific leaf is executed' objectUnderTest.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class) then: 'solution is not implemented yet' - thrown(UnsupportedOperationException) + 1 * mockCpsDataPersistenceService.queryDataLeaf('some-dataspace', 'some-anchor', '/cps-path/@id', Object.class) } } -- cgit