2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.netconf.md.sal.rest.common;
11 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
12 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
13 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
17 * org.opendaylight.controller.md.sal.rest.common
20 * Utility class is centralizing all needed validation functionality for a Restconf osgi module.
21 * All methods have to throw {@link RestconfDocumentedException} only, which is a representation
22 * for all error situation followed by restconf-netconf specification.
23 * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
25 public class RestconfValidationUtils {
27 private RestconfValidationUtils() {
28 throw new UnsupportedOperationException("Utility class");
32 * Method returns {@link RestconfDocumentedException} for a false condition.
34 * @param condition - condition for rise {@link RestconfDocumentedException}
35 * @param type - input {@link ErrorType} for create {@link RestconfDocumentedException}
36 * @param tag - input {@link ErrorTag} for create {@link RestconfDocumentedException}
37 * @param message - input error message for create {@link RestconfDocumentedException}
39 public static void checkDocumentedError(final boolean condition, final ErrorType type,
40 final ErrorTag tag, final String message) {
42 throw new RestconfDocumentedException(message, type, tag);
47 * Method returns {@link RestconfDocumentedException} if value is NULL or same input value.
48 * {@link ErrorType} is relevant for server application layer
49 * {@link ErrorTag} is 404 data-missing
50 * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
52 * @param value - some value from {@link org.opendaylight.yangtools.yang.model.api.Module}
53 * @param moduleName - name of {@link org.opendaylight.yangtools.yang.model.api.Module}
54 * @return - T value (same input value)
56 public static <T> T checkNotNullDocumented(final T value, final String moduleName) {
58 final String errMsg = "Module " + moduleName + " was not found.";
59 throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);