Fix sonar issues - 1 13/13613/1
authoraravind.est <aravindhan.a@est.tech>
Mon, 14 Oct 2024 14:56:19 +0000 (15:56 +0100)
committeraravind.est <aravindhan.a@est.tech>
Mon, 14 Oct 2024 14:56:19 +0000 (15:56 +0100)
Sonar issue fixed

Issue-ID: SMO-151
Change-Id: I18b60c84bf482dc53db4ea55de72c2dbe1e57ef3
Signed-off-by: aravind.est <aravindhan.a@est.tech>
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/FileHelper.java
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/YangModelProcessor.java
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/graphgenerator/EntityGraphGeneratorUml.java
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/schema/BackwardCompatibilityChecker.java
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/schema/data/DataSchemaHelper.java
pgsql-schema-generator/src/main/java/org/oran/smo/teiv/pgsqlgenerator/schema/data/ModelComparator.java
pgsql-schema-generator/src/test/java/org/oran/smo/teiv/pgsqlgenerator/schema/data/DataSchemaGeneratorTest.java
pgsql-schema-generator/src/test/java/org/oran/smo/teiv/pgsqlgenerator/schema/data/GreenFieldInstallationTest.java

index 88662a6..aceb9d1 100644 (file)
@@ -20,6 +20,7 @@
  */
 package org.oran.smo.teiv.pgsqlgenerator;
 
+import java.util.Objects;
 import org.springframework.core.io.ClassPathResource;
 import org.springframework.core.io.Resource;
 import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
@@ -37,6 +38,8 @@ import java.util.List;
 import java.util.Optional;
 
 public class FileHelper {
+    private FileHelper() {
+    }
 
     public static void copyResourceToFile(Resource resource, File destinationFile) throws IOException {
         try {
@@ -71,10 +74,10 @@ public class FileHelper {
     }
 
     private static Optional<File> createTempFileFromJarResource(Resource resource, Path path) throws IOException {
-        if (resource.getFilename().isEmpty()) {
+        if (Objects.requireNonNull(resource.getFilename()).isEmpty()) {
             return Optional.empty();
         }
-        Path pathToFile = Path.of(path + "/" + resource.getFilename());
+        Path pathToFile = Path.of(path + File.pathSeparator + resource.getFilename());
         File file = Files.createFile(pathToFile).toFile();
         writeResourceToFile(file, resource);
         return Optional.of(file);
index 4a39110..1976e57 100644 (file)
@@ -93,24 +93,21 @@ public class YangModelProcessor {
     }
 
     private HashMap<String, String> createDataTypeMapping() {
-        HashMap<String, String> map = new HashMap<String, String>() {
-            {
-                put("string", TEXT);
-                put("uint32", BIGINT);
-                put("int32", INT);
-                put("or-teiv-types:_3GPP_FDN_Type", TEXT);
-                put("enumeration", TEXT);
-                put("types3gpp:PLMNId", JSONB);
-                put("[]", JSONB);
-                put(JSONB, JSONB);
-                put("[uses types3gpp:PLMNId]", JSONB);
-                put("geo:geo-location", "geography");
-                put("uint64", BIGINT);
-                put("int64", BIGINT);
-                put("decimal64", DECIMAL);
-                put("[uses or-teiv-types:CM_ID]", JSONB);
-            }
-        };
+        HashMap<String, String> map = new HashMap<>();
+        map.put("string", TEXT);
+        map.put("uint32", BIGINT);
+        map.put("int32", INT);
+        map.put("or-teiv-types:_3GPP_FDN_Type", TEXT);
+        map.put("enumeration", TEXT);
+        map.put("types3gpp:PLMNId", JSONB);
+        map.put("[]", JSONB);
+        map.put(JSONB, JSONB);
+        map.put("[uses types3gpp:PLMNId]", JSONB);
+        map.put("geo:geo-location", "geography");
+        map.put("uint64", BIGINT);
+        map.put("int64", BIGINT);
+        map.put("decimal64", DECIMAL);
+        map.put("[uses or-teiv-types:CM_ID]", JSONB);
         return map;
     }
 
@@ -126,67 +123,74 @@ public class YangModelProcessor {
 
         yangModels.stream().forEach(yangModel -> {
             YModule yModule = yangModel.getYangModelRoot().getModule();
-            System.out.println("Module Name: " + yModule.getModuleName());
+            StringBuilder modelParserLog = new StringBuilder();
+            modelParserLog.append("Module Name: ").append(yModule.getModuleName());
 
             yModule.getLists().stream().forEach(yList -> {
                 final String tableName = getTableName(yModule.getModuleName(), yList.getListName());
-                System.out.printf("\tEntity Name: %s \n", yList.getListName());
+                modelParserLog.append(String.format("%n\tEntity Name: %s %n", yList.getListName()));
                 List<Attribute> attributes = new ArrayList<>();
-                List constraint = List.of(PrimaryKeyConstraint.builder().constraintName("PK_" + yList.getListName() + "_id")
-                        .tableName(yList.getListName()).columnToAddConstraintTo("id").build());
+                List<Object> constraint = List.of(PrimaryKeyConstraint.builder().constraintName("PK_" + yList
+                        .getListName() + "_id").tableName(yList.getListName()).columnToAddConstraintTo("id").build());
 
                 attributes.add(Attribute.builder().name("id").yangDataType("string").dataType(TEXT).constraints(constraint)
                         .build());
                 yList.getContainers().forEach(yContainer -> {
-                    System.out.printf("\t\tContainer Name: %s \n", yContainer.getContainerName());
+                    modelParserLog.append(String.format("\t\tContainer Name: %s %n", yContainer.getContainerName()));
                     if (yContainer.getContainerName().equals("attributes")) {
-
+                        String leafNameFormat = "\t\t\tLeaf Name: %s %n";
+                        String leafTypeFormat = "\t\t\t\tLeaf Type: %s %n";
+                        String dataTypeFormat = "\t\t\t\tData Type: %s %n";
                         yContainer.getLeafs().forEach(yLeaf -> {
 
-                            System.out.printf("\t\t\tLeaf Name: %s \n", yLeaf.getLeafName());
-                            System.out.printf("\t\t\t\tLeaf Type: %s \n", yLeaf.getType().getDataType());
-                            System.out.printf("\t\t\t\tData Type: %s \n", dataTypeMapping.get(yLeaf.getType()
-                                    .getDataType()));
+                            modelParserLog.append(String.format(leafNameFormat, yLeaf.getLeafName()));
+                            modelParserLog.append(String.format(leafTypeFormat, yLeaf.getType().getDataType()));
+                            modelParserLog.append(String.format(dataTypeFormat, dataTypeMapping.get(yLeaf.getType()
+                                    .getDataType())));
 
                             if (yLeaf.getDefault() != null) {
 
                                 attributes.add(Attribute.builder().name(yLeaf.getLeafName()).yangDataType(yLeaf.getType()
                                         .getDataType()).dataType(dataTypeMapping.get(yLeaf.getType().getDataType()))
-                                        .defaultValue(yLeaf.getDefault().getValue()).constraints(new ArrayList()).build());
+                                        .defaultValue(yLeaf.getDefault().getValue()).constraints(new ArrayList<>())
+                                        .build());
                             } else {
                                 attributes.add(Attribute.builder().name(yLeaf.getLeafName()).yangDataType(yLeaf.getType()
                                         .getDataType()).dataType(dataTypeMapping.get(yLeaf.getType().getDataType()))
-                                        .constraints(new ArrayList()).build());
+                                        .constraints(new ArrayList<>()).build());
                             }
                         });
                         yContainer.getLeafLists().forEach(yLeafList -> {
 
-                            System.out.printf("\t\t\tLeaf Name: %s \n", yLeafList.getLeafListName());
-                            System.out.printf("\t\t\t\tLeaf Type: %s \n", yLeafList.getType().getDataType());
-                            System.out.printf("\t\t\t\tData Type: %s \n", dataTypeMapping.get(yLeafList.getType()
-                                    .getDataType()));
+                            modelParserLog.append(String.format(leafNameFormat, yLeafList.getLeafListName()));
+                            modelParserLog.append(String.format(leafTypeFormat, yLeafList.getType().getDataType()));
+                            modelParserLog.append(String.format(dataTypeFormat, dataTypeMapping.get(yLeafList.getType()
+                                    .getDataType())));
 
                             attributes.add(Attribute.builder().name(yLeafList.getLeafListName()).yangDataType(yLeafList
                                     .getType().getDataType()).dataType(JSONB).indexType(
-                                            IndexType.GIN_TRGM_OPS_ON_LIST_AS_JSONB).constraints(new ArrayList()).build());
+                                            IndexType.GIN_TRGM_OPS_ON_LIST_AS_JSONB).constraints(new ArrayList<>())
+                                    .build());
                         });
                         yContainer.getLists().forEach(yListAttr -> {
 
-                            System.out.printf("\t\t\tLeaf Name: %s \n", yListAttr.getListName());
-                            System.out.printf("\t\t\t\tLeaf Type: %s \n", yListAttr.getUses());
-                            System.out.printf("\t\t\t\tData Type: %s \n", dataTypeMapping.get(yListAttr.getUses()
-                                    .toString()));
+                            modelParserLog.append(String.format(leafNameFormat, yListAttr.getListName()));
+                            modelParserLog.append(String.format(leafTypeFormat, yListAttr.getUses()));
+                            modelParserLog.append(String.format(dataTypeFormat, dataTypeMapping.get(yListAttr.getUses()
+                                    .toString())));
 
                             attributes.add(Attribute.builder().name(yListAttr.getListName()).yangDataType(yListAttr
                                     .getUses().toString()).dataType(JSONB).indexType(
-                                            IndexType.GIN_TRGM_OPS_ON_LIST_AS_JSONB).constraints(new ArrayList()).build());
+                                            IndexType.GIN_TRGM_OPS_ON_LIST_AS_JSONB).constraints(new ArrayList<>())
+                                    .build());
                         });
                         yContainer.getContainers().forEach(container -> {
 
-                            System.out.printf("\t\t\tContainer Name: %s \n", container.getContainerName());
-                            System.out.printf("\t\t\t\tContainer Type: %s \n", container.getUses());
-                            System.out.printf("\t\t\t\tData Type: %s \n", dataTypeMapping.get(container.getUses()
-                                    .toString()));
+                            modelParserLog.append(String.format("\t\t\tContainer Name: %s %n", container
+                                    .getContainerName()));
+                            modelParserLog.append(String.format("\t\t\t\tContainer Type: %s %n", container.getUses()));
+                            modelParserLog.append(String.format(dataTypeFormat, dataTypeMapping.get(container.getUses()
+                                    .toString())));
 
                             String dataType = dataTypeMapping.get(container.getUses().toString());
                             if (container.getContainerName().equals("geo-location")) {
@@ -194,7 +198,7 @@ public class YangModelProcessor {
                             }
                             Attribute.AttributeBuilder attributeBuilder = Attribute.builder().name(container
                                     .getContainerName()).yangDataType("<< Refer to Module >>").dataType(dataType)
-                                    .constraints(new ArrayList());
+                                    .constraints(new ArrayList<>());
                             if (dataType.equals(JSONB)) {
                                 attributeBuilder.indexType(IndexType.GIN);
                             }
@@ -202,12 +206,12 @@ public class YangModelProcessor {
                         });
                         yContainer.getUses().forEach(uses -> {
 
-                            System.out.printf("\t\t\tUses Name: %s \n", uses.getDomElement().getValue());
+                            modelParserLog.append(String.format("\t\t\tUses Name: %s %n", uses.getDomElement().getValue()));
 
                             attributes.add(Attribute.builder().name(uses.getDomElement().getValue().substring(uses
                                     .getDomElement().getValue().indexOf(':') + 1, uses.getDomElement().getValue().length()))
                                     .yangDataType(uses.getDomElement().getValue()).dataType(dataTypeMapping.get(uses
-                                            .getDomElement().getValue())).constraints(new ArrayList()).build());
+                                            .getDomElement().getValue())).constraints(new ArrayList<>()).build());
                         });
                     }
                 });
@@ -215,6 +219,7 @@ public class YangModelProcessor {
                 entities.add(Entity.builder().entityName(yList.getListName()).storedAt(tableName).moduleReferenceName(
                         yangModel.getYangModelRoot().getModule().getModuleName()).attributes(attributes).build());
             });
+            log.info(modelParserLog.toString());
         });
         entities.sort(Comparator.comparing(Entity::getStoredAt));
         return entities;
@@ -232,20 +237,23 @@ public class YangModelProcessor {
 
         yangModels.stream().forEach(yangModel -> {
             YModule yModule = yangModel.getYangModelRoot().getModule();
-            System.out.println("Module Name: " + yModule.getModuleName());
+            StringBuilder modelParserLog = new StringBuilder();
+            modelParserLog.append(String.format("Module Name: %s ", yModule.getModuleName()));
+
+            String oranSmoTeivCommonYangExt = "o-ran-smo-teiv-common-yang-extensions";
 
-            StatementModuleAndName biDirectionalTopologyRelationship = new StatementModuleAndName(
-                    "o-ran-smo-teiv-common-yang-extensions", "biDirectionalTopologyRelationship");
+            StatementModuleAndName biDirectionalTopologyRelationship = new StatementModuleAndName(oranSmoTeivCommonYangExt,
+                    "biDirectionalTopologyRelationship");
             StatementModuleAndName biDirectionalTopologyRelationshipAside = new StatementModuleAndName(
-                    "o-ran-smo-teiv-common-yang-extensions", "aSide");
+                    oranSmoTeivCommonYangExt, "aSide");
             StatementModuleAndName biDirectionalTopologyRelationshipBside = new StatementModuleAndName(
-                    "o-ran-smo-teiv-common-yang-extensions", "bSide");
+                    oranSmoTeivCommonYangExt, "bSide");
 
             yModule.getChildren(biDirectionalTopologyRelationship).stream().map(
-                    abstractStatement -> (YOranSmoTeivBiDirectionalTopologyRelationship) abstractStatement).forEach(
+                    YOranSmoTeivBiDirectionalTopologyRelationship.class::cast).forEach(
                             yOranSmoTeivBiDirectionalTopologyRelationship -> {
-                                System.out.printf("\tRelationship Name: %s \n",
-                                        yOranSmoTeivBiDirectionalTopologyRelationship.getRelationshipName());
+                                modelParserLog.append(String.format("\tRelationship Name: %s %n",
+                                        yOranSmoTeivBiDirectionalTopologyRelationship.getRelationshipName()));
                                 YOranSmoTeivASide aSide = yOranSmoTeivBiDirectionalTopologyRelationship.getChildStatements()
                                         .stream().filter(abstractStatement -> abstractStatement.getChild(
                                                 biDirectionalTopologyRelationshipAside) != null).toList().get(0).getChild(
@@ -256,10 +264,10 @@ public class YangModelProcessor {
                                                 biDirectionalTopologyRelationshipBside) != null).toList().get(0).getChild(
                                                         biDirectionalTopologyRelationshipBside);
 
-                                System.out.printf("\t\tA Side:\n\t\t\t Name: %s \n\t\t\t Type: %s \n", aSide
-                                        .getParentStatement().getStatementIdentifier(), aSide.getTeivTypeName());
-                                System.out.printf("\t\tB Side:\n\t\t\t Name %s \n\t\t\t Type %s \n", bSide
-                                        .getParentStatement().getStatementIdentifier(), bSide.getTeivTypeName());
+                                modelParserLog.append(String.format("\t\tA Side:%n\t\t\t Name: %s %n\t\t\t Type: %s %n",
+                                        aSide.getParentStatement().getStatementIdentifier(), aSide.getTeivTypeName()));
+                                modelParserLog.append(String.format("\t\tB Side:%n\t\t\t Name %s %n\t\t\t Type %s %n", bSide
+                                        .getParentStatement().getStatementIdentifier(), bSide.getTeivTypeName()));
 
                                 long aSideMinCardinality = 0;
                                 long aSideMaxCardinality = 0;
@@ -286,7 +294,7 @@ public class YangModelProcessor {
                                         .getDomElement().getChildren().stream().filter(name -> name.getNameValue().contains(
                                                 "min-elements 1")).findAny();
 
-                                if (aSide.getParentStatement().getDomElement().getName() == "leaf") {
+                                if (aSide.getParentStatement().getDomElement().getName().equals("leaf")) {
                                     if (aSideMandatory.isPresent() || aSideMinElement.isPresent()) {
                                         bSideMinCardinality = 1;
                                     } else {
@@ -295,7 +303,7 @@ public class YangModelProcessor {
                                     bSideMaxCardinality = 1;
 
                                 }
-                                if (aSide.getParentStatement().getDomElement().getName() == "leaf-list") {
+                                if (aSide.getParentStatement().getDomElement().getName().equals("leaf-list")) {
                                     if (aSideMandatory.isPresent() || aSideMinElement.isPresent()) {
                                         bSideMinCardinality = 1;
                                     } else {
@@ -304,7 +312,7 @@ public class YangModelProcessor {
                                     bSideMaxCardinality = Long.MAX_VALUE;
 
                                 }
-                                if (bSide.getParentStatement().getDomElement().getName() == "leaf") {
+                                if (bSide.getParentStatement().getDomElement().getName().equals("leaf")) {
                                     if (bSideMandatory.isPresent() || bSideMinElement.isPresent()) {
                                         aSideMinCardinality = 1;
                                     } else {
@@ -312,7 +320,7 @@ public class YangModelProcessor {
                                     }
                                     aSideMaxCardinality = 1;
                                 }
-                                if (bSide.getParentStatement().getDomElement().getName() == "leaf-list") {
+                                if (bSide.getParentStatement().getDomElement().getName().equals("leaf-list")) {
                                     if (bSideMandatory.isPresent() || bSideMinElement.isPresent()) {
                                         aSideMinCardinality = 1;
                                     } else {
@@ -363,6 +371,7 @@ public class YangModelProcessor {
                                                                         bSideModuleName, bSideMoType)).build();     // Hard coded for now
                                 relationships.add(relationship);
                             });
+            log.info(modelParserLog.toString());
         });
         relationships.sort(Comparator.comparing(Relationship::getName));
         return relationships;
index 9cd0e0a..f8bad0d 100644 (file)
@@ -70,9 +70,9 @@ public class EntityGraphGeneratorUml {
         sb.append("    BackgroundColor<<Entity>> LightGray\n");
         sb.append("    BackgroundColor<<Module>> LightBlue\n");
         sb.append("}\n");
-        sb.append(String.format("class %s <<Module>> {\n}\n", moduleName));
+        sb.append(String.format("class %s <<Module>> {%n}%n", moduleName));
         for (Entity entity : entities) {
-            sb.append(String.format("class %s <<Entity>> {\n", entity.getEntityName()));
+            sb.append(String.format("class %s <<Entity>> {%n", entity.getEntityName()));
             List<Attribute> attributes = entity.getAttributes();
             for (Attribute attribute : attributes) {
                 sb.append(String.format("    %s : %s\n", attribute.getName(), attribute.getYangDataType()));
index 0fae2fc..be6a66d 100644 (file)
@@ -41,6 +41,7 @@ public class BackwardCompatibilityChecker {
 
     @Value("${green-field-installation}")
     private boolean isGreenFieldInstallation;
+    String noNBCCheckMsg = "No NBC checks done as green field installation is enabled";
 
     public void checkForNBCChangesInModel(List<Relationship> relationshipsInBaselineSql,
             List<Relationship> relationshipsFromModelSvc) {
@@ -64,7 +65,7 @@ public class BackwardCompatibilityChecker {
                 });
             });
         } else {
-            log.info("No NBC checks done as green field installation is enabled");
+            log.info(noNBCCheckMsg);
         }
     }
 
@@ -73,16 +74,15 @@ public class BackwardCompatibilityChecker {
             tablesInBaselineSql.forEach(baselineTable -> {
                 Optional<Table> matchingTable = tablesFromModelSvc.stream().filter(modelTable -> modelTable.getName()
                         .equals(baselineTable.getName())).findFirst();
-                matchingTable.ifPresentOrElse(table -> {
-                    verifyTableColumns(baselineTable.getColumns(), table.getColumns(), table.getName());
-                }, () -> {
-                    throw PgSchemaGeneratorException.nbcChangeIdentifiedException(String.format(
-                            "modified/removed table(%s) present in baseline", baselineTable.getName()),
-                            new UnsupportedOperationException());
-                });
+                matchingTable.ifPresentOrElse(table -> verifyTableColumns(baselineTable.getColumns(), table.getColumns(),
+                        table.getName()), () -> {
+                            throw PgSchemaGeneratorException.nbcChangeIdentifiedException(String.format(
+                                    "modified/removed table(%s) present in baseline", baselineTable.getName()),
+                                    new UnsupportedOperationException());
+                        });
             });
         } else {
-            log.info("No NBC checks done as green field installation is enabled");
+            log.info(noNBCCheckMsg);
         }
     }
 
@@ -93,7 +93,7 @@ public class BackwardCompatibilityChecker {
             final List<Table> skeletonTables = SchemaParser.extractDataFromBaseline(skeletonConsumerDataSchema);
             checkForNBCChangesInData(baselineTables, skeletonTables);
         } else {
-            log.info("No NBC checks done as green field installation is enabled");
+            log.info(noNBCCheckMsg);
         }
     }
 
@@ -118,24 +118,25 @@ public class BackwardCompatibilityChecker {
             Optional<PostgresConstraint> matchingConstraint = modelColumn.getPostgresConstraints().stream().filter(
                     constraint1 -> constraint1.getConstraintName().equals(constraint.getConstraintName())).findFirst();
 
+            String modifiedOrRemovedConstraintFromBaseline = "modified/removed constraint for column(%s.%s) present in baseline";
             matchingConstraint.ifPresentOrElse(constraint1 -> {
                 if (!constraint.getTableToAddConstraintTo().equals(constraint1.getTableToAddConstraintTo()) && !constraint
                         .getColumnToAddConstraintTo().equals(constraint1.getColumnToAddConstraintTo()) && !constraint
                                 .getConstraintName().equals(constraint1.getConstraintName())) {
                     throw PgSchemaGeneratorException.nbcChangeIdentifiedException(String.format(
-                            "modified/removed constraint for column(%s.%s) present in baseline", tableName, baselineColumn
-                                    .getName()), new UnsupportedOperationException());
+                            modifiedOrRemovedConstraintFromBaseline, tableName, baselineColumn.getName()),
+                            new UnsupportedOperationException());
                 }
                 if (constraint instanceof ForeignKeyConstraint && !constraint.getTableToAddConstraintTo().equals(constraint1
                         .getTableToAddConstraintTo())) {
                     throw PgSchemaGeneratorException.nbcChangeIdentifiedException(String.format(
-                            "modified/removed constraint for column(%s.%s) present in baseline", tableName, baselineColumn
-                                    .getName()), new UnsupportedOperationException());
+                            modifiedOrRemovedConstraintFromBaseline, tableName, baselineColumn.getName()),
+                            new UnsupportedOperationException());
                 }
             }, () -> {
                 throw PgSchemaGeneratorException.nbcChangeIdentifiedException(String.format(
-                        "modified/removed constraint for column(%s.%s) present in baseline", tableName, baselineColumn
-                                .getName()), new UnsupportedOperationException());
+                        modifiedOrRemovedConstraintFromBaseline, tableName, baselineColumn.getName()),
+                        new UnsupportedOperationException());
             });
         }
     }
index 84d4a57..1e1e4f5 100644 (file)
@@ -168,11 +168,8 @@ public class DataSchemaHelper {
 
     private StringBuilder generateIndexStatementForColumns(List<Column> columns) {
         StringBuilder indexStmt = new StringBuilder();
-        columns.forEach(column -> {
-            column.getPostgresIndexList().forEach(postgresIndex -> {
-                indexStmt.append(generateIndexStatement(postgresIndex));
-            });
-        });
+        columns.forEach(column -> column.getPostgresIndexList().forEach(postgresIndex -> indexStmt.append(
+                generateIndexStatement(postgresIndex))));
         return indexStmt;
     }
 
@@ -181,12 +178,11 @@ public class DataSchemaHelper {
             return String.format(ALTER_TABLE_TIES_DATA_S_ADD_CONSTRAINT_S + "PRIMARY KEY (\"%s\")", postgresConstraint
                     .getTableToAddConstraintTo(), postgresConstraint.getConstraintName(), postgresConstraint
                             .getColumnToAddConstraintTo());
-        } else if (postgresConstraint instanceof ForeignKeyConstraint) {
+        } else if (postgresConstraint instanceof ForeignKeyConstraint foreignKeyConstraint) {
             return String.format(
                     ALTER_TABLE_TIES_DATA_S_ADD_CONSTRAINT_S + "FOREIGN KEY (\"%s\") REFERENCES ties_data.\"%s\" (id) ON DELETE CASCADE",
                     postgresConstraint.getTableToAddConstraintTo(), postgresConstraint.getConstraintName(),
-                    postgresConstraint.getColumnToAddConstraintTo(), ((ForeignKeyConstraint) postgresConstraint)
-                            .getReferencedTable());
+                    postgresConstraint.getColumnToAddConstraintTo(), foreignKeyConstraint.getReferencedTable());
         } else if (postgresConstraint instanceof UniqueConstraint) {
             return String.format(ALTER_TABLE_TIES_DATA_S_ADD_CONSTRAINT_S + "UNIQUE (\"%s\")", postgresConstraint
                     .getTableToAddConstraintTo(), postgresConstraint.getConstraintName(), postgresConstraint
@@ -268,9 +264,7 @@ public class DataSchemaHelper {
             StringBuilder storeSchema = new StringBuilder();
             for (Column column : table.getColumns()) {
                 if (!column.getPostgresIndexList().isEmpty()) {
-                    column.getPostgresIndexList().forEach(index -> {
-                        storeSchema.append(generateIndexStatement(index));
-                    });
+                    column.getPostgresIndexList().forEach(index -> storeSchema.append(generateIndexStatement(index)));
                 }
             }
             storeSchemaForIndexStatements.append(storeSchema);
index 2eb3281..6d37967 100644 (file)
@@ -96,26 +96,25 @@ public class ModelComparator {
      * Compare columns of each table from module service with columns of each table from baseline schema
      */
     private void compareAndStoreChangesToColumns(List<Table> tablesFromModelService, List<Table> tablesFromBaselineSql) {
-        tablesFromModelService.forEach(tableFromModelService -> {
-            tablesFromBaselineSql.stream().filter(baselineTable -> tableFromModelService.getName().equals(baselineTable
-                    .getName())).findFirst().ifPresent(baselineTable -> {
-
-                        List<Column> columnsInBaseline = new ArrayList<>(baselineTable.getColumns());
-                        List<Column> columnsFromModuleSvc = new ArrayList<>(tableFromModelService.getColumns());
-
-                        columnsInBaseline.sort(Comparator.comparing(Column::getName));
-                        columnsFromModuleSvc.sort(Comparator.comparing(Column::getName));
-
-                        // Check for new columns in table
-                        if (columnsFromModuleSvc.size() > columnsInBaseline.size()) {
-                            storeNewColumns(tableFromModelService.getName(), columnsInBaseline, columnsFromModuleSvc);
-                        }
-                        detectAndStoreDefaultValueChanges(tableFromModelService.getName(), columnsInBaseline,
-                                columnsFromModuleSvc);
-                        detectAndStoreNewlyAddedIndex(tableFromModelService.getName(), columnsInBaseline,
-                                columnsFromModuleSvc);
-                    });
-        });
+        tablesFromModelService.forEach(tableFromModelService -> tablesFromBaselineSql.stream().filter(
+                baselineTable -> tableFromModelService.getName().equals(baselineTable.getName())).findFirst().ifPresent(
+                        baselineTable -> {
+
+                            List<Column> columnsInBaseline = new ArrayList<>(baselineTable.getColumns());
+                            List<Column> columnsFromModuleSvc = new ArrayList<>(tableFromModelService.getColumns());
+
+                            columnsInBaseline.sort(Comparator.comparing(Column::getName));
+                            columnsFromModuleSvc.sort(Comparator.comparing(Column::getName));
+
+                            // Check for new columns in table
+                            if (columnsFromModuleSvc.size() > columnsInBaseline.size()) {
+                                storeNewColumns(tableFromModelService.getName(), columnsInBaseline, columnsFromModuleSvc);
+                            }
+                            detectAndStoreDefaultValueChanges(tableFromModelService.getName(), columnsInBaseline,
+                                    columnsFromModuleSvc);
+                            detectAndStoreNewlyAddedIndex(tableFromModelService.getName(), columnsInBaseline,
+                                    columnsFromModuleSvc);
+                        }));
     }
 
     private List<String> extractTableNames(List<Table> tables) {
@@ -141,14 +140,12 @@ public class ModelComparator {
     private void detectAndStoreDefaultValueChanges(String tableName, List<Column> columnsInBaseline,
             List<Column> columnsFromModuleSvc) {
         List<Column> list = new ArrayList<>();
-        columnsInBaseline.forEach(columnInBaseline -> {
-            columnsFromModuleSvc.forEach(columnInGenerated -> {
-                if (columnInGenerated.getName().equals(columnInBaseline.getName()) && !Objects.equals(columnInGenerated
-                        .getDefaultValue(), columnInBaseline.getDefaultValue())) {
-                    list.add(columnInGenerated);
-                }
-            });
-        });
+        columnsInBaseline.forEach(columnInBaseline -> columnsFromModuleSvc.forEach(columnInGenerated -> {
+            if (columnInGenerated.getName().equals(columnInBaseline.getName()) && !Objects.equals(columnInGenerated
+                    .getDefaultValue(), columnInBaseline.getDefaultValue())) {
+                list.add(columnInGenerated);
+            }
+        }));
         if (!list.isEmpty()) {
             identifiedChangesToModels.get(DEFAULT).add(Table.builder().name(tableName).columns(list).build());
         }
index 60ac6db..db2bf75 100644 (file)
@@ -40,7 +40,7 @@ import org.springframework.util.ResourceUtils;
 @SpringBootTest(classes = { DataSchemaGenerator.class, ModelComparator.class, DataSchemaHelper.class, TableBuilder.class,
         HashInfoDataGenerator.class, BackwardCompatibilityChecker.class }, properties = {
                 "green-field-installation=false" })
-public class DataSchemaGeneratorTest {
+class DataSchemaGeneratorTest {
     @Autowired
     private DataSchemaGenerator dataSchemaGenerator;
     @Value("${green-field-installation}")
index 78b4add..4bf0d65 100644 (file)
@@ -44,7 +44,7 @@ import org.oran.smo.teiv.pgsqlgenerator.schema.model.HashInfoDataGenerator;
 
 @SpringBootTest(classes = { DataSchemaGenerator.class, ModelComparator.class, DataSchemaHelper.class, TableBuilder.class,
         HashInfoDataGenerator.class, BackwardCompatibilityChecker.class }, properties = { "green-field-installation=true" })
-public class GreenFieldInstallationTest {
+class GreenFieldInstallationTest {
 
     static File outputSqlFile;
     @Autowired