/* * 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.netconf.md.sal.rest.common; import org.opendaylight.restconf.common.errors.RestconfDocumentedException; import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag; import org.opendaylight.restconf.common.errors.RestconfError.ErrorType; /** * sal-rest-connector * org.opendaylight.controller.md.sal.rest.common * *
* 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 RESTCONF.
*/
public class RestconfValidationUtils {
private RestconfValidationUtils() {
throw new UnsupportedOperationException("Utility class");
}
/**
* Method returns {@link RestconfDocumentedException} for a false condition.
*
* @param condition - condition for rise {@link RestconfDocumentedException}
* @param type - input {@link ErrorType} for create {@link RestconfDocumentedException}
* @param tag - input {@link ErrorTag} for create {@link RestconfDocumentedException}
* @param message - input error message for create {@link RestconfDocumentedException}
*/
public static void checkDocumentedError(final boolean condition, final ErrorType type,
final ErrorTag tag, final String message) {
if (!condition) {
throw new RestconfDocumentedException(message, type, tag);
}
}
/**
* 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 RESTCONF.
*
* @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