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.controller.md.sal.rest.common;
11 import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException;
12 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag;
13 import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType;
17 * 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 {@link https://tools.ietf.org/html/draft-bierman-netconf-restconf-02}
24 * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
26 * Created: Feb 24, 2015
28 public class RestconfValidationUtils {
30 private RestconfValidationUtils () {
31 throw new UnsupportedOperationException("Utility class");
35 * Method returns {@link RestconfDocumentedException} for a false condition.
37 * @param condition - condition for rise {@link RestconfDocumentedException}
38 * @param type - input {@link ErrorType} for create {@link RestconfDocumentedException}
39 * @param tag - input {@link ErrorTag} for create {@link RestconfDocumentedException}
40 * @param message - input error message for create {@link RestconfDocumentedException}
42 public static void checkDocumentedError(final boolean condition, final ErrorType type,
43 final ErrorTag tag, final String message) {
45 throw new RestconfDocumentedException(message, type, tag);
50 * Method returns {@link RestconfDocumentedException} if value is NULL or same input value.
51 * {@link ErrorType} is relevant for server application layer
52 * {@link ErrorTag} is 404 data-missing
53 * @see {@link https://tools.ietf.org/html/draft-bierman-netconf-restconf-02}
55 * @param value - some value from {@link org.opendaylight.yangtools.yang.model.api.Module}
56 * @param moduleName - name of {@link org.opendaylight.yangtools.yang.model.api.Module}
57 * @return - T value (same input value)
59 public static <T> T checkNotNullDocumented(final T value, final String moduleName) {
61 final String errMsg = "Module " + moduleName + "was not found.";
62 throw new RestconfDocumentedException(errMsg, ErrorType.APPLICATION, ErrorTag.DATA_MISSING);