Java Code Examples for org.pentaho.di.core.row.value.ValueMetaFactory#getIdForValueMeta()

The following examples show how to use org.pentaho.di.core.row.value.ValueMetaFactory#getIdForValueMeta() . 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: RowsFromResultDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  stepname = wStepname.getText(); // return value
  int nrfields = wFields.nrNonEmpty();
  input.allocate( nrfields );
  //CHECKSTYLE:Indentation:OFF
  for ( int i = 0; i < nrfields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );
    input.getFieldname()[i] = item.getText( 1 );
    input.getType()[i] = ValueMetaFactory.getIdForValueMeta( item.getText( 2 ) );
    input.getLength()[i] = Const.toInt( item.getText( 3 ), -1 );
    input.getPrecision()[i] = Const.toInt( item.getText( 4 ), -1 );
  }
  dispose();
}
 
Example 2
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
/**
 * @param set The data set to load the dialog information into
 */
public void getInfo( DataSet set ) {

  set.setName( wName.getText() );
  set.setDescription( wDescription.getText() );
  set.setGroup( DataSetConst.findDataSetGroup( groups, wDataSetGroup.getText() ) );
  set.setTableName( wTableName.getText() );
  set.getFields().clear();
  int nrFields = wFieldMapping.nrNonEmpty();
  for ( int i = 0; i < nrFields; i++ ) {
    TableItem item = wFieldMapping.getNonEmpty( i );
    int colnr = 1;
    String fieldName = item.getText( colnr++ );
    String columnName = item.getText( colnr++ );
    int type = ValueMetaFactory.getIdForValueMeta( item.getText( colnr++ ) );
    String format = item.getText( colnr++ );
    int length = Const.toInt( item.getText( colnr++ ), -1 );
    int precision = Const.toInt( item.getText( colnr++ ), -1 );
    String comment = item.getText( colnr++ );

    DataSetField field = new DataSetField( fieldName, columnName, type, length, precision, comment, format );
    set.getFields().add( field );
  }

}
 
Example 3
Source File: ConstantMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  for ( int i = 0; i < fieldName.length; i++ ) {
    if ( fieldName[i] != null && fieldName[i].length() != 0 ) {
      int type = ValueMetaFactory.getIdForValueMeta( fieldType[i] );
      if ( type == ValueMetaInterface.TYPE_NONE ) {
        type = ValueMetaInterface.TYPE_STRING;
      }
      try {
        ValueMetaInterface v = ValueMetaFactory.createValueMeta( fieldName[i], type );
        v.setLength( fieldLength[i] );
        v.setPrecision( fieldPrecision[i] );
        v.setOrigin( name );
        v.setConversionMask( fieldFormat[i] );
        rowMeta.addValueMeta( v );
      } catch ( Exception e ) {
        throw new KettleStepException( e );
      }
    }
  }
}
 
Example 4
Source File: CalculatorMetaFunction.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public CalculatorMetaFunction( Node calcnode ) {
  fieldName = XMLHandler.getTagValue( calcnode, "field_name" );
  calcType = getCalcFunctionType( XMLHandler.getTagValue( calcnode, "calc_type" ) );
  fieldA = XMLHandler.getTagValue( calcnode, "field_a" );
  fieldB = XMLHandler.getTagValue( calcnode, "field_b" );
  fieldC = XMLHandler.getTagValue( calcnode, "field_c" );
  valueType = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( calcnode, "value_type" ) );
  valueLength = Const.toInt( XMLHandler.getTagValue( calcnode, "value_length" ), -1 );
  valuePrecision = Const.toInt( XMLHandler.getTagValue( calcnode, "value_precision" ), -1 );
  removedFromResult = "Y".equalsIgnoreCase( XMLHandler.getTagValue( calcnode, "remove" ) );
  conversionMask = XMLHandler.getTagValue( calcnode, "conversion_mask" );
  decimalSymbol = XMLHandler.getTagValue( calcnode, "decimal_symbol" );
  groupingSymbol = XMLHandler.getTagValue( calcnode, "grouping_symbol" );
  currencySymbol = XMLHandler.getTagValue( calcnode, "currency_symbol" );

  // Fix 2.x backward compatibility
  // The conversion mask was added in a certain revision.
  // Anything that we load from before then should get masks set to retain backward compatibility
  //
  if ( XMLHandler.getSubNode( calcnode, "conversion_mask" ) == null ) {
    fixBackwardCompatibility();
  }
}
 
Example 5
Source File: ScriptValuesMetaMod.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
  try {
    String script = rep.getStepAttributeString( id_step, "script" );
    compatible = rep.getStepAttributeBoolean( id_step, 0, "compatible", true );
    optimizationLevel = rep.getStepAttributeString( id_step, 0, "optimizationLevel" );

    // When in compatibility mode, we load the script, not the other tabs...
    //
    if ( !Utils.isEmpty( script ) ) {
      jsScripts = new ScriptValuesScript[1];
      jsScripts[0] = new ScriptValuesScript( ScriptValuesScript.TRANSFORM_SCRIPT, "ScriptValue", script );
    } else {
      int nrScripts = rep.countNrStepAttributes( id_step, JSSCRIPT_TAG_NAME );
      jsScripts = new ScriptValuesScript[nrScripts];
      for ( int i = 0; i < nrScripts; i++ ) {
        jsScripts[i] = new ScriptValuesScript(
          (int) rep.getStepAttributeInteger( id_step, i, JSSCRIPT_TAG_TYPE ),
          rep.getStepAttributeString( id_step, i, JSSCRIPT_TAG_NAME ),
          rep.getStepAttributeString( id_step, i, JSSCRIPT_TAG_SCRIPT ) );
      }
    }

    int nrfields = rep.countNrStepAttributes( id_step, "field_name" );
    allocate( nrfields );

    for ( int i = 0; i < nrfields; i++ ) {
      fieldname[i] = rep.getStepAttributeString( id_step, i, "field_name" );
      rename[i] = rep.getStepAttributeString( id_step, i, "field_rename" );
      type[i] = ValueMetaFactory.getIdForValueMeta( rep.getStepAttributeString( id_step, i, "field_type" ) );
      length[i] = (int) rep.getStepAttributeInteger( id_step, i, "field_length" );
      precision[i] = (int) rep.getStepAttributeInteger( id_step, i, "field_precision" );
      replace[i] = rep.getStepAttributeBoolean( id_step, i, "field_replace" );
    }
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "ScriptValuesMetaMod.Exception.UnexpectedErrorInReadingStepInfo" ), e );
  }
}
 
Example 6
Source File: SasInputField.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SasInputField( Repository rep, ObjectId stepId, int fieldNr ) throws KettleException {
  name = rep.getStepAttributeString( stepId, fieldNr, "field_name" );
  rename = rep.getStepAttributeString( stepId, fieldNr, "field_rename" );
  type = ValueMetaFactory.getIdForValueMeta( rep.getStepAttributeString( stepId, fieldNr, "field_type" ) );
  length = (int) rep.getStepAttributeInteger( stepId, fieldNr, "field_length" );
  precision = (int) rep.getStepAttributeInteger( stepId, fieldNr, "field_precision" );
  conversionMask = rep.getStepAttributeString( stepId, fieldNr, "field_conversion_mask" );
  decimalSymbol = rep.getStepAttributeString( stepId, fieldNr, "field_decimal" );
  groupingSymbol = rep.getStepAttributeString( stepId, fieldNr, "field_grouping" );
  trimType = ValueMetaString.getTrimTypeByCode( rep.getStepAttributeString( stepId, fieldNr, "field_trim_type" ) );
}
 
Example 7
Source File: SasInputField.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SasInputField( Node node ) throws KettleXMLException {
  name = XMLHandler.getTagValue( node, "name" );
  rename = XMLHandler.getTagValue( node, "rename" );
  type = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( node, "type" ) );
  length = Const.toInt( XMLHandler.getTagValue( node, "length" ), -1 );
  precision = Const.toInt( XMLHandler.getTagValue( node, "precision" ), -1 );
  conversionMask = XMLHandler.getTagValue( node, "conversion_mask" );
  decimalSymbol = XMLHandler.getTagValue( node, "decimal" );
  groupingSymbol = XMLHandler.getTagValue( node, "grouping" );
  trimType = ValueMetaString.getTrimTypeByCode( XMLHandler.getTagValue( node, "trim_type" ) );
}
 
Example 8
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 9
Source File: ExcelWriterStep_StyleFormatTest.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Setup any meta information for Excel Writer step
 *
 * @param fileType
 * @throws KettleException
 */
private void createStepMeta( String fileType ) throws KettleException {
  stepMeta = new ExcelWriterStepMeta();
  stepMeta.setDefault();

  stepMeta.setFileName( "testExcel" );
  stepMeta.setExtension( fileType );
  stepMeta.setSheetname( "Sheet1" );
  stepMeta.setHeaderEnabled( true );
  stepMeta.setStartingCell( "A2" );

  // Try different combinations of specifying data format and style from cell
  //   1. Only format, no style
  //   2. No format, only style
  //   3. Format, and a different style without a format defined
  //   4. Format, and a different style with a different format defined but gets overridden
  ExcelWriterStepField[] outputFields = new ExcelWriterStepField[4];
  outputFields[0] = new ExcelWriterStepField( "col 1", ValueMetaFactory.getIdForValueMeta( "Integer" ), "0.00000" );
  outputFields[0].setStyleCell( "" );
  outputFields[1] = new ExcelWriterStepField( "col 2", ValueMetaFactory.getIdForValueMeta( "Number" ), "" );
  outputFields[1].setStyleCell( "G1" );
  outputFields[2] = new ExcelWriterStepField( "col 3", ValueMetaFactory.getIdForValueMeta( "BigNumber" ), "0.00000" );
  outputFields[2].setStyleCell( "F1" );
  outputFields[3] = new ExcelWriterStepField( "col 4", ValueMetaFactory.getIdForValueMeta( "Integer" ), "0.00000" );
  outputFields[3].setStyleCell( "G1" );
  stepMeta.setOutputFields( outputFields );
}
 
Example 10
Source File: JaninoDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  stepname = wStepname.getText(); // return value

  currentMeta.allocate( wFields.nrNonEmpty() );

  int nrNonEmptyFields = wFields.nrNonEmpty();
  for ( int i = 0; i < nrNonEmptyFields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );

    String fieldName = item.getText( 1 );
    String formula = item.getText( 2 );
    int valueType = ValueMetaFactory.getIdForValueMeta( item.getText( 3 ) );
    int valueLength = Const.toInt( item.getText( 4 ), -1 );
    int valuePrecision = Const.toInt( item.getText( 5 ), -1 );
    String replaceField = item.getText( 6 );

    //CHECKSTYLE:Indentation:OFF
    currentMeta.getFormula()[i] = new JaninoMetaFunction( fieldName, formula, valueType,
      valueLength, valuePrecision, replaceField );
  }

  if ( !originalMeta.equals( currentMeta ) ) {
    currentMeta.setChanged();
    changed = currentMeta.hasChanged();
  }

  dispose();
}
 
Example 11
Source File: BeamBQInputMeta.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
@Override public void getFields( RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, VariableSpace space, Repository repository, IMetaStore metaStore )
  throws KettleStepException {

  try {
    for ( BQField field : fields ) {
      int type = ValueMetaFactory.getIdForValueMeta( field.getKettleType() );
      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( field.getNewNameOrName(), type, -1, -1 );
      valueMeta.setOrigin( name );
      inputRowMeta.addValueMeta( valueMeta );
    }
  } catch ( Exception e ) {
    throw new KettleStepException( "Error getting Beam BQ Input step output", e );
  }
}
 
Example 12
Source File: TextFileInputDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the input width to minimal width...
 *
 */
public void setMinimalWidth() {
  int nrNonEmptyFields = wFields.nrNonEmpty();
  for ( int i = 0; i < nrNonEmptyFields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );

    item.setText( 5, "" );
    item.setText( 6, "" );
    item.setText( 12, ValueMetaString.getTrimTypeDesc( ValueMetaInterface.TRIM_TYPE_BOTH ) );

    int type = ValueMetaFactory.getIdForValueMeta( item.getText( 2 ) );
    switch ( type ) {
      case ValueMetaInterface.TYPE_STRING:
        item.setText( 3, "" );
        break;
      case ValueMetaInterface.TYPE_INTEGER:
        item.setText( 3, "0" );
        break;
      case ValueMetaInterface.TYPE_NUMBER:
        item.setText( 3, "0.#####" );
        break;
      case ValueMetaInterface.TYPE_DATE:
        break;
      default:
        break;
    }
  }

  for ( int i = 0; i < input.inputFields.length; i++ ) {
    input.inputFields[i].setTrimType( ValueMetaInterface.TRIM_TYPE_BOTH );
  }

  wFields.optWidth( true );
}
 
Example 13
Source File: JaninoMetaInjectionIT.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private JaninoMeta populateJaninoMeta() {
  JaninoMeta meta = new JaninoMeta();
  meta.allocate( NR_FIELDS );

  // CHECKSTYLE:Indentation:OFF
  for ( int i = 0; i < NR_FIELDS; i++ ) {
    meta.getFormula()[i] = new JaninoMetaFunction( NEW_FIELDNAME + i, JAVA_EXPRESSION + i,
      ValueMetaFactory.getIdForValueMeta( VALUE_TYPE ), LENGTH + i, PRECISION + i, REPLACE_VALUE + i );
  }

  return meta;
}
 
Example 14
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
/**
 * Look at the metadata specified here and create the table accordingly...
 * - Create a table for the Database Group type
 * - Create a metadata file for the CSV group type
 */
protected void createTable() {
  try {
    verifySettings();

    DataSet set = new DataSet();
    getInfo( set );
    DataSetGroup group = set.getGroup();

    String tableName = wTableName.getText();

    // Calculate the row metadata of the table
    //
    RowMetaInterface rowMeta = new RowMeta();
    int nrFields = wFieldMapping.nrNonEmpty();
    for ( int i = 0; i < nrFields; i++ ) {
      TableItem item = wFieldMapping.getNonEmpty( i );
      int colnr = 2;
      String columnName = item.getText( colnr++ );
      if ( StringUtil.isEmpty( columnName ) ) {
        throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoColumnName", Integer.toString( i ) ) );
      }
      int fieldType = ValueMetaFactory.getIdForValueMeta( item.getText( colnr++ ) );
      if ( fieldType == ValueMetaInterface.TYPE_NONE ) {
        throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoDataType", Integer.toString( i ) ) );
      }
      int length = Const.toInt( item.getText( colnr++ ), -1 );
      int precision = Const.toInt( item.getText( colnr++ ), -1 );

      ValueMetaInterface valueMeta = ValueMetaFactory.createValueMeta( columnName, fieldType, length, precision );
      rowMeta.addValueMeta( valueMeta );
    }

    group.createTable( tableName, rowMeta );

  } catch ( Exception e ) {
    new ErrorDialog( shell, "Error", "Error retrieving metadata from dataset table", e );
  }

}
 
Example 15
Source File: CalculatorDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  stepname = wStepname.getText(); // return value

  currentMeta.setFailIfNoFile( wFailIfNoFile.getSelection() );

  int nrNonEmptyFields = wFields.nrNonEmpty();
  currentMeta.allocate( nrNonEmptyFields );

  for ( int i = 0; i < nrNonEmptyFields; i++ ) {
    TableItem item = wFields.getNonEmpty( i );

    String fieldName = item.getText( 1 );
    int calcType = CalculatorMetaFunction.getCalcFunctionType( item.getText( 2 ) );
    String fieldA = item.getText( 3 );
    String fieldB = item.getText( 4 );
    String fieldC = item.getText( 5 );
    int valueType = ValueMetaFactory.getIdForValueMeta( item.getText( 6 ) );
    int valueLength = Const.toInt( item.getText( 7 ), -1 );
    int valuePrecision = Const.toInt( item.getText( 8 ), -1 );
    boolean removed = BaseMessages.getString( PKG, "System.Combo.Yes" ).equalsIgnoreCase( item.getText( 9 ) );
    String conversionMask = item.getText( 10 );
    String decimalSymbol = item.getText( 11 );
    String groupingSymbol = item.getText( 12 );
    String currencySymbol = item.getText( 13 );

    //CHECKSTYLE:Indentation:OFF
    currentMeta.getCalculation()[i] = new CalculatorMetaFunction(
      fieldName, calcType, fieldA, fieldB, fieldC, valueType, valueLength, valuePrecision, removed,
      conversionMask, decimalSymbol, groupingSymbol, currencySymbol );
  }

  if ( !originalMeta.equals( currentMeta ) ) {
    currentMeta.setChanged();
    changed = currentMeta.hasChanged();
  }

  dispose();
}
 
Example 16
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 17
Source File: GaInputStepMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {

  try {
    // Check for legacy fields (user/pass/API key), present an error if found
    String user = XMLHandler.getTagValue( stepnode, "user" );
    String pass = XMLHandler.getTagValue( stepnode, "pass" );
    String apiKey = XMLHandler.getTagValue( stepnode, "apiKey" );

    oauthServiceAccount = XMLHandler.getTagValue( stepnode, "oauthServiceAccount" );
    oauthKeyFile = XMLHandler.getTagValue( stepnode, "oauthKeyFile" );

    // Are we loading a legacy transformation?
    if ( ( user != null || pass != null || apiKey != null )
      && ( oauthServiceAccount == null && oauthKeyFile == null ) ) {
      logError( BaseMessages.getString( PKG, "GoogleAnalytics.Error.TransformationUpdateNeeded" ) );
    }
    gaAppName = XMLHandler.getTagValue( stepnode, "appName" );
    gaProfileName = XMLHandler.getTagValue( stepnode, "profileName" );
    gaProfileTableId = XMLHandler.getTagValue( stepnode, "profileTableId" );
    gaCustomTableId = XMLHandler.getTagValue( stepnode, "customTableId" );
    useCustomTableId = getBooleanAttributeFromNode( stepnode, "useCustomTableId" );
    startDate = XMLHandler.getTagValue( stepnode, "startDate" );
    endDate = XMLHandler.getTagValue( stepnode, "endDate" );
    dimensions = XMLHandler.getTagValue( stepnode, "dimensions" );
    metrics = XMLHandler.getTagValue( stepnode, "metrics" );
    filters = XMLHandler.getTagValue( stepnode, "filters" );
    sort = XMLHandler.getTagValue( stepnode, "sort" );
    useSegment =
      XMLHandler.getTagValue( stepnode, "useSegment" ) == null ? true : getBooleanAttributeFromNode(
        stepnode, "useSegment" ); // assume true for non-present
    useCustomSegment = getBooleanAttributeFromNode( stepnode, "useCustomSegment" );
    customSegment = XMLHandler.getTagValue( stepnode, "customSegment" );
    segmentId = XMLHandler.getTagValue( stepnode, "segmentId" );
    segmentName = XMLHandler.getTagValue( stepnode, "segmentName" );
    samplingLevel = XMLHandler.getTagValue( stepnode, "samplingLevel" );
    rowLimit = Const.toInt( XMLHandler.getTagValue( stepnode, "rowLimit" ), 0 );

    allocate( 0 );

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

    for ( int i = 0; i < nrFields; i++ ) {
      Node knode = XMLHandler.getSubNodeByNr( stepnode, "feedField", i );

      feedFieldType[ i ] = XMLHandler.getTagValue( knode, "feedFieldType" );
      feedField[ i ] = XMLHandler.getTagValue( knode, "feedField" );
      outputField[ i ] = XMLHandler.getTagValue( knode, "outField" );
      outputType[ i ] = ValueMetaFactory.getIdForValueMeta( XMLHandler.getTagValue( knode, "type" ) );
      conversionMask[ i ] = XMLHandler.getTagValue( knode, "conversionMask" );

      if ( outputType[ i ] < 0 ) {
        outputType[ i ] = ValueMetaInterface.TYPE_STRING;
      }

    }

  } catch ( Exception e ) {
    throw new KettleXMLException( BaseMessages.getString( PKG, "GoogleAnalytics.Error.UnableToReadFromXML" ), e );
  }

}
 
Example 18
Source File: BaseFileField.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Injection( name = "FIELD_TYPE", group = "FIELDS" )
public void setType( String value ) {
  this.type = ValueMetaFactory.getIdForValueMeta( value );
}
 
Example 19
Source File: KettleDatabaseRepositoryValueDelegate.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public ValueMetaAndData loadValueMetaAndData( ObjectId id_value ) throws KettleException {
  ValueMetaAndData valueMetaAndData = new ValueMetaAndData();
  try {
    RowMetaAndData r = getValue( id_value );
    if ( r != null ) {
      String name = r.getString( KettleDatabaseRepository.FIELD_VALUE_NAME, null );
      int valtype = ValueMetaFactory.getIdForValueMeta(
        r.getString( KettleDatabaseRepository.FIELD_VALUE_VALUE_TYPE, null ) );
      boolean isNull = r.getBoolean( KettleDatabaseRepository.FIELD_VALUE_IS_NULL, false );
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( name, valtype );
      valueMetaAndData.setValueMeta( v );

      if ( isNull ) {
        valueMetaAndData.setValueData( null );
      } else {
        ValueMetaInterface stringValueMeta = new ValueMetaString( name );
        ValueMetaInterface valueMeta = valueMetaAndData.getValueMeta();
        stringValueMeta.setConversionMetadata( valueMeta );

        valueMeta.setDecimalSymbol( ValueMetaAndData.VALUE_REPOSITORY_DECIMAL_SYMBOL );
        valueMeta.setGroupingSymbol( ValueMetaAndData.VALUE_REPOSITORY_GROUPING_SYMBOL );

        switch ( valueMeta.getType() ) {
          case ValueMetaInterface.TYPE_NUMBER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_NUMBER_CONVERSION_MASK );
            break;
          case ValueMetaInterface.TYPE_INTEGER:
            valueMeta.setConversionMask( ValueMetaAndData.VALUE_REPOSITORY_INTEGER_CONVERSION_MASK );
            break;
          default:
            break;
        }

        String string = r.getString( "VALUE_STR", null );
        valueMetaAndData.setValueData( stringValueMeta.convertDataUsingConversionMetaData( string ) );

        // OK, now comes the dirty part...
        // We want the defaults back on there...
        //
        valueMeta = ValueMetaFactory.createValueMeta( name, valueMeta.getType() );
      }
    }

    return valueMetaAndData;
  } catch ( KettleException dbe ) {
    throw new KettleException( "Unable to load Value from repository with id_value=" + id_value, dbe );
  }
}
 
Example 20
Source File: SelectMetadataChange.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Injection( name = "META_TYPE", group = "METAS" )
public void setType( String value ) {
  type = ValueMetaFactory.getIdForValueMeta( value );
}