blob: 987ce42c84f559b9e924cdd90ff029244f6152c3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}
}
|