Java Code Examples for org.pentaho.di.core.util.StringUtil#isEmpty()

The following examples show how to use org.pentaho.di.core.util.StringUtil#isEmpty() . 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: ExecuteTestsDialog.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
private void ok() {
  if ( StringUtil.isEmpty( wStepname.getText() ) ) {
    return;
  }

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

  input.setChanged();

  input.setTestNameInputField( wTestNameInputField.getText() );
  input.setTypeToExecute( DataSetConst.getTestTypeForDescription( wTypeToExecute.getText() ) );
  input.setTransformationNameField( wTransformationNameField.getText() );
  input.setUnitTestNameField( wUnitTestNameField.getText() );
  input.setDataSetNameField( wDataSetNameField.getText() );
  input.setStepNameField( wStepNameField.getText() );
  input.setErrorField( wErrorField.getText() );
  input.setCommentField( wCommentField.getText() );

  dispose();
}
 
Example 2
Source File: VFSFileSelection.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private Optional<String> promptForFile() {
  String curFile = abstractMeta.environmentSubstitute( wFileName.getText() );
  FileObject root;

  try {
    root = KettleVFS.getFileObject( curFile != null ? curFile : Const.getUserHomeDirectory() );
    VfsFileChooserDialog vfsFileChooser = Spoon.getInstance().getVfsFileChooserDialog( root.getParent(), root );
    if ( StringUtil.isEmpty( initialScheme ) ) {
      initialScheme = "file";
    }
    FileObject file = vfsFileChooser.open( getShell(), null, initialScheme, true, curFile, fileFilters, fileFilterNames, false,
      fileDialogMode, showLocation, true );
    if ( file == null ) {
      return Optional.empty();
    }

    String filePath = getRelativePath( file.getName().toString() );
    return Optional.ofNullable( filePath );
  } catch ( IOException | KettleException e ) {
    new ErrorDialog( getShell(),
      BaseMessages.getString( PKG, "VFSFileSelection.ErrorLoadingFile.DialogTitle" ),
      BaseMessages.getString( PKG, "VFSFileSelection.ErrorLoadingFile.DialogMessage" ), e );
  }
  return Optional.empty();
}
 
Example 3
Source File: DataSetHelper.java    From pentaho-pdi-dataset with Apache License 2.0 6 votes vote down vote up
public static String validateDataSet( DataSet dataSet, String previousName, List<String> setNames ) {

    String message = null;

    String newName = dataSet.getName();
    if ( StringUtil.isEmpty( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.NoNameSpecified.Message" );
    } else if ( !StringUtil.isEmpty( previousName ) && !previousName.equals( newName ) ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.RenamingOfADataSetsNotSupported.Message" );
    } else if ( dataSet.getGroup() == null ) {
      message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.NoGroupSpecified.Message" );
    } else {
      if ( StringUtil.isEmpty( previousName ) && Const.indexOfString( newName, setNames ) >= 0 ) {
        message = BaseMessages.getString( PKG, "DataSetHelper.DataSet.ADataSetWithNameExists.Message", newName );
      }
    }

    return message;
  }
 
Example 4
Source File: MongoDbModel.java    From pentaho-mongodb-plugin with Apache License 2.0 5 votes vote down vote up
public boolean validate() {
  boolean valid = false;

  valid = ( !StringUtil.isEmpty( hostname ) )
      //   (!StringUtil.isEmpty(port)) &&     // port can be empty; MongoDb will assume 27017
      && ( !StringUtil.isEmpty( dbName ) ) && ( !StringUtil.isEmpty( collection ) ) && ( fields.size() > 0 );

  firePropertyChange( "validate", null, valid );
  return valid;
}
 
Example 5
Source File: SpecialMethodProcessor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
private void askForField( PartitionSettings settings, SpoonDelegates delegates ) throws KettleException {
  StepDialogInterface partitionDialog =
    delegates.steps.getPartitionerDialog( settings.getStepMeta(), settings.getStepMeta().getStepPartitioningMeta(),
      settings.getTransMeta() );
  String  fieldName = partitionDialog.open();
  if ( StringUtil.isEmpty( fieldName ) ) {
    settings.rollback( settings.getBefore() );
  }
}
 
Example 6
Source File: SpecialMethodProcessor.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
@Override
public void schemaSelection( PartitionSettings settings, Shell shell, SpoonDelegates delegates )
  throws KettleException {
  String schema =
    super.askForSchema( settings.getSchemaNamesArray(), shell, settings.getDefaultSelectedSchemaIndex() );
  super.processForKnownSchema( schema, settings );
  if ( !StringUtil.isEmpty( schema ) ) {
    askForField( settings, delegates );
  }
}
 
Example 7
Source File: StepOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void checkBoolean( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                                 String identifier, String value ) {
  if ( !StringUtil.isEmpty( space.environmentSubstitute( value ) ) && null == BooleanUtils
    .toBooleanObject( space.environmentSubstitute( value ) ) ) {
    remarks.add( new CheckResult(
      CheckResultInterface.TYPE_RESULT_ERROR,
      BaseMessages.getString( PKG, "StepOption.CheckResult.NotABoolean", identifier ),
      stepMeta ) );
  }
}
 
Example 8
Source File: StepOption.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static void checkInteger( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                                 String identifier, String value ) {
  try {
    if ( !StringUtil.isEmpty( space.environmentSubstitute( value ) ) ) {
      Integer.parseInt( space.environmentSubstitute( value ) );
    }
  } catch ( NumberFormatException e ) {
    remarks.add( new CheckResult(
      CheckResultInterface.TYPE_RESULT_ERROR,
      BaseMessages.getString( PKG, "StepOption.CheckResult.NotAInteger", identifier ),
      stepMeta ) );
  }
}
 
Example 9
Source File: JobEntryBase.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * <p>Appends the date, time and/or datetime to the given filename (before the extension if it exists), using the
 * provided patterns.</p>
 *
 * @param filename       the original filename (can have path and variables)
 * @param addDate        if the date is to be added
 * @param datePattern    the pattern to be used for the date
 * @param addTime        if the time is to be added
 * @param timePattern    the pattern to be used for the time
 * @param specifyFormat  if the datetime is to be added
 * @param datetimeFormat the pattern to be used for the datetime
 * @return the resulting filename after adding the specified suffixes to the given filename
 */
protected String addDatetimeToFilename( String filename, boolean addDate, String datePattern, boolean addTime,
                                        String timePattern, boolean specifyFormat, String datetimeFormat ) {

  if ( Utils.isEmpty( filename ) ) {
    return null;
  }

  // Replace possible environment variables...
  String realfilename = environmentSubstitute( filename );
  String filenameNoExtension = FilenameUtils.removeExtension( realfilename );
  String extension = FilenameUtils.getExtension( realfilename );

  // If an extension exists, add the corresponding dot before
  if ( !StringUtil.isEmpty( extension ) ) {
    extension = '.' + extension;
  }

  final SimpleDateFormat sdf = new SimpleDateFormat();
  Date now = new Date();

  if ( specifyFormat && !Utils.isEmpty( datetimeFormat ) ) {
    sdf.applyPattern( datetimeFormat );
    String dt = sdf.format( now );
    filenameNoExtension += dt;
  } else {
    if ( addDate && null != datePattern ) {
      sdf.applyPattern( datePattern );
      String d = sdf.format( now );
      filenameNoExtension += '_' + d;
    }
    if ( addTime && null != timePattern ) {
      sdf.applyPattern( timePattern );
      String t = sdf.format( now );
      filenameNoExtension += '_' + t;
    }
  }

  return filenameNoExtension + extension;
}
 
Example 10
Source File: DataSetConst.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
public static final DataSetGroup findDataSetGroup( List<DataSetGroup> list, String dataSetGroupName ) {
  if ( StringUtil.isEmpty( dataSetGroupName ) ) {
    return null;
  }
  for ( DataSetGroup dataSetGroup : list ) {
    if ( dataSetGroupName.equals( dataSetGroup.getName() ) ) {
      return dataSetGroup;
    }
  }
  return null;
}
 
Example 11
Source File: S3CsvInputMeta.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
/**
 * For legacy transformations containing AWS S3 access credentials, {@link Const#KETTLE_USE_AWS_DEFAULT_CREDENTIALS} can force Spoon to use
 * the Amazon Default Credentials Provider Chain instead of using the credentials embedded in the transformation metadata.
 *
 * @return true if {@link Const#KETTLE_USE_AWS_DEFAULT_CREDENTIALS} is true or AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are not specified
 */
public boolean getUseAwsDefaultCredentials() {
  if ( ValueMetaBase.convertStringToBoolean( Const.NVL( EnvUtil.getSystemProperty( Const.KETTLE_USE_AWS_DEFAULT_CREDENTIALS ), "N" ) ) ) {
    return true;
  } else if ( StringUtil.isEmpty( awsAccessKey ) && StringUtil.isEmpty( awsSecretKey ) ) {
    return true;
  }
  return false;
}
 
Example 12
Source File: MQTTClientBuilder.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
static void checkVersion( List<CheckResultInterface> remarks, StepMeta stepMeta, VariableSpace space,
                          String value ) {
  String version = space.environmentSubstitute( value );
  if ( !StringUtil.isEmpty( version ) ) {
    try {
      ( new MqttConnectOptions() ).setMqttVersion( Integer.parseInt( version ) );
    } catch ( Exception e ) {
      remarks.add( new CheckResult(
        CheckResultInterface.TYPE_RESULT_ERROR,
        getString( PKG, "MQTTMeta.CheckResult.NotCorrectVersion",
          getString( PKG, "MQTTDialog.Options." + MQTT_VERSION ), version ),
        stepMeta ) );
    }
  }
}
 
Example 13
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
/**
 * Look at the metadata specified here and create the table accordingly...
 * - Create a table for the Database Group type
 * - Create a metadata file for the CSV group type
 */
protected void createTable() {
  try {
    verifySettings();

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

    String tableName = wTableName.getText();

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

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

    group.createTable( tableName, rowMeta );

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

}
 
Example 14
Source File: DataSetDialog.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
private void verifySettings() throws KettleException {
  DataSetGroup group = DataSetConst.findDataSetGroup( groups, wDataSetGroup.getText() );

  if ( group == null ) {
    throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoGroupSpecified" ) );
  }
  if ( StringUtil.isEmpty( wTableName.getText() ) ) {
    throw new KettleException( BaseMessages.getString( PKG, "DataSetDialog.Error.NoTableSpecified" ) );
  }
  group.verifySettings();

}
 
Example 15
Source File: DataSetDatabaseGroup.java    From pentaho-pdi-dataset with Apache License 2.0 5 votes vote down vote up
public static final void writeDataSetData( LoggingObjectInterface loggingObject, DataSetGroup dataSetGroup, String tableName,
                                           RowMetaInterface rowMeta, List<Object[]> rows ) throws KettleException {

  Database database = new Database( loggingObject, dataSetGroup.getDatabaseMeta() );
  try {
    database.connect();

    String schemaTable = dataSetGroup.getDatabaseMeta().getQuotedSchemaTableCombination( dataSetGroup.getSchemaName(), tableName );

    String sql;
    if ( database.checkTableExists( schemaTable ) ) {
      // Clean out old junk, allow for rollback
      //
      database.truncateTable( schemaTable );
      sql = database.getAlterTableStatement( schemaTable, rowMeta, null, false, null, true );
    } else {
      sql = database.getCreateTableStatement( schemaTable, rowMeta, null, false, null, true );
    }
    if ( !StringUtil.isEmpty( sql ) ) {
      database.execStatements( sql );
    }
    database.prepareInsert( rowMeta, schemaTable );
    for ( Object[] row : rows ) {
      database.setValuesInsert( new RowMetaAndData( rowMeta, row ) );
      database.insertRow();
    }

    database.commit();
  } finally {
    database.disconnect();
  }

}
 
Example 16
Source File: Neo4JOutput.java    From knowbi-pentaho-pdi-neo4j-output with Apache License 2.0 4 votes vote down vote up
private void outputGraphValue( RowMetaInterface rowMeta, Object[] row ) throws KettleException {

    try {

      GraphData graphData = new GraphData();
      graphData.setSourceTransformationName( getTransMeta().getName() );
      graphData.setSourceStepName( getStepMeta().getName() );

      GraphNodeData sourceNodeData = null;
      GraphNodeData targetNodeData = null;
      GraphRelationshipData relationshipData;

      if ( meta.getFromNodeProps().length > 0 ) {
        sourceNodeData = createGraphNodeData( rowMeta, row, meta.getFromNodeLabels(), data.fromLabelValues, data.fromNodeLabelIndexes,
          data.fromNodePropIndexes, meta.getFromNodePropNames(), meta.getFromNodePropPrimary(), "from" );
        if ( !meta.isOnlyCreatingRelationships() ) {
          graphData.getNodes().add( sourceNodeData );
        }
      }
      if ( meta.getToNodeProps().length > 0 ) {
        targetNodeData = createGraphNodeData( rowMeta, row, meta.getToNodeLabels(), data.toLabelValues, data.toNodeLabelIndexes,
          data.toNodePropIndexes, meta.getToNodePropNames(), meta.getToNodePropPrimary(), "to" );
        if ( !meta.isOnlyCreatingRelationships() ) {
          graphData.getNodes().add( targetNodeData );
        }
      }

      String relationshipLabel = null;
      if ( data.relationshipIndex >= 0 ) {
        relationshipLabel = getInputRowMeta().getString( row, data.relationshipIndex );
      }
      if ( StringUtil.isEmpty( relationshipLabel ) && StringUtils.isNotEmpty( data.relationshipLabelValue ) ) {
        relationshipLabel = data.relationshipLabelValue;
      }
      if ( sourceNodeData != null && targetNodeData != null && StringUtils.isNotEmpty( relationshipLabel ) ) {

        relationshipData = new GraphRelationshipData();
        relationshipData.setSourceNodeId( sourceNodeData.getId() );
        relationshipData.setTargetNodeId( targetNodeData.getId() );
        relationshipData.setLabel( relationshipLabel );
        relationshipData.setId( sourceNodeData.getId() + " -> " + targetNodeData.getId() );
        relationshipData.setPropertySetId( "relationship" );

        // Add relationship properties...
        //
        // Set the properties
        //
        for ( int i = 0; i < data.relPropIndexes.length; i++ ) {

          ValueMetaInterface valueMeta = rowMeta.getValueMeta( data.relPropIndexes[ i ] );
          Object valueData = row[ data.relPropIndexes[ i ] ];

          String propertyName = meta.getRelPropNames()[ i ];
          GraphPropertyDataType propertyType = GraphPropertyDataType.getTypeFromKettle( valueMeta );
          Object propertyNeoValue = propertyType.convertFromKettle( valueMeta, valueData );
          boolean propertyPrimary = false;

          relationshipData.getProperties().add(
            new GraphPropertyData( propertyName, propertyNeoValue, propertyType, propertyPrimary )
          );
        }

        graphData.getRelationships().add( relationshipData );
      }

      // Pass it forward...
      //
      Object[] outputRowData = RowDataUtil.createResizedCopy( row, data.outputRowMeta.size() );
      int startIndex = rowMeta.size();
      outputRowData[ rowMeta.size() ] = graphData;
      putRow( data.outputRowMeta, outputRowData );

    } catch ( Exception e ) {
      throw new KettleException( "Unable to calculate graph output value", e );
    }
  }
 
Example 17
Source File: MQTTClientBuilder.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private MqttConnectOptions getOptions() {
  MqttConnectOptions options = new MqttConnectOptions();

  if ( isSecure ) {
    setSSLProps( options );
  }
  if ( !StringUtil.isEmpty( username ) ) {
    options.setUserName( username );
  }
  if ( !StringUtil.isEmpty( password ) ) {
    options.setPassword( password.toCharArray() );
  }

  if ( !StringUtil.isEmpty( keepAliveInterval ) ) {
    options.setKeepAliveInterval( Integer.parseInt( keepAliveInterval ) );
  }

  if ( !StringUtil.isEmpty( maxInflight ) ) {
    options.setMaxInflight( Integer.parseInt( maxInflight ) );
  }

  if ( !StringUtil.isEmpty( connectionTimeout ) ) {
    options.setConnectionTimeout( Integer.parseInt( connectionTimeout ) );
  }

  if ( !StringUtil.isEmpty( cleanSession ) ) {
    options.setCleanSession( BooleanUtils.toBoolean( cleanSession ) );
  }

  if ( !StringUtil.isEmpty( serverUris ) ) {
    options.setServerURIs(
      Arrays.stream( serverUris.split( ";" ) ).map( uri -> getProtocol() + uri ).toArray( String[]::new ) );
  }

  if ( !StringUtil.isEmpty( mqttVersion ) ) {
    options.setMqttVersion( Integer.parseInt( mqttVersion ) );
  }

  if ( !StringUtil.isEmpty( automaticReconnect ) ) {
    options.setAutomaticReconnect( BooleanUtils.toBoolean( automaticReconnect ) );
  }

  return options;
}
 
Example 18
Source File: JmsProducer.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
private void setOptions( JMSProducer producer ) {
  String optionValue = meta.getDisableMessageId();
  getLogChannel().logDebug( "Disable Message ID is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDisableMessageID( BooleanUtils.toBoolean( optionValue ) );
  }

  optionValue = meta.getDisableMessageTimestamp();
  getLogChannel().logDebug( "Disable Message Timestamp is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDisableMessageTimestamp( BooleanUtils.toBoolean( optionValue ) );
  }

  optionValue = meta.getDeliveryMode();
  getLogChannel().logDebug( "Delivery Mode is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDeliveryMode( Integer.parseInt( optionValue ) );
  }

  optionValue = meta.getPriority();
  getLogChannel().logDebug( "Priority is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setPriority( Integer.parseInt( optionValue ) );
  }

  optionValue = meta.getTimeToLive();
  getLogChannel().logDebug( "Time to Live is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setTimeToLive( Long.parseLong( optionValue ) );
  }

  optionValue = meta.getDeliveryDelay();
  getLogChannel().logDebug( "Delivery Delay is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setDeliveryDelay( Long.parseLong( optionValue ) );
  }

  optionValue = meta.getJmsCorrelationId();
  getLogChannel().logDebug( "JMS Correlation ID is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setJMSCorrelationID( optionValue );
  }

  optionValue = meta.getJmsType();
  getLogChannel().logDebug( "JMS Type is set to " + optionValue );
  if ( !StringUtil.isEmpty( optionValue ) ) {
    producer.setJMSType( optionValue );
  }
}
 
Example 19
Source File: HelpUtils.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public static boolean isPluginDocumented( PluginInterface plugin ) {
  if ( plugin == null ) {
    return false;
  }
  return !StringUtil.isEmpty( plugin.getDocumentationUrl() );
}
 
Example 20
Source File: GoogleBigQueryDatabaseMeta.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Override public String getURL( String hostname, String port, String databaseName ) {
  return "jdbc:bigquery://" + hostname + ":"
    + ( StringUtil.isEmpty( port ) ? "443" : port ) + ";"
    + ( StringUtil.isEmpty( databaseName ) ? "" : "ProjectId=" + databaseName ) + ";";
}