org.pentaho.di.core.row.value.ValueMetaBase Java Examples

The following examples show how to use org.pentaho.di.core.row.value.ValueMetaBase. 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: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogMessageInDetailedModeFotWriteToSalesForce() throws KettleException {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta = generateSalesforceInsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );
  when( sfInputStep.getLogChannel().isDetailed() ).thenReturn( true );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  verify( sfInputStep.getLogChannel(), never() ).logDetailed( anyString() );
  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  verify( sfInputStep.getLogChannel() ).logDetailed( "Called writeToSalesForce with 0 out of 2" );
}
 
Example #2
Source File: ParquetConverter.java    From pentaho-hadoop-shims with Apache License 2.0 6 votes vote down vote up
private Object convertFromSourceToTargetType( IValueMetaConverter valueMetaConverter, Object stagingValue,
                                              IParquetInputField f ) {
  try {
    String dateFormatStr = f.getStringFormat();
    if ( ( dateFormatStr == null ) || ( dateFormatStr.trim().length() == 0 ) ) {
      dateFormatStr = ValueMetaBase.DEFAULT_DATE_FORMAT_MASK;
    }
    valueMetaConverter.setDatePattern( new SimpleDateFormat( dateFormatStr ) );

    return valueMetaConverter.convertFromSourceToTargetDataType(
      f.getParquetType().getPdiType(), f.getPentahoType(), stagingValue );
  } catch ( ValueMetaConversionException e ) {
    logger.error( e );
    return null;
  }
}
 
Example #3
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public String encodeAttributeValue( Object object ) throws Exception {
  if ( object == null ) {
    return "";
  }
  if ( object instanceof String ) {
    return "S:" + object.toString();
  }
  if ( object instanceof Timestamp ) {
    return "T:" + new SimpleTimestampFormat(
      ValueMetaBase.DEFAULT_TIMESTAMP_FORMAT_MASK ).format( (Timestamp) object );
  }
  if ( object instanceof Date ) {
    return "D:" + new SimpleDateFormat( ValueMetaBase.DEFAULT_DATE_FORMAT_MASK ).format( (Date) object );
  }
  if ( object instanceof Double ) {
    return "N:" + Double.toString( (Double) object );
  }
  if ( object instanceof Long ) {
    return "I:" + Long.toString( (Long) object );
  }
  if ( object instanceof Boolean ) {
    return "B:" + ( ( (Boolean) object ) ? "true" : "false" );
  }

  throw new KettleException( "Can't encode object of class : " + object.getClass().getName() );
}
 
Example #4
Source File: SwitchCaseMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
  try {
    fieldname = rep.getStepAttributeString( id_step, "fieldname" );
    isContains = rep.getStepAttributeBoolean( id_step, "use_contains" );
    caseValueType = ValueMetaBase.getType( rep.getStepAttributeString( id_step, "case_value_type" ) );
    caseValueFormat = rep.getStepAttributeString( id_step, "case_value_format" );
    caseValueDecimal = rep.getStepAttributeString( id_step, "case_value_decimal" );
    caseValueGroup = rep.getStepAttributeString( id_step, "case_value_group" );

    defaultTargetStepname = rep.getStepAttributeString( id_step, "default_target_step" );

    int nrCases = rep.countNrStepAttributes( id_step, "case_value" );
    allocate();
    for ( int i = 0; i < nrCases; i++ ) {
      SwitchCaseTarget target = new SwitchCaseTarget();
      target.caseValue = rep.getStepAttributeString( id_step, i, "case_value" );
      target.caseTargetStepname = rep.getStepAttributeString( id_step, i, "case_target_step" );
      caseTargets.add( target );
    }
  } catch ( Exception e ) {
    throw new KettleException( BaseMessages.getString(
      PKG, "SwitchCaseMeta.Exception.UnexpectedErrorInReadingStepInfoFromRepository" ), e );
  }
}
 
Example #5
Source File: StringEvaluatorIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void recognisesNumeric_WhenParenthesesMeanNegative_Integer() throws Exception {
  String[] samples = { "1,234,567,890", "(1,234,567,890)" };

  final Locale environmentLocale = Locale.getDefault();
  try {
    Locale.setDefault( Locale.US );

    StringEvaluationResult numericResult = doEvaluation( new StringEvaluator(), samples );
    ValueMetaInterface meta = numericResult.getConversionMeta();
    assertTrue( Integer.toString( meta.getType() ), ValueMetaBase.isNumeric( meta.getType() ) );
    assertEquals( "#,##0.00;(#,##0.00)", meta.getConversionMask() );
  } finally {
    Locale.setDefault( environmentLocale );
  }
}
 
Example #6
Source File: KettleDatabaseRepositoryMetaStoreDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * supported types:
 * <p/>
 * <pre>
 * S : String (java.lang.String)
 * D : Date (java.util.Date)
 * N : Number (Double)
 * I : Integer (Long)
 * B : Boolean (Boolean)
 *
 * Examples
 * S:Pentaho Data Integration
 * D:2013/08/23 17:25:00
 * N:1039348.9347
 * I:12345678
 * B:true
 * </pre>
 *
 * @param value
 * @return The native value
 * @throws Exception in case of conversion trouble
 */
public Object parseAttributeValue( String value ) throws Exception {
  if ( Utils.isEmpty( value ) || value.length() < 3 ) {
    return null;
  }
  String valueString = value.substring( 2 );
  char type = value.charAt( 0 );
  switch ( type ) {
    case 'S':
      return valueString;
    case 'T':
      return new SimpleTimestampFormat( ValueMetaBase.DEFAULT_TIMESTAMP_FORMAT_MASK ).parse( valueString );
    case 'D':
      return new SimpleDateFormat( ValueMetaBase.DEFAULT_DATE_FORMAT_MASK ).parse( valueString );
    case 'N':
      return Double.valueOf( valueString );
    case 'I':
      return Long.valueOf( valueString );
    case 'B':
      return "true".equalsIgnoreCase( valueString ) || "y".equalsIgnoreCase( valueString );
    default:
      throw new KettleException( "Unknown data type : " + type );
  }
}
 
Example #7
Source File: SwitchCaseMeta.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private void readData( Node stepnode ) throws KettleXMLException {
  try {
    fieldname = XMLHandler.getTagValue( stepnode, "fieldname" );
    isContains = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "use_contains" ) );
    caseValueType = ValueMetaBase.getType( XMLHandler.getTagValue( stepnode, "case_value_type" ) );
    caseValueFormat = XMLHandler.getTagValue( stepnode, "case_value_format" );
    caseValueDecimal = XMLHandler.getTagValue( stepnode, "case_value_decimal" );
    caseValueGroup = XMLHandler.getTagValue( stepnode, "case_value_group" );

    defaultTargetStepname = XMLHandler.getTagValue( stepnode, "default_target_step" );

    Node casesNode = XMLHandler.getSubNode( stepnode, XML_TAG_CASE_VALUES );
    int nrCases = XMLHandler.countNodes( casesNode, XML_TAG_CASE_VALUE );
    allocate();
    for ( int i = 0; i < nrCases; i++ ) {
      Node caseNode = XMLHandler.getSubNodeByNr( casesNode, XML_TAG_CASE_VALUE, i );
      SwitchCaseTarget target = new SwitchCaseTarget();
      target.caseValue = XMLHandler.getTagValue( caseNode, "value" );
      target.caseTargetStepname = XMLHandler.getTagValue( caseNode, "target_step" );
      caseTargets.add( target );
    }
  } catch ( Exception e ) {
    throw new KettleXMLException( BaseMessages.getString(
      PKG, "SwitchCaseMeta.Exception..UnableToLoadStepInfoFromXML" ), e );
  }
}
 
Example #8
Source File: StringEvaluatorIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void recognisesNumeric_WhenParenthesesMeanNegative_Double() throws Exception {
  String[] samples = { "1,234,567,890.12", "(1,234,567,890.12)" };

  final Locale environmentLocale = Locale.getDefault();
  try {
    Locale.setDefault( Locale.US );

    StringEvaluationResult numericResult = doEvaluation( new StringEvaluator(), samples );
    ValueMetaInterface meta = numericResult.getConversionMeta();
    assertTrue( Integer.toString( meta.getType() ), ValueMetaBase.isNumeric( meta.getType() ) );
    assertEquals( "#,##0.00;(#,##0.00)", meta.getConversionMask() );
  } finally {
    Locale.setDefault( environmentLocale );
  }
}
 
Example #9
Source File: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForcePentahoIntegerValue() throws Exception {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta =
    generateSalesforceInsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaInteger( "IntValue" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { 1L } );
  XmlObject sObject = data.sfBuffer[ 0 ].getChild( ACCOUNT_ID );
  Assert.assertEquals( sObject.getValue(), 1 );
}
 
Example #10
Source File: JobEntryLogTable.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public List<RowMetaInterface> getRecommendedIndexes() {
  List<RowMetaInterface> indexes = new ArrayList<RowMetaInterface>();
  LogTableField keyField = getKeyField();

  if ( keyField.isEnabled() ) {
    RowMetaInterface batchIndex = new RowMeta();

    ValueMetaInterface keyMeta = new ValueMetaBase( keyField.getFieldName(), keyField.getDataType() );
    keyMeta.setLength( keyField.getLength() );
    batchIndex.addValueMeta( keyMeta );

    indexes.add( batchIndex );
  }

  return indexes;
}
 
Example #11
Source File: RssInputMetaTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Override
public RssInputField getTestObject() {
  RssInputField rtn = new RssInputField();
  rtn.setCurrencySymbol( UUID.randomUUID().toString() );
  rtn.setDecimalSymbol( UUID.randomUUID().toString() );
  rtn.setFormat( UUID.randomUUID().toString() );
  rtn.setGroupSymbol( UUID.randomUUID().toString() );
  rtn.setName( UUID.randomUUID().toString() );
  rtn.setTrimType( rand.nextInt( ValueMetaBase.trimTypeCode.length ) );
  rtn.setPrecision( rand.nextInt( 9 ) );
  rtn.setRepeated( rand.nextBoolean() );
  rtn.setLength( rand.nextInt( 50 ) );
  rtn.setType( rand.nextInt( ValueMetaBase.typeCodes.length ) );
  rtn.setColumn( rand.nextInt( RssInputField.ColumnCode.length ) );
  return rtn;
}
 
Example #12
Source File: SwitchCaseDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
  wFieldName.setText( Const.NVL( input.getFieldname(), "" ) );
  wContains.setSelection( input.isContains() );
  wDataType.setText( ValueMetaBase.getTypeDesc( input.getCaseValueType() ) );
  wDecimalSymbol.setText( Const.NVL( input.getCaseValueDecimal(), "" ) );
  wGroupingSymbol.setText( Const.NVL( input.getCaseValueGroup(), "" ) );
  wConversionMask.setText( Const.NVL( input.getCaseValueFormat(), "" ) );

  for ( int i = 0; i < input.getCaseTargets().size(); i++ ) {
    TableItem item = wValues.table.getItem( i );
    SwitchCaseTarget target = input.getCaseTargets().get( i );
    if ( target != null ) {
      item.setText( 1, Const.NVL( target.caseValue, "" ) ); // The value
      item.setText( 2, target.caseTargetStep == null ? "" : target.caseTargetStep.getName() ); // The target step name
    }
  }
  wValues.removeEmptyRows();
  wValues.setRowNums();
  wValues.optWidth( true );

  wDefaultTarget.setText( input.getDefaultTargetStep() == null ? "" : input.getDefaultTargetStep().getName() );

  wStepname.selectAll();
  wStepname.setFocus();
}
 
Example #13
Source File: RestorePDIEnvironment.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
void defaultInit() throws Throwable {
  // make sure static class initializers are correctly initialized
  // re-init
  cleanUp();
  KettleClientEnvironment.init();

  // initialize some classes, this will fail if some tests init this classes before any PDI init()
  // the best thing to do is to invoke this ClassRule in every test
  Class.forName( Database.class.getName() );
  Class.forName( Timestamp.class.getName() );
  Class.forName( ValueMetaBase.class.getName() );
  Class.forName( SimpleTimestampFormat.class.getName() );
  Class.forName( SimpleDateFormat.class.getName() );
  Class.forName( XMLHandler.class.getName() );
  Class.forName( LogChannel.class.getName() );
  DatabaseMeta.init();
  ExtensionPointMap.getInstance().reInitialize();
  KettleVFS.getInstance().reset(); // reinit
}
 
Example #14
Source File: SalesforceUpdateTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceUpdate sfInputStep =
    new SalesforceUpdate( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpdateMeta meta = generateSalesforceUpdateMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpdateData data = generateSalesforceUpdateData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #15
Source File: SalesforceUpdateTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceUpdate sfInputStep =
    new SalesforceUpdate( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpdateMeta meta =
    generateSalesforceUpdateMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceUpdateData data = generateSalesforceUpdateData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #16
Source File: SalesforceUpdateTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceUpdate sfInputStep =
    new SalesforceUpdate( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpdateMeta meta = generateSalesforceUpdateMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpdateData data = generateSalesforceUpdateData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( ACCOUNT_ID, SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertEquals( "001i000001c5Nv9AAE", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertFalse( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].hasChildren() );
}
 
Example #17
Source File: SalesforceUpdateTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceUpdate sfInputStep =
    new SalesforceUpdate( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpdateMeta meta =
    generateSalesforceUpdateMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceUpdateData data = generateSalesforceUpdateData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { "tkas88" } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( "Account", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertFalse( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].hasChildren() );
}
 
Example #18
Source File: SalesforceUpdateTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogMessageInDetailedModeFotWriteToSalesForce() throws KettleException {
  SalesforceUpdate sfInputStep =
    new SalesforceUpdate( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpdateMeta meta = generateSalesforceUpdateMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpdateData data = generateSalesforceUpdateData();
  sfInputStep.init( meta, data );
  when( sfInputStep.getLogChannel().isDetailed() ).thenReturn( true );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  verify( sfInputStep.getLogChannel(), never() ).logDetailed( anyString() );
  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  verify( sfInputStep.getLogChannel() ).logDetailed( "Called writeToSalesForce with 0 out of 2" );
}
 
Example #19
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceUpsert sfInputStep =
      new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta = generateSalesforceUpsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #20
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceUpsert sfInputStep =
      new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta =
      generateSalesforceUpsertMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #21
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceUpsert sfInputStep =
      new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta = generateSalesforceUpsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( ACCOUNT_ID, SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertEquals( "001i000001c5Nv9AAE", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertFalse( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].hasChildren() );
}
 
Example #22
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceUpsert sfInputStep =
      new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta =
      generateSalesforceUpsertMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  String extIdValue = "tkas88";
  sfInputStep.writeToSalesForce( new Object[] { extIdValue } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( "Account", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertEquals( extIdValue, SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getChild( EXT_ID_ACCOUNT_ID_C ).getValue() );
}
 
Example #23
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testLogMessageInDetailedModeFotWriteToSalesForce() throws KettleException {
  SalesforceUpsert sfInputStep =
      new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta = generateSalesforceUpsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );
  when( sfInputStep.getLogChannel().isDetailed() ).thenReturn( true );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  verify( sfInputStep.getLogChannel(), never() ).logDetailed( anyString() );
  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  verify( sfInputStep.getLogChannel() ).logDetailed( "Called writeToSalesForce with 0 out of 2" );
}
 
Example #24
Source File: SalesforceUpsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForcePentahoIntegerValue() throws Exception {
  SalesforceUpsert sfInputStep =
    new SalesforceUpsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceUpsertMeta meta =
    generateSalesforceUpsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceUpsertData data = generateSalesforceUpsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaInteger( "IntValue" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { 1L } );
  XmlObject sObject = data.sfBuffer[ 0 ].getChild( ACCOUNT_ID );
  Assert.assertEquals( sObject.getValue(), 1 );
}
 
Example #25
Source File: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta = generateSalesforceInsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #26
Source File: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta =
    generateSalesforceInsertMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { null } );
  assertEquals( 1, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( ACCOUNT_ID, data.sfBuffer[0].getFieldsToNull()[0] );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] ) );
}
 
Example #27
Source File: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdNO() throws Exception {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta = generateSalesforceInsertMeta( new String[] { ACCOUNT_ID }, new Boolean[] { false } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccNoExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { "001i000001c5Nv9AAE" } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( ACCOUNT_ID, SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertEquals( "001i000001c5Nv9AAE", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertFalse( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].hasChildren() );
}
 
Example #28
Source File: SalesforceInsertTest.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@Test
public void testWriteToSalesForceForNotNullExtIdField_WithExtIdYES() throws Exception {
  SalesforceInsert sfInputStep =
    new SalesforceInsert( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans );
  SalesforceInsertMeta meta =
    generateSalesforceInsertMeta( new String[] { ACCOUNT_EXT_ID_ACCOUNT_ID_C_ACCOUNT }, new Boolean[] { true } );
  SalesforceInsertData data = generateSalesforceInsertData();
  sfInputStep.init( meta, data );

  RowMeta rowMeta = new RowMeta();
  ValueMetaBase valueMeta = new ValueMetaString( "AccExtId" );
  rowMeta.addValueMeta( valueMeta );
  smh.initStepDataInterface.inputRowMeta = rowMeta;

  sfInputStep.writeToSalesForce( new Object[] { "tkas88" } );
  assertEquals( 0, data.sfBuffer[0].getFieldsToNull().length );
  assertEquals( 1, SalesforceConnection.getChildren( data.sfBuffer[0] ).length );
  assertEquals( Constants.PARTNER_SOBJECT_NS,
    SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getNamespaceURI() );
  assertEquals( "Account", SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getName().getLocalPart() );
  assertNull( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].getValue() );
  assertFalse( SalesforceConnection.getChildren( data.sfBuffer[0] )[0].hasChildren() );
}
 
Example #29
Source File: StepFieldsDialog.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Copy information from the meta-data input to the dialog fields.
 */
public void getData() {
  int i;

  for ( i = 0; i < input.size(); i++ ) {
    TableItem item = wFields.table.getItem( i );
    ValueMetaInterface v = input.getValueMeta( i );
    int idx = 1;
    if ( v.getName() != null ) {
      item.setText( idx++, v.getName() );
    }
    item.setText( idx++, v.getTypeDesc() );
    item.setText( idx++, v.getLength() < 0 ? "-" : "" + v.getLength() );
    item.setText( idx++, v.getPrecision() < 0 ? "-" : "" + v.getPrecision() );
    item.setText( idx++, Const.NVL( v.getOrigin(), "" ) );
    item.setText( idx++, ValueMetaBase.getStorageTypeCode( v.getStorageType() ) );
    item.setText( idx++, Const.NVL( v.getConversionMask(), "" ) );
    item.setText( idx++, Const.NVL( v.getCurrencySymbol(), "" ) );
    item.setText( idx++, Const.NVL( v.getDecimalSymbol(), "" ) );
    item.setText( idx++, Const.NVL( v.getGroupingSymbol(), "" ) );
    item.setText( idx++, ValueMetaBase.getTrimTypeDesc( v.getTrimType() ) );
    item.setText( idx++, Const.NVL( v.getComments(), "" ) );

  }
  wFields.optWidth( true );
}
 
Example #30
Source File: WidgetUtils.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * creates a ComboVar populated with fields from the previous step.
 * @param parentComposite - the composite in which the widget will be placed
 * @param props - PropsUI props for L&F
 * @param stepMeta - stepMeta of the current step
 * @param formData - FormData to use for placement
 */
public static ComboVar createFieldDropDown(
  Composite parentComposite, PropsUI props, BaseStepMeta stepMeta, FormData formData ) {
  TransMeta transMeta = stepMeta.getParentStepMeta().getParentTransMeta();
  ComboVar fieldDropDownCombo = new ComboVar( transMeta, parentComposite, SWT.SINGLE | SWT.LEFT | SWT.BORDER );
  props.setLook( fieldDropDownCombo );
  fieldDropDownCombo.addModifyListener( e -> stepMeta.setChanged() );

  fieldDropDownCombo.setLayoutData( formData );
  Listener focusListener = e -> {
    String current = fieldDropDownCombo.getText();
    fieldDropDownCombo.getCComboWidget().removeAll();
    fieldDropDownCombo.setText( current );

    try {
      RowMetaInterface rmi = transMeta.getPrevStepFields( stepMeta.getParentStepMeta().getName() );
      List ls = rmi.getValueMetaList();
      for ( Object l : ls ) {
        ValueMetaBase vmb = (ValueMetaBase) l;
        fieldDropDownCombo.add( vmb.getName() );
      }
    } catch ( KettleStepException ex ) {
      // can be ignored, since previous step may not be set yet.
      stepMeta.logDebug( ex.getMessage(), ex );
    }
  };
  fieldDropDownCombo.getCComboWidget().addListener( SWT.FocusIn, focusListener );
  return fieldDropDownCombo;
}