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.yanglibrary;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.stream.Collectors;
27 import org.oran.smo.yangtools.parser.ParserExecutionContext;
28 import org.oran.smo.yangtools.parser.data.dom.YangDataDomNode;
29 import org.oran.smo.yangtools.parser.findings.Finding;
30 import org.oran.smo.yangtools.parser.findings.ParserFindingType;
31 import org.oran.smo.yangtools.parser.yanglibrary.Module.IetfYangLibraryConformanceType;
34 * A populater implementation that extracts data in accordance with RFC8525.
36 * @author Mark Hollmann
38 public class RFC8525Populator implements YangLibraryPopulator {
41 public void populateModulesState(final ParserExecutionContext context, final ModulesState modulesState,
42 final YangDataDomNode modulesStateDomNode) {
44 modulesState.setModuleSetId(IetfYangLibraryParser.getValueOfChild(context, modulesStateDomNode, "module-set-id",
45 "---unspecified value---"));
49 public void populateModuleInModulesState(final ParserExecutionContext context, final Module module,
50 final YangDataDomNode moduleDomNode) {
52 module.setName(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "name", ""));
53 module.setRevision(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "revision", ""));
54 module.setNamespace(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "namespace", ""));
55 module.setFeatures(IetfYangLibraryParser.getValueOfChildren(context, moduleDomNode, "feature"));
56 module.setConformanceType(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "conformance-type", ""));
58 if (module.getName().isEmpty()) {
59 context.getFindingsManager().addFinding(new Finding(moduleDomNode,
60 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing module name."));
62 if (module.getNamespace().isEmpty()) {
63 context.getFindingsManager().addFinding(new Finding(moduleDomNode,
64 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing module namespace."));
66 if (module.getConformanceType() == IetfYangLibraryConformanceType.UNKNOWN) {
67 context.getFindingsManager().addFinding(new Finding(moduleDomNode,
68 ParserFindingType.P081_INCORRECT_YANG_LIBRARY_DATA.toString(),
69 "missing / incorrect module conformance-type."));
72 final String schemaLocation = IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "schema", "");
73 if (schemaLocation != null && !schemaLocation.isEmpty()) {
74 module.setSchemaLocations(Collections.singletonList(schemaLocation));
77 final List<YangDataDomNode> deviationDomNodes = IetfYangLibraryParser.getDomChildren(moduleDomNode, "deviation");
78 module.setDeviatedByModuleNames(deviationDomNodes.stream().map(dli -> IetfYangLibraryParser.getValueOfChild(context,
79 dli, "name", "")).collect(Collectors.toList()));
83 public void populateSubmoduleInModulesState(final ParserExecutionContext context, final Submodule submodule,
84 final YangDataDomNode submoduleDomNode) {
86 submodule.setName(IetfYangLibraryParser.getValueOfChild(context, submoduleDomNode, "name", ""));
87 submodule.setRevision(IetfYangLibraryParser.getValueOfChild(context, submoduleDomNode, "revision", ""));
89 if (submodule.getName().isEmpty()) {
90 context.getFindingsManager().addFinding(new Finding(submoduleDomNode,
91 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing submodule name."));
94 final String subModuleSchemaLocation = IetfYangLibraryParser.getValueOfChild(context, submoduleDomNode, "schema",
96 if (subModuleSchemaLocation != null && !subModuleSchemaLocation.isEmpty()) {
97 submodule.setSchemaLocations(Collections.singletonList(subModuleSchemaLocation));
102 public void populateYangLibrary(final ParserExecutionContext context, final YangLibrary yangLibrary,
103 final YangDataDomNode yangLibraryDomNode) {
105 yangLibrary.setContentId(IetfYangLibraryParser.getValueOfChild(context, yangLibraryDomNode, "content-id",
106 "---unspecified value---"));
110 public void populateModuleSet(final ParserExecutionContext context, final ModuleSet moduleSet,
111 final YangDataDomNode moduleSetDomNode) {
113 moduleSet.setName(IetfYangLibraryParser.getValueOfChild(context, moduleSetDomNode, "name", ""));
114 if (moduleSet.getName().isEmpty()) {
115 context.getFindingsManager().addFinding(new Finding(moduleSetDomNode,
116 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing module-set name."));
121 public void populateModuleInYangLibrary(final ParserExecutionContext context, final Module module,
122 final YangDataDomNode moduleDomNode, final String conformanceType) {
124 module.setName(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "name", ""));
125 module.setRevision(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "revision", ""));
126 module.setNamespace(IetfYangLibraryParser.getValueOfChild(context, moduleDomNode, "namespace", ""));
127 module.setSchemaLocations(IetfYangLibraryParser.getValueOfChildren(context, moduleDomNode, "location"));
128 module.setFeatures(IetfYangLibraryParser.getValueOfChildren(context, moduleDomNode, "feature"));
129 module.setConformanceType(conformanceType);
131 if (module.getName().isEmpty()) {
132 context.getFindingsManager().addFinding(new Finding(moduleDomNode,
133 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing module name."));
135 if (module.getNamespace().isEmpty()) {
136 context.getFindingsManager().addFinding(new Finding(moduleDomNode,
137 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing module namespace."));
140 module.setDeviatedByModuleNames(IetfYangLibraryParser.getValueOfChildren(context, moduleDomNode, "deviation"));
144 public void populateSubmoduleInYangLibrary(final ParserExecutionContext context, final Submodule submodule,
145 final YangDataDomNode submoduleDomNode) {
147 submodule.setName(IetfYangLibraryParser.getValueOfChild(context, submoduleDomNode, "name", ""));
148 submodule.setRevision(IetfYangLibraryParser.getValueOfChild(context, submoduleDomNode, "revision", ""));
149 submodule.setSchemaLocations(IetfYangLibraryParser.getValueOfChildren(context, submoduleDomNode, "location"));
151 if (submodule.getName().isEmpty()) {
152 context.getFindingsManager().addFinding(new Finding(submoduleDomNode,
153 ParserFindingType.P082_YANG_LIBRARY_MANDATORY_VALUE_MISSING.toString(), "Missing submodule name."));