2 * Copyright (c) 2016 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.utils.validation;
10 import java.text.ParseException;
11 import java.util.Date;
12 import java.util.Iterator;
13 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
14 import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
15 import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
16 import org.opendaylight.restconf.common.validation.RestconfValidationUtils;
17 import org.opendaylight.restconf.utils.parser.builder.ParserBuilderConstants;
18 import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
21 * Util class for validations.
23 * @deprecated move to splitted module restconf-nb-rfc8040
26 public final class RestconfValidation {
28 private RestconfValidation() {
29 throw new UnsupportedOperationException("Util class.");
33 * Validation and parsing of revision.
37 * @return {@link Date}
39 public static Date validateAndGetRevision(final Iterator<String> revisionDate) {
40 RestconfValidationUtils.checkDocumentedError(revisionDate.hasNext(), ErrorType.PROTOCOL,
41 ErrorTag.INVALID_VALUE, "Revision date must be supplied.");
43 return SimpleDateFormatUtil.getRevisionFormat().parse(revisionDate.next());
44 } catch (final ParseException e) {
45 throw new RestconfDocumentedException("Supplied revision is not in expected date format YYYY-mm-dd", e);
54 * @return {@link String}
56 public static String validateAndGetModulName(final Iterator<String> moduleName) {
57 RestconfValidationUtils.checkDocumentedError(
59 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
60 "Module name must be supplied."
63 final String name = moduleName.next();
65 RestconfValidationUtils.checkDocumentedError(
66 !name.isEmpty() && ParserBuilderConstants.Deserializer.IDENTIFIER_FIRST_CHAR.matches(name.charAt(0)),
67 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
68 "Identifier must start with character from set 'a-zA-Z_"
71 RestconfValidationUtils.checkDocumentedError(
72 !name.toUpperCase().startsWith("XML"),
73 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
74 "Identifier must NOT start with XML ignore case."
77 RestconfValidationUtils.checkDocumentedError(
78 ParserBuilderConstants.Deserializer.IDENTIFIER.matchesAllOf(name.substring(1)),
79 ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE,
80 "Supplied name has not expected identifier format."