Java Code Examples for org.pentaho.di.core.util.Utils

The following examples show how to use org.pentaho.di.core.util.Utils. These examples are extracted from open source projects. 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
@Override
public Collection<IExternalResourceInfo> getResourcesFromRow(
  GetXMLData textFileInput, RowMetaInterface rowMeta, Object[] row ) {
  Collection<IExternalResourceInfo> resources = new LinkedList<IExternalResourceInfo>();
  // For some reason the step doesn't return the StepMetaInterface directly, so go around it
  GetXMLDataMeta meta = (GetXMLDataMeta) textFileInput.getStepMetaInterface();
  if ( meta == null ) {
    meta = (GetXMLDataMeta) textFileInput.getStepMeta().getStepMetaInterface();
  }

  try {
    if ( meta.getIsAFile() ) {
      String filename = ( meta == null ) ? null : rowMeta.getString( row, meta.getXMLField(), null );
      if ( !Utils.isEmpty( filename ) ) {
        FileObject fileObject = KettleVFS.getFileObject( filename );
        resources.add( ExternalResourceInfoFactory.createFileResource( fileObject, true ) );
      }
    }
    // TODO URLs?
  } catch ( KettleException kve ) {
    // TODO throw exception or ignore?
  }

  return resources;
}
 
Example 2
Source Project: pentaho-kettle   Source File: ReplaceString.java    License: Apache License 2.0 6 votes vote down vote up
synchronized Object[] getOneRow( RowMetaInterface rowMeta, Object[] row ) throws KettleException {

    Object[] rowData = RowDataUtil.resizeArray( row, data.outputRowMeta.size() );
    int index = 0;
    Set<Integer> numFieldsAlreadyBeenTransformed = new HashSet<Integer>();
    for ( int i = 0; i < data.numFields; i++ ) {

      RowMetaInterface currentRowMeta =
          ( numFieldsAlreadyBeenTransformed.contains( data.inStreamNrs[i] ) ) ? data.outputRowMeta : getInputRowMeta();
      String value =
          replaceString( currentRowMeta.getString( rowData, data.inStreamNrs[i] ), data.patterns[i],
          getResolvedReplaceByString( i, row ) );

      if ( Utils.isEmpty( data.outStreamNrs[i] ) ) {
        // update field value
        rowData[data.inStreamNrs[i]] = value;
        numFieldsAlreadyBeenTransformed.add( data.inStreamNrs[i] );
      } else {
        // add new field value
        rowData[data.inputFieldsNr + index++] = value;
      }
    }
    return rowData;
  }
 
Example 3
/**
 * Read the slave servers in the repository and add them to this transformation if they are not yet present.
 *
 * @param jobMeta
 *          The job to put the slave servers in
 * @param overWriteShared
 *          if an object with the same name exists, overwrite
 * @throws KettleException
 */
public void readSlaves( JobMeta jobMeta, boolean overWriteShared ) throws KettleException {
  try {
    ObjectId[] dbids = repository.getSlaveIDs( false );
    for ( int i = 0; i < dbids.length; i++ ) {
      SlaveServer slaveServer = repository.loadSlaveServer( dbids[i], null ); // Load last version
      slaveServer.shareVariablesWith( jobMeta );

      SlaveServer check = jobMeta.findSlaveServer( slaveServer.getName() ); // Check if there already is one in the
                                                                            // transformation
      if ( check == null || overWriteShared ) {
        if ( !Utils.isEmpty( slaveServer.getName() ) ) {
          jobMeta.addOrReplaceSlaveServer( slaveServer );
          if ( !overWriteShared ) {
            slaveServer.setChanged( false );
          }
        }
      }
    }
  } catch ( KettleDatabaseException dbe ) {
    throw new KettleException( BaseMessages
      .getString( PKG, "JobMeta.Log.UnableToReadSlaveServersFromRepository" ), dbe );
  }
}
 
Example 4
Source Project: pentaho-kettle   Source File: TableExistsDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  input.setDatabase( transMeta.findDatabase( wConnection.getText() ) );
  input.setSchemaname( wSchemaname.getText() );
  input.setDynamicTablenameField( wTableName.getText() );
  input.setResultFieldName( wResult.getText() );

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

  if ( input.getDatabase() == null ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "TableExistsDialog.InvalidConnection.DialogMessage" ) );
    mb.setText( BaseMessages.getString( PKG, "TableExistsDialog.InvalidConnection.DialogTitle" ) );
    mb.open();
  }

  dispose();
}
 
Example 5
Source Project: pentaho-kettle   Source File: SymmetricCryptoTransMeta.java    License: Apache License 2.0 6 votes vote down vote up
public void getFields( RowMetaInterface rowMeta, String origin, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {

  if ( !Utils.isEmpty( getResultfieldname() ) ) {
    int type = ValueMetaInterface.TYPE_STRING;
    if ( isOutputResultAsBinary() ) {
      type = ValueMetaInterface.TYPE_BINARY;
    }
    try {
      ValueMetaInterface v = ValueMetaFactory.createValueMeta( getResultfieldname(), type );
      v.setOrigin( origin );
      rowMeta.addValueMeta( v );
    } catch ( Exception e ) {
      throw new KettleStepException( e );
    }
  }
}
 
Example 6
Source Project: pentaho-kettle   Source File: XMLOutputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. So
 * what this does is turn the name of the base path into an absolute path.
 * 
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 * 
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
    ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore )
  throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    if ( !Utils.isEmpty( fileName ) ) {
      FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName ), space );
      fileName = resourceNamingInterface.nameResource( fileObject, space, true );
    }

    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 7
Source Project: pentaho-kettle   Source File: BaseStreamStepMeta.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public List<ResourceReference> getResourceDependencies( TransMeta transMeta, StepMeta stepInfo ) {
  List<ResourceReference> references = new ArrayList<>( 5 );
  String realFilename = transMeta.environmentSubstitute( transformationPath );
  ResourceReference reference = new ResourceReference( stepInfo );
  references.add( reference );

  if ( !Utils.isEmpty( realFilename ) ) {
    // Add the filename to the references, including a reference to this step
    // meta data.
    //
    reference.getEntries().add( new ResourceEntry( realFilename, ResourceEntry.ResourceType.ACTIONFILE ) );
  }

  return references;
}
 
Example 8
Source Project: pentaho-kettle   Source File: TableInputDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void setFlags() {
  if ( !Utils.isEmpty( wDatefrom.getText() ) ) {
    // The foreach check box...
    wEachRow.setEnabled( true );
    wlEachRow.setEnabled( true );

    // The preview button...
    wPreview.setEnabled( false );
  } else {
    // The foreach check box...
    wEachRow.setEnabled( false );
    wEachRow.setSelection( false );
    wlEachRow.setEnabled( false );

    // The preview button...
    wPreview.setEnabled( true );
  }

}
 
Example 9
Source Project: pentaho-kettle   Source File: XBaseInputDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  try {
    stepname = wStepname.getText(); // return value
    getInfo( input );
  } catch ( KettleStepException e ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( e.toString() );
    mb.setText( BaseMessages.getString( PKG, "System.Warning" ) );
    mb.open();
  }
  dispose();
}
 
Example 10
Source Project: pentaho-kettle   Source File: KettleFileTableModel.java    License: Apache License 2.0 6 votes vote down vote up
public static String getLogging( ReportSubjectLocation filename ) throws KettleException {
  List<LogTableInterface> logTables;
  if ( filename.isTransformation() ) {
    TransMeta transMeta = TransformationInformation.getInstance().getTransMeta( filename );
    logTables = transMeta.getLogTables();
  } else {
    JobMeta jobMeta = JobInformation.getInstance().getJobMeta( filename );
    logTables = jobMeta.getLogTables();
  }
  String logging = "";
  for ( Iterator<LogTableInterface> iterator = logTables.iterator(); iterator.hasNext(); ) {
    LogTableInterface logTableInterface = iterator.next();
    if ( logTableInterface.getDatabaseMeta() != null && !Utils.isEmpty( logTableInterface.getTableName() ) ) {
      if ( logging.length() > 0 ) {
        logging += ", ";
      }
      logging += logTableInterface.getTableName() + "@" + logTableInterface.getDatabaseMeta().getName();
    }
  }
  return logging;
}
 
Example 11
Source Project: pentaho-kettle   Source File: JobEntryTransDialog.java    License: Apache License 2.0 6 votes vote down vote up
protected void ok() {
  if ( Utils.isEmpty( wName.getText() ) ) {
    final Dialog dialog = new SimpleMessageDialog( shell,
      BaseMessages.getString( PKG, "System.StepJobEntryNameMissing.Title" ),
      BaseMessages.getString( PKG, "System.JobEntryNameMissing.Msg" ), MessageDialog.ERROR );
    dialog.open();
    return;
  }
  // Check if all parameters have names. If so, continue on.
  if ( parameterTableHelper.checkParams( shell ) ) {
    return;
  }

  jobEntry.setName( wName.getText() );

  try {
    getInfo( jobEntry );
  } catch ( KettleException e ) {
    // suppress exceptions at this time - we will let the runtime report on any errors
  }
  jobEntry.setChanged();
  dispose();
}
 
Example 12
Source Project: pentaho-kettle   Source File: AccessInputMeta.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @param space
 *          the variable space to use
 * @param definitions
 * @param resourceNamingInterface
 * @param repository
 *          The repository to optionally load other resources from (to be converted to XML)
 * @param metaStore
 *          the metaStore in which non-kettle metadata could reside.
 *
 * @return the filename of the exported resource
 */
public String exportResources( VariableSpace space, Map<String, ResourceDefinition> definitions,
  ResourceNamingInterface resourceNamingInterface, Repository repository, IMetaStore metaStore ) throws KettleException {
  try {
    // The object that we're modifying here is a copy of the original!
    // So let's change the filename from relative to absolute by grabbing the file object...
    //
    // Replace the filename ONLY (folder or filename)
    //
    for ( int i = 0; i < fileName.length; i++ ) {
      FileObject fileObject = KettleVFS.getFileObject( space.environmentSubstitute( fileName[i] ), space );
      fileName[i] = resourceNamingInterface.nameResource( fileObject, space, Utils.isEmpty( fileMask[i] ) );
    }
    return null;
  } catch ( Exception e ) {
    throw new KettleException( e );
  }
}
 
Example 13
Source Project: pentaho-kettle   Source File: TransSupplier.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the appropriate trans.  Either 1)  A {@link TransWebSocketEngineAdapter} wrapping an Engine if an alternate
 * execution engine has been selected 2)  A legacy {@link Trans} otherwise.
 */
public Trans get() {
  if ( Utils.isEmpty( transMeta.getVariable( "engine" ) ) ) {
    log.logBasic( BaseMessages.getString( PKG, MSG_KETTLE_ENGINE ) );
    return fallbackSupplier.get();
  }

  Variables variables = new Variables();
  variables.initializeVariablesFrom( null );
  String protocol = transMeta.environmentSubstitute( transMeta.getVariable( "engine.scheme" ) );
  String url = transMeta.environmentSubstitute( transMeta.getVariable( "engine.url" ) );

  URI uri = URI.create( protocol + url );

  //default value for ssl for now false
  boolean ssl = "https".equalsIgnoreCase( protocol ) || "wss".equalsIgnoreCase( protocol );
  log.logBasic( BaseMessages.getString( PKG, MSG_SPARK_ENGINE, protocol, url ) );
  return new TransWebSocketEngineAdapter( transMeta, uri.getHost(), uri.getPort(), ssl );
}
 
Example 14
Source Project: pentaho-kettle   Source File: GetPreviousRowFieldMeta.java    License: Apache License 2.0 6 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 {

  // Add new field?
  for ( int i = 0; i < fieldOutStream.length; i++ ) {
    if ( !Utils.isEmpty( fieldOutStream[i] ) ) {
      int index = inputRowMeta.indexOfValue( fieldInStream[i] );
      if ( index >= 0 ) {
        ValueMetaInterface in = inputRowMeta.getValueMeta( index );
        try {
          ValueMetaInterface v =
            ValueMetaFactory.createValueMeta( space.environmentSubstitute( fieldOutStream[i] ), in.getType() );
          v.setName( space.environmentSubstitute( fieldOutStream[i] ) );
          v.setLength( in.getLength() );
          v.setPrecision( in.getPrecision() );
          v.setConversionMask( in.getConversionMask() );
          v.setOrigin( name );
          inputRowMeta.addValueMeta( v );
        } catch ( Exception e ) {
          throw new KettleStepException( e );
        }
      }
    }
  }
}
 
Example 15
Source Project: pentaho-kettle   Source File: SlaveServer.java    License: Apache License 2.0 6 votes vote down vote up
public String constructUrl( String serviceAndArguments ) throws UnsupportedEncodingException {
  String realHostname = null;
  String proxyHostname = null;
  lock.readLock().lock();
  try {
    realHostname = environmentSubstitute( hostname );
    proxyHostname = environmentSubstitute( getProxyHostname() );
  } finally {
    lock.readLock().unlock();
  }
  if ( !Utils.isEmpty( proxyHostname ) && realHostname.equals( "localhost" ) ) {
    realHostname = "127.0.0.1";
  }

  if ( !StringUtils.isBlank( webAppName ) ) {
    serviceAndArguments = "/" + environmentSubstitute( getWebAppName() ) + serviceAndArguments;
  }

  String result =
    ( isSslMode() ? HTTPS : HTTP ) + "://" + realHostname + getPortSpecification() + serviceAndArguments;
  result = Const.replace( result, " ", "%20" );
  return result;

}
 
Example 16
Source Project: pentaho-kettle   Source File: SimpleMappingMeta.java    License: 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 {
  String method = rep.getStepAttributeString( id_step, "specification_method" );
  specificationMethod = ObjectLocationSpecificationMethod.getSpecificationMethodByCode( method );
  String transId = rep.getStepAttributeString( id_step, "trans_object_id" );
  transObjectId = Utils.isEmpty( transId ) ? null : new StringObjectId( transId );
  transName = rep.getStepAttributeString( id_step, "trans_name" );
  fileName = rep.getStepAttributeString( id_step, "filename" );
  directoryPath = rep.getStepAttributeString( id_step, "directory_path" );

  // Backward compatibility check for object specification
  //
  checkObjectLocationSpecificationMethod();

  inputMapping = new MappingIODefinition( rep, id_step, "input_", 0 );
  outputMapping = new MappingIODefinition( rep, id_step, "output_", 0 );

  mappingParameters = new MappingParameters( rep, id_step );
}
 
Example 17
Source Project: pentaho-kettle   Source File: LucidDBBulkLoaderDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  // Get the information for the dialog into the input structure.
  getInfo( input );

  if ( input.getDatabaseMeta() == null ) {
    MessageBox mb = new MessageBox( shell, SWT.OK | SWT.ICON_ERROR );
    mb.setMessage( BaseMessages.getString( PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogMessage" ) );
    mb.setText( BaseMessages.getString( PKG, "LucidDBBulkLoaderDialog.InvalidConnection.DialogTitle" ) );
    mb.open();
  }

  dispose();
}
 
Example 18
Source Project: pentaho-kettle   Source File: JobEntryTransDialog.java    License: Apache License 2.0 6 votes vote down vote up
private void pickFileVFS() {
  String prevName = jobMeta.environmentSubstitute( wPath.getText() );
  if ( !Utils.isEmpty( prevName ) ) {
    try {
      if ( !KettleVFS.fileExists( prevName ) ) {
        if ( !prevName.endsWith( ".ktr" ) ) {
          prevName = getEntryName( Const.trim( wPath.getText() ) + ".ktr" );
        }
        if ( KettleVFS.fileExists( prevName ) ) {
          wPath.setText( prevName );
          specificationMethod = ObjectLocationSpecificationMethod.FILENAME;
          return;
        // File specified doesn't exist. Ask if we should create the file...
        } else if ( askToCreateNewTransformation( prevName ) ) {
          return;
        }
      }
    } catch ( Exception e ) {
      // do nothing
    }
  }
  selectTransformation( ProviderFilterType.LOCAL );
}
 
Example 19
Source Project: pentaho-kettle   Source File: PGBulkLoaderMeta.java    License: Apache License 2.0 5 votes vote down vote up
public RowMetaInterface getRequiredFields( VariableSpace space ) throws KettleException {
  String realTableName = space.environmentSubstitute( tableName );
  String realSchemaName = space.environmentSubstitute( schemaName );

  if ( databaseMeta != null ) {
    Database db = new Database( loggingObject, databaseMeta );
    try {
      db.connect();

      if ( !Utils.isEmpty( realTableName ) ) {
        String schemaTable = databaseMeta.getQuotedSchemaTableCombination( realSchemaName, realTableName );

        // Check if this table exists...
        if ( db.checkTableExists( schemaTable ) ) {
          return db.getTableFields( schemaTable );
        } else {
          throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotFound" ) );
        }
      } else {
        throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.TableNotSpecified" ) );
      }
    } catch ( Exception e ) {
      throw new KettleException(
        BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ErrorGettingFields" ), e );
    } finally {
      db.disconnect();
    }
  } else {
    throw new KettleException( BaseMessages.getString( PKG, "GPBulkLoaderMeta.Exception.ConnectionNotDefined" ) );
  }

}
 
Example 20
Source Project: pentaho-kettle   Source File: RepositoryExplorerDialog.java    License: Apache License 2.0 5 votes vote down vote up
public boolean renameJob( String name, RepositoryDirectoryInterface repdir, String newname ) {
  boolean retval = false;

  try {
    if ( Utils.isEmpty( newname ) ) {
      throw new KettleException( BaseMessages.getString(
        PKG, "RepositoryExplorerDialog.Exception.NameCanNotBeEmpty" ) );
    }
    if ( !name.equals( newname ) ) {
      ObjectId id = rep.getJobId( name, repdir );
      if ( id != null ) {
        // System.out.println("Renaming transformation ["+name+"] with ID = "+id);
        String comment = BaseMessages.getString( REPOSITORY_PKG, "Repository.Rename", name, newname );
        rep.renameJob( id, comment, repdir, newname );
        retval = true;
      } else {
        MessageBox mb = new MessageBox( shell, SWT.ICON_ERROR | SWT.OK );
        mb
          .setMessage( BaseMessages.getString(
            PKG, "RepositoryExplorerDialog.Job.Rename.ErrorFinding.Message1" )
            + name + "]" + Const.CR
            + BaseMessages.getString( PKG, "RepositoryExplorerDialog.Job.Rename.ErrorFinding.Message2" ) );
        mb.setText( BaseMessages.getString( PKG, "RepositoryExplorerDialog.Job.Rename.ErrorFinding.Title" ) );
        mb.open();
      }
    }
  } catch ( KettleException dbe ) {
    new ErrorDialog(
      shell,
      BaseMessages.getString( PKG, "RepositoryExplorerDialog.Job.Rename.UnexpectedError.Title" ), BaseMessages
        .getString( PKG, "RepositoryExplorerDialog.Job.Rename.UnexpectedError.Message" )
        + name + "]", dbe );
  }

  return retval;
}
 
Example 21
Source Project: pentaho-kettle   Source File: BaseLogTable.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return the connectionName
 */
public String getActualConnectionName() {
  String name = space.environmentSubstitute( connectionName );
  if ( Utils.isEmpty( name ) ) {
    name = space.getVariable( getConnectionNameVariable() );
  }
  if ( Utils.isEmpty( name ) ) {
    return null;
  } else {
    return name;
  }
}
 
Example 22
Source Project: pentaho-kettle   Source File: Translator2.java    License: Apache License 2.0 5 votes vote down vote up
private void applyChangedValue() {
  // Hang on, before we clear it all, did we have a previous value?
  //
  int todoIndex = wTodo.getSelectionIndex();

  if ( selectedKey != null
    && selectedLocale != null && selectedMessagesPackage != null && lastValueChanged
    && selectedSourceFolder != null ) {
    // Store the last modified value
    //
    if ( !Utils.isEmpty( lastValue ) ) {
      store.storeValue( selectedLocale, selectedSourceFolder, selectedMessagesPackage, selectedKey, lastValue );
      lastValueChanged = false;

      if ( !wAll.getSelection() ) {
        wTodo.remove( selectedKey );
        if ( wTodo.getSelectionIndex() < 0 ) {
          // Select the next one in the list...
          if ( todoIndex > wTodo.getItemCount() ) {
            todoIndex = wTodo.getItemCount() - 1;
          }

          if ( todoIndex >= 0 && todoIndex < wTodo.getItemCount() ) {
            wTodo.setSelection( todoIndex );
            showKeySelection( wTodo.getSelection()[0] );
          } else {
            refreshGrid();
          }
        }
      }
    }
    lastValue = null;
    wApply.setEnabled( false );
    wRevert.setEnabled( false );
  }
}
 
Example 23
Source Project: pentaho-kettle   Source File: XBaseInput.java    License: Apache License 2.0 5 votes vote down vote up
private void openNextFile() throws KettleException {
  // Close the last file before opening the next...
  if ( data.xbi != null ) {
    logBasic( BaseMessages.getString( PKG, "XBaseInput.Log.FinishedReadingRecords" ) );
    data.xbi.close();
  }

  // Replace possible environment variables...
  data.file_dbf = data.files.getFile( data.fileNr );
  data.fileNr++;

  try {
    data.xbi = new XBase( log, KettleVFS.getInputStream( data.file_dbf ) );
    data.xbi.setDbfFile( data.file_dbf.getName().getURI() );
    data.xbi.open();
    if ( !Utils.isEmpty( meta.getCharactersetName() ) ) {
      data.xbi.getReader().setCharactersetName( meta.getCharactersetName() );
    }

    logBasic( BaseMessages.getString( PKG, "XBaseInput.Log.OpenedXBaseFile" ) + " : [" + data.xbi + "]" );
    data.fields = data.xbi.getFields();

    // Add this to the result file names...
    ResultFile resultFile =
      new ResultFile( ResultFile.FILE_TYPE_GENERAL, data.file_dbf, getTransMeta().getName(), getStepname() );
    resultFile.setComment( BaseMessages.getString( PKG, "XBaseInput.ResultFile.Comment" ) );
    addResultFile( resultFile );
  } catch ( Exception e ) {
    logError( BaseMessages.getString( PKG, "XBaseInput.Log.Error.CouldNotOpenXBaseFile1" )
      + data.file_dbf + BaseMessages.getString( PKG, "XBaseInput.Log.Error.CouldNotOpenXBaseFile2" )
      + e.getMessage() );
    throw new KettleException( e );
  }
}
 
Example 24
Source Project: pentaho-kettle   Source File: JobEntryDelayTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testGetRealMaximumTimeout() {
  JobEntryDelay entry = new JobEntryDelay();
  assertTrue( Utils.isEmpty( entry.getRealMaximumTimeout() ) );

  entry.setMaximumTimeout( " 1" );
  assertEquals( "1", entry.getRealMaximumTimeout() );

  entry.setVariable( "testValue", " 20" );
  entry.setMaximumTimeout( "${testValue}" );
  assertEquals( "20", entry.getRealMaximumTimeout() );
}
 
Example 25
Source Project: pentaho-kettle   Source File: FileExists.java    License: Apache License 2.0 5 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (FileExistsMeta) smi;
  data = (FileExistsData) sdi;

  if ( super.init( smi, sdi ) ) {
    if ( Utils.isEmpty( meta.getResultFieldName() ) ) {
      logError( BaseMessages.getString( PKG, "FileExists.Error.ResultFieldMissing" ) );
      return false;
    }
    return true;
  }
  return false;
}
 
Example 26
Source Project: pentaho-kettle   Source File: DetectLastRow.java    License: Apache License 2.0 5 votes vote down vote up
public boolean init( StepMetaInterface smi, StepDataInterface sdi ) {
  meta = (DetectLastRowMeta) smi;
  data = (DetectLastRowData) sdi;

  if ( super.init( smi, sdi ) ) {
    if ( Utils.isEmpty( meta.getResultFieldName() ) ) {
      logError( BaseMessages.getString( PKG, "DetectLastRow.Error.ResultFieldMissing" ) );
      return false;
    }

    return true;
  }
  return false;
}
 
Example 27
Source Project: pentaho-kettle   Source File: ScriptValuesMetaMod.java    License: 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 28
Source Project: pentaho-kettle   Source File: MySQLBulkLoaderMeta.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * If we use injection we can have different arrays lengths.
 * We need synchronize them for consistency behavior with UI
 */
@AfterInjection
public void afterInjectionSynchronization() {
  int nrFields = ( fieldTable == null ) ? -1 : fieldTable.length;
  if ( nrFields <= 0 ) {
    return;
  }
  String[][] rtnStrings = Utils.normalizeArrays( nrFields, fieldStream );
  fieldStream = rtnStrings[ 0 ];

  int[][] rtnInts = Utils.normalizeArrays( nrFields, fieldFormatType );
  fieldFormatType = rtnInts[ 0 ];
}
 
Example 29
Source Project: pentaho-kettle   Source File: SapInputMeta.java    License: Apache License 2.0 5 votes vote down vote up
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
  try {
    rep.saveDatabaseMetaStepAttribute( id_transformation, id_step, "id_connection", databaseMeta );
    if ( function != null && !Utils.isEmpty( function.getName() ) ) {
      rep.saveStepAttribute( id_transformation, id_step, "function_name", function.getName() );
      rep.saveStepAttribute( id_transformation, id_step, "function_description", function.getDescription() );
      rep.saveStepAttribute( id_transformation, id_step, "function_group", function.getGroup() );
      rep.saveStepAttribute( id_transformation, id_step, "function_application", function.getApplication() );
      rep.saveStepAttribute( id_transformation, id_step, "function_host", function.getHost() );
    }

    for ( int i = 0; i < parameters.size(); i++ ) {
      SapParameter parameter = parameters.get( i );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_field_name", parameter.getFieldName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_sap_type", parameter.getSapType() == null
        ? null : parameter.getSapType().getCode() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_table_name", parameter.getTableName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_name", parameter.getParameterName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "parameter_target_type", ValueMeta
        .getTypeDesc( parameter.getTargetType() ) );
    }

    for ( int i = 0; i < outputFields.size(); i++ ) {
      SapOutputField field = outputFields.get( i );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_sap_field_name", field.getSapFieldName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_sap_type", field.getSapType() == null
        ? null : field.getSapType().getCode() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_table_name", field.getTableName() );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_target_type", ValueMeta.getTypeDesc( field
        .getTargetType() ) );
      rep.saveStepAttribute( id_transformation, id_step, i, "field_new_name", field.getNewName() );
    }
  } catch ( Exception e ) {
    throw new KettleException( "Unable to save step information to the repository for id_step=" + id_step, e );
  }
}
 
Example 30
Source Project: pentaho-kettle   Source File: JobEntryTableExistsDialog.java    License: 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() );
  jobEntry.setDatabase( jobMeta.findDatabase( wConnection.getText() ) );
  jobEntry.setTablename( wTablename.getText() );
  jobEntry.setSchemaname( wSchemaname.getText() );

  dispose();
}