Merge "Removed ExtendedModuleReference Object"
[cps.git] / cps-service / src / main / java / org / onap / cps / yang / YangTextSchemaSourceSetBuilder.java
index 712d9a0..fd53497 100644 (file)
@@ -1,12 +1,14 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Pantheon.tech
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
  *  You may obtain a copy of the License at
  *
  *        http://www.apache.org/licenses/LICENSE-2.0
+ *
  *  Unless required by applicable law or agreed to in writing, software
  *  distributed under the License is distributed on an "AS IS" BASIS,
  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -30,7 +32,6 @@ import java.nio.charset.StandardCharsets;
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 import lombok.NoArgsConstructor;
@@ -62,7 +63,7 @@ public final class YangTextSchemaSourceSetBuilder {
     }
 
     public YangTextSchemaSourceSet build() {
-        final SchemaContext schemaContext = generateSchemaContext(yangModelMap.build());
+        final var schemaContext = generateSchemaContext(yangModelMap.build());
         return new YangTextSchemaSourceSetImpl(schemaContext);
     }
 
@@ -97,8 +98,8 @@ public final class YangTextSchemaSourceSetBuilder {
 
         private static ModuleReference toModuleReference(final Module module) {
             return ModuleReference.builder()
-                .name(module.getName())
-                .namespace(module.getNamespace().toString())
+                .moduleName(module.getName())
+                .namespace(module.getQNameModule().getNamespace().toString())
                 .revision(module.getRevision().map(Revision::toString).orElse(null))
                 .build();
         }
@@ -127,7 +128,8 @@ public final class YangTextSchemaSourceSetBuilder {
                     String.format("Exception occurred on reading resource %s.", resourceName), e);
             } catch (final YangSyntaxErrorException e) {
                 throw new ModelValidationException("Yang resource is invalid.",
-                    String.format("Yang syntax validation failed for resource %s.", resourceName), e);
+                    String.format(
+                            "Yang syntax validation failed for resource %s:%n%s", resourceName, e.getMessage()), e);
             }
         }
         try {
@@ -148,7 +150,7 @@ public final class YangTextSchemaSourceSetBuilder {
     }
 
     private static YangTextSchemaSource toYangTextSchemaSource(final String sourceName, final String source) {
-        final RevisionSourceIdentifier revisionSourceIdentifier =
+        final var revisionSourceIdentifier =
             createIdentifierFromSourceName(checkNotNull(sourceName));
 
         return new YangTextSchemaSource(revisionSourceIdentifier) {
@@ -166,7 +168,7 @@ public final class YangTextSchemaSourceSetBuilder {
     }
 
     private static RevisionSourceIdentifier createIdentifierFromSourceName(final String sourceName) {
-        final Matcher matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
+        final var matcher = RFC6020_RECOMMENDED_FILENAME_PATTERN.matcher(sourceName);
         if (matcher.matches()) {
             return RevisionSourceIdentifier.create(matcher.group(1), Revision.of(matcher.group(2)));
         }