Java Code Examples for org.pentaho.di.core.variables.VariableSpace#listVariables()

The following examples show how to use org.pentaho.di.core.variables.VariableSpace#listVariables() . 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: BeamGenericStepHandler.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private List<VariableValue> getVariableValues( VariableSpace space ) {

    List<VariableValue> variableValues = new ArrayList<>();
    for ( String variable : space.listVariables() ) {
      String value = space.getVariable( variable );
      variableValues.add( new VariableValue( variable, value ) );
    }
    return variableValues;
  }
 
Example 2
Source File: JobExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void setVariables( VariableSpace space ) {
  this.variables = new HashMap<String, String>();

  for ( String name : space.listVariables() ) {
    String value = space.getVariable( name );
    this.variables.put( name, value );
  }
}
 
Example 3
Source File: JobExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getUsedVariables( JobMeta jobMeta ) {
  Properties sp = new Properties();
  VariableSpace space = Variables.getADefaultVariableSpace();

  String[] keys = space.listVariables();
  for ( int i = 0; i < keys.length; i++ ) {
    sp.put( keys[i], space.getVariable( keys[i] ) );
  }

  List<String> vars = jobMeta.getUsedVariables();
  if ( vars != null && vars.size() > 0 ) {
    HashMap<String, String> newVariables = new HashMap<String, String>();

    for ( int i = 0; i < vars.size(); i++ ) {
      String varname = vars.get( i );
      if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) {
        // add all new non-internal variables to newVariablesMap
        newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
      }
    }
    // variables.clear();
    variables.putAll( newVariables );
  }

  // Also add the internal job variables if these are set...
  //
  for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
    String value = jobMeta.getVariable( variableName );
    if ( !Utils.isEmpty( value ) ) {
      variables.put( variableName, value );
    }
  }
}
 
Example 4
Source File: TransExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void setVariables( VariableSpace space ) {
  this.variables = new HashMap<String, String>();

  for ( String name : space.listVariables() ) {
    String value = space.getVariable( name );
    this.variables.put( name, value );
  }
}
 
Example 5
Source File: TransExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getAllVariables( TransMeta transMeta ) {
  Properties sp = new Properties();
  VariableSpace space = Variables.getADefaultVariableSpace();

  String[] keys = space.listVariables();
  for ( int i = 0; i < keys.length; i++ ) {
    sp.put( keys[i], space.getVariable( keys[i] ) );
  }

  String[] vars = transMeta.listVariables();
  if ( vars != null && vars.length > 0 ) {
    HashMap<String, String> newVariables = new HashMap<String, String>();

    for ( int i = 0; i < vars.length; i++ ) {
      String varname = vars[i];
      newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
    }
    // variables.clear();
    variables.putAll( newVariables );
  }

  // Also add the internal job variables if these are set...
  //
  for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
    String value = transMeta.getVariable( variableName );
    if ( !Utils.isEmpty( value ) ) {
      variables.put( variableName, value );
    }
  }
}
 
Example 6
Source File: TransExecutionConfiguration.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getUsedVariables( TransMeta transMeta ) {
  Properties sp = new Properties();
  VariableSpace space = Variables.getADefaultVariableSpace();

  String[] keys = space.listVariables();
  for ( int i = 0; i < keys.length; i++ ) {
    sp.put( keys[i], space.getVariable( keys[i] ) );
  }

  List<String> vars = transMeta.getUsedVariables();
  if ( vars != null && vars.size() > 0 ) {
    HashMap<String, String> newVariables = new HashMap<String, String>();

    for ( int i = 0; i < vars.size(); i++ ) {
      String varname = vars.get( i );
      if ( !varname.startsWith( Const.INTERNAL_VARIABLE_PREFIX ) ) {
        newVariables.put( varname, Const.NVL( variables.get( varname ), sp.getProperty( varname, "" ) ) );
      }
    }
    // variables.clear();
    variables.putAll( newVariables );
  }

  // Also add the internal job variables if these are set...
  //
  for ( String variableName : Const.INTERNAL_JOB_VARIABLES ) {
    String value = transMeta.getVariable( variableName );
    if ( !Utils.isEmpty( value ) ) {
      variables.put( variableName, value );
    }
  }
}
 
Example 7
Source File: StepWithMappingMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static  void addMissingVariables( VariableSpace fromSpace, VariableSpace toSpace ) {
  if ( toSpace == null ) {
    return;
  }
  String[] variableNames = toSpace.listVariables();
  for ( String variable : variableNames ) {
    if ( fromSpace.getVariable( variable ) == null ) {
      fromSpace.setVariable( variable, toSpace.getVariable( variable ) );
    }
  }
}
 
Example 8
Source File: StepWithMappingMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void replaceVariableValues( VariableSpace childTransMeta, VariableSpace replaceBy, String type ) {
  if ( replaceBy == null ) {
    return;
  }
  String[] variableNames = replaceBy.listVariables();
  for ( String variableName : variableNames ) {
    if ( childTransMeta.getVariable( variableName ) != null && !isInternalVariable( variableName, type ) ) {
      childTransMeta.setVariable( variableName, replaceBy.getVariable( variableName ) );
    }
  }
}
 
Example 9
Source File: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static final String getVariableName( Shell shell, VariableSpace space ) {
  String[] keys = space.listVariables();
  Arrays.sort( keys );

  int size = keys.length;
  String[] key = new String[size];
  String[] val = new String[size];
  String[] str = new String[size];

  for ( int i = 0; i < keys.length; i++ ) {
    key[i] = keys[i];
    val[i] = space.getVariable( key[i] );
    str[i] = key[i] + "  [" + val[i] + "]";
  }

  EnterSelectionDialog esd = new EnterSelectionDialog( shell, str,
    BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Title" ),
    BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Message" ) );
  esd.clearModal();
  if ( esd.open() != null ) {
    int nr = esd.getSelectionNr();
    String var = key[nr];

    return var;
  } else {
    return null;
  }
}
 
Example 10
Source File: ControlSpaceKeyAdapter.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static final String[] getVariableNames( VariableSpace space ) {
  String[] variableNames = space.listVariables();
  for ( int i = 0; i < variableNames.length; i++ ) {
    for ( int j = 0; j < Const.DEPRECATED_VARIABLES.length; j++ ) {
      if ( variableNames[i].equals( Const.DEPRECATED_VARIABLES[j] ) ) {
        variableNames[i] = variableNames[i] + Const.getDeprecatedPrefix();
        break;
      }
    }
  }

  Arrays.sort( variableNames, new Comparator<String>() {
    public int compare( String var1, String var2 ) {
      if ( var1.endsWith( Const.getDeprecatedPrefix() ) && var2.endsWith( Const.getDeprecatedPrefix() ) ) {
        return 0;
      }
      if ( var1.endsWith( Const.getDeprecatedPrefix() ) && !var2.endsWith( Const.getDeprecatedPrefix() ) ) {
        return 1;
      }
      if ( !var1.endsWith( Const.getDeprecatedPrefix() ) && var2.endsWith( Const.getDeprecatedPrefix() ) ) {
        return -1;
      }
      return var1.compareTo( var2 );
    }
  } );
  return variableNames;
}
 
Example 11
Source File: KettleVFS.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private static FileSystemOptions buildFsOptions( VariableSpace varSpace, FileSystemOptions sourceOptions,
                                                 String vfsFilename, String scheme ) throws IOException {
  if ( varSpace == null || vfsFilename == null ) {
    // We cannot extract settings from a non-existant variable space
    return null;
  }

  IKettleFileSystemConfigBuilder configBuilder =
    KettleFileSystemConfigBuilderFactory.getConfigBuilder( varSpace, scheme );

  FileSystemOptions fsOptions = ( sourceOptions == null ) ? new FileSystemOptions() : sourceOptions;

  String[] varList = varSpace.listVariables();

  for ( String var : varList ) {
    if ( var.equalsIgnoreCase( CONNECTION ) && varSpace.getVariable( var ) != null ) {
      FileSystemOptions fileSystemOptions = VFSHelper.getOpts( vfsFilename, varSpace.getVariable( var ) );
      if ( fileSystemOptions != null ) {
        return fileSystemOptions;
      }
    }
    if ( var.startsWith( "vfs." ) ) {
      String param = configBuilder.parseParameterName( var, scheme );
      String varScheme = KettleGenericFileSystemConfigBuilder.extractScheme( var );
      if ( param != null ) {
        if ( varScheme == null || varScheme.equals( "sftp" ) || varScheme.equals( scheme ) ) {
          configBuilder.setParameter( fsOptions, param, varSpace.getVariable( var ), var, vfsFilename );
        }
      } else {
        throw new IOException( "FileSystemConfigBuilder could not parse parameter: " + var );
      }
    }
  }
  return fsOptions;
}
 
Example 12
Source File: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
    final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
    final VariableSpace space ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = space.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[size];
      String[] val = new String[size];
      String[] str = new String[size];

      for ( int i = 0; i < keys.length; i++ ) {
        key[i] = keys[i];
        val[i] = space.getVariable( key[i] );
        str[i] = key[i] + "  [" + val[i] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd =
          new EnterSelectionDialog( composite.getShell(), str, BaseMessages.getString( PKG,
              "System.Dialog.SelectEnvironmentVar.Title" ), BaseMessages.getString( PKG,
                  "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[nr] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}
 
Example 13
Source File: VariableButtonListenerFactory.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static final SelectionAdapter getSelectionAdapter( final Composite composite, final Text destination,
  final GetCaretPositionInterface getCaretPositionInterface, final InsertTextInterface insertTextInterface,
  final VariableSpace space ) {
  return new SelectionAdapter() {
    public void widgetSelected( SelectionEvent e ) {
      String[] keys = space.listVariables();
      Arrays.sort( keys );

      int size = keys.length;
      String[] key = new String[size];
      String[] val = new String[size];
      String[] str = new String[size];

      for ( int i = 0; i < keys.length; i++ ) {
        key[i] = keys[i];
        val[i] = space.getVariable( key[i] );
        str[i] = key[i] + "  [" + val[i] + "]";
      }

      // Before focus is lost, we get the position of where the selected variable needs to be inserted.
      int position = 0;
      if ( getCaretPositionInterface != null ) {
        position = getCaretPositionInterface.getCaretPosition();
      }

      EnterSelectionDialog esd = new EnterSelectionDialog( composite.getShell(), str,
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Title" ),
        BaseMessages.getString( PKG, "System.Dialog.SelectEnvironmentVar.Message" ) );
      if ( esd.open() != null ) {
        int nr = esd.getSelectionNr();
        String var = "${" + key[nr] + "}";

        if ( insertTextInterface == null ) {
          destination.insert( var );
          // destination.setToolTipText(StringUtil.environmentSubstitute( destination.getText() ) );
          e.doit = false;
        } else {
          insertTextInterface.insertText( var, position );
        }
      }
    }
  };
}