summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-service/src/main/java/org/onap
diff options
context:
space:
mode:
authorleventecsanyi <levente.csanyi@est.tech>2022-10-26 10:44:08 +0200
committerleventecsanyi <levente.csanyi@est.tech>2022-12-01 21:32:44 +0100
commit37d72855721caa646144ad323fe51ae78af15507 (patch)
tree0d4494c83572f779aded34a7de3b03774c19873c /cps-ncmp-service/src/main/java/org/onap
parent94d77dd3430bf504b1fe1209760cfeedb47752a7 (diff)
Filter on private properties of CM Handles
- Moved cm handle query validation to cps-ncmp-service (where it belongs!) - Added new enum type for private/public field types - Created new methods for private and public queries - Added new REST endpoint - Created service methods for filtering on different types of properties - Refactored getPublicPropertyPairs and queryCmHandleAnyProperties - Added unit test for the controller layer - Fixed refactoring suggestions - Imporved code coverage with unit tests - Refactoring - Added new functionality to NcmpRestInputMapper - Updated version number to 3.2.1-SNAPSHOT and updated release-notes.rst Issue-ID: CPS-1236 Change-Id: I0ddf6866473f7c3c6b8507d222d441bf97ca6bdc Signed-off-by: leventecsanyi <levente.csanyi@est.tech>
Diffstat (limited to 'cps-ncmp-service/src/main/java/org/onap')
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyCmHandlerQueryService.java10
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java9
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyCmHandlerQueryServiceImpl.java109
-rwxr-xr-xcps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java27
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java42
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java42
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidator.java125
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueries.java14
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/CmHandleQueriesImpl.java19
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/enums/PropertyType.java34
-rw-r--r--cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleQueryServiceParameters.java42
11 files changed, 449 insertions, 24 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/NetworkCmProxyCmHandlerQueryService.java
index faf58b95bf..7322ebc113 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/NetworkCmProxyCmHandlerQueryService.java
@@ -21,8 +21,8 @@
package org.onap.cps.ncmp.api;
import java.util.Set;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
public interface NetworkCmProxyCmHandlerQueryService {
/**
@@ -40,4 +40,12 @@ public interface NetworkCmProxyCmHandlerQueryService {
* @return collection of cm handle ids
*/
Set<String> queryCmHandleIds(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
+
+ /**
+ * Query and return cm handles that match the given query parameters.
+ *
+ * @param cmHandleQueryServiceParameters the cm handle query parameters
+ * @return collection of cm handle ids
+ */
+ Set<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 0ea0674281..c9810e9a66 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
@@ -30,6 +30,7 @@ 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;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
import org.onap.cps.ncmp.api.models.DmiPluginRegistrationResponse;
import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle;
@@ -183,4 +184,12 @@ public interface NetworkCmProxyDataService {
* @return set of cm handle IDs
*/
Set<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
+ */
+ Set<String> executeCmHandleIdSearchForInventory(CmHandleQueryServiceParameters cmHandleQueryServiceParameters);
}
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
index 1674c52fc9..a8fc6d7057 100644
--- 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
@@ -20,11 +20,11 @@
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.FETCH_DIRECT_CHILDREN_ONLY;
import static org.onap.cps.spi.FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCpsPathConditionProperties;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateModuleNameConditionProperties;
import java.util.ArrayList;
import java.util.Collection;
@@ -40,16 +40,18 @@ 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.Anchor;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
import org.onap.cps.spi.model.ConditionProperties;
import org.onap.cps.spi.model.DataNode;
-import org.onap.cps.utils.ValidQueryProperties;
import org.springframework.stereotype.Service;
@Service
@@ -113,6 +115,92 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
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) {
@@ -164,7 +252,8 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
}
final Map<String, String> publicPropertyQueryPairs =
- getPublicPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters());
+ getPropertyPairs(cmHandleQueryServiceParameters.getCmHandleQueryParameters(),
+ CmHandleQueryConditions.HAS_ALL_PROPERTIES.getConditionName());
final Map<String, NcmpServiceCmHandle> propertiesQueryResult = publicPropertyQueryPairs.isEmpty()
? NO_QUERY_TO_EXECUTE : cmHandleQueries.queryCmHandlePublicProperties(publicPropertyQueryPairs);
@@ -178,7 +267,7 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
private Collection<String> getModuleNamesForQuery(final List<ConditionProperties> conditionProperties) {
final List<String> result = new ArrayList<>();
- getConditions(conditionProperties, ValidQueryProperties.HAS_ALL_MODULES.getQueryProperty())
+ getConditions(conditionProperties, CmHandleQueryConditions.HAS_ALL_MODULES.getConditionName())
.parallelStream().forEach(
conditionProperty -> {
validateModuleNameConditionProperties(conditionProperty);
@@ -190,15 +279,15 @@ public class NetworkCmProxyCmHandlerQueryServiceImpl implements NetworkCmProxyCm
private Map<String, String> getCpsPath(final List<ConditionProperties> conditionProperties) {
final Map<String, String> result = new HashMap<>();
- getConditions(conditionProperties, ValidQueryProperties.WITH_CPS_PATH.getQueryProperty()).forEach(
+ getConditions(conditionProperties, CmHandleQueryConditions.WITH_CPS_PATH.getConditionName()).forEach(
result::putAll);
return result;
}
- private Map<String, String> getPublicPropertyPairs(final List<ConditionProperties> conditionProperties) {
+ private Map<String, String> getPropertyPairs(final List<ConditionProperties> conditionProperties,
+ final String queryProperty) {
final Map<String, String> result = new HashMap<>();
- getConditions(conditionProperties,
- ValidQueryProperties.HAS_ALL_PROPERTIES.getQueryProperty()).forEach(result::putAll);
+ getConditions(conditionProperties, queryProperty).forEach(result::putAll);
return result;
}
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 27c3646a5e..d00d2119b1 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
@@ -25,7 +25,7 @@ package org.onap.cps.ncmp.api.impl;
import static org.onap.cps.ncmp.api.impl.constants.DmiRegistryConstants.NFP_OPERATIONAL_DATASTORE_DATASPACE_NAME;
import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum;
-import static org.onap.cps.utils.CmHandleQueryRestParametersValidator.validateCmHandleQueryParameters;
+import static org.onap.cps.ncmp.api.impl.utils.RestQueryParametersValidator.validateCmHandleQueryParameters;
import com.hazelcast.map.IMap;
import java.time.OffsetDateTime;
@@ -45,6 +45,8 @@ 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;
import org.onap.cps.ncmp.api.impl.operations.DmiOperations;
+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.impl.yangmodels.YangModelCmHandle;
import org.onap.cps.ncmp.api.inventory.CmHandleQueries;
@@ -54,6 +56,7 @@ import org.onap.cps.ncmp.api.inventory.CompositeStateUtils;
import org.onap.cps.ncmp.api.inventory.DataStoreSyncState;
import org.onap.cps.ncmp.api.inventory.InventoryPersistence;
import org.onap.cps.ncmp.api.models.CmHandleQueryApiParameters;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse;
import org.onap.cps.ncmp.api.models.CmHandleRegistrationResponse.RegistrationError;
import org.onap.cps.ncmp.api.models.DmiPluginRegistration;
@@ -64,7 +67,6 @@ import org.onap.cps.spi.exceptions.AlreadyDefinedExceptionBatch;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.onap.cps.spi.exceptions.DataValidationException;
-import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
import org.onap.cps.spi.model.ModuleDefinition;
import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.utils.JsonObjectMapper;
@@ -171,9 +173,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
public Set<NcmpServiceCmHandle> executeCmHandleSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-
- validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
-
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
return networkCmProxyCmHandlerQueryService.queryCmHandles(cmHandleQueryServiceParameters);
}
@@ -187,9 +187,7 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
public Set<String> executeCmHandleIdSearch(final CmHandleQueryApiParameters cmHandleQueryApiParameters) {
final CmHandleQueryServiceParameters cmHandleQueryServiceParameters = jsonObjectMapper.convertToValueType(
cmHandleQueryApiParameters, CmHandleQueryServiceParameters.class);
-
- validateCmHandleQueryParameters(cmHandleQueryServiceParameters);
-
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, CmHandleQueryConditions.ALL_CONDITION_NAMES);
return networkCmProxyCmHandlerQueryService.queryCmHandleIds(cmHandleQueryServiceParameters);
}
@@ -238,6 +236,19 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService
}
/**
+ * Get all cm handle IDs by various properties.
+ *
+ * @param cmHandleQueryServiceParameters cm handle query parameters
+ * @return set of cm handle IDs
+ */
+ @Override
+ public Set<String> executeCmHandleIdSearchForInventory(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters) {
+ validateCmHandleQueryParameters(cmHandleQueryServiceParameters, InventoryQueryConditions.ALL_CONDITION_NAMES);
+ return networkCmProxyCmHandlerQueryService.queryCmHandleIdsForInventory(cmHandleQueryServiceParameters);
+ }
+
+ /**
* Retrieve cm handle details for a given cm handle.
*
* @param cmHandleId cm handle identifier
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java
new file mode 100644
index 0000000000..b1bb7f767b
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/CmHandleQueryConditions.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.utils;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.stream.Collectors;
+import lombok.Getter;
+
+@Getter
+public enum CmHandleQueryConditions {
+ HAS_ALL_PROPERTIES("hasAllProperties"),
+ HAS_ALL_MODULES("hasAllModules"),
+ WITH_CPS_PATH("cmHandleWithCpsPath");
+
+ public static final Collection<String> ALL_CONDITION_NAMES = Arrays.stream(CmHandleQueryConditions.values())
+ .map(CmHandleQueryConditions::getConditionName).collect(Collectors.toList());
+
+ private final String conditionName;
+
+ CmHandleQueryConditions(final String conditionName) {
+ this.conditionName = conditionName;
+ }
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java
new file mode 100644
index 0000000000..9437cf0bac
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/InventoryQueryConditions.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.utils;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.stream.Collectors;
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum InventoryQueryConditions {
+
+ HAS_ALL_PROPERTIES("hasAllProperties"),
+ HAS_ALL_ADDITIONAL_PROPERTIES("hasAllAdditionalProperties"),
+ CM_HANDLE_WITH_DMI_PLUGIN("cmHandleWithDmiPlugin");
+
+ public static final List<String> ALL_CONDITION_NAMES = Arrays.stream(InventoryQueryConditions.values())
+ .map(InventoryQueryConditions::getName).collect(Collectors.toList());
+
+ private final String name;
+
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidator.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidator.java
new file mode 100644
index 0000000000..2ef97cab5c
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/utils/RestQueryParametersValidator.java
@@ -0,0 +1,125 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.utils;
+
+import com.google.common.base.Strings;
+import java.util.Collection;
+import java.util.Map;
+import lombok.AccessLevel;
+import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.ncmp.api.models.CmHandleQueryServiceParameters;
+import org.onap.cps.spi.exceptions.DataValidationException;
+
+@Slf4j
+@NoArgsConstructor(access = AccessLevel.PRIVATE)
+public class RestQueryParametersValidator {
+
+ /**
+ * Validate query parameters.
+ *
+ * @param cmHandleQueryServiceParameters name of data to be validated
+ * @param validConditionNames valid condition names
+ */
+ public static void validateCmHandleQueryParameters(
+ final CmHandleQueryServiceParameters cmHandleQueryServiceParameters,
+ final Collection<String> validConditionNames) {
+ cmHandleQueryServiceParameters.getCmHandleQueryParameters().forEach(
+ cmHandleQueryParameter -> {
+ if (validConditionNames.stream().noneMatch(validConditionName ->
+ validConditionName.equals(cmHandleQueryParameter.getConditionName()))) {
+ throw createDataValidationException(
+ String.format("Wrong 'conditionName': %s - please supply a valid name.",
+ cmHandleQueryParameter.getConditionName()));
+ }
+ if (cmHandleQueryParameter.getConditionParameters().isEmpty()) {
+ throw createDataValidationException(
+ "Empty 'conditionsParameters' - please supply a valid condition parameter.");
+ }
+ cmHandleQueryParameter.getConditionParameters().forEach(
+ RestQueryParametersValidator::validateConditionParameter
+ );
+ }
+ );
+ }
+
+ private static void validateConditionParameter(final Map<String, String> conditionParameter) {
+ if (conditionParameter.isEmpty()) {
+ throw createDataValidationException(
+ "Empty 'conditionsParameter' - please supply a valid condition parameter.");
+ }
+ if (conditionParameter.size() > 1) {
+ throw createDataValidationException("Too many names in one 'conditionsParameter' -"
+ + " please supply one name in one condition parameter.");
+ }
+ conditionParameter.forEach((key, value) -> {
+ if (Strings.isNullOrEmpty(key)) {
+ throw createDataValidationException(
+ "Missing 'conditionsParameterName' - please supply a valid name.");
+ }
+ });
+ }
+
+ /**
+ * Validate module name condition properties.
+ * @param conditionProperty name of data to be validated
+ */
+ public static void validateModuleNameConditionProperties(final Map<String, String> conditionProperty) {
+ if (conditionProperty.containsKey("moduleName") && !conditionProperty.get("moduleName").isEmpty()) {
+ return;
+ }
+ throw createDataValidationException("Wrong module condition property. - "
+ + "please supply a valid condition property.");
+ }
+
+ /**
+ * Validate CPS path condition properties.
+ * @param conditionProperty name of data to be validated
+ */
+ public static boolean validateCpsPathConditionProperties(final Map<String, String> conditionProperty) {
+ if (conditionProperty.isEmpty()) {
+ return true;
+ }
+ if (conditionProperty.size() > 1) {
+ throw createDataValidationException("Only one condition property is allowed for the CPS path query.");
+ }
+ if (!conditionProperty.containsKey("cpsPath")) {
+ throw createDataValidationException(
+ "Wrong CPS path condition property. - expecting \"cpsPath\" as the condition property.");
+ }
+ final String cpsPath = conditionProperty.get("cpsPath");
+ if (cpsPath.isBlank()) {
+ throw createDataValidationException(
+ "Wrong CPS path. - please supply a valid CPS path.");
+ }
+ if (cpsPath.contains("/additional-properties")) {
+ log.debug("{} - Private metadata cannot be queried. Nothing to be returned",
+ cpsPath);
+ return false;
+ }
+ return true;
+ }
+
+ private static DataValidationException createDataValidationException(final String details) {
+ return new DataValidationException("Invalid Query Parameter.", details);
+ }
+
+}
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 daabbb56fa..bae0262b07 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
@@ -30,12 +30,22 @@ import org.onap.cps.spi.model.DataNode;
public interface CmHandleQueries {
/**
- * Query CmHandles based on PublicProperties.
+ * Query CmHandles based on additional (private) properties.
+ *
+ * @param additionalPropertyQueryPairs private properties for query
+ * @return CmHandles which have these private properties
+ */
+ Map<String, NcmpServiceCmHandle> queryCmHandleAdditionalProperties(
+ Map<String, String> additionalPropertyQueryPairs);
+
+ /**
+ * Query CmHandles based on public properties.
*
* @param publicPropertyQueryPairs public properties for query
* @return CmHandles which have these public properties
*/
- Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(Map<String, String> publicPropertyQueryPairs);
+ Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
+ Map<String, String> publicPropertyQueryPairs);
/**
* Combine Maps of CmHandles.
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 e9e2fcacff..1a54a824b2 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
@@ -34,6 +34,7 @@ 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;
@@ -51,16 +52,28 @@ public class CmHandleQueriesImpl implements CmHandleQueries {
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) {
+ return queryCmHandleAnyProperties(privatePropertyQueryPairs, PropertyType.ADDITIONAL);
+ }
@Override
public Map<String, NcmpServiceCmHandle> queryCmHandlePublicProperties(
final Map<String, String> publicPropertyQueryPairs) {
- if (publicPropertyQueryPairs.isEmpty()) {
+ 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 : publicPropertyQueryPairs.entrySet()) {
- final String cpsPath = "//public-properties[@name=\"" + publicPropertyQueryPair.getKey()
+ for (final Map.Entry<String, String> publicPropertyQueryPair : propertyQueryPairs.entrySet()) {
+ final String cpsPath = "//" + propertyType.getYangContainerName() + "[@name=\""
+ + publicPropertyQueryPair.getKey()
+ "\" and @value=\"" + publicPropertyQueryPair.getValue() + "\"]";
final Collection<DataNode> dataNodes = queryCmHandleDataNodesByCpsPath(cpsPath, INCLUDE_ALL_DESCENDANTS);
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/enums/PropertyType.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/enums/PropertyType.java
new file mode 100644
index 0000000000..c3c46c35e1
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/inventory/enums/PropertyType.java
@@ -0,0 +1,34 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.inventory.enums;
+
+import lombok.AllArgsConstructor;
+import lombok.Getter;
+
+@Getter
+@AllArgsConstructor
+public enum PropertyType {
+ ADDITIONAL("additional-properties"),
+ PUBLIC("public-properties"),
+ DMI_PLUGIN("dmiPluginName");
+
+ private final String yangContainerName;
+}
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleQueryServiceParameters.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleQueryServiceParameters.java
new file mode 100644
index 0000000000..774f04b5a4
--- /dev/null
+++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/models/CmHandleQueryServiceParameters.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * 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.models;
+
+import com.fasterxml.jackson.annotation.JsonInclude;
+import com.fasterxml.jackson.annotation.JsonInclude.Include;
+import com.fasterxml.jackson.annotation.JsonProperty;
+import java.util.Collections;
+import java.util.List;
+import javax.validation.Valid;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.Setter;
+import org.onap.cps.spi.model.ConditionProperties;
+
+@Setter
+@Getter
+@EqualsAndHashCode
+@JsonInclude(Include.NON_EMPTY)
+public class CmHandleQueryServiceParameters {
+ @JsonProperty("cmHandleQueryParameters")
+ @Valid
+ private List<ConditionProperties> cmHandleQueryParameters = Collections.emptyList();
+}