@Override public boolean getBooleanValueOfVariable( String variableName, boolean defaultValue ) { if ( !Utils.isEmpty( variableName ) ) { String value = environmentSubstitute( variableName ); if ( !Utils.isEmpty( value ) ) { return ValueMetaString.convertStringToBoolean( value ); } } return defaultValue; }
/** * Read shared objects. * * @return the shared objects * @throws KettleException the kettle exception */ public SharedObjects readSharedObjects() throws KettleException { // Extract the shared steps, connections, etc. using the SharedObjects // class // String soFile = environmentSubstitute( sharedObjectsFile ); SharedObjects sharedObjects = new SharedObjects( soFile ); Map<?, SharedObjectInterface> objectsMap = sharedObjects.getObjectsMap(); // First read the databases... // We read databases & slaves first because there might be dependencies // that need to be resolved. // for ( SharedObjectInterface object : objectsMap.values() ) { loadSharedObject( object ); } return sharedObjects; }
/** * Gets the shared objects. * * @return the sharedObjects */ public SharedObjects getSharedObjects() { if ( sharedObjects == null ) { try { String soFile = environmentSubstitute( sharedObjectsFile ); sharedObjects = new SharedObjects( soFile ); } catch ( KettleException e ) { LogChannel.GENERAL.logDebug( e.getMessage(), e ); } } return sharedObjects; }
@Test public void testEnvironmentSubstitute() throws Exception { // This is just a delegate method, verify it's called VariableSpace vars = mock( VariableSpace.class ); // This method is reused by the stub to set the mock as the variables object meta.setInternalKettleVariables( vars ); meta.environmentSubstitute( "${param}" ); verify( vars, times( 1 ) ).environmentSubstitute( "${param}" ); String[] params = new String[]{ "${param}" }; meta.environmentSubstitute( params ); verify( vars, times( 1 ) ).environmentSubstitute( params ); }
@Override public void callExtensionPoint( LogChannelInterface logChannelInterface, Object o ) throws KettleException { AbstractMeta abstractMeta = (AbstractMeta) ( (Object[]) o )[ 0 ]; String runConfiguration = (String) ( (Object[]) o )[ 1 ]; final EmbeddedMetaStore embeddedMetaStore = abstractMeta.getEmbeddedMetaStore(); RunConfigurationManager embeddedRunConfigurationManager = EmbeddedRunConfigurationManager.build( embeddedMetaStore ); embeddedRunConfigurationManager.deleteAll(); RunConfiguration loadedRunConfiguration = runConfigurationManager.load( abstractMeta.environmentSubstitute( runConfiguration ) ); embeddedRunConfigurationManager.save( loadedRunConfiguration ); }
@Override public void saveSharedObjects() throws KettleException { try { // Load all the shared objects... String soFile = environmentSubstitute( sharedObjectsFile ); SharedObjects sharedObjects = new SharedObjects( soFile ); // in-memory shared objects are supposed to be in sync, discard those on file to allow edit/delete sharedObjects.setObjectsMap( new Hashtable<>() ); for ( SharedObjectInterface sharedObject : getAllSharedObjects() ) { if ( sharedObject.isShared() ) { sharedObjects.storeObject( sharedObject ); } } sharedObjects.saveToFile(); } catch ( Exception e ) { throw new KettleException( "Unable to save shared ojects", e ); } }
@Test public void testGetSetSharedObjects() throws Exception { SharedObjects sharedObjects = mock( SharedObjects.class ); meta.setSharedObjects( sharedObjects ); assertEquals( sharedObjects, meta.getSharedObjects() ); meta.setSharedObjects( null ); AbstractMeta spyMeta = spy( meta ); doThrow( KettleException.class ).when( spyMeta ).environmentSubstitute( anyString() ); assertNull( spyMeta.getSharedObjects() ); }