/** * Gets the XML representation of this transformation. * * @return the XML representation of this transformation * @throws KettleException * if any errors occur during generation of the XML * @see org.pentaho.di.core.xml.XMLInterface#getXML() */ @Override public String getXML() throws KettleException { return getXML( true, true, true, true, true ); }
/** * Gets the XML representation of this transformation, including or excluding step, database, slave server, cluster, * or partition information as specified by the parameters * * @param includeSteps * whether to include step data * @param includeDatabase * whether to include database data * @param includeSlaves * whether to include slave server data * @param includeClusters * whether to include cluster data * @param includePartitions * whether to include partition data * @return the XML representation of this transformation * @throws KettleException * if any errors occur during generation of the XML */ public String getXML( boolean includeSteps, boolean includeDatabase, boolean includeSlaves, boolean includeClusters, boolean includePartitions ) throws KettleException { return getXML( true, true, true, true, true, true, true, true, true, true ); }
public String getXML() throws IOException, KettleException { StringBuilder xml = new StringBuilder( 200 ); xml.append( "<" + XML_TAG + ">" ).append( Const.CR ); xml.append( transMeta.getXML() ); xml.append( transExecutionConfiguration.getXML() ); xml.append( "</" + XML_TAG + ">" ).append( Const.CR ); return xml.toString(); }
@Override protected String toXml( TransMeta meta ) throws Exception { return meta.getXML(); }
/** * Utility method to write the XML of this transformation to a file, mostly for testing purposes. * * @param filename * The filename to save to * @throws KettleXMLException * in case something goes wrong. */ public void writeXML( String filename ) throws KettleXMLException { FileOutputStream fos = null; try { fos = new FileOutputStream( filename ); fos.write( XMLHandler.getXMLHeader().getBytes( Const.XML_ENCODING ) ); fos.write( getXML().getBytes( Const.XML_ENCODING ) ); } catch ( Exception e ) { throw new KettleXMLException( "Unable to save to XML file '" + filename + "'", e ); } finally { if ( fos != null ) { try { fos.close(); } catch ( IOException e ) { throw new KettleXMLException( "Unable to close file '" + filename + "'", e ); } } } }
/** * Writes the generated meta injection transformation to the file system. * @param targetFilePath the filesystem path to which to save the generated injection ktr * @throws KettleException */ private void writeInjectedKtrToFs( String targetFilePath ) throws KettleException { OutputStream os = null; try { os = KettleVFS.getOutputStream( targetFilePath, false ); os.write( XMLHandler.getXMLHeader().getBytes( Const.XML_ENCODING ) ); os.write( data.transMeta.getXML().getBytes( Const.XML_ENCODING ) ); } catch ( IOException e ) { throw new KettleException( "Unable to write target file (ktr after injection) to file '" + targetFilePath + "'", e ); } finally { if ( os != null ) { try { os.close(); } catch ( Exception e ) { throw new KettleException( e ); } } } }
@Override public TransMeta answer( InvocationOnMock invocation ) throws Throwable { String transName = String.class.cast( invocation.getArguments()[ 0 ] ); TransMeta transMeta = Mockito.mock( TransMeta.class ); Mockito.when( transMeta.getXML() ).thenReturn( "<" + transName + ">" + "found" + "</" + transName + ">" ); Mockito.when( transMeta.getName() ).thenReturn( transName ); return transMeta; } };
public void export( ProgressMonitorListener monitor, List<RepositoryFile> files, OutputStreamWriter writer ) throws KettleException { List<TransMeta> transformations = repository.loadTransformations( monitor, log, files, true ); Iterator<TransMeta> transMetasIter = transformations.iterator(); Iterator<RepositoryFile> filesIter = files.iterator(); while ( ( monitor == null || !monitor.isCanceled() ) && transMetasIter.hasNext() ) { TransMeta trans = transMetasIter.next(); setGlobalVariablesOfLogTablesNull( trans.getLogTables() ); RepositoryFile file = filesIter.next(); try { // Validate against the import rules first! if ( toExport( trans ) ) { writer.write( trans.getXML() + Const.CR ); } } catch ( Exception ex ) { // if exception while writing one item is occurred logging it and continue looping log.logError( BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_SAVE_TRANSFORMATION", trans.getName(), file.getPath() ), ex ); //$NON-NLS-1$ } } } }
String strTrans = XMLHandler.getXMLHeader( Const.XML_ENCODING ) + transMeta.getXML(); File transFile = new File( kar.getPath() + "/" + TRANSFORMATION_FILENAME ); fos = new FileOutputStream( transFile );
@Test public void testTransSplitterReadsRep() throws KettleException { TransMeta meta = mock( TransMeta.class ); Repository rep = mock( Repository.class ); when( meta.getRepository() ).thenReturn( rep ); TransMeta meta2 = mock( TransMeta.class ); TransMetaFactory factory = mock( TransMetaFactory.class ); when( factory.create( any( Node.class ), any( Repository.class ) ) ).thenReturn( meta2 ); when( meta.getXML() ).thenReturn( "<transformation></transformation>" ); try { new TransSplitter( meta, factory ); } catch ( Exception e ) { // ignore } verify( rep, times( 1 ) ).readTransSharedObjects( meta2 ); }
return new ByteArrayInputStream( transMeta.getXML().getBytes() );
public void copyTransformation( TransMeta transMeta ) { if ( transMeta == null ) { return; } try { if ( RepositorySecurityUI.verifyOperations( shell, rep, RepositoryOperation.MODIFY_TRANSFORMATION, RepositoryOperation.EXECUTE_TRANSFORMATION ) ) { return; } toClipboard( XMLHandler.getXMLHeader() + transMeta.getXML() ); } catch ( Exception ex ) { new ErrorDialog( getShell(), "Error", "Error encoding to XML", ex ); } }
findHops( copyTransMeta, hop -> true ).forEach( createHop( transformation ) ); transformation.setConfig( TRANS_META_CONF_KEY, copyTransMeta.getXML() ); transformation.setConfig( TRANS_META_NAME_CONF_KEY, Optional.ofNullable( transMeta.getName() ).orElse( TRANS_DEFAULT_NAME ) );
String xml = XMLHandler.getXMLHeader() + ti.getXML();
@Test public void testClonesTransMeta() throws KettleException { class ResultCaptor implements Answer<Object> { private Object result; public Object getResult() { return result; } @Override public java.lang.Object answer( InvocationOnMock invocationOnMock ) throws Throwable { result = invocationOnMock.callRealMethod(); return result; } } TransMeta originalTransMeta = spy( new TransMeta() ); ResultCaptor cloneTransMetaCaptor = new ResultCaptor(); doAnswer( cloneTransMetaCaptor ).when( originalTransMeta ).realClone( eq( false ) ); originalTransMeta.setName( "TransName" ); TransMetaConverter.convert( originalTransMeta ); TransMeta cloneTransMeta = (TransMeta) cloneTransMetaCaptor.getResult(); verify( originalTransMeta ).realClone( eq( false ) ); assertThat( cloneTransMeta.getName(), is( originalTransMeta.getName() ) ); verify( originalTransMeta, never() ).getXML(); verify( cloneTransMeta ).getXML(); } @Test
logDetailed( "XML of transformation after injection: " + data.transMeta.getXML() );
String transMetaContent = transMeta.getXML();
String transXML = transMeta.getXML(); this.originalTransformation = transMetaFactory
writer.writeTrans( transMeta.getXML() + Const.CR ); } else { log.logError( BaseMessages.getString( PKG,
/** * @param args not used */ public static void main( String[] args ) { try { // Kettle Environment must always be initialized first when using PDI // It bootstraps the PDI engine by loading settings, appropriate plugins // etc. KettleEnvironment.init( false ); // Create an instance of this demo class for convenience instance = new GeneratingTransformations(); // generates a simple transformation, returning the TransMeta object describing it TransMeta transMeta = instance.generateTransformation(); // get the xml of the definition and save it to a file for inspection in spoon String outputFilename = "etl/generated_transformation.ktr"; System.out.println( "- Saving to " + outputFilename ); String xml = transMeta.getXML(); File file = new File( outputFilename ); FileUtils.writeStringToFile( file, xml, "UTF-8" ); System.out.println( "DONE" ); } catch ( Exception e ) { e.printStackTrace(); return; } }