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

The following examples show how to use org.pentaho.di.core.util.Utils. 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: JobEntryTransDialog.java    From pentaho-kettle with 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 #2
Source File: XBaseInputDialog.java    From pentaho-kettle with 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 #3
Source File: KettleFileTableModel.java    From pentaho-kettle with 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 #4
Source File: TableInputDialog.java    From pentaho-kettle with 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 #5
Source File: SymmetricCryptoTransMeta.java    From pentaho-kettle with 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 File: SlaveServer.java    From pentaho-kettle with 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 #7
Source File: JobEntryTransDialog.java    From pentaho-kettle with 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 #8
Source File: AccessInputMeta.java    From pentaho-kettle with 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 #9
Source File: XMLOutputMeta.java    From pentaho-kettle with 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 #10
Source File: TableExistsDialog.java    From pentaho-kettle with 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 #11
Source File: KettleDatabaseRepositoryJobDelegate.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * 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 #12
Source File: ReplaceString.java    From pentaho-kettle with 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 #13
Source File: GetPreviousRowFieldMeta.java    From pentaho-kettle with 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 #14
Source File: GetXMLDataExternalResourceConsumer.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
@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 #15
Source File: TransSupplier.java    From pentaho-kettle with 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 #16
Source File: LucidDBBulkLoaderDialog.java    From pentaho-kettle with 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 #17
Source File: BaseStreamStepMeta.java    From pentaho-kettle with 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 #18
Source File: SimpleMappingMeta.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 {
  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 #19
Source File: HypersonicDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public String getURL( String hostname, String port, String databaseName ) {
  if ( getAccessType() == DatabaseMeta.TYPE_ACCESS_ODBC ) {
    return "jdbc:odbc:" + databaseName;
  } else {
    if ( ( Utils.isEmpty( port ) || "-1".equals( port ) ) && Utils.isEmpty( hostname ) ) {
      // When no port is specified, or port is 0 support local/memory
      // HSQLDB databases.
      return "jdbc:hsqldb:" + databaseName;
    } else {
      return "jdbc:hsqldb:hsql://" + hostname + ":" + port + "/" + databaseName;
    }
  }
}
 
Example #20
Source File: LDAPOutputDialog.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();
  try {
    getInfo( input );
  } catch ( KettleException e ) {
    new ErrorDialog(
      shell, BaseMessages.getString( PKG, "LDAPOutputDialog.ErrorParsingData.DialogTitle" ), BaseMessages
        .getString( PKG, "LDAPOutputDialog.ErrorParsingData.DialogMessage" ), e );
  }
  dispose();
}
 
Example #21
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 #22
Source File: SalesforceUpsertMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
  VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
  String realfieldname = space.environmentSubstitute( getSalesforceIDFieldName() );
  if ( !Utils.isEmpty( realfieldname ) ) {
    ValueMetaInterface v = new ValueMetaString( realfieldname );
    v.setLength( 18 );
    v.setOrigin( name );
    r.addValueMeta( v );
  }
}
 
Example #23
Source File: SQLFileOutputMeta.java    From pentaho-kettle with 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 ) ) {
        // Check if this table exists...
        if ( db.checkTableExists( realSchemaName, realTableName ) ) {
          return db.getTableFieldsMeta( realSchemaName, realTableName );
        } else {
          throw new KettleException( BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.TableNotFound" ) );
        }
      } else {
        throw new KettleException( BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.TableNotSpecified" ) );
      }
    } catch ( Exception e ) {
      throw new KettleException(
        BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.ErrorGettingFields" ), e );
    } finally {
      db.disconnect();
    }
  } else {
    throw new KettleException( BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.ConnectionNotDefined" ) );
  }
}
 
Example #24
Source File: ParGzipCsvInputDialog.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void ok() {
  if ( Utils.isEmpty( wStepname.getText() ) ) {
    return;
  }

  getInfo( inputMeta );
  stepname = wStepname.getText();
  dispose();
}
 
Example #25
Source File: SQLFileOutputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public SQLStatement getSQLStatements( TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev,
  Repository repository, IMetaStore metaStore ) {
  SQLStatement retval = new SQLStatement( stepMeta.getName(), databaseMeta, null ); // default: nothing to do!

  if ( databaseMeta != null ) {
    if ( prev != null && prev.size() > 0 ) {
      if ( !Utils.isEmpty( tablename ) ) {
        Database db = new Database( loggingObject, databaseMeta );
        db.shareVariablesWith( transMeta );
        try {
          db.connect();

          String schemaTable = databaseMeta.getQuotedSchemaTableCombination( schemaName, tablename );
          String cr_table = db.getDDL( schemaTable, prev );

          // Empty string means: nothing to do: set it to null...
          if ( cr_table == null || cr_table.length() == 0 ) {
            cr_table = null;
          }

          retval.setSQL( cr_table );
        } catch ( KettleDatabaseException dbe ) {
          retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.ErrorConnecting", dbe
            .getMessage() ) );
        } finally {
          db.disconnect();
        }
      } else {
        retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Exception.TableNotSpecified" ) );
      }
    } else {
      retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.NoInput" ) );
    }
  } else {
    retval.setError( BaseMessages.getString( PKG, "SQLFileOutputMeta.Error.NoConnection" ) );
  }

  return retval;
}
 
Example #26
Source File: JobEntryTelnet.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public List<ResourceReference> getResourceDependencies( JobMeta jobMeta ) {
  List<ResourceReference> references = super.getResourceDependencies( jobMeta );
  if ( !Utils.isEmpty( hostname ) ) {
    String realServername = jobMeta.environmentSubstitute( hostname );
    ResourceReference reference = new ResourceReference( this );
    reference.getEntries().add( new ResourceEntry( realServername, ResourceType.SERVER ) );
    references.add( reference );
  }
  return references;
}
 
Example #27
Source File: RowsToResultDialog.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

  dispose();
}
 
Example #28
Source File: KettleDatabaseRepositoryConnectionDelegate.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public String[] getStrings( String sql, ObjectId... objectId ) throws KettleException {
  // Get the prepared statement
  //
  PreparedStatement ps = getPreparedStatement( sql );

  // Assemble the parameters (if any)
  //
  // Assemble the parameters (if any)
  //
  RowMetaInterface parameterMeta = new RowMeta();
  Object[] parameterData = new Object[ objectId.length ];
  for ( int i = 0; i < objectId.length; i++ ) {
    parameterMeta.addValueMeta( new ValueMetaInteger( "id" + ( i + 1 ) ) );
    parameterData[ i ] = ( (LongObjectId) objectId[ i ] ).longValue();
  }

  // Get the result set back...
  //
  return callRead( new Callable<String[]>() {
    @Override public String[] call() throws Exception {
      ResultSet resultSet = database.openQuery( ps, parameterMeta, parameterData );
      List<Object[]> rows = database.getRows( resultSet, 0, null );
      if ( Utils.isEmpty( rows ) ) {
        return new String[ 0 ];
      }

      // assemble the result
      //
      RowMetaInterface rowMeta = database.getReturnRowMeta();
      String[] strings = new String[ rows.size() ];
      for ( int i = 0; i < strings.length; i++ ) {
        Object[] row = rows.get( i );
        strings[ i ] = rowMeta.getString( row, 0 );
      }

      return strings;
    }
  } );
}
 
Example #29
Source File: XMLInputSax.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private Object[] getRowFromXML() throws KettleValueException {
  // finished reading the file, read the next file!
  //
  if ( data.document == null ) {
    data.filename = null;
  } else if ( !data.document.hasNext() ) {
    data.filename = null;
  }

  // First, see if we need to open a new file
  if ( data.filename == null ) {
    if ( !openNextFile() ) {
      return null;
    }
  }

  Object[] outputRowData = data.document.getNext();
  int outputIndex = meta.getInputFields().length;

  // Node itemNode = XMLHandler.getSubNodeByNr(data.section,
  // data.itemElement, data.itemPosition);
  // data.itemPosition++;

  // See if we need to add the filename to the row...
  //
  if ( meta.includeFilename() && !Utils.isEmpty( meta.getFilenameField() ) ) {
    outputRowData[outputIndex++] = data.filename;
  }

  // See if we need to add the row number to the row...
  if ( meta.includeRowNumber() && !Utils.isEmpty( meta.getRowNumberField() ) ) {
    outputRowData[outputIndex] = new Long( data.rownr );
  }

  data.rownr++;

  return outputRowData;
}
 
Example #30
Source File: GetRepositoryNames.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private List<RepositoryElementMetaInterface> getRepositoryObjects( Repository repository,
    RepositoryDirectoryInterface directory, boolean subdirs, String nameMask, String excludeNameMask )
  throws KettleException {
  List<RepositoryElementMetaInterface> list = new ArrayList<RepositoryElementMetaInterface>();
  List<RepositoryElementMetaInterface> objects = new ArrayList<RepositoryElementMetaInterface>();
  if ( meta.getObjectTypeSelection().areTransformationsSelected() ) {
    objects.addAll( repository.getTransformationObjects( directory.getObjectId(), false ) );
  }
  if ( meta.getObjectTypeSelection().areJobsSelected() ) {
    objects.addAll( repository.getJobObjects( directory.getObjectId(), false ) );
  }

  for ( RepositoryElementMetaInterface object : objects ) {
    boolean add = false;
    if ( Utils.isEmpty( nameMask ) || object.getName().matches( nameMask ) ) {
      add = true;
    }
    if ( !Utils.isEmpty( excludeNameMask ) && object.getName().matches( excludeNameMask ) ) {
      add = false;
    }
    if ( add ) {
      list.add( object );
    }
  }

  if ( subdirs ) {
    for ( RepositoryDirectoryInterface child : directory.getChildren() ) {
      list.addAll( getRepositoryObjects( repository, child, subdirs, nameMask, excludeNameMask ) );
    }
  }

  return list;
}