2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024 Ericsson
4 * Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
21 package org.oran.smo.yangtools.parser.model.statements.oran;
23 import java.util.Arrays;
24 import java.util.List;
25 import java.util.regex.Pattern;
27 import org.oran.smo.yangtools.parser.ParserExecutionContext;
28 import org.oran.smo.yangtools.parser.findings.Finding;
29 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
30 import org.oran.smo.yangtools.parser.model.statements.AbstractStatement;
31 import org.oran.smo.yangtools.parser.model.statements.ExtensionStatement;
32 import org.oran.smo.yangtools.parser.model.statements.StatementModuleAndName;
33 import org.oran.smo.yangtools.parser.model.statements.yang.CY;
34 import org.oran.smo.yangtools.parser.model.yangdom.YangDomElement;
36 public class YOranSmoTeivLabel extends ExtensionStatement {
40 private int correction;
42 public YOranSmoTeivLabel(final AbstractStatement parentStatement, final YangDomElement domNode) {
43 super(parentStatement, domNode);
47 public StatementArgumentType getArgumentType() {
48 return StatementArgumentType.VALUE;
52 public StatementModuleAndName getStatementModuleAndName() {
53 return CORAN.ORAN_SMO_TEIV_COMMON_YANG_EXTENSIONS__LABEL;
57 public boolean argumentIsMandatory() {
61 public String getLabel() {
62 return getValue() != null ? getValue() : "";
65 public int getVersion() {
69 public int getRelease() {
73 public int getCorrection() {
77 private static final List<StatementModuleAndName> REQUIRED_PARENTS = Arrays.asList(CY.STMT_REVISION);
80 public boolean canBeChildOf(final StatementModuleAndName parentSman) {
81 return REQUIRED_PARENTS.contains(parentSman);
84 private static final Pattern VALID_PATTERN = Pattern.compile("[0-9]+\\.[0-9]+\\.[0-9]+");
87 protected void validate(final ParserExecutionContext context) {
89 * From o-ran-smo-teiv-common-yang-extensions:
91 * The label can be used to give modules and submodules a semantic version, in addition to their revision.
93 * The format of the label is 'x.y.z' – expressed as pattern, it is [0-9]+\.[0-9]+\.[0-9]+
95 * The statement MUST only be a substatement of the revision statement. Zero or one revision label statements
96 * per parent statement are allowed.
98 * Revision labels MUST be unique amongst all revisions of a module or submodule.
100 validateArgumentNotNullNotEmpty(context);
102 final String label = getLabel();
103 if (!VALID_PATTERN.matcher(label).matches()) {
104 context.addFinding(new Finding(this, ParserFindingType.P025_INVALID_EXTENSION,
105 "Label value must be in 'version.release.correction' format."));
107 version = Integer.parseInt(label.substring(0, label.indexOf('.')));
108 release = Integer.parseInt(label.substring(label.indexOf('.') + 1, label.lastIndexOf('.')));
109 correction = Integer.parseInt(label.substring(label.lastIndexOf('.') + 1));
112 checkParent(context);
113 checkCardinalityUnderParent(context, 1);