PoC Code Cleanup WHOLE Project 47/141947/4
authorToineSiebelink <toine.siebelink@est.tech>
Wed, 27 Aug 2025 15:55:00 +0000 (16:55 +0100)
committerToine Siebelink <toine.siebelink@est.tech>
Thu, 28 Aug 2025 13:38:07 +0000 (13:38 +0000)
Check Nordix for comparing IntelliJ Clean Code Differences
(https://gerrit.onap.org/r/c/cps/+/141947)

Patch #1 : Community Edition
Patch #2 : Ultimate Edition
Patch #3 : Community Edition, Manually undo 2 incorrect updates
Patch #4 : #3 plus checkstyle (indentation) and copyright fixes
Patch #5 : #4 plus SonarQube warning fixes & refactoring

Issue-ID:CPS-2941
Change-Id: Idfefbbb501b96644295d043cf6141833da65b2a9
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
21 files changed:
cps-ncmp-service/src/main/java/org/onap/cps/ncmp/impl/inventory/CmHandleRegistrationService.java
cps-ri/src/main/java/org/onap/cps/ri/CpsModulePersistenceServiceImpl.java
cps-service/src/main/java/org/onap/cps/utils/PrefixResolver.java
cps-service/src/main/java/org/onap/cps/utils/YangParser.java
cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java
cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java
cps-service/src/test/groovy/org/onap/cps/impl/CpsDataServiceImplSpec.groovy
cps-service/src/test/groovy/org/onap/cps/impl/CpsDeltaServiceImplSpec.groovy
cps-service/src/test/groovy/org/onap/cps/impl/CpsNotificationServiceImplSpec.groovy
cps-service/src/test/groovy/org/onap/cps/impl/DataNodeBuilderSpec.groovy
cps-service/src/test/groovy/org/onap/cps/impl/DataNodeFactorySpec.groovy
cps-service/src/test/groovy/org/onap/cps/impl/E2ENetworkSliceSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/JsonParserStreamSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/PrefixResolverSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/RestConfStylePathToCpsPathUtilSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/XmlFileUtilsSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/YangParserHelperSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/YangParserSpec.groovy
cps-service/src/test/groovy/org/onap/cps/utils/deltareport/DeltaReportExecutorSpec.groovy
cps-service/src/test/groovy/org/onap/cps/yang/YangTextSchemaSourceSetBuilderSpec.groovy
docs/api/swagger/cps/openapi.yaml

index 391fd6a..63e0882 100644 (file)
@@ -115,9 +115,9 @@ public class CmHandleRegistrationService {
      * @param cmHandleId                 cm handle id
      * @param dataSyncEnabledTargetValue data sync enabled flag
      */
-    public void setDataSyncEnabled(final String cmHandleId, final Boolean dataSyncEnabledTargetValue) {
+    public void setDataSyncEnabled(final String cmHandleId, final boolean dataSyncEnabledTargetValue) {
         final CompositeState compositeState = inventoryPersistence.getCmHandleState(cmHandleId);
-        if (dataSyncEnabledTargetValue.equals(compositeState.getDataSyncEnabled())) {
+        if (dataSyncEnabledTargetValue == compositeState.getDataSyncEnabled()) {
             log.info("Data-Sync Enabled flag is already: {} ", dataSyncEnabledTargetValue);
             return;
         }
@@ -146,7 +146,7 @@ public class CmHandleRegistrationService {
      */
     public void addAlternateIdsToCache(final Collection<YangModelCmHandle> yangModelCmHandles) {
         final Map<String, String> cmHandleIdPerAlternateIdToRegister = new HashMap<>(yangModelCmHandles.size());
-        for (final YangModelCmHandle yangModelCmHandle: yangModelCmHandles) {
+        for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandles) {
             final String cmHandleId = yangModelCmHandle.getId();
             final String alternateId = yangModelCmHandle.getAlternateId();
             if (StringUtils.isNotBlank(alternateId)) {
@@ -277,7 +277,7 @@ public class CmHandleRegistrationService {
     private void processTrustLevels(final Collection<NcmpServiceCmHandle> cmHandlesToBeCreated,
                                     final Collection<String> succeededCmHandleIds) {
         final Map<String, TrustLevel> initialTrustLevelPerCmHandleId = new HashMap<>(cmHandlesToBeCreated.size());
-        for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
+        for (final NcmpServiceCmHandle ncmpServiceCmHandle : cmHandlesToBeCreated) {
             if (succeededCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
                 initialTrustLevelPerCmHandleId.put(ncmpServiceCmHandle.getCmHandleId(),
                     ncmpServiceCmHandle.getRegistrationTrustLevel());
@@ -384,7 +384,7 @@ public class CmHandleRegistrationService {
         final List<YangModelCmHandle> yangModelCmHandlesToRegister = new ArrayList<>(cmHandlesToBeCreated.size());
         final List<CmHandleRegistrationResponse> cmHandleRegistrationResponses =
             new ArrayList<>(cmHandlesToBeCreated.size());
-        for (final NcmpServiceCmHandle ncmpServiceCmHandle: cmHandlesToBeCreated) {
+        for (final NcmpServiceCmHandle ncmpServiceCmHandle : cmHandlesToBeCreated) {
             if (!rejectedCmHandleIds.contains(ncmpServiceCmHandle.getCmHandleId())) {
                 yangModelCmHandlesToRegister.add(getYangModelCmHandle(dmiPluginRegistration, ncmpServiceCmHandle));
                 cmHandleRegistrationResponses.add(
@@ -411,7 +411,7 @@ public class CmHandleRegistrationService {
     }
 
     void removeAlternateIdsFromCache(final Collection<YangModelCmHandle> yangModelCmHandles) {
-        for (final YangModelCmHandle yangModelCmHandle: yangModelCmHandles) {
+        for (final YangModelCmHandle yangModelCmHandle : yangModelCmHandles) {
             final String cmHandleId = yangModelCmHandle.getId();
             final String alternateId = yangModelCmHandle.getAlternateId();
             if (StringUtils.isNotBlank(alternateId)) {
index 46ab5d1..ef3a4c3 100755 (executable)
@@ -82,7 +82,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     private static final String NO_MODULE_REVISION = null;
     private static final Pattern CHECKSUM_EXCEPTION_PATTERN = Pattern.compile(".*\\(checksum\\)=\\((\\w+)\\).*");
     private static final Pattern RFC6020_RECOMMENDED_FILENAME_PATTERN = Pattern
-            .compile("([\\w-]+)@(\\d{4}-\\d{2}-\\d{2})(?:\\.yang)?", Pattern.CASE_INSENSITIVE);
+        .compile("([\\w-]+)@(\\d{4}-\\d{2}-\\d{2})(?:\\.yang)?", Pattern.CASE_INSENSITIVE);
 
     private final YangResourceRepository yangResourceRepository;
 
@@ -112,18 +112,18 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     public Collection<ModuleReference> getYangResourceModuleReferences(final String dataspaceName,
                                                                        final String anchorName) {
         final Set<YangResourceModuleReference> yangResourceModuleReferenceList =
-                yangResourceRepository
-                        .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
+            yangResourceRepository
+                .findAllModuleReferencesByDataspaceAndAnchor(dataspaceName, anchorName);
         return yangResourceModuleReferenceList.stream().map(CpsModulePersistenceServiceImpl::toModuleReference)
-                .collect(Collectors.toList());
+            .collect(Collectors.toList());
     }
 
     @Override
     public Collection<ModuleDefinition> getYangResourceDefinitions(final String dataspaceName,
                                                                    final String anchorName) {
         final Set<YangResourceEntity> yangResourceEntities =
-                yangResourceRepository.findAllModuleDefinitionsByDataspaceAndAnchorAndModule(dataspaceName, anchorName,
-                    NO_MODULE_NAME_FILTER, NO_MODULE_REVISION);
+            yangResourceRepository.findAllModuleDefinitionsByDataspaceAndAnchorAndModule(dataspaceName, anchorName,
+                NO_MODULE_NAME_FILTER, NO_MODULE_REVISION);
         return convertYangResourceEntityToModuleDefinition(yangResourceEntities);
     }
 
@@ -141,7 +141,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     private List<ModuleDefinition> convertYangResourceEntityToModuleDefinition(final Set<YangResourceEntity>
                                                                                    yangResourceEntities) {
         final List<ModuleDefinition> resultModuleDefinitions = new ArrayList<>(yangResourceEntities.size());
-        for (final YangResourceEntity yangResourceEntity: yangResourceEntities) {
+        for (final YangResourceEntity yangResourceEntity : yangResourceEntities) {
             resultModuleDefinitions.add(toModuleDefinition(yangResourceEntity));
         }
         return resultModuleDefinitions;
@@ -180,7 +180,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
         final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
         final List<SchemaSetEntity> schemaSetEntities = schemaSetRepository.findByDataspace(dataspaceEntity);
         return schemaSetEntities.stream()
-                .map(CpsModulePersistenceServiceImpl::toSchemaSet).collect(Collectors.toList());
+            .map(CpsModulePersistenceServiceImpl::toSchemaSet).collect(Collectors.toList());
     }
 
     @Override
@@ -247,31 +247,31 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
 
         // return ALL yang resourceEntities
         return ImmutableSet.<YangResourceEntity>builder()
-                .addAll(existingYangResourceEntities)
-                .addAll(newYangResourceEntities)
-                .build();
+            .addAll(existingYangResourceEntities)
+            .addAll(newYangResourceEntities)
+            .build();
     }
 
     private static Map<String, YangResourceEntity> getYangResourceEntityPerChecksum(
         final Map<String, String> yangResourceContentPerName) {
-        return yangResourceContentPerName.entrySet().stream().map(entry -> {
-            final String checksum = DigestUtils.sha256Hex(entry.getValue().getBytes(StandardCharsets.UTF_8));
-            final Map<String, String> moduleNameAndRevisionMap = createModuleNameAndRevisionMap(entry.getKey(),
-                        entry.getValue());
-            final YangResourceEntity yangResourceEntity = new YangResourceEntity();
-            yangResourceEntity.setContent(entry.getValue());
-            final String moduleName = moduleNameAndRevisionMap.get("moduleName");
-            final String revision = moduleNameAndRevisionMap.get("revision");
-            yangResourceEntity.setModuleName(moduleName);
-            yangResourceEntity.setRevision(revision);
-            yangResourceEntity.setFileName(moduleName + "@" + revision + RFC6020_YANG_FILE_EXTENSION);
-            yangResourceEntity.setChecksum(checksum);
-            return yangResourceEntity;
-        })
-    .collect(Collectors.toMap(
-        YangResourceEntity::getChecksum,
-        entity -> entity
-    ));
+        return yangResourceContentPerName.entrySet().stream().map(CpsModulePersistenceServiceImpl::toYangResourceEntity)
+            .collect(Collectors.toMap(YangResourceEntity::getChecksum, entity -> entity));
+    }
+
+    private static YangResourceEntity toYangResourceEntity(final Map.Entry<String, String> entry) {
+        final String yangResourceContent = entry.getValue();
+        final String checksum = DigestUtils.sha256Hex(yangResourceContent.getBytes(StandardCharsets.UTF_8));
+        final Map<String, String> moduleNameAndRevisionMap
+            = createModuleNameAndRevisionMap(entry.getKey(), yangResourceContent);
+        final YangResourceEntity yangResourceEntity = new YangResourceEntity();
+        yangResourceEntity.setContent(yangResourceContent);
+        final String moduleName = moduleNameAndRevisionMap.get("moduleName");
+        final String revision = moduleNameAndRevisionMap.get("revision");
+        yangResourceEntity.setModuleName(moduleName);
+        yangResourceEntity.setRevision(revision);
+        yangResourceEntity.setFileName(moduleName + "@" + revision + RFC6020_YANG_FILE_EXTENSION);
+        yangResourceEntity.setChecksum(checksum);
+        return yangResourceEntity;
     }
 
     private void createAndSaveSchemaSetEntity(final String dataspaceName,
@@ -302,7 +302,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
 
             @Override
             protected MoreObjects.ToStringHelper addToStringAttributes(
-                    final MoreObjects.ToStringHelper toStringHelper) {
+                final MoreObjects.ToStringHelper toStringHelper) {
                 return toStringHelper;
             }
 
@@ -318,7 +318,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
             metaDataMap.put("revision", yangModelDependencyInfo.getFormattedRevision());
         } catch (final YangSyntaxErrorException | IOException e) {
             throw new ModelValidationException("Yang resource is invalid.",
-                   String.format("Yang syntax validation failed for resource %s:%n%s", sourceName, e.getMessage()), e);
+                String.format("Yang syntax validation failed for resource %s:%n%s", sourceName, e.getMessage()), e);
         }
         return metaDataMap;
     }
@@ -343,27 +343,26 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
      * Convert the specified data integrity violation exception into a CPS duplicated Yang resource exception
      * if the cause of the error is a yang checksum database constraint violation.
      *
-     * @param originalException the original db exception.
+     * @param originalException    the original db exception.
      * @param yangResourceEntities the collection of Yang resources involved in the db failure.
      * @return an optional converted CPS duplicated Yang resource exception. The optional is empty if the original
      *      cause of the error is not a yang checksum database constraint violation.
      */
     private Optional<DuplicatedYangResourceException> convertToDuplicatedYangResourceException(
-            final DataIntegrityViolationException originalException,
-            final Collection<YangResourceEntity> yangResourceEntities) {
+        final DataIntegrityViolationException originalException,
+        final Collection<YangResourceEntity> yangResourceEntities) {
 
         // The exception result
         DuplicatedYangResourceException duplicatedYangResourceException = null;
 
         final Throwable cause = originalException.getCause();
-        if (cause instanceof final ConstraintViolationException constraintException) {
-            if (YANG_RESOURCE_CHECKSUM_CONSTRAINT_NAME.equals(constraintException.getConstraintName())) {
-                // Db constraint related to yang resource checksum uniqueness is not respected
-                final String checksumInError = getDuplicatedChecksumFromException(constraintException);
-                final String nameInError = getNameForChecksum(checksumInError, yangResourceEntities);
-                duplicatedYangResourceException =
-                        new DuplicatedYangResourceException(nameInError, checksumInError, constraintException);
-            }
+        if (cause instanceof final ConstraintViolationException constraintException
+            && YANG_RESOURCE_CHECKSUM_CONSTRAINT_NAME.equals(constraintException.getConstraintName())) {
+            // Db constraint related to yang resource checksum uniqueness is not respected
+            final String checksumInError = getDuplicatedChecksumFromException(constraintException);
+            final String nameInError = getNameForChecksum(checksumInError, yangResourceEntities);
+            duplicatedYangResourceException =
+                new DuplicatedYangResourceException(nameInError, checksumInError, constraintException);
         }
 
         return Optional.ofNullable(duplicatedYangResourceException);
@@ -373,9 +372,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
     private String getNameForChecksum(final String checksum,
                                       final Collection<YangResourceEntity> yangResourceEntities) {
         final Optional<String> optionalFileName = yangResourceEntities.stream()
-                        .filter(entity -> Strings.CS.equals(checksum, (entity.getChecksum())))
-                        .findFirst()
-                        .map(YangResourceEntity::getFileName);
+            .filter(entity -> Strings.CS.equals(checksum, (entity.getChecksum())))
+            .findFirst()
+            .map(YangResourceEntity::getFileName);
         return optionalFileName.orElse("no filename");
     }
 
@@ -404,14 +403,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
 
     private static ModuleDefinition toModuleDefinition(final YangResourceEntity yangResourceEntity) {
         return new ModuleDefinition(
-                yangResourceEntity.getModuleName(),
-                yangResourceEntity.getRevision(),
-                yangResourceEntity.getContent());
+            yangResourceEntity.getModuleName(),
+            yangResourceEntity.getRevision(),
+            yangResourceEntity.getContent());
     }
 
     private static SchemaSet toSchemaSet(final SchemaSetEntity schemaSetEntity) {
         return SchemaSet.builder().name(schemaSetEntity.getName())
-                .dataspaceName(schemaSetEntity.getDataspace().getName()).build();
+            .dataspaceName(schemaSetEntity.getDataspace().getName()).build();
     }
 
 }
index e59029f..0d94825 100644 (file)
@@ -59,7 +59,7 @@ public class PrefixResolver {
         final String topLevelContainerName = cpsPathQuery.getContainerNames().get(0);
         final YangTextSchemaSourceSet yangTextSchemaSourceSet =
             yangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName);
-        final SchemaContext schemaContext = yangTextSchemaSourceSet.getSchemaContext();
+        final SchemaContext schemaContext = yangTextSchemaSourceSet.schemaContext();
 
         return schemaContext.getChildNodes().stream()
             .filter(DataNodeContainer.class::isInstance)
index dfce4bf..755c619 100644 (file)
@@ -137,12 +137,12 @@ public class YangParser {
 
     private SchemaContext getSchemaContext(final Anchor anchor) {
         return yangTextSchemaSourceSetCache.get(anchor.getDataspaceName(), anchor.getSchemaSetName())
-                       .getSchemaContext();
+                       .schemaContext();
     }
 
     private SchemaContext getSchemaContext(final Map<String, String> yangResourceContentPerName) {
         return timedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName)
-                       .getSchemaContext();
+                       .schemaContext();
     }
 
     private void invalidateCache(final Anchor anchor) {
index e7e04c8..10ec184 100644 (file)
@@ -41,5 +41,5 @@ public interface YangTextSchemaSourceSet {
      *  Return SchemaContext for given YangSchema.
      * @return SchemaContext
      */
-    SchemaContext getSchemaContext();
+    SchemaContext schemaContext();
 }
index 04b4916..efbe488 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Pantheon.tech
- *  Modifications Copyright (C) 2022-2023 Nordix Foundation.
+ *  Modifications Copyright (C) 2022-2025 OpenInfra Foundation Europe.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ public final class YangTextSchemaSourceSetBuilder {
     private final ImmutableMap.Builder<String, String> yangModelMap = new ImmutableMap.Builder<>();
 
     private static final YangParserFactory YANG_PARSER_FACTORY =
-            new DefaultYangParserFactory(new DefaultXPathParserFactory());
+        new DefaultYangParserFactory(new DefaultXPathParserFactory());
 
     /**
      * Add Yang resource context.
@@ -104,13 +104,7 @@ public final class YangTextSchemaSourceSetBuilder {
         generateSchemaContext(yangResourceNameToContent);
     }
 
-    private static class YangTextSchemaSourceSetImpl implements YangTextSchemaSourceSet {
-
-        private final SchemaContext schemaContext;
-
-        private YangTextSchemaSourceSetImpl(final SchemaContext schemaContext) {
-            this.schemaContext = schemaContext;
-        }
+    private record YangTextSchemaSourceSetImpl(SchemaContext schemaContext) implements YangTextSchemaSourceSet {
 
         @Override
         public List<ModuleReference> getModuleReferences() {
@@ -124,11 +118,6 @@ public final class YangTextSchemaSourceSetBuilder {
                 .revision(module.getRevision().map(Revision::toString).orElse(null))
                 .build();
         }
-
-        @Override
-        public SchemaContext getSchemaContext() {
-            return schemaContext;
-        }
     }
 
     /**
index 53325bc..2a74f2c 100644 (file)
@@ -578,8 +578,8 @@ class CpsDataServiceImplSpec extends Specification {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
         def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(yangResources)
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 
 }
index 7aaeedb..5057f84 100644 (file)
@@ -349,15 +349,15 @@ class CpsDeltaServiceImplSpec extends Specification {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
         def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(yangResources)
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 
     def setupSchemaSetMocksForDelta(yangResourceContentPerName) {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourceContentPerName) >> mockYangTextSchemaSourceSet
         mockYangTextSchemaSourceSetCache.get(_, _) >> mockYangTextSchemaSourceSet
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 }
index ab7853c..eda6c75 100644 (file)
@@ -185,7 +185,7 @@ class CpsNotificationServiceImplSpec extends Specification {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
         def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(yangResources)
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 }
index 1597d45..28ba0a9 100644 (file)
@@ -59,7 +59,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode (tree) to a DataNode (tree).'() {
         given: 'the schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'the json data parsed into container node object'
             def jsonData = TestUtils.getResourceFileContent('test-tree.json')
             def containerNode = yangParserHelper.parseData(ContentType.JSON, jsonData, schemaContext, '', validateAndParse)
@@ -79,7 +79,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode (tree) to a DataNode (tree) for known parent node.'() {
         given: 'a schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'the json data parsed into container node object'
             def jsonData = '{ "branch": [{ "name": "Branch", "nest": { "name": "Nest", "birds": ["bird"] } }] }'
             def containerNode = yangParserHelper.parseData(ContentType.JSON, jsonData, schemaContext, '/test-tree', validateAndParse)
@@ -95,7 +95,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode (tree) to a DataNode (tree) -- augmentation case.'() {
         given: 'a schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(networkTopologyModelRfc8345)
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'the json data parsed into container node object'
             def jsonData = TestUtils.getResourceFileContent('ietf/data/ietf-network-topology-sample-rfc8345.json')
             def containerNode = yangParserHelper.parseData(ContentType.JSON, jsonData, schemaContext, '', validateAndParse)
@@ -126,7 +126,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode (tree) to a DataNode (tree) for known parent node -- augmentation case.'() {
         given: 'a schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(networkTopologyModelRfc8345)
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'parent node xpath referencing augmentation node within a model'
             def parentNodeXpath = "/networks/network[@network-id='otn-hc']/link[@link-id='D1,1-2-1,D2,2-1-1']"
         and: 'the json data fragment parsed into container node object for given parent node xpath'
@@ -143,7 +143,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode (tree) to a DataNode (tree) -- with ChoiceNode.'() {
         given: 'a schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('yang-with-choice-node.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'the json data fragment parsed into container node object'
             def jsonData = TestUtils.getResourceFileContent('data-with-choice-node.json')
             def containerNode = yangParserHelper.parseData(ContentType.JSON, jsonData, schemaContext, '', validateAndParse)
@@ -160,7 +160,7 @@ class DataNodeBuilderSpec extends Specification {
     def 'Converting ContainerNode into DataNode collection: #scenario.'() {
         given: 'a schema context for expected model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent) schemaContext()
         and: 'parent node xpath referencing parent of list element'
             def parentNodeXpath = '/test-tree'
         and: 'the json data fragment (list element) parsed into container node object'
index 082fb33..5e8c5f2 100644 (file)
@@ -182,15 +182,15 @@ class DataNodeFactorySpec extends Specification {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
         def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(yangResources)
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 
     def setupSchemaSetMocksForDelta(Map<String, String> yangResourcesNameToContentMap) {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockTimedYangTextSchemaSourceSetBuilder.getYangTextSchemaSourceSet(yangResourcesNameToContentMap) >> mockYangTextSchemaSourceSet
         mockYangTextSchemaSourceSetCache.get(_, _) >> mockYangTextSchemaSourceSet
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesNameToContentMap).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 }
index 5d1c937..5906bae 100755 (executable)
@@ -81,7 +81,7 @@ class E2ENetworkSliceSpec extends Specification {
         given: 'Valid yang resource as name-to-content map'
             def yangResourceContentPerName = TestUtils.getYangResourcesAsMap(
                     'e2e/basic/cps-cavsta-onap-internal2021-01-28.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).schemaContext()
             def dataNodeStored
         and : 'a valid json is provided for the model'
             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-Cavsta-Data.txt')
@@ -112,7 +112,7 @@ class E2ENetworkSliceSpec extends Specification {
         def dataNodeStored
         given: 'valid yang resource as name-to-content map'
             def yangResourceContentPerName = TestUtils.getYangResourcesAsMap('e2e/basic/cps-ran-inventory@2021-01-28.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).schemaContext()
         and : 'a valid json is provided for the model'
             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-inventory-data.json')
         and : 'all the further dependencies are mocked '
@@ -154,7 +154,7 @@ class E2ENetworkSliceSpec extends Specification {
         and : 'json data'
             def jsonData = TestUtils.getResourceFileContent('e2e/basic/cps-ran-schema-model-data-v4.json')
         expect: 'schema context is built with no exception indicating the schema set being valid '
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceContentPerName).schemaContext()
         and: 'data is parsed with no exception indicating the model match'
             new YangParserHelper().parseData(ContentType.JSON, jsonData, schemaContext, '', false) != null
     }
index 2eede23..0a4e642 100644 (file)
@@ -44,7 +44,7 @@ class JsonParserStreamSpec extends Specification{
             def jsonReader = new JsonReader(new StringReader(jsonData))
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('multipleDataTree.yang')
         and: 'schema context'
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).schemaContext()
         and: 'variable to store the result of parsing'
             DataContainerNodeBuilder<YangInstanceIdentifier.NodeIdentifier, ContainerNode> builder =
                     Builders.containerBuilder().withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(schemaContext.getQName()))
@@ -69,4 +69,4 @@ class JsonParserStreamSpec extends Specification{
             1       | 'last-container'
 
     }
-}
\ No newline at end of file
+}
index 3198e54..0d13f54 100644 (file)
@@ -39,13 +39,13 @@ class PrefixResolverSpec extends Specification {
 
     def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
 
-    def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+    def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
 
     def anchor = new Anchor(dataspaceName: 'testDataspace', name: 'testAnchor')
 
     def 'get xpath prefix using node schema context'() {
         given: 'the schema source cache contains the schema context for the test-tree module'
-            mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+            mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
             mockYangTextSchemaSourceSetCache.get(*_) >> mockYangTextSchemaSourceSet
         when: 'the prefix of the yang module is retrieved'
             def result = objectUnderTest.getPrefix(anchor, xpath)
index 789524c..8786925 100644 (file)
@@ -35,7 +35,7 @@ class RestConfStylePathToCpsPathUtilSpec extends Specification {
 
     def setup() {
         def yangResources = TestUtils.getYangResourcesAsMap('bookstore.yang')
-        schemaContext = YangTextSchemaSourceSetBuilder.of(yangResources).getSchemaContext()
+        schemaContext = YangTextSchemaSourceSetBuilder.of(yangResources).schemaContext()
     }
 
     def 'Convert RestConf style paths when (#scenario) to CPS paths'() {
index 5f9db83..6d88f93 100644 (file)
@@ -35,7 +35,7 @@ class XmlFileUtilsSpec extends Specification {
     def 'Parse a valid xml content #scenario'() {
         given: 'YANG model schema context'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'the xml data is parsed'
             def parsedXmlContent = XmlFileUtils.prepareXmlContent(xmlData, schemaContext)
         then: 'the result xml is wrapped by root node defined in YANG schema'
@@ -50,7 +50,7 @@ class XmlFileUtilsSpec extends Specification {
     def 'Parse a invalid xml content'() {
         given: 'YANG model schema context'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'attempt to parse invalid xml'
             XmlFileUtils.prepareXmlContent('invalid-xml', schemaContext)
         then: 'a Sax Parser exception is thrown'
@@ -60,7 +60,7 @@ class XmlFileUtilsSpec extends Specification {
     def 'Parse a xml content with XPath container #scenario'() {
         given: 'YANG model schema context'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         and: 'Parent schema node by xPath'
             def parentSchemaNode = YangParserHelper.getDataSchemaNodeAndIdentifiersByXpath(xPath, schemaContext).get('dataSchemaNode')
         when: 'the XML data is parsed'
@@ -133,4 +133,4 @@ class XmlFileUtilsSpec extends Specification {
 
     }
 
-}
\ No newline at end of file
+}
index 646faa0..2f99101 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2024 Nordix Foundation
+ *  Copyright (C) 2024-2025 OpenInfra Foundation Europe. All rights reserved.
  *  ================================================================================
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -38,7 +38,7 @@ class YangParserHelperSpec extends Specification {
             def jsonData = TestUtils.getResourceFileContent('multiple-object-data.json')
         and: 'a model for that data'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('multipleDataTree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'the json data is parsed'
             def result = objectUnderTest.parseData(ContentType.JSON, jsonData, schemaContext, '', validateAndParse)
         then: 'a ContainerNode holding collection of normalized nodes is returned'
@@ -56,7 +56,7 @@ class YangParserHelperSpec extends Specification {
             def fileData = TestUtils.getResourceFileContent(contentFile)
         and: 'a model for that data'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'the data is parsed'
             NormalizedNode result = objectUnderTest.parseData(contentType, fileData, schemaContext, '', validateAndParse)
         then: 'the result is a normalized node of the correct type'
@@ -74,7 +74,7 @@ class YangParserHelperSpec extends Specification {
     def 'Parsing invalid data: #description.'() {
         given: 'a yang model (file)'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'invalid data is parsed'
             objectUnderTest.parseData(contentType, invalidData, schemaContext, '', validateAndParse)
         then: 'an exception is thrown'
@@ -92,7 +92,7 @@ class YangParserHelperSpec extends Specification {
     def 'Parsing data fragment by xpath for #scenario.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).schemaContext()
         when: 'json string is parsed'
             def result = objectUnderTest.parseData(contentType, nodeData, schemaContext, parentNodeXpath, validateAndParse)
         then: 'a ContainerNode holding collection of normalized nodes is returned'
@@ -112,7 +112,7 @@ class YangParserHelperSpec extends Specification {
     def 'Parsing json data fragment by xpath error scenario: #scenario.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('test-tree.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).schemaContext()
         when: 'json string is parsed'
             objectUnderTest.parseData(ContentType.JSON, '{"nest": {"name" : "Nest", "birds": ["bird"]}}', schemaContext, parentNodeXpath, validateAndParse)
         then: 'expected exception is thrown'
@@ -129,7 +129,7 @@ class YangParserHelperSpec extends Specification {
     def 'Parsing json data with invalid json string: #description.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).schemaContext()
         when: 'malformed json string is parsed'
             objectUnderTest.parseData(ContentType.JSON, invalidJson, schemaContext, '', validateAndParse)
         then: 'an exception is thrown'
@@ -143,7 +143,7 @@ class YangParserHelperSpec extends Specification {
     def 'Parsing json data with space.'() {
         given: 'schema context'
             def yangResourcesMap = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourcesMap).schemaContext()
         and: 'some json data with space in the array elements'
             def jsonDataWithSpacesInArrayElement = TestUtils.getResourceFileContent('bookstore.json')
         when: 'that json data is parsed'
@@ -169,7 +169,7 @@ class YangParserHelperSpec extends Specification {
             def fileData = TestUtils.getResourceFileContent(contentFile)
         and: 'the schema context is built for that data model'
             def yangResourceNameToContent = TestUtils.getYangResourcesAsMap('bookstore.yang')
-            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         when: 'the data is parsed to be validated'
             objectUnderTest.parseData(contentType, fileData, schemaContext,  parentNodeXpath, validateOnly)
         then: 'no exception is thrown'
index ad661f6..ad60360 100644 (file)
@@ -55,7 +55,7 @@ class YangParserSpec extends Specification {
 
     def setup() {
         mockYangTextSchemaSourceSetCache.get('my dataspace', 'my schema') >> mockYangTextSchemaSourceSet
-        mockYangTextSchemaSourceSet.getSchemaContext() >> mockSchemaContext
+        mockYangTextSchemaSourceSet.schemaContext() >> mockSchemaContext
     }
 
     def 'Convert RestConf-style path to CPS path'() {
index 7c27efc..577e9db 100644 (file)
@@ -151,7 +151,7 @@ class DeltaReportExecutorSpec extends Specification {
         def mockYangTextSchemaSourceSet = Mock(YangTextSchemaSourceSet)
         mockYangTextSchemaSourceSetCache.get(dataspaceName, schemaSetName) >> mockYangTextSchemaSourceSet
         def yangResourceNameToContent = TestUtils.getYangResourcesAsMap(yangResources)
-        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
-        mockYangTextSchemaSourceSet.getSchemaContext() >> schemaContext
+        def schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
+        mockYangTextSchemaSourceSet.schemaContext() >> schemaContext
     }
 }
index d8f72f0..c5a8a02 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2020-2021 Pantheon.tech
- *  Modifications Copyright (C) 2020-2022 Nordix Foundation
+ *  Modifications Copyright (C) 2020-2025 OpenInfra Foundation Europe.
  *  Modifications Copyright (C) 2021 Bell Canada.
  *  Modifications Copyright (C) 2022 TechMahindra Ltd.
  *  ================================================================================
@@ -36,7 +36,7 @@ class YangTextSchemaSourceSetBuilderSpec extends Specification {
         given: 'a yang model (file)'
             def yangResourceNameToContent = [filename: TestUtils.getResourceFileContent('bookstore.yang')]
         when: 'the content is parsed'
-            def result = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getSchemaContext()
+            def result = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).schemaContext()
         then: 'it can be validated successfully'
             YangTextSchemaSourceSetBuilder.validate(yangResourceNameToContent)
         and: 'the result contains 1 module of the correct name and revision'
index 48b6ff0..350fbc0 100644 (file)
@@ -2384,6 +2384,76 @@ paths:
       summary: Get delta between an anchor and JSON payload
       tags:
       - cps-delta
+  /v2/dataspaces/{dataspace-name}/anchors/{source-anchor-name}/applyChangesInDeltaReport:
+    post:
+      description: Use the delta report to perform batch operations on an anchor in
+        a dataspace.
+      operationId: applyChangesInDeltaReport
+      parameters:
+      - description: dataspace-name
+        in: path
+        name: dataspace-name
+        required: true
+        schema:
+          example: my-dataspace
+          type: string
+      - description: source-anchor-name
+        in: path
+        name: source-anchor-name
+        required: true
+        schema:
+          example: my-anchor
+          type: string
+      requestBody:
+        content:
+          application/json:
+            examples:
+              dataSample:
+                $ref: '#/components/examples/deltaReportSample'
+            schema:
+              type: string
+        required: true
+      responses:
+        "201":
+          content:
+            application/json:
+              schema:
+                example: my-resource
+                type: string
+          description: Created
+        "400":
+          content:
+            application/json:
+              example:
+                status: 400
+                message: Bad Request
+                details: The provided request is not valid
+              schema:
+                $ref: '#/components/schemas/ErrorMessage'
+          description: Bad Request
+        "403":
+          content:
+            application/json:
+              example:
+                status: 403
+                message: Request Forbidden
+                details: This request is forbidden
+              schema:
+                $ref: '#/components/schemas/ErrorMessage'
+          description: Forbidden
+        "500":
+          content:
+            application/json:
+              example:
+                status: 500
+                message: Internal Server Error
+                details: Internal Server Error occurred
+              schema:
+                $ref: '#/components/schemas/ErrorMessage'
+          description: Internal Server Error
+      summary: Apply delta to an anchor
+      tags:
+      - cps-delta
   /v1/dataspaces/{dataspace-name}/anchors/{anchor-name}/nodes/query:
     get:
       deprecated: true