Пример #1
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);
    }
  }
Пример #2
0
  public void saveRep(
      Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step)
      throws KettleException {
    try {
      rep.saveStepAttribute(id_transformation, id_step, "file_type", fileType);
      rep.saveStepAttribute(id_transformation, id_step, "section", section);
      rep.saveStepAttribute(id_transformation, id_step, "encoding", encoding);
      rep.saveStepAttribute(id_transformation, id_step, "ini_section", includeIniSection);
      rep.saveStepAttribute(id_transformation, id_step, "ini_section_field", iniSectionField);
      rep.saveStepAttribute(id_transformation, id_step, "include", includeFilename);
      rep.saveStepAttribute(id_transformation, id_step, "include_field", filenameField);
      rep.saveStepAttribute(id_transformation, id_step, "rownum", includeRowNumber);
      rep.saveStepAttribute(id_transformation, id_step, "isaddresult", isaddresult);
      rep.saveStepAttribute(id_transformation, id_step, "filefield", filefield);
      rep.saveStepAttribute(id_transformation, id_step, "filename_Field", dynamicFilenameField);
      rep.saveStepAttribute(id_transformation, id_step, "rownum_field", rowNumberField);
      rep.saveStepAttribute(id_transformation, id_step, "limit", rowLimit);
      rep.saveStepAttribute(id_transformation, id_step, "reset_rownumber", resetRowNumber);
      rep.saveStepAttribute(
          id_transformation, id_step, "resolve_value_variable", resolvevaluevariable);
      rep.saveStepAttribute(id_transformation, id_step, "sizeFieldName", sizeFieldName);

      for (int i = 0; i < fileName.length; i++) {
        rep.saveStepAttribute(id_transformation, id_step, i, "file_name", fileName[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "file_mask", fileMask[i]);
        rep.saveStepAttribute(
            id_transformation, id_step, i, "exclude_file_mask", excludeFileMask[i]);
        rep.saveStepAttribute(id_transformation, id_step, i, "file_required", fileRequired[i]);
        rep.saveStepAttribute(
            id_transformation, id_step, i, "include_subfolders", includeSubFolders[i]);
      }

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

        rep.saveStepAttribute(id_transformation, id_step, i, "field_name", field.getName());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_column", field.getColumnCode());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_type", field.getTypeDesc());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_format", field.getFormat());
        rep.saveStepAttribute(
            id_transformation, id_step, i, "field_currency", field.getCurrencySymbol());
        rep.saveStepAttribute(
            id_transformation, id_step, i, "field_decimal", field.getDecimalSymbol());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_group", field.getGroupSymbol());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_length", field.getLength());
        rep.saveStepAttribute(
            id_transformation, id_step, i, "field_precision", field.getPrecision());
        rep.saveStepAttribute(
            id_transformation, id_step, i, "field_trim_type", field.getTrimTypeCode());
        rep.saveStepAttribute(id_transformation, id_step, i, "field_repeat", field.isRepeated());
      }
      rep.saveStepAttribute(id_transformation, id_step, "shortFileFieldName", shortFileFieldName);
      rep.saveStepAttribute(id_transformation, id_step, "pathFieldName", pathFieldName);
      rep.saveStepAttribute(id_transformation, id_step, "hiddenFieldName", hiddenFieldName);
      rep.saveStepAttribute(
          id_transformation,
          id_step,
          "lastModificationTimeFieldName",
          lastModificationTimeFieldName);
      rep.saveStepAttribute(id_transformation, id_step, "uriNameFieldName", uriNameFieldName);
      rep.saveStepAttribute(
          id_transformation, id_step, "rootUriNameFieldName", rootUriNameFieldName);
      rep.saveStepAttribute(id_transformation, id_step, "extensionFieldName", extensionFieldName);
    } catch (Exception e) {
      throw new KettleException(
          BaseMessages.getString(
              PKG, "PropertyInputMeta.Exception.ErrorSavingToRepository", "" + id_step),
          e);
    }
  }
Пример #3
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);
    }
  }