summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'cps-service/src/main')
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java36
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java36
2 files changed, 68 insertions, 4 deletions
diff --git a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java
index c3811eb485..7fe47be2da 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/CmHandleQueryRestParametersValidator.java
@@ -22,18 +22,17 @@ package org.onap.cps.utils;
import com.google.common.base.Strings;
import java.util.Arrays;
-import java.util.List;
import java.util.Map;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.spi.model.CmHandleQueryServiceParameters;
+@Slf4j
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CmHandleQueryRestParametersValidator {
- private static final List<String> VALID_PROPERTY_NAMES = Arrays.asList("hasAllProperties", "hasAllModules");
-
/**
* Validate cm handle query parameters.
* @param cmHandleQueryServiceParameters name of data to be validated
@@ -45,7 +44,8 @@ public class CmHandleQueryRestParametersValidator {
if (Strings.isNullOrEmpty(conditionApiProperty.getConditionName())) {
throwDataValidationException("Missing 'conditionName' - please supply a valid name.");
}
- if (!VALID_PROPERTY_NAMES.contains(conditionApiProperty.getConditionName())) {
+ if (Arrays.stream(ValidQueryProperties.values()).noneMatch(validQueryProperty ->
+ validQueryProperty.getQueryProperty().equals(conditionApiProperty.getConditionName()))) {
throwDataValidationException(
String.format("Wrong 'conditionName': %s - please supply a valid name.",
conditionApiProperty.getConditionName()));
@@ -89,6 +89,34 @@ public class CmHandleQueryRestParametersValidator {
throwDataValidationException("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) {
+ throwDataValidationException("Only one condition property is allowed for the CPS path query.");
+ }
+ if (!conditionProperty.containsKey("cpsPath")) {
+ throwDataValidationException(
+ "Wrong CPS path condition property. - expecting \"cpsPath\" as the condition property.");
+ }
+ final String cpsPath = conditionProperty.get("cpsPath");
+ if (cpsPath.isBlank()) {
+ throwDataValidationException(
+ "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 void throwDataValidationException(final String details) {
throw new DataValidationException("Invalid Query Parameter.", details);
}
diff --git a/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java b/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java
new file mode 100644
index 0000000000..1d7ccb91df
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/utils/ValidQueryProperties.java
@@ -0,0 +1,36 @@
+/*
+ * ============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.utils;
+
+import lombok.Getter;
+
+@Getter
+public enum ValidQueryProperties {
+ HAS_ALL_PROPERTIES("hasAllProperties"),
+ HAS_ALL_MODULES("hasAllModules"),
+ WITH_CPS_PATH("cmHandleWithCpsPath");
+
+ private final String queryProperty;
+
+ ValidQueryProperties(final String queryProperty) {
+ this.queryProperty = queryProperty;
+ }
+}