aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org
diff options
context:
space:
mode:
Diffstat (limited to 'cps-ncmp-service/src/main/java/org')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java (renamed from cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java)12
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java16
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java268
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java317
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java26
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java29
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java113
7 files changed, 339 insertions, 442 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java
index 7322ebc113..91e98e866b 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandleQueryService.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,18 +20,18 @@
package org.onap.cps.ncmp.api;
-import java.util.Set;
+import java.util.Collection;
import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-public interface NetworkCmProxyCmHandlerQueryService {
+public interface NetworkCmProxyCmHandleQueryService {
/**
* Query and return cm handles that match the given query parameters.
*
* @param cmHandleQueryServiceParameters the cm handle query parameters
* @return collection of cm handles
*/
- Set<NcmpServiceCmHandle> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<NcmpServiceCmHandle> queryCmHandles(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
/**
* Query and return cm handles that match the given query parameters.
@@ -39,7 +39,7 @@ public interface NetworkCmProxyCmHandlerQueryService {
* @param cmHandleQueryServiceParameters the cm handle query parameters
* @return collection of cm handle ids
*/
- Set<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
/**
* Query and return cm handles that match the given query parameters.
@@ -47,5 +47,5 @@ public interface NetworkCmProxyCmHandlerQueryService {
* @param cmHandleQueryServiceParameters the cm handle query parameters
* @return collection of cm handle ids
*/
- Set<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<String> queryCmHandleIdsForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
index c9810e9a66..128eed3f2c 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java
@@ -1,7 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2021 highstreet technologies GmbH
- * Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2021-2023 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 Bell Canada
* ================================================================================
@@ -27,7 +27,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum
import java.util.Collection;
import java.util.Map;
-import java.util.Set;
import org.onap.cps.ncmp.api.inventory.CompositeState;
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
@@ -159,7 +158,7 @@ public interface NetworkCmProxyDataService {
* @param cmHandleQueryApiParameters the cm handle query parameters
* @return collection of cm handles
*/
- Set<NcmpServiceCmHandle> executeCmHandleSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
+ Collection<NcmpServiceCmHandle> executeCmHandleSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
/**
* Query and return cm handle ids that match the given query parameters.
@@ -167,7 +166,7 @@ public interface NetworkCmProxyDataService {
* @param cmHandleQueryApiParameters the cm handle query parameters
* @return collection of cm handle ids
*/
- Set<String> executeCmHandleIdSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
+ Collection<String> executeCmHandleIdSearch(CmHandleQueryApiParameters cmHandleQueryApiParameters);
/**
* Set the data sync enabled flag, along with the data sync state to true or false based on the cm handle id.
@@ -181,15 +180,16 @@ public interface NetworkCmProxyDataService {
* Get all cm handle IDs by DMI plugin identifier.
*
* @param dmiPluginIdentifier DMI plugin identifier
- * @return set of cm handle IDs
+ * @return collection of cm handle IDs
*/
- Set<String> getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
+ Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
/**
* Get all cm handle IDs by various search criteria.
*
* @param cmHandleQueryServiceParameters cm handle query parameters
- * @return set of cm handle IDs
+ * @return collection of cm handle IDs
*/
- Set<String> executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+ Collection<String> executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters
+ cmHandleQueryServiceParameters);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java
new file mode 100644
index 0000000000..54d89ba00e
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandleQueryServiceImpl.java
@@ -0,0 +1,268 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022-2023 Nordix Foundation
+ * Modifications Copyright (C) 2023 TechMahindra Ltd.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.api.impl;
+
+import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_MODULES;
+import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.HAS_ALL_PROPERTIES;
+import static org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions.WITH_CPS_PATH;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties;
+import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
+import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY;
+import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.cpspath.parser.PathParsingException;
+import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
+import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
+import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
+import org.onap.cps.ncmp.api.impl.yangmodels.YangModelCmHandle;
+import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
+import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
+import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
+import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
+import org.onap.cps.spi.exceptions.DataValidationException;
+import org.onap.cps.spi.model.ConditionProperties;
+import org.onap.cps.spi.model.DataNode;
+import org.springframework.stereotype.Service;
+
+@Service
+@Slf4j
+@RequiredArgsConstructor
+public class NetworkCmProxyCmHandleQueryServiceImpl implements NetworkCmProxyCmHandleQueryService {
+
+ private static final Collection<String> NO_QUERY_TO_EXECUTE = null;
+ private final CmHandleQueries cmHandleQueries;
+ private final InventoryPersistence inventoryPersistence;
+
+ @Override
+ public Collection<String> queryCmHandleIds(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ return executeQueries(cmHandleQueryServiceParameters,
+ this::executeCpsPathQuery,
+ this::queryCmHandlesByPublicProperties,
+ this::executeModuleNameQuery);
+ }
+
+ @Override
+ public Collection<String> queryCmHandleIdsForInventory(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ return executeQueries(cmHandleQueryServiceParameters,
+ this::queryCmHandlesByPublicProperties,
+ this::queryCmHandlesByPrivateProperties,
+ this::queryCmHandlesByDmiPlugin);
+ }
+
+ @Override
+ public Collection<NcmpServiceCmHandle> queryCmHandles(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+ if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
+ return getAllCmHandles();
+ }
+
+ final Collection<String> cmHandleIds = queryCmHandleIds(cmHandleQueryServiceParameters);
+
+ return getNcmpServiceCmHandles(cmHandleIds);
+ }
+
+ private Collection<String> queryCmHandlesByDmiPlugin(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final Map<String, String> dmiPropertyQueryPairs =
+ getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+ InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName());
+ if (dmiPropertyQueryPairs.isEmpty()) {
+ return NO_QUERY_TO_EXECUTE;
+ }
+
+ final String dmiPluginIdentifierValue = dmiPropertyQueryPairs
+ .get(PropertyType.DMI_PLUGIN.getYangContainerName());
+
+ return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifierValue);
+ }
+
+ private Collection<String> queryCmHandlesByPrivateProperties(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+ final Map<String, String> privatePropertyQueryPairs =
+ getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+ InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName());
+
+ return privatePropertyQueryPairs.isEmpty()
+ ? NO_QUERY_TO_EXECUTE
+ : cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
+ }
+
+ private Collection<String> queryCmHandlesByPublicProperties(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+
+ final Map<String, String> publicPropertyQueryPairs =
+ getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+ HAS_ALL_PROPERTIES.getConditionName());
+
+ return publicPropertyQueryPairs.isEmpty()
+ ? NO_QUERY_TO_EXECUTE
+ : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
+ }
+
+ private Collection<String> executeModuleNameQuery(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final Collection<String> moduleNamesForQuery =
+ getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (moduleNamesForQuery.isEmpty()) {
+ return NO_QUERY_TO_EXECUTE;
+ }
+ return inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery);
+ }
+
+ private Collection<String> executeCpsPathQuery(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ final Map<String, String> cpsPathCondition
+ = getCpsPathCondition(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ if (!validateCpsPathConditionProperties(cpsPathCondition)) {
+ return Collections.emptySet();
+ }
+ final Collection<String> cpsPathQueryResult;
+ if (cpsPathCondition.isEmpty()) {
+ return NO_QUERY_TO_EXECUTE;
+ }
+ try {
+ cpsPathQueryResult = collectCmHandleIdsFromDataNodes(
+ cmHandleQueries.queryCmHandleDataNodesByCpsPath(cpsPathCondition.get("cpsPath"), OMIT_DESCENDANTS));
+ } catch (final PathParsingException pathParsingException) {
+ throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
+ pathParsingException);
+ }
+ return cpsPathQueryResult;
+ }
+
+ private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
+ final List<String> result = new ArrayList<>();
+ getConditions(conditionProperties, HAS_ALL_MODULES.getConditionName()).forEach(
+ conditionProperty -> {
+ validateModuleNameConditionProperties(conditionProperty);
+ result.add(conditionProperty.get("moduleName"));
+ });
+ return result;
+ }
+
+ private Map<String, String> getCpsPathCondition(final List<ConditionProperties> conditionProperties) {
+ final Map<String, String> result = new HashMap<>();
+ getConditions(conditionProperties, WITH_CPS_PATH.getConditionName()).forEach(result::putAll);
+ return result;
+ }
+
+ private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
+ final String queryProperty) {
+ final Map<String, String> result = new HashMap<>();
+ getConditions(conditionProperties, queryProperty).forEach(result::putAll);
+ return result;
+ }
+
+ private List<Map<String, String>> getConditions(final List<ConditionProperties> conditionProperties,
+ final String name) {
+ for (final ConditionProperties conditionProperty : conditionProperties) {
+ if (conditionProperty.getConditionName().equals(name)) {
+ return conditionProperty.getConditionParameters();
+ }
+ }
+ return Collections.emptyList();
+ }
+
+ private Collection<NcmpServiceCmHandle> getAllCmHandles() {
+ final DataNode dataNode = inventoryPersistence.getDataNode("/dmi-registry").iterator().next();
+ return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
+ }
+
+ private Collection<String> getAllCmHandleIds() {
+ final DataNode dataNode = inventoryPersistence.getDataNode("/dmi-registry", DIRECT_CHILDREN_ONLY)
+ .iterator().next();
+ return collectCmHandleIdsFromDataNodes(dataNode.getChildDataNodes());
+ }
+
+ private Collection<NcmpServiceCmHandle> getNcmpServiceCmHandles(final Collection<String> cmHandleIds) {
+ final Collection<YangModelCmHandle> yangModelcmHandles
+ = inventoryPersistence.getYangModelCmHandles(cmHandleIds);
+
+ final Collection<NcmpServiceCmHandle> ncmpServiceCmHandles = new ArrayList<>(yangModelcmHandles.size());
+
+ yangModelcmHandles.forEach(yangModelcmHandle ->
+ ncmpServiceCmHandles.add(YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle(yangModelcmHandle))
+ );
+ return ncmpServiceCmHandles;
+ }
+
+ private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
+ return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
+ .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
+ }
+
+ private Collection<String> executeQueries(final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final Function<CmHandleQueryServiceParameters, Collection<String>>...
+ queryFunctions) {
+ if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
+ return getAllCmHandleIds();
+ }
+ Collection<String> combinedQueryResult = NO_QUERY_TO_EXECUTE;
+ for (final Function<CmHandleQueryServiceParameters, Collection<String>> queryFunction : queryFunctions) {
+ final Collection<String> queryResult = queryFunction.apply(cmHandleQueryServiceParameters);
+ if (noEntriesFoundCanStopQuerying(queryResult)) {
+ return Collections.emptySet();
+ }
+ combinedQueryResult = combineCmHandleQueryResults(combinedQueryResult, queryResult);
+ }
+ return combinedQueryResult;
+ }
+
+ private boolean noEntriesFoundCanStopQuerying(final Collection<String> queryResult) {
+ return queryResult != NO_QUERY_TO_EXECUTE && queryResult.isEmpty();
+ }
+
+ private Collection<String> combineCmHandleQueryResults(final Collection<String> firstQuery,
+ final Collection<String> secondQuery) {
+ if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) {
+ return NO_QUERY_TO_EXECUTE;
+ } else if (firstQuery == NO_QUERY_TO_EXECUTE) {
+ return secondQuery;
+ } else if (secondQuery == NO_QUERY_TO_EXECUTE) {
+ return firstQuery;
+ } else {
+ firstQuery.retainAll(secondQuery);
+ return firstQuery;
+ }
+ }
+
+ private Collection<String> collectCmHandleIdsFromDataNodes(final Collection<DataNode> dataNodes) {
+ return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ }
+
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
deleted file mode 100644
index f6f042dc12..0000000000
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * ============LICENSE_START=======================================================
- * Copyright (C) 2022-2023 Nordix Foundation
- * Modifications Copyright (C) 2023 TechMahindra Ltd.
- * ================================================================================
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- * SPDX-License-Identifier: Apache-2.0
- * ============LICENSE_END=========================================================
- */
-
-package org.onap.cps.ncmp.api.impl;
-
-import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCpsPathConditionProperties;
-import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateModuleNameConditionProperties;
-import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
-import static org.onap.cps.spi.FetchDescendantsOption.DIRECT_CHILDREN_ONLY;
-import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.function.Function;
-import java.util.stream.Collectors;
-import lombok.RequiredArgsConstructor;
-import lombok.extern.slf4j.Slf4j;
-import org.onap.cps.cpspath.parser.PathParsingException;
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
-import org.onap.cps.ncmp.api.impl.utils.CmHandleQueryConditions;
-import org.onap.cps.ncmp.api.impl.utils.InventoryQueryConditions;
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
-import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
-import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
-import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
-import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.ConditionProperties;
-import org.onap.cps.spi.model.DataNode;
-import org.springframework.stereotype.Service;
-
-@Service
-@Slf4j
-@RequiredArgsConstructor
-public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCmHandlerQueryService {
-
- private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
- private final CmHandleQueries cmHandleQueries;
- private final InventoryPersistence inventoryPersistence;
-
- /**
- * Query and return cm handles that match the given query parameters.
- *
- * @param cmHandleQueryServiceParameters the cm handle query parameters
- * @return collection of cm handles
- */
- @Override
- public Set<NcmpServiceCmHandle> queryCmHandles(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-
- if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
- return getAllCmHandles();
- }
-
- final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
- cmHandleQueryServiceParameters);
-
- return new HashSet<>(combineWithModuleNameQuery(cmHandleQueryServiceParameters, combinedQueryResult).values());
- }
-
- /**
- * Query and return cm handles that match the given query parameters.
- *
- * @param cmHandleQueryServiceParameters the cm handle query parameters
- * @return collection of cm handle ids
- */
- @Override
- public Set<String> queryCmHandleIds(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-
- if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
- return getAllCmHandleIds();
- }
-
- final Map<String, NcmpServiceCmHandle> combinedQueryResult = executeInventoryQueries(
- cmHandleQueryServiceParameters);
-
- final Collection<String> moduleNamesForQuery =
- getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
- if (moduleNamesForQuery.isEmpty()) {
- return combinedQueryResult.keySet();
- }
- final Set<String> moduleNameQueryResult =
- new HashSet<>(inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery));
-
- if (combinedQueryResult == NO_QUERY_TO_EXECUTE) {
- return moduleNameQueryResult;
- }
-
- moduleNameQueryResult.retainAll(combinedQueryResult.keySet());
- return moduleNameQueryResult;
- }
-
- @Override
- public Set<String> queryCmHandleIdsForInventory(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-
- if (cmHandleQueryServiceParameters.getCmHandleQueryParameters().isEmpty()) {
- return getAllCmHandleIds();
- }
-
- final Map<String, NcmpServiceCmHandle> publicPropertiesQueryResult = queryCmHandlesByPublicProperties(
- cmHandleQueryServiceParameters);
- if (publicPropertiesQueryResult != null && publicPropertiesQueryResult.isEmpty()) {
- return Collections.emptySet();
- }
-
- final Map<String, NcmpServiceCmHandle> privatePropertiesQueryResult = queryCmHandlesByPrivateProperties(
- cmHandleQueryServiceParameters);
- if (privatePropertiesQueryResult != null && privatePropertiesQueryResult.isEmpty()) {
- return Collections.emptySet();
- }
-
- final Map<String, NcmpServiceCmHandle> dmiPropertiesQueryResult = queryCmHandlesByDmiPlugin(
- cmHandleQueryServiceParameters);
- if (dmiPropertiesQueryResult != null && dmiPropertiesQueryResult.isEmpty()) {
- return Collections.emptySet();
- }
-
- final Map<String, NcmpServiceCmHandle> combinedResult =
- combineQueryResults(publicPropertiesQueryResult, privatePropertiesQueryResult, dmiPropertiesQueryResult);
-
- return combinedResult.keySet();
- }
-
- private Map<String, NcmpServiceCmHandle> queryCmHandlesByDmiPlugin(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
- final Map<String, String> dmiPropertyQueryPairs =
- getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
- InventoryQueryConditions.CM_HANDLE_WITH_DMI_PLUGIN.getName());
- if (dmiPropertyQueryPairs.isEmpty()) {
- return NO_QUERY_TO_EXECUTE;
- }
-
- final String dmiPluginIdentifierValue = dmiPropertyQueryPairs.get(
- PropertyType.DMI_PLUGIN.getYangContainerName());
-
- final Set<NcmpServiceCmHandle> cmHandlesByDmiPluginIdentifier = cmHandleQueries
- .getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifierValue);
-
- return cmHandlesByDmiPluginIdentifier.stream()
- .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId, cmH -> cmH));
- }
-
- private Map<String, NcmpServiceCmHandle> queryCmHandlesByPrivateProperties(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-
- final Map<String, String> privatePropertyQueryPairs =
- getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
- InventoryQueryConditions.HAS_ALL_ADDITIONAL_PROPERTIES.getName());
-
- return privatePropertyQueryPairs.isEmpty()
- ? NO_QUERY_TO_EXECUTE
- : cmHandleQueries.queryCmHandleAdditionalProperties(privatePropertyQueryPairs);
- }
-
- private Map<String, NcmpServiceCmHandle> queryCmHandlesByPublicProperties(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
-
- final Map<String, String> publicPropertyQueryPairs =
- getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
- CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName());
-
- return publicPropertyQueryPairs.isEmpty()
- ? NO_QUERY_TO_EXECUTE
- : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
- }
-
- private Map<String, NcmpServiceCmHandle> combineQueryResults(
- final Map<String, NcmpServiceCmHandle> publicPropertiesQueryResult,
- final Map<String, NcmpServiceCmHandle> privatePropertiesQueryResult,
- final Map<String, NcmpServiceCmHandle> dmiPropertiesQueryResult) {
-
- final Map<String, NcmpServiceCmHandle> propertiesCombinedResult = cmHandleQueries
- .combineCmHandleQueries(publicPropertiesQueryResult, privatePropertiesQueryResult);
- return cmHandleQueries
- .combineCmHandleQueries(propertiesCombinedResult, dmiPropertiesQueryResult);
- }
-
- private Map<String, NcmpServiceCmHandle> combineWithModuleNameQuery(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
- final Map<String, NcmpServiceCmHandle> previousQueryResult) {
- final Collection<String> moduleNamesForQuery =
- getModuleNamesForQuery(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
- if (moduleNamesForQuery.isEmpty()) {
- return previousQueryResult;
- }
- final Collection<String> cmHandleIdsByModuleName =
- inventoryPersistence.getCmHandleIdsWithGivenModules(moduleNamesForQuery);
- if (cmHandleIdsByModuleName.isEmpty()) {
- return Collections.emptyMap();
- }
- final Map<String, NcmpServiceCmHandle> queryResult = new HashMap<>(cmHandleIdsByModuleName.size());
- if (previousQueryResult == NO_QUERY_TO_EXECUTE) {
- cmHandleIdsByModuleName.forEach(cmHandleId ->
- queryResult.put(cmHandleId, createNcmpServiceCmHandle(inventoryPersistence
- .getDataNode("/dmi-registry/cm-handles[@id='" + cmHandleId + "']").iterator().next()))
- );
- return queryResult;
- }
- previousQueryResult.keySet().retainAll(cmHandleIdsByModuleName);
- queryResult.putAll(previousQueryResult);
- return queryResult;
- }
-
- private Map<String, NcmpServiceCmHandle> executeInventoryQueries(
- final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
- final Map<String, String> cpsPath = getCpsPath(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
- if (!validateCpsPathConditionProperties(cpsPath)) {
- return Collections.emptyMap();
- }
- final Map<String, NcmpServiceCmHandle> cpsPathQueryResult;
- if (cpsPath.isEmpty()) {
- cpsPathQueryResult = NO_QUERY_TO_EXECUTE;
- } else {
- try {
- cpsPathQueryResult = cmHandleQueries.queryCmHandleDataNodesByCpsPath(
- cpsPath.get("cpsPath"), INCLUDE_ALL_DESCENDANTS)
- .stream().map(this::createNcmpServiceCmHandle)
- .collect(Collectors.toMap(NcmpServiceCmHandle::getCmHandleId,
- Function.identity()));
- } catch (final PathParsingException pathParsingException) {
- throw new DataValidationException(pathParsingException.getMessage(), pathParsingException.getDetails(),
- pathParsingException);
- }
- if (cpsPathQueryResult.isEmpty()) {
- return Collections.emptyMap();
- }
- }
-
- final Map<String, String> publicPropertyQueryPairs =
- getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
- CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName());
- final Map<String, NcmpServiceCmHandle> propertiesQueryResult = publicPropertyQueryPairs.isEmpty()
- ? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
-
- return cmHandleQueries.combineCmHandleQueries(cpsPathQueryResult, propertiesQueryResult);
- }
-
- private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
- final List<String> result = new ArrayList<>();
- getConditions(conditionProperties, CmHandleQueryConditions.HAS_ALL_MODULES.getConditionName())
- .parallelStream().forEach(
- conditionProperty -> {
- validateModuleNameConditionProperties(conditionProperty);
- result.add(conditionProperty.get("moduleName"));
- }
- );
- return result;
- }
-
- private Map<String, String> getCpsPath(final List<ConditionProperties> conditionProperties) {
- final Map<String, String> result = new HashMap<>();
- getConditions(conditionProperties, CmHandleQueryConditions.WITH_CPS_PATH.getConditionName()).forEach(
- result::putAll);
- return result;
- }
-
- private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
- final String queryProperty) {
- final Map<String, String> result = new HashMap<>();
- getConditions(conditionProperties, queryProperty).forEach(result::putAll);
- return result;
- }
-
- private List<Map<String, String>> getConditions(final List<ConditionProperties> conditionProperties,
- final String name) {
- for (final ConditionProperties conditionProperty : conditionProperties) {
- if (conditionProperty.getConditionName().equals(name)) {
- return conditionProperty.getConditionParameters();
- }
- }
- return Collections.emptyList();
- }
-
- private Set<NcmpServiceCmHandle> getAllCmHandles() {
- final DataNode dataNode = inventoryPersistence.getDataNode("/dmi-registry").iterator().next();
- return dataNode.getChildDataNodes().stream().map(this::createNcmpServiceCmHandle).collect(Collectors.toSet());
- }
-
- private Set<String> getAllCmHandleIds() {
- final DataNode dataNodes = inventoryPersistence.getDataNode("/dmi-registry", DIRECT_CHILDREN_ONLY)
- .iterator().next();
- return dataNodes.getChildDataNodes().stream().map(dataNode -> dataNode.getLeaves().get("id").toString())
- .collect(Collectors.toSet());
- }
-
- private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
- return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
- .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
- }
-}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
index d26a59b054..d3a4f530f1 100755
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java
@@ -42,7 +42,7 @@ import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.onap.cps.api.CpsDataService;
-import org.onap.cps.ncmp.api.NetworkCmProxyCmHandlerQueryService;
+import org.onap.cps.ncmp.api.NetworkCmProxyCmHandleQueryService;
import org.onap.cps.ncmp.api.NetworkCmProxyDataService;
import org.onap.cps.ncmp.api.impl.event.lcm.LcmEventsCmHandleStateHandler;
import org.onap.cps.ncmp.api.impl.operations.DmiDataOperations;
@@ -86,7 +86,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
private final NetworkCmProxyDataServicePropertyHandler networkCmProxyDataServicePropertyHandler;
private final InventoryPersistence inventoryPersistence;
private final CmHandleQueries cmHandleQueries;
- private final NetworkCmProxyCmHandlerQueryService networkCmProxyCmHandlerQueryService;
+ private final NetworkCmProxyCmHandleQueryService networkCmProxyCmHandleQueryService;
private final LcmEventsCmHandleStateHandler lcmEventsCmHandleStateHandler;
private final CpsDataService cpsDataService;
private final IMap<String, Object> moduleSyncStartedOnCmHandles;
@@ -177,11 +177,12 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* @return cm handles with details
*/
@Override
- public Set<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+ public Collection<NcmpServiceCmHandle> executeCmHandleSearch(
+ final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
- return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters);
+ return networkCmProxyCmHandleQueryService.queryCmHandles(cmHandleQueryServiceParameters);
}
/**
@@ -191,11 +192,11 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* @return cm handle ids
*/
@Override
- public Set<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
+ public Collection<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
- return networkCmProxyCmHandlerQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
+ return networkCmProxyCmHandleQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
}
/**
@@ -234,12 +235,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* @return set of cm handle IDs
*/
@Override
- public Set<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
- final Set<NcmpServiceCmHandle> ncmpServiceCmHandles =
- cmHandleQueries.getCmHandlesByDmiPluginIdentifier(dmiPluginIdentifier);
- final Set<String> cmHandleIds = new HashSet<>(ncmpServiceCmHandles.size());
- ncmpServiceCmHandles.forEach(cmHandle -> cmHandleIds.add(cmHandle.getCmHandleId()));
- return cmHandleIds;
+ public Collection<String> getAllCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+ return cmHandleQueries.getCmHandleIdsByDmiPluginIdentifier(dmiPluginIdentifier);
}
/**
@@ -249,10 +246,10 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
* @return set of cm handle IDs
*/
@Override
- public Set<String> executeCmHandleIdSearchForInventory(
+ public Collection<String> executeCmHandleIdSearchForInventory(
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
- return networkCmProxyCmHandlerQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
+ return networkCmProxyCmHandleQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
}
/**
@@ -426,4 +423,5 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
return CmHandleRegistrationResponse.createFailureResponses(cmHandleIds, exception);
}
}
+
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
index bae0262b07..ff78f00229 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,10 +20,9 @@
package org.onap.cps.ncmp.api.inventory;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
-import java.util.Set;
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
@@ -33,10 +32,9 @@ public interface CmHandleQueries {
* Query CmHandles based on additional (private) properties.
*
* @param additionalPropertyQueryPairs private properties for query
- * @return CmHandles which have these private properties
+ * @return Ids of CmHandles which have these private properties
*/
- Map<String, NcmpServiceCmHandle> queryCmHandleAdditionalProperties(
- Map<String, String> additionalPropertyQueryPairs);
+ Collection<String> queryCmHandleAdditionalProperties(Map<String, String> additionalPropertyQueryPairs);
/**
* Query CmHandles based on public properties.
@@ -44,18 +42,7 @@ public interface CmHandleQueries {
* @param publicPropertyQueryPairs public properties for query
* @return CmHandles which have these public properties
*/
- Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
- Map<String, String> publicPropertyQueryPairs);
-
- /**
- * Combine Maps of CmHandles.
- *
- * @param firstQuery first CmHandles Map
- * @param secondQuery second CmHandles Map
- * @return combined Map of CmHandles
- */
- Map<String, NcmpServiceCmHandle> combineCmHandleQueries(Map<String, NcmpServiceCmHandle> firstQuery,
- Map<String, NcmpServiceCmHandle> secondQuery);
+ Collection<String> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
/**
* Method which returns cm handles by the cm handles state.
@@ -91,10 +78,10 @@ public interface CmHandleQueries {
List<DataNode> queryCmHandlesByOperationalSyncState(DataStoreSyncState dataStoreSyncState);
/**
- * Get all cm handles by DMI plugin identifier.
+ * Get all cm handles ids by DMI plugin identifier.
*
* @param dmiPluginIdentifier DMI plugin identifier
- * @return set of cm handles
+ * @return collection of cm handles
*/
- Set<NcmpServiceCmHandle> getCmHandlesByDmiPluginIdentifier(String dmiPluginIdentifier);
+ Collection<String> getCmHandleIdsByDmiPluginIdentifier(String dmiPluginIdentifier);
}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
index 0f86cb7be6..f61d6c348a 100644
--- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java
@@ -1,6 +1,6 @@
/*
* ============LICENSE_START=======================================================
- * Copyright (C) 2022 Nordix Foundation
+ * Copyright (C) 2022-2023 Nordix Foundation
* Modifications Copyright (C) 2023 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -21,22 +21,17 @@
package org.onap.cps.ncmp.api.inventory;
-import static org.onap.cps.ncmp.api.impl.utils.YangDataConverter.convertYangModelCmHandleToNcmpServiceCmHandle;
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
import static org.onap.cps.spi.FetchDescendantsOption.OMIT_DESCENDANTS;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
-import java.util.Set;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
-import org.onap.cps.ncmp.api.impl.utils.YangDataConverter;
import org.onap.cps.ncmp.api.inventory.enums.PropertyType;
-import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
import org.onap.cps.spi.CpsDataPersistenceService;
import org.onap.cps.spi.FetchDescendantsOption;
import org.onap.cps.spi.model.DataNode;
@@ -51,63 +46,18 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
private static final String DESCENDANT_PATH = "//";
private final CpsDataPersistenceService cpsDataPersistenceService;
- private static final Map<String, NcmpServiceCmHandle> NO_QUERY_TO_EXECUTE = null;
private static final String ANCESTOR_CM_HANDLES = "/ancestor::cm-handles";
@Override
- public Map<String, NcmpServiceCmHandle> queryCmHandleAdditionalProperties(
- final Map<String, String> privatePropertyQueryPairs) {
+ public Collection<String> queryCmHandleAdditionalProperties(final Map<String, String> privatePropertyQueryPairs) {
return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL);
}
@Override
- public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
- final Map<String, String> publicPropertyQueryPairs) {
+ public Collection<String> queryCmHandlePublicProperties(final Map<String, String> publicPropertyQueryPairs) {
return queryCmHandleAnyProperties(publicPropertyQueryPairs, PropertyType.PUBLIC);
}
- private Map<String, NcmpServiceCmHandle> queryCmHandleAnyProperties(
- final Map<String, String> propertyQueryPairs,
- final PropertyType propertyType) {
- if (propertyQueryPairs.isEmpty()) {
- return Collections.emptyMap();
- }
- Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandles = null;
- for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
- final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
- + publicPropertyQueryPair.getKey()
- + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
-
- final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
- if (cmHandleIdToNcmpServiceCmHandles == null) {
- cmHandleIdToNcmpServiceCmHandles = collectDataNodesToNcmpServiceCmHandles(dataNodes);
- } else {
- final Collection<String> cmHandleIdsToRetain = dataNodes.parallelStream()
- .map(dataNode -> dataNode.getLeaves().get("id").toString()).collect(Collectors.toSet());
- cmHandleIdToNcmpServiceCmHandles.keySet().retainAll(cmHandleIdsToRetain);
- }
- if (cmHandleIdToNcmpServiceCmHandles.isEmpty()) {
- break;
- }
- }
- return cmHandleIdToNcmpServiceCmHandles;
- }
-
- @Override
- public Map<String, NcmpServiceCmHandle> combineCmHandleQueries(final Map<String, NcmpServiceCmHandle> firstQuery,
- final Map<String, NcmpServiceCmHandle> secondQuery) {
- if (firstQuery == NO_QUERY_TO_EXECUTE && secondQuery == NO_QUERY_TO_EXECUTE) {
- return NO_QUERY_TO_EXECUTE;
- } else if (firstQuery == NO_QUERY_TO_EXECUTE) {
- return secondQuery;
- } else if (secondQuery == NO_QUERY_TO_EXECUTE) {
- return firstQuery;
- } else {
- firstQuery.keySet().retainAll(secondQuery.keySet());
- return firstQuery;
- }
- }
-
@Override
public List<DataNode> queryCmHandlesByState(final CmHandleState cmHandleState) {
return queryCmHandleDataNodesByCpsPath("//state[@cm-handle-state=\"" + cmHandleState + "\"]",
@@ -134,36 +84,47 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
+ dataStoreSyncState + "\"]", FetchDescendantsOption.OMIT_DESCENDANTS);
}
- private Map<String, NcmpServiceCmHandle> collectDataNodesToNcmpServiceCmHandles(
- final Collection<DataNode> dataNodes) {
- final Map<String, NcmpServiceCmHandle> cmHandleIdToNcmpServiceCmHandle = new HashMap<>();
- dataNodes.forEach(dataNode -> {
- final NcmpServiceCmHandle ncmpServiceCmHandle = createNcmpServiceCmHandle(dataNode);
- cmHandleIdToNcmpServiceCmHandle.put(ncmpServiceCmHandle.getCmHandleId(), ncmpServiceCmHandle);
- });
- return cmHandleIdToNcmpServiceCmHandle;
- }
-
- private NcmpServiceCmHandle createNcmpServiceCmHandle(final DataNode dataNode) {
- return convertYangModelCmHandleToNcmpServiceCmHandle(YangDataConverter
- .convertCmHandleToYangModel(dataNode, dataNode.getLeaves().get("id").toString()));
- }
-
@Override
- public Set<NcmpServiceCmHandle> getCmHandlesByDmiPluginIdentifier(final String dmiPluginIdentifier) {
- final Map<String, DataNode> cmHandleAsDataNodePerCmHandleId = new HashMap<>();
+ public Collection<String> getCmHandleIdsByDmiPluginIdentifier(final String dmiPluginIdentifier) {
+ final Collection<String> cmHandleIds = new HashSet<>();
for (final ModelledDmiServiceLeaves modelledDmiServiceLeaf : ModelledDmiServiceLeaves.values()) {
for (final DataNode cmHandleAsDataNode: getCmHandlesByDmiPluginIdentifierAndDmiProperty(
dmiPluginIdentifier,
modelledDmiServiceLeaf.getLeafName())) {
- cmHandleAsDataNodePerCmHandleId.put(
- cmHandleAsDataNode.getLeaves().get("id").toString(), cmHandleAsDataNode);
+ cmHandleIds.add(cmHandleAsDataNode.getLeaves().get("id").toString());
+ }
+ }
+ return cmHandleIds;
+ }
+
+ private Collection<String> collectCmHandleIdsFromDataNodes(final Collection<DataNode> dataNodes) {
+ return dataNodes.stream().map(dataNode -> (String) dataNode.getLeaves().get("id")).collect(Collectors.toSet());
+ }
+
+ private Collection<String> queryCmHandleAnyProperties(
+ final Map<String, String> propertyQueryPairs,
+ final PropertyType propertyType) {
+ if (propertyQueryPairs.isEmpty()) {
+ return Collections.emptySet();
+ }
+ Collection<String> cmHandleIds = null;
+ for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
+ final String cpsPath = DESCENDANT_PATH + propertyType.getYangContainerName() + "[@name=\""
+ + publicPropertyQueryPair.getKey()
+ + "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
+
+ final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, OMIT_DESCENDANTS);
+ if (cmHandleIds == null) {
+ cmHandleIds = collectCmHandleIdsFromDataNodes(dataNodes);
+ } else {
+ final Collection<String> cmHandleIdsToRetain = collectCmHandleIdsFromDataNodes(dataNodes);
+ cmHandleIds.retainAll(cmHandleIdsToRetain);
+ }
+ if (cmHandleIds.isEmpty()) {
+ break;
}
}
- final Set<NcmpServiceCmHandle> ncmpServiceCmHandles = new HashSet<>(cmHandleAsDataNodePerCmHandleId.size());
- cmHandleAsDataNodePerCmHandleId.values().forEach(
- cmHandleAsDataNode -> ncmpServiceCmHandles.add(createNcmpServiceCmHandle(cmHandleAsDataNode)));
- return ncmpServiceCmHandles;
+ return cmHandleIds;
}
private List<DataNode> getCmHandlesByDmiPluginIdentifierAndDmiProperty(final String dmiPluginIdentifier,