@Override
  public void getFields(
      RowMetaInterface row,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    for (SasInputField field : outputFields) {
      try {
        ValueMetaInterface valueMeta =
            ValueMetaFactory.createValueMeta(field.getRename(), field.getType());
        valueMeta.setLength(field.getLength(), field.getPrecision());
        valueMeta.setDecimalSymbol(field.getDecimalSymbol());
        valueMeta.setGroupingSymbol(field.getGroupingSymbol());
        valueMeta.setConversionMask(field.getConversionMask());
        valueMeta.setTrimType(field.getTrimType());
        valueMeta.setOrigin(name);

        row.addValueMeta(valueMeta);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }
  }
Пример #2
0
 public RowMetaInterface createResultRowMetaInterface() {
   RowMetaInterface rm = new RowMeta();
   try {
     ValueMetaInterface[] valuesMeta = {
       ValueMetaFactory.createValueMeta("timestamp1", ValueMetaInterface.TYPE_TIMESTAMP),
       ValueMetaFactory.createValueMeta("int1", ValueMetaInterface.TYPE_INTEGER),
       ValueMetaFactory.createValueMeta("timestamp plus 1 day", ValueMetaInterface.TYPE_DATE)
     };
     for (int i = 0; i < valuesMeta.length; i++) {
       rm.addValueMeta(valuesMeta[i]);
     }
   } catch (Exception ex) {
     return null;
   }
   return rm;
 }
Пример #3
0
 private Object convertDataToTargetValueMeta(int i, Object formulaResult) throws KettleException {
   if (formulaResult == null) {
     return formulaResult;
   }
   ValueMetaInterface target = data.outputRowMeta.getValueMeta(i);
   ValueMetaInterface actual = ValueMetaFactory.guessValueMetaInterface(formulaResult);
   Object value = target.convertData(actual, formulaResult);
   return value;
 }
  private Date getIncrementalFieldValue() throws KettleException {
    Date result = null;
    boolean firstRow = true;
    Object[] row;
    RowMetaInterface inputRowMeta;

    while ((row = getRow()) != null) {
      if (firstRow) {
        firstRow = false;
        inputRowMeta = getInputRowMeta();

        if (inputRowMeta == null || inputRowMeta.size() <= 0) {
          if (log.isBasic()) {
            logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows"));
          }
          return null;
        }

        String filenameField = environmentSubstitute(meta.getTimestampFieldName());
        int fieldIndex = inputRowMeta.indexOfValue(filenameField);
        if (fieldIndex < 0) {
          throw new KettleStepException(
              BaseMessages.getString(
                  PKG, "ZendeskInputIncremental.Exception.StartDateFieldNotFound", filenameField));
        }
        ValueMetaInterface fieldValueMeta = inputRowMeta.getValueMeta(fieldIndex);
        if (!(fieldValueMeta instanceof ValueMetaDate)) {
          throw new KettleStepException(
              BaseMessages.getString(
                  PKG,
                  "ZendeskInput.Error.WrongFieldType",
                  ValueMetaFactory.getValueMetaName(fieldValueMeta.getType())));
        } else {
          result = fieldValueMeta.getDate(row[fieldIndex]);
        }
      } else {
        if (log.isDetailed()) {
          logDetailed(
              BaseMessages.getString(PKG, "ZendeskInput.Warning.IgnoringAdditionalInputRows"));
        }
      }
    }

    if (firstRow) {
      if (log.isBasic()) {
        logBasic(BaseMessages.getString(PKG, "ZendeskInput.Error.NoIncomingRows"));
      }
    }

    return result;
  }
  public void readRep(
      Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases)
      throws KettleException {
    try {

      urlInField = rep.getStepAttributeBoolean(id_step, "url_in_field");
      urlFieldname = rep.getStepAttributeString(id_step, "url_field_name");
      includeRowNumber = rep.getStepAttributeBoolean(id_step, "rownum");
      rowNumberField = rep.getStepAttributeString(id_step, "rownum_field");
      includeUrl = rep.getStepAttributeBoolean(id_step, "include_url");
      urlField = rep.getStepAttributeString(id_step, "url_Field");
      readfrom = rep.getStepAttributeString(id_step, "read_from");
      rowLimit = rep.getStepAttributeInteger(id_step, "limit");

      int nrFields = rep.countNrStepAttributes(id_step, "field_name");
      int nrUrls = rep.countNrStepAttributes(id_step, "url_name");

      allocate(nrUrls, nrFields);

      for (int i = 0; i < nrUrls; i++) {
        url[i] = rep.getStepAttributeString(id_step, i, "url_name");
      }

      for (int i = 0; i < nrFields; i++) {
        RssInputField field = new RssInputField();

        field.setName(rep.getStepAttributeString(id_step, i, "field_name"));
        field.setColumn(
            RssInputField.getColumnByCode(rep.getStepAttributeString(id_step, i, "field_column")));
        field.setType(
            ValueMetaFactory.getIdForValueMeta(
                rep.getStepAttributeString(id_step, i, "field_type")));
        field.setFormat(rep.getStepAttributeString(id_step, i, "field_format"));
        field.setCurrencySymbol(rep.getStepAttributeString(id_step, i, "field_currency"));
        field.setDecimalSymbol(rep.getStepAttributeString(id_step, i, "field_decimal"));
        field.setGroupSymbol(rep.getStepAttributeString(id_step, i, "field_group"));
        field.setLength((int) rep.getStepAttributeInteger(id_step, i, "field_length"));
        field.setPrecision((int) rep.getStepAttributeInteger(id_step, i, "field_precision"));
        field.setTrimType(
            RssInputField.getTrimTypeByCode(
                rep.getStepAttributeString(id_step, i, "field_trim_type")));
        field.setRepeated(rep.getStepAttributeBoolean(id_step, i, "field_repeat"));

        inputFields[i] = field;
      }
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "RssInputMeta.Exception.ErrorReadingRepository"), e);
    }
  }
  private JaninoMeta populateJaninoMeta() {
    JaninoMeta meta = new JaninoMeta();
    meta.allocate(NR_FIELDS);

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

    return meta;
  }
Пример #7
0
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface info[],
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {
    int i;
    for (i = 0; i < inputFields.length; i++) {
      RssInputField field = inputFields[i];

      int type = field.getType();
      if (type == ValueMeta.TYPE_NONE) type = ValueMeta.TYPE_STRING;
      try {
        ValueMetaInterface v =
            ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
        v.setLength(field.getLength(), field.getPrecision());
        v.setOrigin(name);
        r.addValueMeta(v);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }

    if (includeUrl) {
      ValueMetaInterface v =
          new ValueMeta(space.environmentSubstitute(urlField), ValueMeta.TYPE_STRING);
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (includeRowNumber) {
      ValueMetaInterface v =
          new ValueMeta(space.environmentSubstitute(rowNumberField), ValueMeta.TYPE_INTEGER);
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
  }
Пример #8
0
  private void getInfo(FixedInputMeta fixedInputMeta) {

    fixedInputMeta.setFilename(wFilename.getText());
    fixedInputMeta.setLineWidth(wLineWidth.getText());
    fixedInputMeta.setBufferSize(wBufferSize.getText());
    fixedInputMeta.setLazyConversionActive(wLazyConversion.getSelection());
    fixedInputMeta.setHeaderPresent(wHeaderPresent.getSelection());
    fixedInputMeta.setLineFeedPresent(wLineFeedPresent.getSelection());
    fixedInputMeta.setRunningInParallel(wRunningInParallel.getSelection());
    fixedInputMeta.setFileType(FixedInputMeta.getFileType(wFileType.getText()));
    fixedInputMeta.setEncoding(wEncoding.getText());
    fixedInputMeta.setAddResultFile(wAddResult.getSelection());

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

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

      FixedFileInputField field = new FixedFileInputField();

      field.setName(item.getText(colnr++));
      field.setType(ValueMetaFactory.getIdForValueMeta(item.getText(colnr++)));
      field.setFormat(item.getText(colnr++));
      field.setWidth(Const.toInt(item.getText(colnr++), -1));
      field.setLength(Const.toInt(item.getText(colnr++), -1));
      field.setPrecision(Const.toInt(item.getText(colnr++), -1));
      field.setCurrency(item.getText(colnr++));
      field.setDecimal(item.getText(colnr++));
      field.setGrouping(item.getText(colnr++));
      field.setTrimType(ValueMetaString.getTrimTypeByDesc(item.getText(colnr++)));

      // CHECKSTYLE:Indentation:OFF
      fixedInputMeta.getFieldDefinition()[i] = field;
    }
    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth(true);

    fixedInputMeta.setChanged();
  }
Пример #9
0
  /** Copy information from the meta-data input to the dialog fields. */
  public void getData() {
    wStepname.setText(stepname);
    wFilename.setText(Const.NVL(inputMeta.getFilename(), ""));
    wLineWidth.setText(Const.NVL(inputMeta.getLineWidth(), ""));
    wLineFeedPresent.setSelection(inputMeta.isLineFeedPresent());
    wBufferSize.setText(Const.NVL(inputMeta.getBufferSize(), ""));
    wLazyConversion.setSelection(inputMeta.isLazyConversionActive());
    wHeaderPresent.setSelection(inputMeta.isHeaderPresent());
    wRunningInParallel.setSelection(inputMeta.isRunningInParallel());
    wFileType.setText(inputMeta.getFileTypeDesc());
    wEncoding.setText(Const.NVL(inputMeta.getEncoding(), ""));
    wAddResult.setSelection(inputMeta.isAddResultFile());

    for (int i = 0; i < inputMeta.getFieldDefinition().length; i++) {
      TableItem item = new TableItem(wFields.table, SWT.NONE);
      int colnr = 1;
      FixedFileInputField field = inputMeta.getFieldDefinition()[i];

      item.setText(colnr++, Const.NVL(field.getName(), ""));
      item.setText(colnr++, ValueMetaFactory.getValueMetaName(field.getType()));
      item.setText(colnr++, Const.NVL(field.getFormat(), ""));
      item.setText(colnr++, field.getWidth() >= 0 ? Integer.toString(field.getWidth()) : "");
      item.setText(colnr++, field.getLength() >= 0 ? Integer.toString(field.getLength()) : "");
      item.setText(
          colnr++, field.getPrecision() >= 0 ? Integer.toString(field.getPrecision()) : "");
      item.setText(colnr++, Const.NVL(field.getCurrency(), ""));
      item.setText(colnr++, Const.NVL(field.getDecimal(), ""));
      item.setText(colnr++, Const.NVL(field.getGrouping(), ""));
      item.setText(colnr++, ValueMetaString.getTrimTypeCode(field.getTrimType()));
    }
    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth(true);

    enableFields();

    wStepname.selectAll();
    wStepname.setFocus();
  }
Пример #10
0
  public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {
    meta = (DatabaseLookupMeta) smi;
    data = (DatabaseLookupData) sdi;

    boolean sendToErrorRow = false;
    String errorMessage = null;

    Object[] r = getRow(); // Get row from input rowset & set row busy!
    if (r == null) { // no more input to be expected...
      setOutputDone();
      return false;
    }

    if (first) {
      first = false;

      // create the output metadata
      data.outputRowMeta = getInputRowMeta().clone();
      meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

      if (meta.isCached()) {
        if (meta.getCacheSize() > 0) {
          data.look = new Hashtable<RowMetaAndData, TimedRow>((int) (meta.getCacheSize() * 1.5));
        } else {
          data.look = new Hashtable<RowMetaAndData, TimedRow>();
        }
      }

      data.db.setLookup(
          environmentSubstitute(meta.getSchemaName()),
          environmentSubstitute(meta.getTablename()),
          meta.getTableKeyField(),
          meta.getKeyCondition(),
          meta.getReturnValueField(),
          meta.getReturnValueNewName(),
          meta.getOrderByClause(),
          meta.isFailingOnMultipleResults());

      // lookup the values!
      if (log.isDetailed()) {
        logDetailed(
            BaseMessages.getString(PKG, "DatabaseLookup.Log.CheckingRow")
                + getInputRowMeta().getString(r));
      }

      data.keynrs = new int[meta.getStreamKeyField1().length];
      data.keynrs2 = new int[meta.getStreamKeyField1().length];

      for (int i = 0; i < meta.getStreamKeyField1().length; i++) {
        data.keynrs[i] = getInputRowMeta().indexOfValue(meta.getStreamKeyField1()[i]);
        if (data.keynrs[i] < 0
            && // couldn't find field!
            !"IS NULL".equalsIgnoreCase(meta.getKeyCondition()[i])
            && // No field needed!
            !"IS NOT NULL".equalsIgnoreCase(meta.getKeyCondition()[i]) // No field needed!
        ) {
          throw new KettleStepException(
              BaseMessages.getString(PKG, "DatabaseLookup.ERROR0001.FieldRequired1.Exception")
                  + meta.getStreamKeyField1()[i]
                  + BaseMessages.getString(
                      PKG, "DatabaseLookup.ERROR0001.FieldRequired2.Exception"));
        }
        data.keynrs2[i] = getInputRowMeta().indexOfValue(meta.getStreamKeyField2()[i]);
        if (data.keynrs2[i] < 0
            && // couldn't find field!
            "BETWEEN".equalsIgnoreCase(meta.getKeyCondition()[i]) // 2 fields needed!
        ) {
          throw new KettleStepException(
              BaseMessages.getString(PKG, "DatabaseLookup.ERROR0001.FieldRequired3.Exception")
                  + meta.getStreamKeyField2()[i]
                  + BaseMessages.getString(
                      PKG, "DatabaseLookup.ERROR0001.FieldRequired4.Exception"));
        }
        if (log.isDebug()) {
          logDebug(
              BaseMessages.getString(PKG, "DatabaseLookup.Log.FieldHasIndex1")
                  + meta.getStreamKeyField1()[i]
                  + BaseMessages.getString(PKG, "DatabaseLookup.Log.FieldHasIndex2")
                  + data.keynrs[i]);
        }
      }

      data.nullif = new Object[meta.getReturnValueField().length];

      for (int i = 0; i < meta.getReturnValueField().length; i++) {
        ValueMetaInterface stringMeta = new ValueMeta("string", ValueMetaInterface.TYPE_STRING);
        ValueMetaInterface returnMeta =
            data.outputRowMeta.getValueMeta(i + getInputRowMeta().size());

        if (!Const.isEmpty(meta.getReturnValueDefault()[i])) {
          data.nullif[i] = returnMeta.convertData(stringMeta, meta.getReturnValueDefault()[i]);
        } else {
          data.nullif[i] = null;
        }
      }

      // Determine the types...
      data.keytypes = new int[meta.getTableKeyField().length];
      String schemaTable =
          meta.getDatabaseMeta()
              .getQuotedSchemaTableCombination(
                  environmentSubstitute(meta.getSchemaName()),
                  environmentSubstitute(meta.getTablename()));
      RowMetaInterface fields = data.db.getTableFields(schemaTable);
      if (fields != null) {
        // Fill in the types...
        for (int i = 0; i < meta.getTableKeyField().length; i++) {
          ValueMetaInterface key = fields.searchValueMeta(meta.getTableKeyField()[i]);
          if (key != null) {
            data.keytypes[i] = key.getType();
          } else {
            throw new KettleStepException(
                BaseMessages.getString(PKG, "DatabaseLookup.ERROR0001.FieldRequired5.Exception")
                    + meta.getTableKeyField()[i]
                    + BaseMessages.getString(
                        PKG, "DatabaseLookup.ERROR0001.FieldRequired6.Exception"));
          }
        }
      } else {
        throw new KettleStepException(
            BaseMessages.getString(PKG, "DatabaseLookup.ERROR0002.UnableToDetermineFieldsOfTable")
                + schemaTable
                + "]");
      }

      // Count the number of values in the lookup as well as the metadata to send along with it.
      //
      data.lookupMeta = new RowMeta();

      for (int i = 0; i < meta.getStreamKeyField1().length; i++) {
        if (data.keynrs[i] >= 0) {
          ValueMetaInterface inputValueMeta = getInputRowMeta().getValueMeta(data.keynrs[i]);

          // Try to convert type if needed in a clone, we don't want to
          // change the type in the original row
          //
          ValueMetaInterface value =
              ValueMetaFactory.cloneValueMeta(inputValueMeta, data.keytypes[i]);

          data.lookupMeta.addValueMeta(value);
        }
        if (data.keynrs2[i] >= 0) {
          ValueMetaInterface inputValueMeta = getInputRowMeta().getValueMeta(data.keynrs2[i]);

          // Try to convert type if needed in a clone, we don't want to
          // change the type in the original row
          //
          ValueMetaInterface value =
              ValueMetaFactory.cloneValueMeta(inputValueMeta, data.keytypes[i]);

          data.lookupMeta.addValueMeta(value);
        }
      }

      // We also want to know the metadata of the return values beforehand (null handling)
      data.returnMeta = new RowMeta();

      for (int i = 0; i < meta.getReturnValueField().length; i++) {
        ValueMetaInterface v =
            data.outputRowMeta.getValueMeta(getInputRowMeta().size() + i).clone();
        data.returnMeta.addValueMeta(v);
      }

      // If the user selected to load all data into the cache at startup, that's what we do now...
      //
      if (meta.isCached() && meta.isLoadingAllDataInCache()) {
        loadAllTableDataIntoTheCache();
      }
    }

    if (log.isRowLevel()) {
      logRowlevel(
          BaseMessages.getString(PKG, "DatabaseLookup.Log.GotRowFromPreviousStep")
              + getInputRowMeta().getString(r));
    }

    try {
      // add new lookup values to the row
      Object[] outputRow = lookupValues(getInputRowMeta(), r);

      if (outputRow != null) {
        // copy row to output rowset(s);
        putRow(data.outputRowMeta, outputRow);

        if (log.isRowLevel()) {
          logRowlevel(
              BaseMessages.getString(PKG, "DatabaseLookup.Log.WroteRowToNextStep")
                  + getInputRowMeta().getString(r));
        }
        if (checkFeedback(getLinesRead())) {
          logBasic("linenr " + getLinesRead());
        }
      }
    } catch (KettleException e) {
      if (getStepMeta().isDoingErrorHandling()) {
        sendToErrorRow = true;
        errorMessage = e.toString();
      } else {
        logError(
            BaseMessages.getString(PKG, "DatabaseLookup.ERROR003.UnexpectedErrorDuringProcessing")
                + e.getMessage());
        setErrors(1);
        stopAll();
        setOutputDone(); // signal end to receiver(s)
        return false;
      }
      if (sendToErrorRow) {
        // Simply add this row to the error row
        putError(getInputRowMeta(), r, 1, errorMessage, null, "DBLOOKUPD001");
      }
    }

    return true;
  }
Пример #11
0
  public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException {

    meta = (GaInputStepMeta) smi;
    data = (GaInputStepData) sdi;

    if (first) {

      first = false;

      data.outputRowMeta = new RowMeta();
      meta.getFields(data.outputRowMeta, getStepname(), null, null, this, repository, metaStore);

      // stores the indices where to look for the key fields in the input rows
      data.conversionMeta = new ValueMetaInterface[meta.getFieldsCount()];

      for (int i = 0; i < meta.getFieldsCount(); i++) {

        // get output and from-string conversion format for each field
        ValueMetaInterface returnMeta = data.outputRowMeta.getValueMeta(i);

        ValueMetaInterface conversionMeta;

        conversionMeta =
            ValueMetaFactory.cloneValueMeta(returnMeta, ValueMetaInterface.TYPE_STRING);
        conversionMeta.setConversionMask(meta.getConversionMask()[i]);
        conversionMeta.setDecimalSymbol("."); // google analytics is en-US
        conversionMeta.setGroupingSymbol(null); // google analytics uses no grouping symbol

        data.conversionMeta[i] = conversionMeta;
      }
    }

    // generate output row, make it correct size
    Object[] outputRow = RowDataUtil.allocateRowData(data.outputRowMeta.size());

    List<String> entry = getNextDataEntry();

    if (entry != null
        && (meta.getRowLimit() <= 0
            || getLinesWritten() < meta.getRowLimit())) { // another record to
      // fill the output fields with look up data
      for (int i = 0, j = 0; i < meta.getFieldsCount(); i++) {
        String fieldName = environmentSubstitute(meta.getFeedField()[i]);
        Object dataObject;
        String type = environmentSubstitute(meta.getFeedFieldType()[i]);

        // We handle fields differently depending on whether its a Dimension/Metric, Data Source
        // Property, or
        // Data Source Field. Also the API doesn't exactly match the concepts anymore (see
        // individual comments below),
        // so there is quite a bit of special processing.
        if (GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY.equals(type)) {
          // Account name has to be handled differently, it's in the Accounts API not Profiles API
          if (GaInputStepMeta.PROPERTY_DATA_SOURCE_ACCOUNT_NAME.equals(fieldName)) {
            // We expect a single account name, and already fetched it during init
            dataObject = accountName;
          } else {
            dataObject = data.feed.getProfileInfo().get(removeClassifier(fieldName));
          }
        } else if (GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_FIELD.equals(type)) {
          // Get tableId or tableName
          if (GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_ID.equals(fieldName)) {
            dataObject = data.feed.getProfileInfo().get(removeClassifier(fieldName));
          } else {
            // We only have two Data Source Fields and they're hard-coded, so we handle tableName in
            // this else-clause
            // since tableId was done in the if-clause. We have to handle the two differently
            // because tableName is
            // actually the profile name in this version (v3) of the Google Analytics API.
            dataObject = data.feed.getProfileInfo().getProfileName();
          }
        } else if (GaInputStepMeta.DEPRECATED_FIELD_TYPE_CONFIDENCE_INTERVAL.equals(type)) {
          dataObject = null;
          if (log.isRowLevel()) {
            logRowlevel(
                BaseMessages.getString(
                    PKG,
                    "GoogleAnalytics.Warn.FieldTypeNotSupported",
                    GaInputStepMeta.DEPRECATED_FIELD_TYPE_CONFIDENCE_INTERVAL));
          }
        } else {
          // Assume it's a Dimension or Metric, we've covered the rest of the cases above.
          dataObject = entry.get(j++);
        }
        outputRow[i] =
            data.outputRowMeta.getValueMeta(i).convertData(data.conversionMeta[i], dataObject);
      }

      // copy row to possible alternate rowset(s)
      putRow(data.outputRowMeta, outputRow);

      // Some basic logging
      if (checkFeedback(getLinesWritten())) {
        if (log.isBasic()) {
          logBasic("Linenr " + getLinesWritten());
        }
      }
      return true;

    } else {
      setOutputDone();
      return false;
    }
  }
Пример #12
0
  public String open() {
    Shell parent = getParent();
    Display display = parent.getDisplay();

    shell = new Shell(parent, SWT.DIALOG_TRIM | SWT.RESIZE | SWT.MIN | SWT.MAX);
    props.setLook(shell);
    setShellImage(shell, inputMeta);

    ModifyListener lsMod =
        new ModifyListener() {
          public void modifyText(ModifyEvent e) {
            inputMeta.setChanged();
          }
        };
    changed = inputMeta.hasChanged();

    FormLayout formLayout = new FormLayout();
    formLayout.marginWidth = Const.FORM_MARGIN;
    formLayout.marginHeight = Const.FORM_MARGIN;

    shell.setLayout(formLayout);
    shell.setText(BaseMessages.getString(PKG, "FixedInputDialog.Shell.Title"));

    int middle = props.getMiddlePct();
    int margin = Const.MARGIN;

    // Step name line
    //
    wlStepname = new Label(shell, SWT.RIGHT);
    wlStepname.setText(BaseMessages.getString(PKG, "FixedInputDialog.Stepname.Label"));
    props.setLook(wlStepname);
    fdlStepname = new FormData();
    fdlStepname.left = new FormAttachment(0, 0);
    fdlStepname.right = new FormAttachment(middle, -margin);
    fdlStepname.top = new FormAttachment(0, margin);
    wlStepname.setLayoutData(fdlStepname);
    wStepname = new Text(shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wStepname);
    wStepname.addModifyListener(lsMod);
    fdStepname = new FormData();
    fdStepname.left = new FormAttachment(middle, 0);
    fdStepname.top = new FormAttachment(0, margin);
    fdStepname.right = new FormAttachment(100, 0);
    wStepname.setLayoutData(fdStepname);
    Control lastControl = wStepname;

    // Filename...
    //
    // The filename browse button
    //
    wbbFilename = new Button(shell, SWT.PUSH | SWT.CENTER);
    props.setLook(wbbFilename);
    wbbFilename.setText(BaseMessages.getString(PKG, "System.Button.Browse"));
    wbbFilename.setToolTipText(
        BaseMessages.getString(PKG, "System.Tooltip.BrowseForFileOrDirAndAdd"));
    FormData fdbFilename = new FormData();
    fdbFilename.top = new FormAttachment(lastControl, margin);
    fdbFilename.right = new FormAttachment(100, 0);
    wbbFilename.setLayoutData(fdbFilename);

    // The field itself...
    //
    Label wlFilename = new Label(shell, SWT.RIGHT);
    wlFilename.setText(BaseMessages.getString(PKG, "FixedInputDialog.Filename.Label"));
    props.setLook(wlFilename);
    FormData fdlFilename = new FormData();
    fdlFilename.top = new FormAttachment(lastControl, margin);
    fdlFilename.left = new FormAttachment(0, 0);
    fdlFilename.right = new FormAttachment(middle, -margin);
    wlFilename.setLayoutData(fdlFilename);
    wFilename = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wFilename);
    wFilename.addModifyListener(lsMod);
    FormData fdFilename = new FormData();
    fdFilename.top = new FormAttachment(lastControl, margin);
    fdFilename.left = new FormAttachment(middle, 0);
    fdFilename.right = new FormAttachment(wbbFilename, -margin);
    wFilename.setLayoutData(fdFilename);
    lastControl = wFilename;

    // delimiter
    Label wlLineWidth = new Label(shell, SWT.RIGHT);
    wlLineWidth.setText(BaseMessages.getString(PKG, "FixedInputDialog.LineWidth.Label"));
    props.setLook(wlLineWidth);
    FormData fdlLineWidth = new FormData();
    fdlLineWidth.top = new FormAttachment(lastControl, margin);
    fdlLineWidth.left = new FormAttachment(0, 0);
    fdlLineWidth.right = new FormAttachment(middle, -margin);
    wlLineWidth.setLayoutData(fdlLineWidth);
    wLineWidth = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wLineWidth);
    wLineWidth.addModifyListener(lsMod);
    FormData fdLineWidth = new FormData();
    fdLineWidth.top = new FormAttachment(lastControl, margin);
    fdLineWidth.left = new FormAttachment(middle, 0);
    fdLineWidth.right = new FormAttachment(100, 0);
    wLineWidth.setLayoutData(fdLineWidth);
    lastControl = wLineWidth;

    // delimiter
    Label wlLineFeedPresent = new Label(shell, SWT.RIGHT);
    wlLineFeedPresent.setText(
        BaseMessages.getString(PKG, "FixedInputDialog.LineFeedPresent.Label"));
    props.setLook(wlLineFeedPresent);
    FormData fdlLineFeedPresent = new FormData();
    fdlLineFeedPresent.top = new FormAttachment(lastControl, margin);
    fdlLineFeedPresent.left = new FormAttachment(0, 0);
    fdlLineFeedPresent.right = new FormAttachment(middle, -margin);
    wlLineFeedPresent.setLayoutData(fdlLineFeedPresent);
    wLineFeedPresent = new Button(shell, SWT.CHECK);
    props.setLook(wLineFeedPresent);
    FormData fdLineFeedPresent = new FormData();
    fdLineFeedPresent.top = new FormAttachment(lastControl, margin);
    fdLineFeedPresent.left = new FormAttachment(middle, 0);
    fdLineFeedPresent.right = new FormAttachment(100, 0);
    wLineFeedPresent.setLayoutData(fdLineFeedPresent);
    lastControl = wLineFeedPresent;

    // bufferSize
    //
    Label wlBufferSize = new Label(shell, SWT.RIGHT);
    wlBufferSize.setText(BaseMessages.getString(PKG, "FixedInputDialog.BufferSize.Label"));
    props.setLook(wlBufferSize);
    FormData fdlBufferSize = new FormData();
    fdlBufferSize.top = new FormAttachment(lastControl, margin);
    fdlBufferSize.left = new FormAttachment(0, 0);
    fdlBufferSize.right = new FormAttachment(middle, -margin);
    wlBufferSize.setLayoutData(fdlBufferSize);
    wBufferSize = new TextVar(transMeta, shell, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
    props.setLook(wBufferSize);
    wBufferSize.addModifyListener(lsMod);
    FormData fdBufferSize = new FormData();
    fdBufferSize.top = new FormAttachment(lastControl, margin);
    fdBufferSize.left = new FormAttachment(middle, 0);
    fdBufferSize.right = new FormAttachment(100, 0);
    wBufferSize.setLayoutData(fdBufferSize);
    lastControl = wBufferSize;

    // performingLazyConversion?
    //
    Label wlLazyConversion = new Label(shell, SWT.RIGHT);
    wlLazyConversion.setText(BaseMessages.getString(PKG, "FixedInputDialog.LazyConversion.Label"));
    props.setLook(wlLazyConversion);
    FormData fdlLazyConversion = new FormData();
    fdlLazyConversion.top = new FormAttachment(lastControl, margin);
    fdlLazyConversion.left = new FormAttachment(0, 0);
    fdlLazyConversion.right = new FormAttachment(middle, -margin);
    wlLazyConversion.setLayoutData(fdlLazyConversion);
    wLazyConversion = new Button(shell, SWT.CHECK);
    props.setLook(wLazyConversion);
    FormData fdLazyConversion = new FormData();
    fdLazyConversion.top = new FormAttachment(lastControl, margin);
    fdLazyConversion.left = new FormAttachment(middle, 0);
    fdLazyConversion.right = new FormAttachment(100, 0);
    wLazyConversion.setLayoutData(fdLazyConversion);
    lastControl = wLazyConversion;

    // header row?
    //
    Label wlHeaderPresent = new Label(shell, SWT.RIGHT);
    wlHeaderPresent.setText(BaseMessages.getString(PKG, "FixedInputDialog.HeaderPresent.Label"));
    props.setLook(wlHeaderPresent);
    FormData fdlHeaderPresent = new FormData();
    fdlHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdlHeaderPresent.left = new FormAttachment(0, 0);
    fdlHeaderPresent.right = new FormAttachment(middle, -margin);
    wlHeaderPresent.setLayoutData(fdlHeaderPresent);
    wHeaderPresent = new Button(shell, SWT.CHECK);
    props.setLook(wHeaderPresent);
    FormData fdHeaderPresent = new FormData();
    fdHeaderPresent.top = new FormAttachment(lastControl, margin);
    fdHeaderPresent.left = new FormAttachment(middle, 0);
    fdHeaderPresent.right = new FormAttachment(100, 0);
    wHeaderPresent.setLayoutData(fdHeaderPresent);
    lastControl = wHeaderPresent;

    // running in parallel?
    //
    Label wlRunningInParallel = new Label(shell, SWT.RIGHT);
    wlRunningInParallel.setText(
        BaseMessages.getString(PKG, "FixedInputDialog.RunningInParallel.Label"));
    props.setLook(wlRunningInParallel);
    FormData fdlRunningInParallel = new FormData();
    fdlRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdlRunningInParallel.left = new FormAttachment(0, 0);
    fdlRunningInParallel.right = new FormAttachment(middle, -margin);
    wlRunningInParallel.setLayoutData(fdlRunningInParallel);
    wRunningInParallel = new Button(shell, SWT.CHECK);
    props.setLook(wRunningInParallel);
    FormData fdRunningInParallel = new FormData();
    fdRunningInParallel.top = new FormAttachment(lastControl, margin);
    fdRunningInParallel.left = new FormAttachment(middle, 0);
    wRunningInParallel.setLayoutData(fdRunningInParallel);

    // The file type...
    //
    wlFileType = new Label(shell, SWT.RIGHT);
    wlFileType.setText(BaseMessages.getString(PKG, "FixedInputDialog.FileType.Label"));
    wlFileType.setToolTipText(BaseMessages.getString(PKG, "FixedInputDialog.FileType.ToolTip"));
    props.setLook(wlFileType);
    FormData fdlFileType = new FormData();
    fdlFileType.top = new FormAttachment(lastControl, margin);
    fdlFileType.left = new FormAttachment(wRunningInParallel, margin * 2);
    wlFileType.setLayoutData(fdlFileType);
    wFileType = new CCombo(shell, SWT.BORDER | SWT.READ_ONLY);
    wFileType.setToolTipText(BaseMessages.getString(PKG, "FixedInputDialog.FileType.ToolTip"));
    props.setLook(wFileType);
    wFileType.setItems(FixedInputMeta.fileTypeDesc);
    FormData fdFileType = new FormData();
    fdFileType.top = new FormAttachment(lastControl, margin);
    fdFileType.left = new FormAttachment(wlFileType, margin);
    fdFileType.right = new FormAttachment(100, 0);
    wFileType.setLayoutData(fdFileType);
    lastControl = wFileType;

    wRunningInParallel.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent event) {
            enableFields();
          }
        });

    Label wlEncoding = new Label(shell, SWT.RIGHT);
    wlEncoding.setText(BaseMessages.getString(PKG, "FixedInputDialog.Encoding.Label"));
    props.setLook(wlEncoding);
    FormData fdlEncoding = new FormData();
    fdlEncoding.left = new FormAttachment(0, 0);
    fdlEncoding.top = new FormAttachment(lastControl, margin);
    fdlEncoding.right = new FormAttachment(middle, -margin);
    wlEncoding.setLayoutData(fdlEncoding);
    wEncoding = new ComboVar(transMeta, shell, SWT.BORDER | SWT.READ_ONLY);
    wEncoding.setEditable(true);
    props.setLook(wEncoding);
    wEncoding.addModifyListener(lsMod);
    FormData fdEncoding = new FormData();
    fdEncoding.left = new FormAttachment(middle, 0);
    fdEncoding.top = new FormAttachment(lastControl, margin);
    fdEncoding.right = new FormAttachment(100, 0);
    wEncoding.setLayoutData(fdEncoding);
    lastControl = wEncoding;

    wEncoding.addFocusListener(
        new FocusListener() {
          public void focusLost(org.eclipse.swt.events.FocusEvent e) {}

          public void focusGained(org.eclipse.swt.events.FocusEvent e) {
            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
            shell.setCursor(busy);
            setEncodings();
            shell.setCursor(null);
            busy.dispose();
          }
        });

    wlAddResult = new Label(shell, SWT.RIGHT);
    wlAddResult.setText(BaseMessages.getString(PKG, "FixedInputDialog.AddResult.Label"));
    props.setLook(wlAddResult);
    fdlAddResult = new FormData();
    fdlAddResult.left = new FormAttachment(0, 0);
    fdlAddResult.top = new FormAttachment(lastControl, margin);
    fdlAddResult.right = new FormAttachment(middle, -margin);
    wlAddResult.setLayoutData(fdlAddResult);
    wAddResult = new Button(shell, SWT.CHECK);
    props.setLook(wAddResult);
    wAddResult.setToolTipText(BaseMessages.getString(PKG, "FixedInputDialog.AddResult.Tooltip"));
    fdAddResult = new FormData();
    fdAddResult.left = new FormAttachment(middle, 0);
    fdAddResult.top = new FormAttachment(lastControl, margin);
    wAddResult.setLayoutData(fdAddResult);
    lastControl = wAddResult;

    // Some buttons first, so that the dialog scales nicely...
    //
    wOK = new Button(shell, SWT.PUSH);
    wOK.setText(BaseMessages.getString(PKG, "System.Button.OK"));
    wPreview = new Button(shell, SWT.PUSH);
    wPreview.setText(BaseMessages.getString(PKG, "System.Button.Preview"));
    wGet = new Button(shell, SWT.PUSH);
    wGet.setText(BaseMessages.getString(PKG, "System.Button.GetFields"));
    wCancel = new Button(shell, SWT.PUSH);
    wCancel.setText(BaseMessages.getString(PKG, "System.Button.Cancel"));

    setButtonPositions(new Button[] {wOK, wGet, wPreview, wCancel}, margin, null);

    // Fields
    ColumnInfo[] colinf =
        new ColumnInfo[] {
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.NameColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.TypeColumn.Column"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMetaFactory.getValueMetaNames(),
              true),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.FormatColumn.Column"),
              ColumnInfo.COLUMN_TYPE_FORMAT,
              2),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.WidthColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.LengthColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.PrecisionColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.CurrencyColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.DecimalColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.GroupColumn.Column"),
              ColumnInfo.COLUMN_TYPE_TEXT,
              false),
          new ColumnInfo(
              BaseMessages.getString(PKG, "FixedInputDialog.TrimColumn.Column"),
              ColumnInfo.COLUMN_TYPE_CCOMBO,
              ValueMetaString.trimTypeDesc),
        };

    colinf[2].setComboValuesSelectionListener(
        new ComboValuesSelectionListener() {

          public String[] getComboValues(TableItem tableItem, int rowNr, int colNr) {
            String[] comboValues = new String[] {};
            int type = ValueMetaFactory.getIdForValueMeta(tableItem.getText(colNr - 1));
            switch (type) {
              case ValueMetaInterface.TYPE_DATE:
                comboValues = Const.getDateFormats();
                break;
              case ValueMetaInterface.TYPE_INTEGER:
              case ValueMetaInterface.TYPE_BIGNUMBER:
              case ValueMetaInterface.TYPE_NUMBER:
                comboValues = Const.getNumberFormats();
                break;
              default:
                break;
            }
            return comboValues;
          }
        });

    wFields =
        new TableView(transMeta, shell, SWT.FULL_SELECTION | SWT.MULTI, colinf, 1, lsMod, props);

    FormData fdFields = new FormData();
    fdFields.top = new FormAttachment(lastControl, margin * 2);
    fdFields.bottom = new FormAttachment(wOK, -margin * 2);
    fdFields.left = new FormAttachment(0, 0);
    fdFields.right = new FormAttachment(100, 0);
    wFields.setLayoutData(fdFields);

    // Add listeners
    lsCancel =
        new Listener() {
          public void handleEvent(Event e) {
            cancel();
          }
        };
    lsOK =
        new Listener() {
          public void handleEvent(Event e) {
            ok();
          }
        };
    lsGet =
        new Listener() {
          public void handleEvent(Event e) {
            getFixed();
          }
        };
    lsPreview =
        new Listener() {
          public void handleEvent(Event e) {
            preview();
          }
        };

    wCancel.addListener(SWT.Selection, lsCancel);
    wOK.addListener(SWT.Selection, lsOK);
    wPreview.addListener(SWT.Selection, lsPreview);
    wGet.addListener(SWT.Selection, lsGet);

    lsDef =
        new SelectionAdapter() {
          public void widgetDefaultSelected(SelectionEvent e) {
            ok();
          }
        };

    wStepname.addSelectionListener(lsDef);
    wFilename.addSelectionListener(lsDef);
    wLineWidth.addSelectionListener(lsDef);
    wBufferSize.addSelectionListener(lsDef);

    // Listen to the browse button next to the file name
    wbbFilename.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(shell, SWT.OPEN);
            dialog.setFilterExtensions(new String[] {"*.txt", "*"});
            if (wFilename.getText() != null) {
              String fname = transMeta.environmentSubstitute(wFilename.getText());
              dialog.setFileName(fname);
            }

            dialog.setFilterNames(
                new String[] {
                  BaseMessages.getString(PKG, "System.FileType.TextFiles"),
                  BaseMessages.getString(PKG, "System.FileType.AllFiles")
                });

            if (dialog.open() != null) {
              String str =
                  dialog.getFilterPath()
                      + System.getProperty("file.separator")
                      + dialog.getFileName();
              wFilename.setText(str);
            }
          }
        });

    // Detect X or ALT-F4 or something that kills this window...
    shell.addShellListener(
        new ShellAdapter() {
          public void shellClosed(ShellEvent e) {
            cancel();
          }
        });

    // Set the shell size, based upon previous time...
    setSize();

    getData();
    inputMeta.setChanged(changed);

    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    return stepname;
  }
 public void init(int index) throws KettlePluginException {
   m_tmpValueMeta = ValueMetaFactory.createValueMeta(ValueMeta.getType(m_kettleType));
   m_outputIndex = index;
 }
Пример #14
0
  public void readRep(
      Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases)
      throws KettleException {
    try {
      fileType = rep.getStepAttributeString(id_step, "file_type");
      section = rep.getStepAttributeString(id_step, "section");
      encoding = rep.getStepAttributeString(id_step, "encoding");
      includeIniSection = rep.getStepAttributeBoolean(id_step, "ini_section");
      iniSectionField = rep.getStepAttributeString(id_step, "ini_section_field");
      includeFilename = rep.getStepAttributeBoolean(id_step, "include");
      filenameField = rep.getStepAttributeString(id_step, "include_field");
      dynamicFilenameField = rep.getStepAttributeString(id_step, "filename_Field");
      includeRowNumber = rep.getStepAttributeBoolean(id_step, "rownum");

      String addresult = rep.getStepAttributeString(id_step, "isaddresult");
      if (Utils.isEmpty(addresult)) {
        isaddresult = true;
      } else {
        isaddresult = rep.getStepAttributeBoolean(id_step, "isaddresult");
      }

      filefield = rep.getStepAttributeBoolean(id_step, "filefield");
      rowNumberField = rep.getStepAttributeString(id_step, "rownum_field");
      resetRowNumber = rep.getStepAttributeBoolean(id_step, "reset_rownumber");
      resolvevaluevariable = rep.getStepAttributeBoolean(id_step, "resolve_value_variable");

      rowLimit = rep.getStepAttributeInteger(id_step, "limit");
      int nrFiles = rep.countNrStepAttributes(id_step, "file_name");
      int nrFields = rep.countNrStepAttributes(id_step, "field_name");

      allocate(nrFiles, nrFields);

      for (int i = 0; i < nrFiles; i++) {
        fileName[i] = rep.getStepAttributeString(id_step, i, "file_name");
        fileMask[i] = rep.getStepAttributeString(id_step, i, "file_mask");
        excludeFileMask[i] = rep.getStepAttributeString(id_step, i, "exclude_file_mask");
        fileRequired[i] = rep.getStepAttributeString(id_step, i, "file_required");
        if (!YES.equalsIgnoreCase(fileRequired[i])) {
          fileRequired[i] = RequiredFilesCode[0];
        }
        includeSubFolders[i] = rep.getStepAttributeString(id_step, i, "include_subfolders");
        if (!YES.equalsIgnoreCase(includeSubFolders[i])) {
          includeSubFolders[i] = RequiredFilesCode[0];
        }
      }

      for (int i = 0; i < nrFields; i++) {
        PropertyInputField field = new PropertyInputField();

        field.setName(rep.getStepAttributeString(id_step, i, "field_name"));
        field.setColumn(
            PropertyInputField.getColumnByCode(
                rep.getStepAttributeString(id_step, i, "field_column")));
        field.setType(
            ValueMetaFactory.getIdForValueMeta(
                rep.getStepAttributeString(id_step, i, "field_type")));
        field.setFormat(rep.getStepAttributeString(id_step, i, "field_format"));
        field.setCurrencySymbol(rep.getStepAttributeString(id_step, i, "field_currency"));
        field.setDecimalSymbol(rep.getStepAttributeString(id_step, i, "field_decimal"));
        field.setGroupSymbol(rep.getStepAttributeString(id_step, i, "field_group"));
        field.setLength((int) rep.getStepAttributeInteger(id_step, i, "field_length"));
        field.setPrecision((int) rep.getStepAttributeInteger(id_step, i, "field_precision"));
        field.setTrimType(
            PropertyInputField.getTrimTypeByCode(
                rep.getStepAttributeString(id_step, i, "field_trim_type")));
        field.setRepeated(rep.getStepAttributeBoolean(id_step, i, "field_repeat"));

        inputFields[i] = field;
      }
      shortFileFieldName = rep.getStepAttributeString(id_step, "shortFileFieldName");
      pathFieldName = rep.getStepAttributeString(id_step, "pathFieldName");
      hiddenFieldName = rep.getStepAttributeString(id_step, "hiddenFieldName");
      lastModificationTimeFieldName =
          rep.getStepAttributeString(id_step, "lastModificationTimeFieldName");
      uriNameFieldName = rep.getStepAttributeString(id_step, "uriNameFieldName");
      rootUriNameFieldName = rep.getStepAttributeString(id_step, "rootUriNameFieldName");
      extensionFieldName = rep.getStepAttributeString(id_step, "extensionFieldName");
      sizeFieldName = rep.getStepAttributeString(id_step, "sizeFieldName");
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(PKG, "PropertyInputMeta.Exception.ErrorReadingRepository"), e);
    }
  }
Пример #15
0
  public void getFields(
      RowMetaInterface r,
      String name,
      RowMetaInterface[] info,
      StepMeta nextStep,
      VariableSpace space,
      Repository repository,
      IMetaStore metaStore)
      throws KettleStepException {

    int i;
    for (i = 0; i < inputFields.length; i++) {
      PropertyInputField field = inputFields[i];

      int type = field.getType();
      if (type == ValueMetaInterface.TYPE_NONE) {
        type = ValueMetaInterface.TYPE_STRING;
      }
      try {
        ValueMetaInterface v =
            ValueMetaFactory.createValueMeta(space.environmentSubstitute(field.getName()), type);
        v.setLength(field.getLength());
        v.setPrecision(field.getPrecision());
        v.setOrigin(name);
        v.setConversionMask(field.getFormat());
        v.setDecimalSymbol(field.getDecimalSymbol());
        v.setGroupingSymbol(field.getGroupSymbol());
        v.setCurrencySymbol(field.getCurrencySymbol());
        r.addValueMeta(v);
      } catch (Exception e) {
        throw new KettleStepException(e);
      }
    }
    String realFilenameField = space.environmentSubstitute(filenameField);
    if (includeFilename && !Utils.isEmpty(realFilenameField)) {
      ValueMetaInterface v = new ValueMetaString(realFilenameField);
      v.setLength(500);
      v.setPrecision(-1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    String realRowNumberField = space.environmentSubstitute(rowNumberField);
    if (includeRowNumber && !Utils.isEmpty(realRowNumberField)) {
      ValueMetaInterface v = new ValueMetaInteger(realRowNumberField);
      v.setLength(ValueMetaInterface.DEFAULT_INTEGER_LENGTH, 0);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    String realSectionField = space.environmentSubstitute(iniSectionField);
    if (includeIniSection && !Utils.isEmpty(realSectionField)) {
      ValueMetaInterface v = new ValueMetaString(realSectionField);
      v.setLength(500);
      v.setPrecision(-1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    // Add additional fields

    if (getShortFileNameField() != null && getShortFileNameField().length() > 0) {
      ValueMetaInterface v =
          new ValueMetaString(space.environmentSubstitute(getShortFileNameField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getExtensionField() != null && getExtensionField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getExtensionField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getPathField() != null && getPathField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getPathField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getSizeField() != null && getSizeField().length() > 0) {
      ValueMetaInterface v = new ValueMetaInteger(space.environmentSubstitute(getSizeField()));
      v.setOrigin(name);
      v.setLength(9);
      r.addValueMeta(v);
    }
    if (isHiddenField() != null && isHiddenField().length() > 0) {
      ValueMetaInterface v = new ValueMetaBoolean(space.environmentSubstitute(isHiddenField()));
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (getLastModificationDateField() != null && getLastModificationDateField().length() > 0) {
      ValueMetaInterface v =
          new ValueMetaDate(space.environmentSubstitute(getLastModificationDateField()));
      v.setOrigin(name);
      r.addValueMeta(v);
    }
    if (getUriField() != null && getUriField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getUriField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }

    if (getRootUriField() != null && getRootUriField().length() > 0) {
      ValueMetaInterface v = new ValueMetaString(space.environmentSubstitute(getRootUriField()));
      v.setLength(100, -1);
      v.setOrigin(name);
      r.addValueMeta(v);
    }
  }
Пример #16
0
  private void readData(Node stepnode) throws KettleXMLException {
    try {
      fileType = XMLHandler.getTagValue(stepnode, "file_type");
      encoding = XMLHandler.getTagValue(stepnode, "encoding");
      includeFilename = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "include"));
      filenameField = XMLHandler.getTagValue(stepnode, "include_field");
      includeRowNumber = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "rownum"));

      String addresult = XMLHandler.getTagValue(stepnode, "isaddresult");
      if (Utils.isEmpty(addresult)) {
        isaddresult = true;
      } else {
        isaddresult = "Y".equalsIgnoreCase(addresult);
      }
      section = XMLHandler.getTagValue(stepnode, "section");
      iniSectionField = XMLHandler.getTagValue(stepnode, "ini_section_field");
      includeIniSection = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "ini_section"));
      filefield = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "filefield"));
      rowNumberField = XMLHandler.getTagValue(stepnode, "rownum_field");
      dynamicFilenameField = XMLHandler.getTagValue(stepnode, "filename_Field");
      resetRowNumber = "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "resetrownumber"));
      resolvevaluevariable =
          "Y".equalsIgnoreCase(XMLHandler.getTagValue(stepnode, "resolvevaluevariable"));
      Node filenode = XMLHandler.getSubNode(stepnode, "file");
      Node fields = XMLHandler.getSubNode(stepnode, "fields");
      int nrFiles = XMLHandler.countNodes(filenode, "name");
      int nrFields = XMLHandler.countNodes(fields, "field");

      allocate(nrFiles, nrFields);

      for (int i = 0; i < nrFiles; i++) {
        Node filenamenode = XMLHandler.getSubNodeByNr(filenode, "name", i);
        Node filemasknode = XMLHandler.getSubNodeByNr(filenode, "filemask", i);
        Node excludefilemasknode = XMLHandler.getSubNodeByNr(filenode, "exclude_filemask", i);
        Node fileRequirednode = XMLHandler.getSubNodeByNr(filenode, "file_required", i);
        Node includeSubFoldersnode = XMLHandler.getSubNodeByNr(filenode, "include_subfolders", i);
        fileName[i] = XMLHandler.getNodeValue(filenamenode);
        fileMask[i] = XMLHandler.getNodeValue(filemasknode);
        excludeFileMask[i] = XMLHandler.getNodeValue(excludefilemasknode);
        fileRequired[i] = XMLHandler.getNodeValue(fileRequirednode);
        includeSubFolders[i] = XMLHandler.getNodeValue(includeSubFoldersnode);
      }

      for (int i = 0; i < nrFields; i++) {
        Node fnode = XMLHandler.getSubNodeByNr(fields, "field", i);
        inputFields[i] = new PropertyInputField();

        inputFields[i].setName(XMLHandler.getTagValue(fnode, "name"));
        inputFields[i].setColumn(getColumnByCode(XMLHandler.getTagValue(fnode, "column")));
        inputFields[i].setType(
            ValueMetaFactory.getIdForValueMeta(XMLHandler.getTagValue(fnode, "type")));
        inputFields[i].setLength(Const.toInt(XMLHandler.getTagValue(fnode, "length"), -1));
        inputFields[i].setPrecision(Const.toInt(XMLHandler.getTagValue(fnode, "precision"), -1));
        String srepeat = XMLHandler.getTagValue(fnode, "repeat");
        inputFields[i].setTrimType(getTrimTypeByCode(XMLHandler.getTagValue(fnode, "trim_type")));

        if (srepeat != null) {
          inputFields[i].setRepeated(YES.equalsIgnoreCase(srepeat));
        } else {
          inputFields[i].setRepeated(false);
        }

        inputFields[i].setFormat(XMLHandler.getTagValue(fnode, "format"));
        inputFields[i].setCurrencySymbol(XMLHandler.getTagValue(fnode, "currency"));
        inputFields[i].setDecimalSymbol(XMLHandler.getTagValue(fnode, "decimal"));
        inputFields[i].setGroupSymbol(XMLHandler.getTagValue(fnode, "group"));
      }

      // Is there a limit on the number of rows we process?
      rowLimit = Const.toLong(XMLHandler.getTagValue(stepnode, "limit"), 0L);
      shortFileFieldName = XMLHandler.getTagValue(stepnode, "shortFileFieldName");
      pathFieldName = XMLHandler.getTagValue(stepnode, "pathFieldName");
      hiddenFieldName = XMLHandler.getTagValue(stepnode, "hiddenFieldName");
      lastModificationTimeFieldName =
          XMLHandler.getTagValue(stepnode, "lastModificationTimeFieldName");
      uriNameFieldName = XMLHandler.getTagValue(stepnode, "uriNameFieldName");
      rootUriNameFieldName = XMLHandler.getTagValue(stepnode, "rootUriNameFieldName");
      extensionFieldName = XMLHandler.getTagValue(stepnode, "extensionFieldName");
      sizeFieldName = XMLHandler.getTagValue(stepnode, "sizeFieldName");

    } catch (Exception e) {
      throw new KettleXMLException("Unable to load step info from XML", e);
    }
  }