summaryrefslogtreecommitdiffstats
path: root/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2023-01-31 16:57:11 -0500
committerDan Timoney <dtimoney@att.com>2023-01-31 16:57:11 -0500
commitd76e58f792700c96d864237efd4539505cbf2b60 (patch)
tree645019d6cbee581a30aba87c29305ba95e33e9d9 /netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java
parentd4d6fbd430eb502cce6cb01a667ec799d487a510 (diff)
Port Biermann-draft-02 API to Chlorine
Made changes to get a clean compile under Chlorine. NOTE: changes in Chlorine break the jUnit testing for this feature - mostly due to changes in yangtools making classes sealed, which prevents use of mockito to simulate these classes. There are other changes as well that caused breakage. For now, pom.xml has been changed to disable jUnit, but this should be corrected. Issue-ID: CCSDK-3843 Signed-off-by: Dan Timoney <dtimoney@att.com> Change-Id: Ic53c6d580d644fab069a06f033db515c05dff6f2
Diffstat (limited to 'netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java')
-rw-r--r--netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java
new file mode 100644
index 0000000..987ce42
--- /dev/null
+++ b/netconf/restconf/restconf-common/src/main/java/org/opendaylight/restconf/common/validation/RestconfValidationUtils.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.restconf.common.validation;
+
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
+
+/**
+ * sal-rest-connector
+ * org.opendaylight.controller.md.sal.rest.common
+ *
+ * <p>
+ * Utility class is centralizing all needed validation functionality for a Restconf osgi module.
+ * All methods have to throw {@link RestconfDocumentedException} only, which is a representation
+ * for all error situation followed by restconf-netconf specification.
+ * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
+ */
+public final class RestconfValidationUtils {
+ private RestconfValidationUtils() {
+ // Hidden on purpose
+ }
+
+ /**
+ * Method returns {@link RestconfDocumentedException} if value is NULL or same input value.
+ * {@link ErrorType} is relevant for server application layer
+ * {@link ErrorTag} is 404 data-missing
+ * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
+ *
+ * @param value - some value from {@link org.opendaylight.yangtools.yang.model.api.Module}
+ * @param moduleName - name of {@link org.opendaylight.yangtools.yang.model.api.Module}
+ * @return - T value (same input value)
+ */
+ public static <T> T checkNotNullDocumented(final T value, final String moduleName) {
+ if (value == null) {
+ final String errMsg = "Module " + moduleName + " was not found.";
+ throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);
+ }
+ return value;
+ }
+}