Java Code Examples for org.pentaho.di.trans.TransMeta#setFilename()
The following examples show how to use
org.pentaho.di.trans.TransMeta#setFilename() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KettleFileRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Override public TransMeta loadTransformation( String transname, RepositoryDirectoryInterface repdir, ProgressMonitorListener monitor, boolean setInternalVariables, String versionName ) throws KettleException { // This is a standard load of a transformation serialized in XML... // String filename = calcDirectoryName( repdir ) + transname + ".ktr"; TransMeta transMeta = new TransMeta( filename, this, setInternalVariables ); transMeta.setRepository( this ); transMeta.setMetaStore( getMetaStore() ); transMeta.setFilename( null ); transMeta.setName( transname ); transMeta.setObjectId( new StringObjectId( calcObjectId( repdir, transname, EXT_TRANSFORMATION ) ) ); readDatabases( transMeta, true ); transMeta.clearChanged(); return transMeta; }
Example 2
Source File: TransMetaConverterTest.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@Test public void transWithHops() { TransMeta meta = new TransMeta(); meta.setFilename( "fileName" ); StepMeta from = new StepMeta( "step1", stepMetaInterface ); meta.addStep( from ); StepMeta to = new StepMeta( "step2", stepMetaInterface ); meta.addStep( to ); meta.addTransHop( new TransHopMeta( from, to ) ); Transformation trans = TransMetaConverter.convert( meta ); assertThat( trans.getId(), is( meta.getFilename() ) ); assertThat( trans.getOperations().size(), is( 2 ) ); assertThat( trans.getHops().size(), is( 1 ) ); assertThat( trans.getHops().get( 0 ).getFrom().getId(), is( from.getName() ) ); assertThat( trans.getHops().get( 0 ).getTo().getId(), is( to.getName() ) ); assertThat( trans.getHops().stream().map( Hop::getType ).collect( Collectors.toList() ), everyItem( is( Hop.TYPE_NORMAL ) ) ); }
Example 3
Source File: JobEntryTransDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private boolean askToCreateNewTransformation( String prevName ) { MessageBox mb = new MessageBox( shell, SWT.YES | SWT.NO | SWT.ICON_QUESTION ); mb.setMessage( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Message" ) ); mb.setText( BaseMessages.getString( PKG, "JobTrans.Dialog.CreateTransformationQuestion.Title" ) ); int answer = mb.open(); if ( answer == SWT.YES ) { Spoon spoon = Spoon.getInstance(); spoon.newTransFile(); TransMeta transMeta = spoon.getActiveTransformation(); transMeta.initializeVariablesFrom( jobEntry ); transMeta.setFilename( jobMeta.environmentSubstitute( prevName ) ); wPath.setText( prevName ); specificationMethod = ObjectLocationSpecificationMethod.FILENAME; spoon.saveFile(); return true; } return false; }
Example 4
Source File: BaseStreamingDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
protected TransMeta createSubTransMeta() { RecordsFromStreamMeta rm = new RecordsFromStreamMeta(); String[] fieldNames = getFieldNames(); int[] empty = new int[ fieldNames.length ]; Arrays.fill( empty, -1 ); rm.setFieldname( fieldNames ); rm.setType( getFieldTypes() ); rm.setLength( empty ); rm.setPrecision( empty ); StepMeta recsFromStream = new StepMeta( "RecordsFromStream", "Get records from stream", rm ); recsFromStream.setLocation( new Point( 100, 100 ) ); recsFromStream.setDraw( true ); TransMeta transMeta = new TransMeta(); transMeta.addStep( recsFromStream ); transMeta.setFilename( "" ); return transMeta; }
Example 5
Source File: SpoonJobDelegate.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@VisibleForTesting void setTransMetaFileNaming( RepositoryDirectoryInterface repdir, String directory, DatabaseMeta sourceDbInfo, DatabaseMeta targetDbInfo, String[] tables, int i, TransMeta transMeta ) { String transname = BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.Transname1" ) + sourceDbInfo + "].[" + tables[i] + BaseMessages.getString( PKG, "Spoon.RipDB.Monitor.Transname2" ) + targetDbInfo + "]"; if ( repdir != null ) { transMeta.setRepositoryDirectory( repdir ); transMeta.setName( transname ); } else { transMeta.setFilename( Const.createFilename( directory, transname, "." + Const.STRING_TRANS_DEFAULT_EXT ) ); } }
Example 6
Source File: PurRepository.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private TransMeta buildTransMeta( final RepositoryFile file, final RepositoryDirectoryInterface parentDir, final NodeRepositoryFileData data, final ObjectRevision revision ) throws KettleException { TransMeta transMeta = new TransMeta(); transMeta.setName( file.getTitle() ); transMeta.setFilename( file.getName() ); transMeta.setDescription( file.getDescription() ); transMeta.setObjectId( new StringObjectId( file.getId().toString() ) ); transMeta.setObjectRevision( revision ); transMeta.setRepository( this ); transMeta.setRepositoryDirectory( parentDir ); transMeta.setMetaStore( getMetaStore() ); readTransSharedObjects( transMeta ); // This should read from the local cache transDelegate.dataNodeToElement( data.getNode(), transMeta ); transMeta.clearChanged(); return transMeta; }
Example 7
Source File: KettleTransFromFileProducer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
protected TransMeta loadTransformation( final Repository repository, final ResourceManager resourceManager, final ResourceKey contextKey ) throws ReportDataFactoryException, KettleException { if ( transformationFile == null ) { throw new ReportDataFactoryException( "No Transformation file given" ); } if ( resourceManager == null || contextKey == null ) { return new TransMeta( transformationFile, repository ); } try { final ResourceKey resourceKey = createKey( resourceManager, contextKey ); final Resource resource = resourceManager.create( resourceKey, contextKey, Document.class ); final Document document = (Document) resource.getResource(); final Node node = XMLHandler.getSubNode( document, TransMeta.XML_TAG ); final TransMeta meta = new TransMeta(); meta.loadXML( node, repository, true, null, null ); final String filename = computeFullFilename( resourceKey ); if ( filename != null ) { logger.debug( "Computed Transformation Location: " + filename ); meta.setFilename( filename ); } else { logger.debug( "No Computed Transformation Location, using raw name: " + transformationFile ); meta.setFilename( transformationFile ); } return meta; } catch ( ResourceException re ) { throw new ReportDataFactoryException( "Unable to load Kettle-Transformation", re ); } }
Example 8
Source File: EmbeddedKettleTransformationProducer.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
private TransMeta loadTransformation( final ResourceKey contextKey ) throws KettleMissingPluginsException, KettlePluginException, KettleXMLException { final Document document = DocumentHelper.loadDocumentFromBytes( getTransformationRaw() ); final Node node = XMLHandler.getSubNode( document, TransMeta.XML_TAG ); final TransMeta meta = new TransMeta(); meta.loadXML( node, null, true, null, null ); final String filename = computeFullFilename( contextKey ); if ( filename != null ) { logger.debug( "Computed Transformation Location: " + filename ); meta.setFilename( filename ); } return meta; }
Example 9
Source File: TransMetaConverterTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Test public void simpleConvert() { TransMeta meta = new TransMeta(); meta.setFilename( "fileName" ); meta.addStep( new StepMeta( "stepName", stepMetaInterface ) ); Transformation trans = TransMetaConverter.convert( meta ); assertThat( trans.getId(), is( meta.getFilename() ) ); assertThat( trans.getOperations().size(), is( 1 ) ); assertThat( trans.getOperations().get( 0 ).getId(), is( "stepName" ) ); }
Example 10
Source File: SharedObjectSyncUtilTest.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private TransMeta createTransMeta() throws KettleException { TransMeta transMeta = new TransMeta(); transMeta.setName( UUID.randomUUID().toString() ); transMeta.setFilename( UUID.randomUUID().toString() ); RepositoryDirectory repositoryDirectory = mock( RepositoryDirectory.class ); doCallRealMethod().when( repositoryDirectory ).setName( anyString() ); doCallRealMethod().when( repositoryDirectory ).getName(); transMeta.setRepositoryDirectory( repositoryDirectory ); initSharedObjects( transMeta, SHARED_OBJECTS_FILE ); when( spoon.getActiveMeta() ).thenReturn( transMeta ); return transMeta; }
Example 11
Source File: OpenMappingExtension.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@Override public void callExtensionPoint( LogChannelInterface log, Object object ) throws KettleException { StepMeta stepMeta = (StepMeta) ( (Object[]) object )[ 0 ]; TransMeta transMeta = (TransMeta) ( (Object[]) object )[ 1 ]; if ( stepMeta.getStepMetaInterface() instanceof MetaInjectMeta ) { // Make sure we don't accidently overwrite this transformation so we'll remove the filename and objectId // Modify the name so the users sees it's a result transMeta.setFilename( null ); transMeta.setObjectId( null ); String appendName = " (" + BaseMessages.getString( PKG, "TransGraph.AfterInjection" ) + ")"; if ( !transMeta.getName().endsWith( appendName ) ) { transMeta.setName( transMeta.getName() + appendName ); } } }
Example 12
Source File: KettleFileRepositoryIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private void verifyTransformationSamples( RepositoryDirectoryInterface samplesDirectory ) throws Exception { File transSamplesFolder = new File( "samples/transformations/" ); String[] files = transSamplesFolder.list( new FilenameFilter() { @Override public boolean accept( File dir, String name ) { return name.endsWith( ".ktr" ) && !name.contains( "HL7" ); } } ); Arrays.sort( files ); for ( String file : files ) { String transFilename = transSamplesFolder.getAbsolutePath() + "/" + file; System.out.println( "Storing/Loading/validating transformation '" + transFilename + "'" ); // Load the TransMeta object... // TransMeta transMeta = new TransMeta( transFilename ); transMeta.setFilename( null ); // The name is sometimes empty in the file, duplicates are present too... // Replaces slashes and the like as well... // transMeta.setName( Const.createName( file ) ); transMeta.setName( transMeta.getName().replace( '/', '-' ) ); // Save it in the repository in the samples folder // transMeta.setRepositoryDirectory( samplesDirectory ); repository.save( transMeta, "unit testing" ); assertNotNull( transMeta.getObjectId() ); // Load it back up again... // TransMeta repTransMeta = repository.loadTransformation( transMeta.getObjectId(), null ); String oneXml = repTransMeta.getXML(); // Save & load it again // repository.save( transMeta, "unit testing" ); repTransMeta = repository.loadTransformation( transMeta.getObjectId(), null ); String twoXml = repTransMeta.getXML(); // The XML needs to be identical after loading // // storeFile(oneXml, "/tmp/one.ktr"); // storeFile(twoXml, "/tmp/two.ktr"); assertEquals( oneXml, twoXml ); } // Verify the number of stored files, see if we can find them all again. // System.out.println( "Stored " + files.length + " transformation samples in folder " + samplesDirectory.getPath() ); String[] transformationNames = repository.getTransformationNames( samplesDirectory.getObjectId(), false ); assertEquals( files.length, transformationNames.length ); }
Example 13
Source File: JobEntryTrans.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * We're going to load the transformation meta data referenced here. Then we're going to give it a new filename, * modify that filename in this entries. The parent caller will have made a copy of it, so it should be OK to do so. * <p/> * Exports the object to a flat-file system, adding content with filename keys to a set of definitions. The supplied * resource naming interface allows the object to name appropriately without worrying about those parts of the * implementation specific details. * * @param space The variable space to resolve (environment) variables with. * @param definitions The map containing the filenames and content * @param namingInterface The resource naming interface allows the object to be named appropriately * @param repository The repository to load resources from * @param metaStore the metaStore to load external metadata from * @return The filename for this object. (also contained in the definitions map) * @throws KettleException in case something goes wrong during the export */ @Override public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface namingInterface, Repository repository, IMetaStore metaStore ) throws KettleException { // Try to load the transformation from repository or file. // Modify this recursively too... // // AGAIN: there is no need to clone this job entry because the caller is responsible for this. // // First load the transformation metadata... // copyVariablesFrom( space ); TransMeta transMeta = getTransMeta( repository, space ); // Also go down into the transformation and export the files there. (mapping recursively down) // String proposedNewFilename = transMeta.exportResources( transMeta, definitions, namingInterface, repository, metaStore ); // To get a relative path to it, we inject ${Internal.Entry.Current.Directory} // String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename; // Set the correct filename inside the XML. // transMeta.setFilename( newFilename ); // exports always reside in the root directory, in case we want to turn this into a file repository... // transMeta.setRepositoryDirectory( new RepositoryDirectory() ); // export to filename ALWAYS (this allows the exported XML to be executed remotely) // setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); // change it in the job entry // filename = newFilename; return proposedNewFilename; }
Example 14
Source File: RepositoryExporter.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private void convertFromFileRepository( TransMeta transMeta ) { Object[] metaInjectObjectArray = new Object[4]; metaInjectObjectArray[0] = transMeta; metaInjectObjectArray[1] = PKG; if ( repository instanceof KettleFileRepository ) { KettleFileRepository fileRep = (KettleFileRepository) repository; metaInjectObjectArray[2] = fileRep; // The id of the transformation is the relative filename. // Setting the filename also sets internal variables needed to load the trans/job referenced. // String transMetaFilename = fileRep.calcFilename( transMeta.getObjectId() ); transMeta.setFilename( transMetaFilename ); for ( StepMeta stepMeta : transMeta.getSteps() ) { if ( stepMeta.isMapping() ) { MappingMeta mappingMeta = (MappingMeta) stepMeta.getStepMetaInterface(); // convert to a named based reference. // if ( mappingMeta.getSpecificationMethod() == ObjectLocationSpecificationMethod.FILENAME ) { try { TransMeta meta = MappingMeta.loadMappingMeta( mappingMeta, fileRep, fileRep.metaStore, transMeta ); FileObject fileObject = KettleVFS.getFileObject( meta.getFilename() ); mappingMeta.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ); mappingMeta.setFileName( null ); mappingMeta.setTransName( meta.getName() ); mappingMeta.setDirectoryPath( Const.NVL( calcRepositoryDirectory( fileRep, fileObject ), "/" ) ); } catch ( Exception e ) { log.logError( BaseMessages.getString( PKG, "Repository.Exporter.Log.UnableToLoadTransInMap", mappingMeta .getName() ), e ); } } } metaInjectObjectArray[3] = stepMeta; try { ExtensionPointHandler.callExtensionPoint( log, KettleExtensionPoint.RepositoryExporterPatchTransStep.id, metaInjectObjectArray ); } catch ( KettleException ke ) { log.logError( ke.getMessage(), ke ); } } } }
Example 15
Source File: MetaInjectMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@Override public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException { try { // Try to load the transformation from repository or file. // Modify this recursively too... // // NOTE: there is no need to clone this step because the caller is // responsible for this. // // First load the executor transformation metadata... // TransMeta executorTransMeta = loadTransformationMeta( repository, space ); // Also go down into the mapping transformation and export the files // there. (mapping recursively down) // String proposedNewFilename = executorTransMeta.exportResources( executorTransMeta, definitions, resourceNamingInterface, repository, metaStore ); // To get a relative path to it, we inject // ${Internal.Entry.Current.Directory} // String newFilename = "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + proposedNewFilename; // Set the correct filename inside the XML. // executorTransMeta.setFilename( newFilename ); // exports always reside in the root directory, in case we want to turn // this into a file repository... // executorTransMeta.setRepositoryDirectory( new RepositoryDirectory() ); // change it in the entry // fileName = newFilename; setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); return proposedNewFilename; } catch ( Exception e ) { throw new KettleException( BaseMessages.getString( PKG, "MetaInjectMeta.Exception.UnableToLoadTrans", fileName ) ); } }