From 2093f870663f6e1b3be5df19de34053ffd985f77 Mon Sep 17 00:00:00 2001 From: Alan Bryant Date: Fri, 20 Dec 2024 08:18:54 -0500 Subject: [PATCH] [BACKLOG-42865] - allow config object rename to same case --- .../connections/ui/dialog/ConnectionDialog.java | 3 ++- .../di/engine/ui/RunConfigurationDialog.java | 1 + .../di/ui/cluster/dialog/ClusterSchemaDialog.java | 1 + .../di/ui/cluster/dialog/SlaveServerDialog.java | 1 + .../core/database/dialog/DataOverrideHandler.java | 1 + .../ui/partition/dialog/PartitionSchemaDialog.java | 1 + .../ui/spoon/delegates/SpoonClustersDelegate.java | 5 ++--- .../di/ui/spoon/delegates/SpoonDBDelegate.java | 12 ++---------- .../spoon/delegates/SpoonPartitionsDelegate.java | 6 +++--- .../di/ui/spoon/delegates/SpoonSlaveDelegate.java | 6 +++--- .../java/org/pentaho/di/ui/util/DialogUtils.java | 14 ++++++++++++-- 11 files changed, 29 insertions(+), 22 deletions(-) diff --git a/plugins/connections/ui/src/main/java/org/pentaho/di/vfs/connections/ui/dialog/ConnectionDialog.java b/plugins/connections/ui/src/main/java/org/pentaho/di/vfs/connections/ui/dialog/ConnectionDialog.java index a557c2c80264..ecffa286b465 100644 --- a/plugins/connections/ui/src/main/java/org/pentaho/di/vfs/connections/ui/dialog/ConnectionDialog.java +++ b/plugins/connections/ui/src/main/java/org/pentaho/di/vfs/connections/ui/dialog/ConnectionDialog.java @@ -465,6 +465,7 @@ private void ok() { connectionDetails.setName( connectionDetails.getName().trim() ); if ( !connectionDetails.getName().equals( originalName ) ) { List names = connectionManager.getNames(); + names.remove( originalName ); if ( names.stream().anyMatch( n -> n.equalsIgnoreCase( connectionDetails.getName().trim() ) ) ) { String title = BaseMessages.getString( PKG, "ConnectionDialog.ConnectionNameExists.Title" ); String message = @@ -478,10 +479,10 @@ private void ok() { } } - connectionManager.save( connectionDetails ); if ( originalName != null && !originalName.equals( connectionDetails.getName() ) ) { connectionManager.delete( originalName ); } + connectionManager.save( connectionDetails ); refreshMenu(); dispose(); } diff --git a/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/ui/RunConfigurationDialog.java b/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/ui/RunConfigurationDialog.java index d8e422f8d3c8..d63b203474aa 100644 --- a/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/ui/RunConfigurationDialog.java +++ b/plugins/engine-configuration/impl/src/main/java/org/pentaho/di/engine/ui/RunConfigurationDialog.java @@ -321,6 +321,7 @@ private void ok() { if ( validated() ) { runConfiguration.setName( runConfiguration.getName().trim() ); if ( !runConfiguration.getName().equals( originalName ) ) { + existingNames.remove( originalName ); if ( existingNames.stream().anyMatch( n -> n.equalsIgnoreCase( runConfiguration.getName().trim() ) ) ) { String title = BaseMessages.getString( PKG, "RunConfigurationDialog.RunConfigurationNameExists.Title" ); String message = diff --git a/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/ClusterSchemaDialog.java b/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/ClusterSchemaDialog.java index f3ae7b3e5d8d..bd33802c8e5e 100644 --- a/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/ClusterSchemaDialog.java +++ b/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/ClusterSchemaDialog.java @@ -453,6 +453,7 @@ public void ok() { clusterSchema.setName( clusterSchema.getName().trim() ); if ( !clusterSchema.getName().equals( originalSchema.getName() ) ) { + DialogUtils.removeMatchingObject( originalSchema.getName(), existingSchemas ); if ( DialogUtils.objectWithTheSameNameExists( clusterSchema, existingSchemas ) ) { String title = BaseMessages.getString( PKG, "ClusterSchemaDialog.ClusterSchemaNameExists.Title" ); String message = diff --git a/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/SlaveServerDialog.java b/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/SlaveServerDialog.java index 5655a6445cd6..7e8ddd40d57f 100644 --- a/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/SlaveServerDialog.java +++ b/ui/src/main/java/org/pentaho/di/ui/cluster/dialog/SlaveServerDialog.java @@ -539,6 +539,7 @@ public void ok() { slaveServer.setName( newName ); String origName = trim( originalServer.getName() ); if ( !newName.equals( origName ) ) { + DialogUtils.removeMatchingObject( origName, existingServers ); if ( DialogUtils.objectWithTheSameNameExists( slaveServer, existingServers ) ) { String title = BaseMessages.getString( PKG, "SlaveServerDialog.SlaveServerNameExists.Title" ); String message = diff --git a/ui/src/main/java/org/pentaho/di/ui/core/database/dialog/DataOverrideHandler.java b/ui/src/main/java/org/pentaho/di/ui/core/database/dialog/DataOverrideHandler.java index 256410eeb023..e32aed230367 100644 --- a/ui/src/main/java/org/pentaho/di/ui/core/database/dialog/DataOverrideHandler.java +++ b/ui/src/main/java/org/pentaho/di/ui/core/database/dialog/DataOverrideHandler.java @@ -64,6 +64,7 @@ public void onOK() { DatabaseMeta database = new DatabaseMeta(); this.getInfo( database ); if ( ! Objects.equals( database.getName(), originalName ) ) { + DialogUtils.removeMatchingObject( originalName, databases ); if ( DialogUtils.objectWithTheSameNameExists( database, databases ) ) { DatabaseDialog.showDatabaseExistsDialog( getShell(), database ); return; diff --git a/ui/src/main/java/org/pentaho/di/ui/partition/dialog/PartitionSchemaDialog.java b/ui/src/main/java/org/pentaho/di/ui/partition/dialog/PartitionSchemaDialog.java index 5ce8dccaf1b6..cca17ecc65b3 100644 --- a/ui/src/main/java/org/pentaho/di/ui/partition/dialog/PartitionSchemaDialog.java +++ b/ui/src/main/java/org/pentaho/di/ui/partition/dialog/PartitionSchemaDialog.java @@ -334,6 +334,7 @@ public void ok() { partitionSchema.setName( partitionSchema.getName().trim() ); if ( !partitionSchema.getName().equals( originalSchema.getName() ) ) { + DialogUtils.removeMatchingObject( originalSchema.getName(), existingSchemas ); if ( DialogUtils.objectWithTheSameNameExists( partitionSchema, existingSchemas ) ) { String title = BaseMessages.getString( PKG, "PartitionSchemaDialog.PartitionSchemaNameExists.Title" ); String message = diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonClustersDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonClustersDelegate.java index 1ff912914372..20dc7af40a08 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonClustersDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonClustersDelegate.java @@ -110,11 +110,10 @@ public void editClusterSchema( TransMeta transMeta, ClusterSchemaManagementInter new ClusterSchemaDialog( spoon.getShell(), clusterSchema, manager.getAll(), slaveServers ); if ( dialog.open() ) { String newName = clusterSchema.getName().trim(); - manager.add( clusterSchema ); - - if ( !newName.equalsIgnoreCase( originalName ) ) { + if ( !newName.equals( originalName ) ) { manager.remove( originalName ); } + manager.add( clusterSchema ); if ( spoon.rep != null && clusterSchema.getObjectId() != null ) { try { saveSharedObjectToRepository( clusterSchema, null ); diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonDBDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonDBDelegate.java index 560011e7ef36..509c5104ac12 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonDBDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonDBDelegate.java @@ -97,22 +97,14 @@ public void editConnection( DatabaseManagementInterface dbManager, DatabaseMeta databaseMeta.setName( originalName ); databaseMeta = getDatabaseDialog().getDatabaseMeta(); - if ( !newname.equals( originalName ) - && databaseMeta.findDatabase( dbManager.getAll(), newname ) != null ) { - databaseMeta.setName( newname.trim() ); - DatabaseDialog.showDatabaseExistsDialog( spoon.getShell(), databaseMeta ); - databaseMeta.setName( originalName ); - databaseMeta.setDisplayName( originalName ); - return; - } databaseMeta.setName( newname.trim() ); databaseMeta.setDisplayName( newname.trim() ); - dbManager.add( databaseMeta ); - if ( !newname.equals( originalName ) ) { dbManager.remove( originalName ); spoon.refreshDbConnection( newname.trim() ); } + + dbManager.add( databaseMeta ); spoon.refreshDbConnection( originalName ); refreshTree(); } diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonPartitionsDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonPartitionsDelegate.java index 10c7b10ef769..512065b1fc23 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonPartitionsDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonPartitionsDelegate.java @@ -104,12 +104,12 @@ public void editPartitionSchema( TransMeta transMeta, PartitionSchemaManagementI databaseMetas, spoon.getBowl().getADefaultVariableSpace() ); if ( dialog.open() ) { String newName = partitionSchema.getName().trim(); - partitionSchemaManager.add( partitionSchema ); - - if ( !newName.equalsIgnoreCase( originalName ) ) { + if ( !newName.equals( originalName ) ) { partitionSchemaManager.remove( originalName ); refreshTree(); } + partitionSchemaManager.add( partitionSchema ); + if ( spoon.rep != null && partitionSchema.getObjectId() != null ) { saveSharedObjectToRepository( partitionSchema, null ); if ( sharedObjectSyncUtil != null ) { diff --git a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonSlaveDelegate.java b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonSlaveDelegate.java index de0538845d4a..2b888639105c 100644 --- a/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonSlaveDelegate.java +++ b/ui/src/main/java/org/pentaho/di/ui/spoon/delegates/SpoonSlaveDelegate.java @@ -163,12 +163,12 @@ public void edit( SlaveServerManagementInterface slaveServerManager, SlaveServer SlaveServerDialog dialog = new SlaveServerDialog( spoon.getShell(), slaveServer, slaveServerManager.getAll() ); if ( dialog.open() ) { String newName = slaveServer.getName().trim(); - slaveServerManager.add( slaveServer ); - - if ( !newName.equalsIgnoreCase( originalName ) ) { + if ( !newName.equals( originalName ) ) { slaveServerManager.remove( originalName ); refreshTree(); } + slaveServerManager.add( slaveServer ); + if ( spoon.rep != null ) { try { saveSharedObjectToRepository( slaveServer, null ); diff --git a/ui/src/main/java/org/pentaho/di/ui/util/DialogUtils.java b/ui/src/main/java/org/pentaho/di/ui/util/DialogUtils.java index 2692c96ad38b..b72413898b6e 100644 --- a/ui/src/main/java/org/pentaho/di/ui/util/DialogUtils.java +++ b/ui/src/main/java/org/pentaho/di/ui/util/DialogUtils.java @@ -22,13 +22,14 @@ package org.pentaho.di.ui.util; -import java.util.Collection; - import org.pentaho.di.core.Const; import org.pentaho.di.repository.RepositoryDirectoryInterface; import org.pentaho.di.repository.RepositoryElementMetaInterface; import org.pentaho.di.shared.SharedObjectInterface; +import java.util.Collection; +import java.util.Iterator; + /** * @author Andrey Khayrutdinov */ @@ -64,6 +65,15 @@ public static boolean objectWithTheSameNameExists( SharedObjectInterface object, return false; } + public static void removeMatchingObject( String nameToRemove, Collection objects ) { + Iterator iter = objects.iterator(); + while ( iter.hasNext() ) { + if ( nameToRemove.equals( iter.next().getName() ) ) { + iter.remove(); + } + } + } + public static String getPath( String parentPath, String path ) { if ( !parentPath.equals( "/" ) && path.startsWith( parentPath ) ) { path = path.replace( parentPath, "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}" );