Rename name column in yang resource table 80/130180/2
authorDylanB95EST <dylan.byrne@est.tech>
Thu, 4 Aug 2022 17:07:24 +0000 (18:07 +0100)
committerDylanB95EST <dylan.byrne@est.tech>
Fri, 5 Aug 2022 08:52:55 +0000 (09:52 +0100)
- Rename name column in yang_resource table to file_name
- Refactor instances where it occures in code and tests
- Add new changelog file to rename occurance

Issue-ID: CPS-529
Change-Id: I2aff97410bdb041b90d8ceaeff75e562ef8d9238
Signed-off-by: DylanB95EST <dylan.byrne@est.tech>
cps-ri/src/main/java/org/onap/cps/spi/entities/YangResourceEntity.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceImpl.java
cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java
cps-ri/src/main/resources/changelog/changelog-master.yaml
cps-ri/src/main/resources/changelog/db/changes/15-rename-column-yang-resource-table.yaml [new file with mode: 0644]
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsDataPersistenceServiceSpec.groovy
cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsModulePersistenceServiceIntegrationSpec.groovy
cps-ri/src/test/resources/data/anchors-schemaset-modules.sql
cps-ri/src/test/resources/data/cps-path-query.sql
cps-ri/src/test/resources/data/fragment.sql
cps-ri/src/test/resources/data/schemaset.sql

index 032745b..7a864a9 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  ============LICENSE_START=======================================================
  *  Copyright (C) 2020 Pantheon.tech
- *  Modifications Copyright (C) 2021 Nordix Foundation
+ *  Modifications Copyright (C) 2021-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.
@@ -56,7 +56,7 @@ public class YangResourceEntity implements Serializable {
 
     @NotNull
     @Column
-    private String name;
+    private String fileName;
 
     @NotNull
     @Column
index 117cb43..9443355 100644 (file)
@@ -263,7 +263,7 @@ public class CpsDataPersistenceServiceImpl implements CpsDataPersistenceService
         final SchemaSetEntity schemaSetEntity = fragmentEntity.getAnchor().getSchemaSet();
         final Map<String, String> yangResourceNameToContent =
                 schemaSetEntity.getYangResources().stream().collect(
-                        Collectors.toMap(YangResourceEntity::getName, YangResourceEntity::getContent));
+                        Collectors.toMap(YangResourceEntity::getFileName, YangResourceEntity::getContent));
         final SchemaContext schemaContext = YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent)
                 .getSchemaContext();
         return schemaContext.getModules().iterator().next().getName();
index 806e7cc..647d6cd 100755 (executable)
@@ -96,7 +96,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
         final var schemaSetEntity =
             schemaSetRepository.getByDataspaceAndName(dataspaceEntity, schemaSetName);
         return schemaSetEntity.getYangResources().stream().collect(
-            Collectors.toMap(YangResourceEntity::getName, YangResourceEntity::getContent));
+            Collectors.toMap(YangResourceEntity::getFileName, YangResourceEntity::getContent));
     }
 
     @Override
@@ -203,7 +203,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
                 final Map<String, String> moduleNameAndRevisionMap = createModuleNameAndRevisionMap(entry.getKey(),
                             entry.getValue());
                 final var yangResourceEntity = new YangResourceEntity();
-                yangResourceEntity.setName(entry.getKey());
+                yangResourceEntity.setFileName(entry.getKey());
                 yangResourceEntity.setContent(entry.getValue());
                 yangResourceEntity.setModuleName(moduleNameAndRevisionMap.get("moduleName"));
                 yangResourceEntity.setRevision(moduleNameAndRevisionMap.get("revision"));
@@ -328,7 +328,7 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ
                 yangResourceEntities.stream()
                         .filter(entity -> StringUtils.equals(checksum, (entity.getChecksum())))
                         .findFirst()
-                        .map(YangResourceEntity::getName)
+                        .map(YangResourceEntity::getFileName)
                         .orElse(null);
     }
 
index aa1b49d..218e78b 100644 (file)
@@ -44,3 +44,5 @@ databaseChangeLog:
       file: changelog/db/changes/13-insert-dmi-registry-2022-02-10-schema-set.yaml
   - include:
       file: changelog/db/changes/14-loadData-dmi-registry-2022-05-10-schema-set.yaml
+  - include:
+      file: changelog/db/changes/15-rename-column-yang-resource-table.yaml
\ No newline at end of file
diff --git a/cps-ri/src/main/resources/changelog/db/changes/15-rename-column-yang-resource-table.yaml b/cps-ri/src/main/resources/changelog/db/changes/15-rename-column-yang-resource-table.yaml
new file mode 100644 (file)
index 0000000..71f11a5
--- /dev/null
@@ -0,0 +1,14 @@
+databaseChangeLog:
+  - changeSet:
+      author: cps
+      label: yang-resource-rename-column
+      id: 15
+      changes:
+        - renameColumn:
+            tableName: yang_resource
+            columnDataType: TEXT
+            oldColumnName: name
+            newColumnName: file_name
+      rollback:
+        - sql:
+            sql: alter table yang_resource rename column file_name to name
\ No newline at end of file
index bb80199..bde2f3d 100644 (file)
@@ -23,7 +23,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
 import org.hibernate.StaleStateException
 import org.onap.cps.spi.FetchDescendantsOption
 import org.onap.cps.spi.entities.AnchorEntity
-import org.onap.cps.spi.entities.DataspaceEntity
 import org.onap.cps.spi.entities.FragmentEntity
 import org.onap.cps.spi.entities.SchemaSetEntity
 import org.onap.cps.spi.entities.YangResourceEntity
@@ -35,9 +34,6 @@ import org.onap.cps.spi.repository.DataspaceRepository
 import org.onap.cps.spi.repository.FragmentRepository
 import org.onap.cps.spi.utils.SessionManager
 import org.onap.cps.utils.JsonObjectMapper
-import org.onap.cps.yang.YangTextSchemaSourceSet
-import org.onap.cps.yang.YangTextSchemaSourceSetBuilder
-import org.opendaylight.yangtools.yang.model.api.SchemaContext
 import spock.lang.Shared
 import spock.lang.Specification
 
@@ -67,7 +63,7 @@ class CpsDataPersistenceServiceSpec extends Specification {
 
     @Shared
     def yangResourceSet = [new YangResourceEntity(moduleName: 'moduleName', content: NEW_RESOURCE_CONTENT,
-            name: 'sampleYangResource'
+            fileName: 'sampleYangResource'
     )] as Set
 
 
index 8a43e51..3249d51 100644 (file)
@@ -30,7 +30,6 @@ import org.onap.cps.spi.model.ModuleDefinition
 import org.onap.cps.spi.model.ModuleReference
 import org.onap.cps.spi.repository.AnchorRepository
 import org.onap.cps.spi.repository.SchemaSetRepository
-import org.onap.cps.spi.repository.YangResourceRepository
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.jdbc.Sql
 
@@ -244,7 +243,7 @@ class CpsModulePersistenceServiceIntegrationSpec extends CpsPersistenceSpecBase
         // assert the attached yang resource content
         YangResourceEntity yangResourceEntity = yangResourceEntities.iterator().next()
         assert yangResourceEntity.id != null
-        yangResourceEntity.name == expectedYangResourceName
+        yangResourceEntity.fileName == expectedYangResourceName
         yangResourceEntity.content == expectedYangResourceContent
         yangResourceEntity.checksum == expectedYangResourceChecksum
         yangResourceEntity.moduleName == expectedYangResourceModuleName
index 45119de..65b3a48 100644 (file)
@@ -1,6 +1,6 @@
 /*
    ============LICENSE_START=======================================================
-    Copyright (C) 2021 Nordix Foundation.
+    Copyright (C) 2021-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.
@@ -27,7 +27,7 @@ INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
     (2003, 'schema-set-3', 1001),
     (2004, 'schema-set-4', 1002);
 
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+INSERT INTO YANG_RESOURCE (ID, FILE_NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
     (3001, 'module1@revA.yang', 'some-content', 'checksum1','module-name-1','revA'),
     (3002, 'module2@revA.yang', 'some-content', 'checksum2','module-name-2','revA'),
     (3003, 'module2@revB.yang', 'some-content', 'checksum3','module-name-2','revB'),
index c406203..b6000cf 100644 (file)
@@ -25,7 +25,7 @@ INSERT INTO DATASPACE (ID, NAME) VALUES
 INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
     (2001, 'SCHEMA-SET-001', 1001);
 
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+INSERT INTO YANG_RESOURCE (ID, FILE_NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
     (4001, 'TEST','', 'SAMPLECHECKSUM','TESTMODULENAME', 'SAMPLEREVISION');
 
 UPDATE YANG_RESOURCE SET
index fd05900..bc6e4e7 100755 (executable)
@@ -27,7 +27,7 @@ INSERT INTO DATASPACE (ID, NAME) VALUES
 INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
     (2001, 'SCHEMA-SET-001', 1001);
 
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+INSERT INTO YANG_RESOURCE (ID, FILE_NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
     (4001, 'TEST','', 'SAMPLECHECKSUM','TESTMODULENAME', 'SAMPLEREVISION');
 
 UPDATE YANG_RESOURCE SET
index 2b0a896..ad61166 100644 (file)
@@ -1,7 +1,7 @@
 /*
    ============LICENSE_START=======================================================
     Copyright (C) 2020-2021 Pantheon.tech
-    Modifications Copyright (C) 2020 Nordix Foundation.
+    Modifications Copyright (C) 2020-2022 Nordix Foundation.
     Modifications Copyright (C) 2020-2021 Bell Canada.
    ================================================================================
    Licensed under the Apache License, Version 2.0 (the "License");
@@ -32,7 +32,7 @@ INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
     (2004, 'SCHEMA-SET-004', 1002),
     (2005, 'SCHEMA-SET-005', 1001);
 
-INSERT INTO YANG_RESOURCE (ID, NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
+INSERT INTO YANG_RESOURCE (ID, FILE_NAME, CONTENT, CHECKSUM, MODULE_NAME, REVISION) VALUES
     (3001, 'module1@2020-02-02.yang', 'CONTENT-001', 'e8bdda931099310de66532e08c3fafec391db29f55c81927b168f6aa8f81b73b',null,null),
     (3002, 'module2@2020-02-02.yang', 'CONTENT-002', '7e7d48afbe066ed0a890a09081859046d3dde52300dfcdb13be5b20780353a11','MODULE-NAME-002','REVISION-002'),
     (3003, 'module3@2020-02-02.yang', 'CONTENT-003', 'ca20c45fec8547633f05ff8905c48ffa7b02b94ec3ad4ed79922e6ba40779df3','MODULE-NAME-003','REVISION-002'),