Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BACKLOG-42865] - allow config object rename to same case #9773

Open
wants to merge 1 commit into
base: project-profile
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ private void ok() {
connectionDetails.setName( connectionDetails.getName().trim() );
if ( !connectionDetails.getName().equals( originalName ) ) {
List<String> 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 =
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
14 changes: 12 additions & 2 deletions ui/src/main/java/org/pentaho/di/ui/util/DialogUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -64,6 +65,15 @@ public static boolean objectWithTheSameNameExists( SharedObjectInterface object,
return false;
}

public static void removeMatchingObject( String nameToRemove, Collection<? extends SharedObjectInterface> objects ) {
Iterator<? extends SharedObjectInterface> 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 + "}" );
Expand Down