Java Code Examples for org.pentaho.di.core.Const#toInt()

The following examples show how to use org.pentaho.di.core.Const#toInt() . 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: DimensionTableDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void addAttributesFromFile(String filename) throws KettleException {
  InputStream inputStream = getClass().getResourceAsStream(filename);
  Document document = XMLHandler.loadXMLFile(inputStream);
  Node attributesNode = XMLHandler.getSubNode(document, "attributes");
  List<Node> attributeNodes = XMLHandler.getNodes(attributesNode, "attribute");
  for (Node node : attributeNodes) {
    String name = XMLHandler.getTagValue(node, "name");
    String description = XMLHandler.getTagValue(node, "description");
    String phName = XMLHandler.getTagValue(node, "physicalname");
    AttributeType attributeType= AttributeType.getAttributeType(XMLHandler.getTagValue(node, "attribute_type"));
    DataType dataType= ConceptUtil.getDataType(XMLHandler.getTagValue(node, "data_type"));
    int length = Const.toInt(XMLHandler.getTagValue(node, "length"), -1);
    int precision = Const.toInt(XMLHandler.getTagValue(node, "precision"), -1);
    // String sourceDb = XMLHandler.getTagValue(node, "source_db");
    // String sourceTable = XMLHandler.getTagValue(node, "source_table");
    // String sourceColumn = XMLHandler.getTagValue(node, "source_column");
    String remarks = XMLHandler.getTagValue(node, "remarks");
    addAttribute(name, description, phName, attributeType, dataType, length, precision, remarks);
  }

}
 
Example 2
Source File: TransExecutorDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void setFlags() {
  // Enable/disable fields...
  //
  if ( wlGroupSize == null || wlGroupSize == null || wlGroupField == null || wGroupField == null
    || wlGroupTime == null || wGroupTime == null ) {
    return;
  }
  boolean enableSize = Const.toInt( transMeta.environmentSubstitute( wGroupSize.getText() ), -1 ) >= 0;
  boolean enableField = !Utils.isEmpty( wGroupField.getText() );
  // boolean enableTime = Const.toInt(transMeta.environmentSubstitute(wGroupTime.getText()), -1)>0;

  wlGroupSize.setEnabled( true );
  wGroupSize.setEnabled( true );
  wlGroupField.setEnabled( !enableSize );
  wGroupField.setEnabled( !enableSize );
  wlGroupTime.setEnabled( !enableSize && !enableField );
  wGroupTime.setEnabled( !enableSize && !enableField );
}
 
Example 3
Source File: SalesforceInsertDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private SalesforceConnection getConnection() throws KettleException {
  String url = transMeta.environmentSubstitute( wURL.getText() );
  // Define a new Salesforce connection
  SalesforceConnection connection =
    new SalesforceConnection( log, url, transMeta.environmentSubstitute( wUserName.getText() ),
      Utils.resolvePassword( transMeta, wPassword.getText() ) );
  int realTimeOut = Const.toInt( transMeta.environmentSubstitute( wTimeOut.getText() ), 0 );
  connection.setTimeOut( realTimeOut );
  // connect to Salesforce
  connection.connect();

  return connection;
}
 
Example 4
Source File: PropsUI.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public FontData getFixedFont() {
  FontData def = getDefaultFontData();

  String name = properties.getProperty( STRING_FONT_FIXED_NAME );
  int size = Const.toInt( properties.getProperty( STRING_FONT_FIXED_SIZE ), def.getHeight() );
  int style = Const.toInt( properties.getProperty( STRING_FONT_FIXED_STYLE ), def.getStyle() );

  return new FontData( name, size, style );
}
 
Example 5
Source File: SelectMetadataChange.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void loadXML( Node metaNode ) {
  name = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_NAME" ) );
  rename = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_RENAME" ) );
  type = ValueMetaFactory.getIdForValueMeta(
    XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_TYPE" ) ) );
  length = Const.toInt( XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_LENGTH" ) ), -2 );
  precision =
    Const.toInt( XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_PRECISION" ) ), -2 );
  storageType =
    ValueMetaBase.getStorageType( XMLHandler.getTagValue( metaNode, attributesInterface
      .getXmlCode( "META_STORAGE_TYPE" ) ) );
  conversionMask = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_CONVERSION_MASK" ) );
  dateFormatLenient =
    Boolean.parseBoolean( XMLHandler.getTagValue( metaNode, attributesInterface
      .getXmlCode( "META_DATE_FORMAT_LENIENT" ) ) );
  dateFormatLocale =
    XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_DATE_FORMAT_LOCALE" ) );
  dateFormatTimeZone =
    XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_DATE_FORMAT_TIMEZONE" ) );
  encoding = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_ENCODING" ) );
  lenientStringToNumber =
    Boolean.parseBoolean( XMLHandler.getTagValue( metaNode, attributesInterface
      .getXmlCode( "META_LENIENT_STRING_TO_NUMBER" ) ) );
  encoding = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_ENCODING" ) );
  decimalSymbol = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_DECIMAL" ) );
  groupingSymbol = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_GROUPING" ) );
  currencySymbol = XMLHandler.getTagValue( metaNode, attributesInterface.getXmlCode( "META_CURRENCY" ) );
}
 
Example 6
Source File: PropsUI.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public FontData getNoteFont() {
  FontData def = getDefaultFontData();

  String name = properties.getProperty( STRING_FONT_NOTE_NAME, def.getName() );
  String ssize = properties.getProperty( STRING_FONT_NOTE_SIZE );
  String sstyle = properties.getProperty( STRING_FONT_NOTE_STYLE );

  int size = Const.toInt( ssize, def.getHeight() );
  int style = Const.toInt( sstyle, def.getStyle() );

  return new FontData( name, size, style );
}
 
Example 7
Source File: JobEntryCheckDbConnectionsDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wName.getText() ) ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setText( BaseMessages.getString( PKG, "System.StepJobEntryNameMissing.Title" ) );
    mb.setMessage( BaseMessages.getString( PKG, "System.JobEntryNameMissing.Msg" ) );
    mb.open();
    return;
  }
  jobEntry.setName( wName.getText() );

  int nritems = wFields.nrNonEmpty();

  DatabaseMeta[] connections = new DatabaseMeta[nritems];
  String[] waitfors = new String[nritems];
  int[] waittimes = new int[nritems];

  for ( int i = 0; i < nritems; i++ ) {
    String arg = wFields.getNonEmpty( i ).getText( 1 );
    DatabaseMeta dbMeta = jobMeta.findDatabase( arg );
    if ( dbMeta != null ) {
      connections[i] = dbMeta;
      waitfors[i] = "" + Const.toInt( wFields.getNonEmpty( i ).getText( 2 ), 0 );
      waittimes[i] =
        JobEntryCheckDbConnections.getWaitTimeByDesc( wFields.getNonEmpty( i ).getText( 3 ) );
    }
  }
  jobEntry.setConnections( connections );
  jobEntry.setWaitfors( waitfors );
  jobEntry.setWaittimes( waittimes );

  dispose();
}
 
Example 8
Source File: SortRows.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (SortRowsMeta) smi;
  data = (SortRowsData) sdi;

  if ( !super.init( smi, sdi ) ) {
    return false;
  }

  //Set Embedded NamedCluter MetatStore Provider Key so that it can be passed to VFS
  if ( getTransMeta().getNamedClusterEmbedManager() != null ) {
    getTransMeta().getNamedClusterEmbedManager()
      .passEmbeddedMetastoreKey( getTransMeta(), getTransMeta().getEmbeddedMetastoreProviderKey() );
  }

  data.sortSize = Const.toInt( environmentSubstitute( meta.getSortSize() ), -1 );
  data.freeMemoryPctLimit = Const.toInt( meta.getFreeMemoryLimit(), -1 );
  if ( data.sortSize <= 0 && data.freeMemoryPctLimit <= 0 ) {
    // Prefer the memory limit as it should never fail
    //
    data.freeMemoryPctLimit = 25;
  }

  // In memory buffer
  //
  data.buffer = new ArrayList<Object[]>( 5000 );

  // Buffer for reading from disk
  //
  data.rowbuffer = new ArrayList<Object[]>( 5000 );

  data.compressFiles = getBooleanValueOfVariable( meta.getCompressFilesVariable(), meta.getCompressFiles() );

  data.tempRows = new ArrayList<RowTempFile>();

  data.minSortSize = 5000;

  return true;
}
 
Example 9
Source File: JobEntryFTPPUT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void loadXML( Node entrynode, List<DatabaseMeta> databases, List<SlaveServer> slaveServers,
                     Repository rep, IMetaStore metaStore ) throws KettleXMLException {
  try {
    super.loadXML( entrynode, databases, slaveServers );
    serverName = XMLHandler.getTagValue( entrynode, "servername" );
    serverPort = XMLHandler.getTagValue( entrynode, "serverport" );
    userName = XMLHandler.getTagValue( entrynode, "username" );
    password = Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( entrynode, "password" ) );
    remoteDirectory = XMLHandler.getTagValue( entrynode, "remoteDirectory" );
    localDirectory = XMLHandler.getTagValue( entrynode, "localDirectory" );
    wildcard = XMLHandler.getTagValue( entrynode, "wildcard" );
    binaryMode = "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "binary" ) );
    timeout = Const.toInt( XMLHandler.getTagValue( entrynode, "timeout" ), 10000 );
    remove = "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "remove" ) );
    onlyPuttingNewFiles = "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "only_new" ) );
    activeConnection = "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "active" ) );
    controlEncoding = XMLHandler.getTagValue( entrynode, "control_encoding" );

    proxyHost = XMLHandler.getTagValue( entrynode, "proxy_host" );
    proxyPort = XMLHandler.getTagValue( entrynode, "proxy_port" );
    proxyUsername = XMLHandler.getTagValue( entrynode, "proxy_username" );
    proxyPassword =
      Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( entrynode, "proxy_password" ) );
    socksProxyHost = XMLHandler.getTagValue( entrynode, "socksproxy_host" );
    socksProxyPort = XMLHandler.getTagValue( entrynode, "socksproxy_port" );
    socksProxyUsername = XMLHandler.getTagValue( entrynode, "socksproxy_username" );
    socksProxyPassword =
      Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( entrynode, "socksproxy_password" ) );

    if ( controlEncoding == null ) {
      // if we couldn't retrieve an encoding, assume it's an old instance and
      // put in the the encoding used before v 2.4.0
      controlEncoding = LEGACY_CONTROL_ENCODING;
    }
  } catch ( KettleXMLException xe ) {
    throw new KettleXMLException( BaseMessages.getString( PKG, "JobFTPPUT.Log.UnableToLoadFromXml" ), xe );
  }
}
 
Example 10
Source File: RowsFromResultMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void readData( Node stepnode ) {
  Node fields = XMLHandler.getSubNode( stepnode, "fields" );
  int nrfields = XMLHandler.countNodes( fields, "field" );

  allocate( nrfields );

  for ( int i = 0; i < nrfields; i++ ) {
    Node line = XMLHandler.getSubNodeByNr( fields, "field", i );
    fieldname[i] = XMLHandler.getTagValue( line, "name" );
    type[i] = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( line, "type" ) );
    length[i] = Const.toInt( XMLHandler.getTagValue( line, "length" ), -2 );
    precision[i] = Const.toInt( XMLHandler.getTagValue( line, "precision" ), -2 );
  }

}
 
Example 11
Source File: RandomCCNumberGenerator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (RandomCCNumberGeneratorMeta) smi;
  data = (RandomCCNumberGeneratorData) sdi;

  if ( super.init( smi, sdi ) ) {
    // Add init code here.

    if ( meta.getFieldCCType() == null ) {
      logError( BaseMessages.getString( PKG, "RandomCCNumberGenerator.Log.NoFieldSpecified" ) );
      return false;
    }
    if ( meta.getFieldCCType().length == 0 ) {
      logError( BaseMessages.getString( PKG, "RandomCCNumberGenerator.Log.NoFieldSpecified" ) );
      return false;
    }

    if ( Utils.isEmpty( meta.getCardNumberFieldName() ) ) {
      logError( BaseMessages.getString( PKG, "RandomCCNumberGenerator.Log.CardNumberFieldMissing" ) );
      return false;
    }

    data.cardTypes = new int[meta.getFieldCCType().length];
    data.cardLen = new int[meta.getFieldCCType().length];
    data.cardSize = new int[meta.getFieldCCType().length];

    for ( int i = 0; i < meta.getFieldCCType().length; i++ ) {
      data.cardTypes[i] = RandomCreditCardNumberGenerator.getCardType( meta.getFieldCCType()[i] );
      String len = environmentSubstitute( meta.getFieldCCLength()[i] );
      data.cardLen[i] = Const.toInt( len, -1 );
      if ( data.cardLen[i] < 0 ) {
        logError( BaseMessages.getString( PKG, "RandomCCNumberGenerator.Log.WrongLength", len, String
          .valueOf( i ) ) );
        return false;
      }
      String size = environmentSubstitute( meta.getFieldCCSize()[i] );
      data.cardSize[i] = Const.toInt( size, -1 );
      if ( data.cardSize[i] < 0 ) {
        logError( BaseMessages
          .getString( PKG, "RandomCCNumberGenerator.Log.WrongSize", size, String.valueOf( i ) ) );
        return false;
      }
    }

    data.addCardTypeOutput = !Utils.isEmpty( meta.getCardTypeFieldName() );
    data.addCardLengthOutput = !Utils.isEmpty( meta.getCardLengthFieldName() );

    return true;
  }
  return false;
}
 
Example 12
Source File: PropsUI.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public int getCanvasGridSize() {
  return Const.toInt( properties.getProperty( CANVAS_GRID_SIZE, "16" ), 16 );
}
 
Example 13
Source File: JobEntryCopy.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public JobEntryCopy( Node entrynode, List<DatabaseMeta> databases, List<SlaveServer> slaveServers, Repository rep,
    IMetaStore metaStore ) throws KettleXMLException {
  try {
    String stype = XMLHandler.getTagValue( entrynode, "type" );
    PluginRegistry registry = PluginRegistry.getInstance();
    PluginInterface jobPlugin = registry.findPluginWithId( JobEntryPluginType.class, stype, true );
    if ( jobPlugin == null ) {
      String name = XMLHandler.getTagValue( entrynode, "name" );
      entry = new MissingEntry( name, stype );
    } else {
      entry = registry.loadClass( jobPlugin, JobEntryInterface.class );
    }
    // Get an empty JobEntry of the appropriate class...
    if ( entry != null ) {
      if ( jobPlugin != null ) {
        entry.setPluginId( jobPlugin.getIds()[0] );
      }
      entry.setMetaStore( metaStore ); // inject metastore
      entry.loadXML( entrynode, databases, slaveServers, rep, metaStore );
      compatibleLoadXml( entrynode, databases, slaveServers, rep );

      // Handle GUI information: nr & location?
      setNr( Const.toInt( XMLHandler.getTagValue( entrynode, "nr" ), 0 ) );
      setLaunchingInParallel( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "parallel" ) ) );
      setDrawn( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "draw" ) ) );
      int x = Const.toInt( XMLHandler.getTagValue( entrynode, "xloc" ), 0 );
      int y = Const.toInt( XMLHandler.getTagValue( entrynode, "yloc" ), 0 );
      setLocation( x, y );

      Node jobEntryCopyAttributesNode = XMLHandler.getSubNode( entrynode, XML_ATTRIBUTE_JOB_ENTRY_COPY );
      if ( jobEntryCopyAttributesNode != null ) {
        attributesMap = AttributesUtil.loadAttributes( jobEntryCopyAttributesNode );
      } else {
        // [PDI-17345] If the appropriate attributes node wasn't found, this must be an old file (prior to this fix).
        // Before this fix it was very probable to exist two attributes groups. While this is not very valid, in some
        // scenarios the Job worked as expected; so by trying to load the LAST one into the JobEntryCopy, we
        // simulate that behaviour.
        attributesMap =
          AttributesUtil.loadAttributes( XMLHandler.getLastSubNode( entrynode, AttributesUtil.XML_TAG ) );
      }

      setDeprecationAndSuggestedJobEntry();
    }
  } catch ( Throwable e ) {
    String message = "Unable to read Job Entry copy info from XML node : " + e.toString();
    throw new KettleXMLException( message, e );
  }
}
 
Example 14
Source File: JobEntryFTPSPUT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
void buildFTPSConnection( FTPSConnection connection ) throws Exception {
  if ( !Utils.isEmpty( proxyHost ) ) {
    String realProxy_host = environmentSubstitute( proxyHost );
    String realProxy_username = environmentSubstitute( proxyUsername );
    String realProxy_password = environmentSubstitute( proxyPassword );
    realProxy_password = Encr.decryptPasswordOptionallyEncrypted( realProxy_password );

    connection.setProxyHost( realProxy_host );
    if ( !Utils.isEmpty( realProxy_username ) ) {
      connection.setProxyUser( realProxy_username );
    }
    if ( !Utils.isEmpty( realProxy_password ) ) {
      connection.setProxyPassword( realProxy_password );
    }
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPSPUT.OpenedProxyConnectionOn", realProxy_host ) );
    }

    int proxyport = Const.toInt( environmentSubstitute( proxyPort ), 21 );
    if ( proxyport != 0 ) {
      connection.setProxyPort( proxyport );
    }
  } else {
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryFTPSPUT.OpenedConnectionTo", connection.getHostName() ) );
    }
  }

  // set activeConnection connectmode ...
  if ( activeConnection ) {
    connection.setPassiveMode( false );
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.Log.SetActiveConnection" ) );
    }
  } else {
    connection.setPassiveMode( true );
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.Log.SetPassiveConnection" ) );
    }
  }

  // Set the timeout
  connection.setTimeOut( timeout );
  if ( isDetailed() ) {
    logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.Log.SetTimeout", timeout ) );
  }

  // login to FTPS host ...
  connection.connect();
  if ( isDetailed() ) {
    // Remove password from logging, you don't know where it ends up.
    logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.Log.Logged", connection.getUserName() ) );
    logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.WorkingDirectory", connection.getWorkingDirectory() ) );
  }

  // Set binary mode
  if ( isBinaryMode() ) {
    connection.setBinaryMode( true );
    if ( isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobFTPSPUT.Log.BinaryMod" ) );
    }
  }
}
 
Example 15
Source File: TransExecutorMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
  try {
    String method = XMLHandler.getTagValue( stepnode, "specification_method" );
    specificationMethod = ObjectLocationSpecificationMethod.getSpecificationMethodByCode( method );
    String transId = XMLHandler.getTagValue( stepnode, "trans_object_id" );
    transObjectId = Utils.isEmpty( transId ) ? null : new StringObjectId( transId );

    transName = XMLHandler.getTagValue( stepnode, "trans_name" );
    fileName = XMLHandler.getTagValue( stepnode, "filename" );
    directoryPath = XMLHandler.getTagValue( stepnode, "directory_path" );

    groupSize = XMLHandler.getTagValue( stepnode, "group_size" );
    groupField = XMLHandler.getTagValue( stepnode, "group_field" );
    groupTime = XMLHandler.getTagValue( stepnode, "group_time" );

    // Load the mapping parameters too..
    //
    Node mappingParametersNode = XMLHandler.getSubNode( stepnode, TransExecutorParameters.XML_TAG );
    parameters = new TransExecutorParameters( mappingParametersNode );

    // The output side...
    //
    executionResultTargetStep = XMLHandler.getTagValue( stepnode, F_EXECUTION_RESULT_TARGET_STEP );
    executionTimeField = XMLHandler.getTagValue( stepnode, "execution_time_field" );
    executionResultField = XMLHandler.getTagValue( stepnode, "execution_result_field" );
    executionNrErrorsField = XMLHandler.getTagValue( stepnode, "execution_errors_field" );
    executionLinesReadField = XMLHandler.getTagValue( stepnode, "execution_lines_read_field" );
    executionLinesWrittenField = XMLHandler.getTagValue( stepnode, "execution_lines_written_field" );
    executionLinesInputField = XMLHandler.getTagValue( stepnode, "execution_lines_input_field" );
    executionLinesOutputField = XMLHandler.getTagValue( stepnode, "execution_lines_output_field" );
    executionLinesRejectedField = XMLHandler.getTagValue( stepnode, "execution_lines_rejected_field" );
    executionLinesUpdatedField = XMLHandler.getTagValue( stepnode, "execution_lines_updated_field" );
    executionLinesDeletedField = XMLHandler.getTagValue( stepnode, "execution_lines_deleted_field" );
    executionFilesRetrievedField = XMLHandler.getTagValue( stepnode, "execution_files_retrieved_field" );
    executionExitStatusField = XMLHandler.getTagValue( stepnode, "execution_exit_status_field" );
    executionLogTextField = XMLHandler.getTagValue( stepnode, "execution_log_text_field" );
    executionLogChannelIdField = XMLHandler.getTagValue( stepnode, "execution_log_channelid_field" );

    outputRowsSourceStep = XMLHandler.getTagValue( stepnode, "result_rows_target_step" );

    int nrFields = XMLHandler.countNodes( stepnode, "result_rows_field" );
    allocate( nrFields );

    for ( int i = 0; i < nrFields; i++ ) {

      Node fieldNode = XMLHandler.getSubNodeByNr( stepnode, "result_rows_field", i );

      outputRowsField[ i ] = XMLHandler.getTagValue( fieldNode, "name" );
      outputRowsType[ i ] = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( fieldNode, "type" ) );
      outputRowsLength[ i ] = Const.toInt( XMLHandler.getTagValue( fieldNode, "length" ), -1 );
      outputRowsPrecision[ i ] = Const.toInt( XMLHandler.getTagValue( fieldNode, "precision" ), -1 );
    }

    resultFilesTargetStep = XMLHandler.getTagValue( stepnode, F_RESULT_FILE_TARGET_STEP );
    resultFilesFileNameField = XMLHandler.getTagValue( stepnode, "result_files_file_name_field" );
    executorsOutputStep = XMLHandler.getTagValue( stepnode, F_EXECUTOR_OUTPUT_STEP );
  } catch ( Exception e ) {
    throw new KettleXMLException( BaseMessages.getString( PKG,
      "TransExecutorMeta.Exception.ErrorLoadingTransExecutorDetailsFromXML" ), e );
  }
}
 
Example 16
Source File: JaninoMetaInjection.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void injectStepMetadataEntries( List<StepInjectionMetaEntry> all ) throws KettleException {

  List<String> fieldNames = new ArrayList<String>();
  List<String> javaExpressions = new ArrayList<String>();
  List<String> valueTypes = new ArrayList<String>();
  List<String> lengths = new ArrayList<String>();
  List<String> precisions = new ArrayList<String>();
  List<String> replaceValues = new ArrayList<String>();

  // Parse the fields, inject into the meta class..
  //
  for ( StepInjectionMetaEntry lookFields : all ) {
    Entry fieldsEntry = Entry.findEntry( lookFields.getKey() );
    if ( fieldsEntry == null ) {
      continue;
    }

    switch ( fieldsEntry ) {
      case EXPRESSION_FIELDS:
        for ( StepInjectionMetaEntry lookField : lookFields.getDetails() ) {
          Entry fieldEntry = Entry.findEntry( lookField.getKey() );
          if ( fieldEntry == Entry.EXPRESSION_FIELD ) {

            String newFieldname = null;
            String javaExpression = null;
            String valueType = null;
            String length = null;
            String precision = null;
            String replaceValue = null;

            List<StepInjectionMetaEntry> entries = lookField.getDetails();
            for ( StepInjectionMetaEntry entry : entries ) {
              Entry metaEntry = Entry.findEntry( entry.getKey() );
              if ( metaEntry != null ) {
                String value = (String) entry.getValue();
                switch ( metaEntry ) {
                  case NEW_FIELDNAME:
                    newFieldname = value;
                    break;
                  case JAVA_EXPRESSION:
                    javaExpression = value;
                    break;
                  case VALUE_TYPE:
                    valueType = value;
                    break;
                  case LENGTH:
                    length = value;
                    break;
                  case PRECISION:
                    precision = value;
                    break;
                  case REPLACE_VALUE:
                    replaceValue = value;
                    break;
                  default:
                    break;
                }
              }
            }
            fieldNames.add( newFieldname );
            javaExpressions.add( javaExpression );
            valueTypes.add( valueType );
            lengths.add( length );
            precisions.add( precision );
            replaceValues.add( replaceValue );

          }
        }
        break;
      default:
        break;
    }
  }

  // Pass the grid to the step metadata
  //
  if ( fieldNames.size() > 0 ) {
    JaninoMetaFunction[] fields = new JaninoMetaFunction[ fieldNames.size() ];

    Iterator<String> iFieldNames = fieldNames.iterator();
    Iterator<String> iJavaExpressions = javaExpressions.iterator();
    Iterator<String> iValueTypes = valueTypes.iterator();
    Iterator<String> iLengths = lengths.iterator();
    Iterator<String> iPrecisions = precisions.iterator();
    Iterator<String> iReplaceValues = replaceValues.iterator();

    int i = 0;

    while ( iFieldNames.hasNext() ) {
      fields[i] = new JaninoMetaFunction( iFieldNames.next(), iJavaExpressions.next(),
        ValueMetaFactory.getIdForValueMeta( iValueTypes.next() ), Const.toInt( iLengths.next(), -1 ),
          Const.toInt( iPrecisions.next(), -1 ), iReplaceValues.next() );

      i++;
    }

    meta.setFormula( fields );
  }
}
 
Example 17
Source File: MailInputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void readData( Node stepnode ) {
  servername = XMLHandler.getTagValue( stepnode, "servername" );
  username = XMLHandler.getTagValue( stepnode, "username" );
  password = Encr.decryptPasswordOptionallyEncrypted( XMLHandler.getTagValue( stepnode, "password" ) );
  usessl = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "usessl" ) );
  sslport = XMLHandler.getTagValue( stepnode, "sslport" );
  retrievemails = Const.toInt( XMLHandler.getTagValue( stepnode, "retrievemails" ), -1 );
  firstmails = XMLHandler.getTagValue( stepnode, "firstmails" );
  delete = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "delete" ) );

  protocol = Const.NVL( XMLHandler.getTagValue( stepnode, "protocol" ), MailConnectionMeta.PROTOCOL_STRING_POP3 );
  valueimaplist =
    MailConnectionMeta.getValueImapListByCode( Const.NVL(
      XMLHandler.getTagValue( stepnode, "valueimaplist" ), "" ) );
  imapfirstmails = XMLHandler.getTagValue( stepnode, "imapfirstmails" );
  imapfolder = XMLHandler.getTagValue( stepnode, "imapfolder" );
  // search term
  senderSearch = XMLHandler.getTagValue( stepnode, "sendersearch" );
  notTermSenderSearch = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "nottermsendersearch" ) );
  recipientSearch = XMLHandler.getTagValue( stepnode, "recipientsearch" );
  notTermRecipientSearch = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "notTermRecipientSearch" ) );
  subjectSearch = XMLHandler.getTagValue( stepnode, "subjectsearch" );
  notTermSubjectSearch = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "nottermsubjectsearch" ) );
  conditionReceivedDate =
    MailConnectionMeta.getConditionByCode( Const.NVL( XMLHandler.getTagValue(
      stepnode, "conditionreceiveddate" ), "" ) );
  notTermReceivedDateSearch =
    "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "nottermreceiveddatesearch" ) );
  receivedDate1 = XMLHandler.getTagValue( stepnode, "receivedDate1" );
  receivedDate2 = XMLHandler.getTagValue( stepnode, "receivedDate2" );
  includesubfolders = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "includesubfolders" ) );
  usedynamicfolder = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "usedynamicfolder" ) );
  folderfield = XMLHandler.getTagValue( stepnode, "folderfield" );
  proxyusername = XMLHandler.getTagValue( stepnode, "proxyusername" );
  useproxy = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "useproxy" ) );
  useBatch = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, Tags.USE_BATCH ) );
  try {
    batchSize = Integer.parseInt( XMLHandler.getTagValue( stepnode, Tags.BATCH_SIZE ) );
  } catch ( NumberFormatException e ) {
    batchSize = DEFAULT_BATCH_SIZE;
  }
  start = XMLHandler.getTagValue( stepnode, Tags.START_MSG );
  end = XMLHandler.getTagValue( stepnode, Tags.END_MSG );
  stopOnError = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, Tags.STOP_ON_ERROR ) );

  rowlimit = XMLHandler.getTagValue( stepnode, "rowlimit" );
  Node fields = XMLHandler.getSubNode( stepnode, "fields" );
  int nrFields = XMLHandler.countNodes( fields, "field" );

  allocate( nrFields );
  for ( int i = 0; i < nrFields; i++ ) {
    Node fnode = XMLHandler.getSubNodeByNr( fields, "field", i );
    inputFields[i] = new MailInputField();
    inputFields[i].setName( XMLHandler.getTagValue( fnode, "name" ) );
    inputFields[i].setColumn( MailInputField.getColumnByCode( XMLHandler.getTagValue( fnode, "column" ) ) );
  }
}
 
Example 18
Source File: TextFileOutputMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * @param varSpace for variable substitution
 * @return At how many rows to split into another file.
 */
@Override
public int getSplitEvery( VariableSpace varSpace ) {
  return Const.toInt( varSpace == null ? splitEveryRows : varSpace.environmentSubstitute( splitEveryRows ), 0 );
}
 
Example 19
Source File: JobEntryMailValidator.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Execute this job entry and return the result. In this case it means, just set the result boolean in the Result
 * class.
 *
 * @param previousResult
 *          The result of the previous execution
 * @return The Result of the execution.
 */
public Result execute( Result previousResult, int nr ) {
  Result result = previousResult;
  result.setNrErrors( 1 );
  result.setResult( false );

  String realEmailAddress = environmentSubstitute( emailAddress );
  if ( Utils.isEmpty( realEmailAddress ) ) {
    logError( BaseMessages.getString( PKG, "JobEntryMailValidator.Error.EmailEmpty" ) );
    return result;
  }
  String realSender = environmentSubstitute( emailSender );
  if ( smtpCheck ) {
    // check sender
    if ( Utils.isEmpty( realSender ) ) {
      logError( BaseMessages.getString( PKG, "JobEntryMailValidator.Error.EmailSenderEmpty" ) );
      return result;
    }
  }

  String realDefaultSMTP = environmentSubstitute( defaultSMTP );
  int timeOut = Const.toInt( environmentSubstitute( timeout ), 0 );

  // Split the mail-address: separated by space
  String[] mailsCheck = realEmailAddress.split( " " );
  boolean exitloop = false;
  boolean mailIsValid = false;
  String MailError = null;
  for ( int i = 0; i < mailsCheck.length && !exitloop; i++ ) {
    String email = mailsCheck[i];
    if ( log.isDetailed() ) {
      logDetailed( BaseMessages.getString( PKG, "JobEntryMailValidator.CheckingMail", email ) );
    }

    // Check if address is valid
    MailValidationResult resultValidator =
      MailValidation.isAddressValid( log, email, realSender, realDefaultSMTP, timeOut, smtpCheck );

    mailIsValid = resultValidator.isValide();
    MailError = resultValidator.getErrorMessage();

    if ( log.isDetailed() ) {
      if ( mailIsValid ) {
        logDetailed( BaseMessages.getString( PKG, "JobEntryMailValidator.MailValid", email ) );
      } else {
        logDetailed( BaseMessages.getString( PKG, "JobEntryMailValidator.MailNotValid", email ) );
        logDetailed( MailError );
      }

    }
    // invalid mail? exit loop
    if ( !resultValidator.isValide() ) {
      exitloop = true;
    }
  }

  result.setResult( mailIsValid );
  if ( mailIsValid ) {
    result.setNrErrors( 0 );
  }

  // return result

  return result;
}
 
Example 20
Source File: XMLInputFieldPosition.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
/**
 * Construnct a new XMLFieldPosition based on an a code: E=Elementame, A=Attributename
 *
 * @param encoded
 */
public XMLInputFieldPosition( String encoded ) throws KettleValueException {
  int equalIndex = encoded.indexOf( '=' );
  if ( equalIndex < 0 ) {
    throw new KettleValueException( BaseMessages.getString(
      PKG, "XMLInputFieldPosition.Exception.InvalidXMLFieldPosition", encoded ) );
  }

  String positionType = Const.trim( encoded.substring( 0, equalIndex ) );
  String nameAndNumber = Const.trim( encoded.substring( equalIndex + 1 ) );
  String positionName = nameAndNumber;

  // Is there an element number?
  int semiIndex = nameAndNumber.indexOf( NR_MARKER );

  if ( semiIndex >= 0 ) {
    this.elementNr = Const.toInt( nameAndNumber.substring( semiIndex + 1 ), 1 ); // Unreadable: default to 1
    positionName = nameAndNumber.substring( 0, semiIndex );
  } else {
    this.elementNr = 1;
  }

  if ( positionType.equalsIgnoreCase( "E" ) ) { // Element

    this.type = XML_ELEMENT;
    this.name = positionName;
  } else if ( positionType.equalsIgnoreCase( "A" ) ) { // Attribute

    this.type = XML_ATTRIBUTE;
    this.name = positionName;
  } else if ( positionType.equalsIgnoreCase( "R" ) ) { // Root of the repeating element. There is only one

    this.type = XML_ROOT;
    this.name = positionName;
  } else {
    throw new KettleValueException( BaseMessages.getString(
      PKG, "XMLInputFieldPosition.Exception.WrongPositionType", positionType ) );
  }

  // Get the element nr

}