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
8 package org.opendaylight.restconf.common.validation;
10 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
11 import org.opendaylight.yangtools.yang.common.ErrorTag;
12 import org.opendaylight.yangtools.yang.common.ErrorType;
16 * org.opendaylight.controller.md.sal.rest.common
19 * Utility class is centralizing all needed validation functionality for a Restconf osgi module.
20 * All methods have to throw {@link RestconfDocumentedException} only, which is a representation
21 * for all error situation followed by restconf-netconf specification.
22 * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
24 public final class RestconfValidationUtils {
25 private RestconfValidationUtils() {
30 * Method returns {@link RestconfDocumentedException} if value is NULL or same input value.
31 * {@link ErrorType} is relevant for server application layer
32 * {@link ErrorTag} is 404 data-missing
33 * See also <a href="https://tools.ietf.org/html/draft-bierman-netconf-restconf-02">RESTCONF</a>.
35 * @param value - some value from {@link org.opendaylight.yangtools.yang.model.api.Module}
36 * @param moduleName - name of {@link org.opendaylight.yangtools.yang.model.api.Module}
37 * @return - T value (same input value)
39 public static <T> T checkNotNullDocumented(final T value, final String moduleName) {
41 final String errMsg = "Module " + moduleName + " was not found.";
42 throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);