protected void replaceSharedObjects( JobMeta transMeta ) throws KettleException { replaceSharedObjects( (AbstractMeta) transMeta ); }
public IRepositoryImporter getImporter() { return new RepositoryImporter( this ); }
@Override public void setTaskName( String taskName ) { addLog( taskName ); }
/** * package-local visibility for testing purposes */ String resolvePath( String rootPath, String entryPath ) { String extraPath = Const.NVL( entryPath, "/" ); if ( needToCheckPathForVariables() ) { if ( containsVariables( entryPath ) ) { return extraPath; } } String newPath = Const.NVL( rootPath, "/" ); if ( newPath.endsWith( "/" ) && extraPath.startsWith( "/" ) ) { newPath = newPath.substring( 0, newPath.length() - 1 ); } else if ( !newPath.endsWith( "/" ) && !extraPath.startsWith( "/" ) ) { newPath += "/"; } else if ( extraPath.equals( "/" ) ) { extraPath = ""; } return newPath + extraPath; }
protected boolean importJob( Node jobnode, RepositoryImportFeedbackInterface feedback ) throws KettleException { JobMeta jobMeta = createJobMetaForNode( jobnode ); feedback.setLabel( BaseMessages.getString( PKG, "RepositoryImporter.ImportJob.Label", Integer.toString( jobNumber ), jobMeta.getName() ) ); validateImportedElement( importRules, jobMeta ); RepositoryDirectoryInterface targetDirectory = getTargetDirectory( directoryPath, jobDirOverride, feedback ); askOverwrite = feedback.isAskingOverwriteConfirmation(); } else { updateDisplay(); replaceSharedObjects( jobMeta ); jobMeta.setRepositoryDirectory( targetDirectory ); jobMeta.setObjectId( existintId ); patchJobEntries( jobMeta ); try { saveJobMeta( jobMeta );
TransMeta transMeta = createTransMetaForNode( transnode ); // ignore shared objects feedback.setLabel( BaseMessages.getString( PKG, "RepositoryImporter.ImportTrans.Label", Integer .toString( transformationNumber ), transMeta.getName() ) ); validateImportedElement( importRules, transMeta ); RepositoryDirectoryInterface targetDirectory = getTargetDirectory( directoryPath, transDirOverride, feedback ); askOverwrite = feedback.isAskingOverwriteConfirmation(); } else { updateDisplay(); replaceSharedObjects( transMeta ); transMeta.setObjectId( existingId ); transMeta.setRepositoryDirectory( targetDirectory ); patchTransSteps( transMeta ); saveTransMeta( transMeta ); feedback.addLog( BaseMessages.getString( PKG, "RepositoryImporter.TransSaved.Log", Integer .toString( transformationNumber ), transMeta.getName() ) );
@Test public void testImportTrans_patchTransEntries_without_variables() throws KettleException { JobEntryInterface jobEntryInterface = createJobEntry( "" ); StepMetaInterface stepMeta = createStepMeta( "/userName" ); RepositoryImporter importer = createRepositoryImporter( jobEntryInterface, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importTransformation( entityNode, feedback ); verify( (HasRepositoryDirectories) stepMeta ).setDirectories( new String[] { ROOT_PATH + USER_NAME_PATH } ); }
@Test public void testImportJob_patchJobEntries_when_directory_path_ends_with_variable() throws KettleException { JobEntryInterface jobEntryInterface = createJobEntry( "/myDir/${USER_VARIABLE}" ); StepMetaInterface stepMeta = createStepMeta( "" ); RepositoryImporter importer = createRepositoryImporter( jobEntryInterface, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importJob( entityNode, feedback ); verify( (HasRepositoryDirectories) jobEntryInterface ).setDirectories( new String[] { "/myDir/${USER_VARIABLE}" } ); JobEntryInterface jobEntryInterface2 = createJobEntry( "/myDir/${USER_VARIABLE}" ); RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter( jobEntryInterface2, stepMeta, false ); importerWithCompatibilityImportPath.setBaseDirectory( baseDirectory ); importerWithCompatibilityImportPath.importJob( entityNode, feedback ); verify( (HasRepositoryDirectories) jobEntryInterface2 ).setDirectories( new String[] { ROOT_PATH + "/myDir/${USER_VARIABLE}" } ); }
protected void replaceSharedObjects( TransMeta transMeta ) throws KettleException { replaceSharedObjects( (AbstractMeta) transMeta ); for ( ClusterSchema clusterSchema : getSharedObjects( ClusterSchema.class ) ) { int index = transMeta.getClusterSchemas().indexOf( clusterSchema ); if ( index < 0 ) { if ( equals( clusterSchema, imported ) || !getPromptResult( BaseMessages.getString( PKG, "RepositoryImporter.Dialog.ClusterSchemaExistsOverWrite.Message", imported.getName() ), BaseMessages .getString( PKG, "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage" ), for ( PartitionSchema partitionSchema : getSharedObjects( PartitionSchema.class ) ) { int index = transMeta.getPartitionSchemas().indexOf( partitionSchema ); if ( index < 0 ) { if ( equals( partitionSchema, imported ) || !getPromptResult( BaseMessages.getString( PKG, "RepositoryImporter.Dialog.PartitionSchemaExistsOverWrite.Message", imported.getName() ), BaseMessages .getString( PKG, "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage" ),
@Override public boolean jobElementRead( String xml, RepositoryImportFeedbackInterface feedback ) { try { Document doc = XMLHandler.loadXMLString( getOrCreateDb(), xml ); Node jobNode = XMLHandler.getSubNode( doc, RepositoryExportSaxParser.STRING_JOB ); if ( !importJob( jobNode, feedback ) ) { return false; } jobNumber++; } catch ( Exception e ) { // Some unexpected error occurred during job import // This is usually a problem with a missing plugin or something // like that... // showError( BaseMessages.getString( PKG, "RepositoryImporter.UnexpectedErrorDuringJobImport.Title" ), BaseMessages .getString( PKG, "RepositoryImporter.UnexpectedErrorDuringJobImport.Message" ), e ); if ( !feedback.askContinueOnErrorQuestion( BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Title" ), BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Message" ) ) ) { return false; } } return true; }
try { loadSharedObjects(); parser.parse( this ); } catch ( Exception e ) { addException( e ); feedback.showError( BaseMessages.getString( PKG, "RepositoryImporter.ErrorGeneral.Title" ), BaseMessages .getString( PKG, "RepositoryImporter.ErrorGeneral.Message" ), e ); case TRANSFORMATION: TransMeta transMeta = rep.loadTransformation( repoObject.getObjectId(), null ); saveTransformationToRepo( transMeta, feedback ); break; case JOB: JobMeta jobMeta = rep.loadJob( repoObject.getObjectId(), null ); saveJobToRepo( jobMeta, feedback ); break; default: addException( e ); feedback.showError( BaseMessages.getString( PKG, "RepositoryImporter.ErrorGeneral.Title" ), BaseMessages .getString( PKG, "RepositoryImporter.ErrorGeneral.Message" ), e );
private void replaceSharedObjects( AbstractMeta abstractMeta ) { for ( DatabaseMeta databaseMeta : getSharedObjects( DatabaseMeta.class ) ) { if ( equals( databaseMeta, imported ) || !getPromptResult( BaseMessages.getString( PKG, "RepositoryImporter.Dialog.ConnectionExistsOverWrite.Message", imported.getName() ), BaseMessages .getString( PKG, "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage" ), for ( SlaveServer slaveServer : getSharedObjects( SlaveServer.class ) ) { int index = abstractMeta.getSlaveServers().indexOf( slaveServer ); if ( index < 0 ) { if ( equals( slaveServer, imported ) || !getPromptResult( BaseMessages.getString( PKG, "RepositoryImporter.Dialog.SlaveServerExistsOverWrite.Message", imported.getName() ), BaseMessages .getString( PKG, "RepositoryImporter.Dialog.ConnectionExistsOverWrite.DontShowAnyMoreMessage" ),
@Override public boolean transformationElementRead( String xml, RepositoryImportFeedbackInterface feedback ) { try { Document doc = XMLHandler.loadXMLString( getOrCreateDb(), xml ); Node transformationNode = XMLHandler.getSubNode( doc, RepositoryExportSaxParser.STRING_TRANSFORMATION ); if ( !importTransformation( transformationNode, feedback ) ) { return false; } transformationNumber++; } catch ( Exception e ) { // Some unexpected error occurred during transformation import // This is usually a problem with a missing plugin or something // like that... // feedback.showError( BaseMessages.getString( PKG, "RepositoryImporter.UnexpectedErrorDuringTransformationImport.Title" ), BaseMessages.getString( PKG, "RepositoryImporter.UnexpectedErrorDuringTransformationImport.Message" ), e ); if ( !feedback.askContinueOnErrorQuestion( BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Title" ), BaseMessages.getString( PKG, "RepositoryImporter.DoYouWantToContinue.Message" ) ) ) { return false; } } return true; }
protected boolean equals( PartitionSchema partitionSchema, PartitionSchema partitionSchema2 ) { if ( !equals( partitionSchema.getName(), partitionSchema2.getName() ) ) { return false; } else if ( !equals( partitionSchema.getPartitionIDs(), partitionSchema2.getPartitionIDs() ) ) { return false; } else if ( !equals( partitionSchema.isDynamicallyDefined(), partitionSchema2.isDynamicallyDefined() ) ) { return false; } else if ( !equals( partitionSchema.getNumberOfPartitionsPerSlave(), partitionSchema2 .getNumberOfPartitionsPerSlave() ) ) { return false; } return true; }
@Test public void testImportTrans_patchTransEntries_when_directory_path_starts_with_variable() throws KettleException { JobEntryInterface jobEntryInterface = createJobEntry( "" ); StepMetaInterface stepMeta = createStepMeta( "${USER_VARIABLE}/myDir" ); RepositoryImporter importer = createRepositoryImporter( jobEntryInterface, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importTransformation( entityNode, feedback ); verify( (HasRepositoryDirectories) stepMeta ).setDirectories( new String[] { "${USER_VARIABLE}/myDir" } ); StepMetaInterface stepMeta2 = createStepMeta( "${USER_VARIABLE}/myDir" ); RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter( jobEntryInterface, stepMeta2, false ); importerWithCompatibilityImportPath.setBaseDirectory( baseDirectory ); importerWithCompatibilityImportPath.importTransformation( entityNode, feedback ); verify( (HasRepositoryDirectories) stepMeta2 ).setDirectories( new String[] { ROOT_PATH + "/${USER_VARIABLE}/myDir" } ); }
@Test public void testImportJob_patchJobEntries_when_directory_path_starts_with_variable() throws KettleException { JobEntryInterface jobEntryInterface = createJobEntry( "${USER_VARIABLE}/myDir" ); StepMetaInterface stepMeta = createStepMeta( "" ); RepositoryImporter importer = createRepositoryImporter( jobEntryInterface, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importJob( entityNode, feedback ); verify( (HasRepositoryDirectories) jobEntryInterface ).setDirectories( new String[] { "${USER_VARIABLE}/myDir" } ); JobEntryInterface jobEntryInterface2 = createJobEntry( "${USER_VARIABLE}/myDir" ); RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter( jobEntryInterface2, stepMeta, false ); importerWithCompatibilityImportPath.setBaseDirectory( baseDirectory ); importerWithCompatibilityImportPath.importJob( entityNode, feedback ); verify( (HasRepositoryDirectories) jobEntryInterface2 ).setDirectories( new String[]{ ROOT_PATH + "/${USER_VARIABLE}/myDir" } ); }
protected boolean equals( ClusterSchema clusterSchema, ClusterSchema clusterSchema2 ) { if ( !equals( clusterSchema.getName(), clusterSchema2.getName() ) ) { return false; } else if ( !equals( clusterSchema.getBasePort(), clusterSchema2.getBasePort() ) ) { return false; } else if ( !equals( clusterSchema.getSocketsBufferSize(), clusterSchema2.getSocketsBufferSize() ) ) { return false; } else if ( !equals( clusterSchema.getSocketsFlushInterval(), clusterSchema2.getSocketsFlushInterval() ) ) { return false; } else if ( !equals( clusterSchema.isSocketsCompressed(), clusterSchema2.isSocketsCompressed() ) ) { return false; } else if ( !equals( clusterSchema.isDynamic(), clusterSchema2.isDynamic() ) ) { return false; } else if ( !equals( clusterSchema.getSlaveServers(), clusterSchema2.getSlaveServers() ) ) { return false; } return true; }
@Test public void testImportTrans_patchTransEntries_when_directory_path_ends_with_variable() throws KettleException { JobEntryInterface jobEntryInterface = createJobEntry( "" ); StepMetaInterface stepMeta = createStepMeta( "/myDir/${USER_VARIABLE}" ); RepositoryImporter importer = createRepositoryImporter( jobEntryInterface, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importTransformation( entityNode, feedback ); verify( (HasRepositoryDirectories) stepMeta ).setDirectories( new String[] { "/myDir/${USER_VARIABLE}" } ); StepMetaInterface stepMeta2 = createStepMeta( "/myDir/${USER_VARIABLE}" ); RepositoryImporter importerWithCompatibilityImportPath = createRepositoryImporter( jobEntryInterface, stepMeta2, false ); importerWithCompatibilityImportPath.setBaseDirectory( baseDirectory ); importerWithCompatibilityImportPath.importTransformation( entityNode, feedback ); verify( (HasRepositoryDirectories) stepMeta2 ).setDirectories( new String[] { ROOT_PATH + "/myDir/${USER_VARIABLE}" } ); }
@Test public void testImportJob_patchJobEntries_without_variables() throws KettleException { JobEntryInterface jobEntry = createJobEntry( "/userName" ); StepMetaInterface stepMeta = createStepMeta( "" ); RepositoryImporter importer = createRepositoryImporter( jobEntry, stepMeta, true ); importer.setBaseDirectory( baseDirectory ); importer.importJob( entityNode, feedback ); verify( (HasRepositoryDirectories) jobEntry ).setDirectories( new String[]{ ROOT_PATH + USER_NAME_PATH } ); }
@Override protected void replaceSharedObjects( TransMeta transMeta ) throws KettleException { populateSharedObjectsMap(); super.replaceSharedObjects( transMeta ); }