Search in sources :

Example 1 with GetXMLDataField

use of org.pentaho.di.trans.steps.getxmldata.GetXMLDataField in project pentaho-kettle by pentaho.

the class RepositoryUnitIT method testGetXMLDataMetaSaveAndReadRep.

/**
 * This test is to ensure that the metadata for the GetXMLData step is preserved when saving to a
 * repository. The test creates a GetXMLData step and saves it to the repository. Then the local
 * data is changed and the step is read back in from the repository. It is then asserted that the
 * field value(s) are equal to what was saved.
 *
 * Test method for
 * {@link org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta#readRep(org.pentaho.di.repository.Repository,
 * org.pentaho.di.repository.ObjectId, java.util.List, java.util.Map)}
 * . Test method for
 * {@link org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta#saveRep(org.pentaho.di.repository.Repository,
 * org.pentaho.di.repository.ObjectId, jorg.pentaho.di.repository.ObjectId)}
 * .
 */
@Test
public void testGetXMLDataMetaSaveAndReadRep() {
    // 
    // Create a new transformation...
    // 
    TransMeta transMeta = new TransMeta();
    transMeta.setName("getxmldata1");
    // 
    // Create a Get XML Data step
    // 
    String getXMLDataName = "get xml data step";
    GetXMLDataMeta gxdm = new GetXMLDataMeta();
    String getXMLDataPid = registry.getPluginId(StepPluginType.class, gxdm);
    StepMeta getXMLDataStep = new StepMeta(getXMLDataPid, getXMLDataName, gxdm);
    transMeta.addStep(getXMLDataStep);
    GetXMLDataField[] fields = new GetXMLDataField[1];
    for (int idx = 0; idx < fields.length; idx++) {
        fields[idx] = new GetXMLDataField();
    }
    fields[0].setName("objectid");
    fields[0].setXPath("ObjectID");
    fields[0].setElementType(GetXMLDataField.ELEMENT_TYPE_NODE);
    fields[0].setResultType(GetXMLDataField.RESULT_TYPE_TYPE_SINGLE_NODE);
    fields[0].setType(ValueMetaInterface.TYPE_STRING);
    fields[0].setFormat("");
    fields[0].setLength(-1);
    fields[0].setPrecision(-1);
    fields[0].setCurrencySymbol("");
    fields[0].setDecimalSymbol("");
    fields[0].setGroupSymbol("");
    fields[0].setTrimType(GetXMLDataField.TYPE_TRIM_NONE);
    gxdm.setDefault();
    gxdm.setEncoding("UTF-8");
    gxdm.setIsAFile(false);
    gxdm.setInFields(true);
    gxdm.setLoopXPath("/");
    gxdm.setXMLField("field1");
    gxdm.setInputFields(fields);
    try {
        // Now save the transformation and then read it back in
        transMeta.setRepository(repository);
        RepositoryDirectoryInterface repositoryDirectory = repository.findDirectory("/");
        transMeta.setRepositoryDirectory(repositoryDirectory);
        repository.transDelegate.saveTransformation(transMeta, "None", null, true);
        // Create a new placeholder meta and set the result type to something different than what was
        // saved,
        // to ensure the saveRep code is working correctly.
        GetXMLDataMeta newMeta = (GetXMLDataMeta) gxdm.clone();
        for (GetXMLDataField f : newMeta.getInputFields()) {
            f.setResultType(GetXMLDataField.RESULT_TYPE_VALUE_OF);
        }
        newMeta.readRep(repository, new MemoryMetaStore(), getXMLDataStep.getObjectId(), repository.getDatabases());
        // Check that the value of Result Type is what was saved in the repo
        assertEquals(newMeta.getInputFields()[0].getResultTypeCode(), "singlenode");
    } catch (KettleException e) {
        fail("Test failed due to exception: " + e.getLocalizedMessage());
    }
}
Also used : MemoryMetaStore(org.pentaho.metastore.stores.memory.MemoryMetaStore) KettleException(org.pentaho.di.core.exception.KettleException) GetXMLDataMeta(org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta) TransMeta(org.pentaho.di.trans.TransMeta) GetXMLDataField(org.pentaho.di.trans.steps.getxmldata.GetXMLDataField) StepMeta(org.pentaho.di.trans.step.StepMeta) Test(org.junit.Test)

Example 2 with GetXMLDataField

use of org.pentaho.di.trans.steps.getxmldata.GetXMLDataField in project pentaho-kettle by pentaho.

the class GetXMLDataDialog method getInfo.

private void getInfo(GetXMLDataMeta in) throws KettleException {
    // return value
    stepname = wStepname.getText();
    // copy info to TextFileInputMeta class (input)
    in.setRowLimit(Const.toLong(wLimit.getText(), 0L));
    in.setPrunePath(wPrunePath.getText());
    in.setLoopXPath(wLoopXPath.getText());
    in.setEncoding(wEncoding.getText());
    in.setFilenameField(wInclFilenameField.getText());
    in.setRowNumberField(wInclRownumField.getText());
    in.setAddResultFile(wAddResult.getSelection());
    in.setIncludeFilename(wInclFilename.getSelection());
    in.setIncludeRowNumber(wInclRownum.getSelection());
    in.setNamespaceAware(wNameSpaceAware.getSelection());
    in.setReadUrl(wreadUrl.getSelection());
    in.setIgnoreComments(wIgnoreComment.getSelection());
    in.setValidating(wValidating.getSelection());
    in.setuseToken(wuseToken.getSelection());
    in.setIgnoreEmptyFile(wIgnoreEmptyFile.getSelection());
    in.setdoNotFailIfNoFile(wdoNotFailIfNoFile.getSelection());
    in.setInFields(wXMLStreamField.getSelection());
    in.setIsAFile(wXMLIsAFile.getSelection());
    in.setXMLField(wXMLField.getText());
    int nrFiles = wFilenameList.getItemCount();
    int nrFields = wFields.nrNonEmpty();
    in.allocate(nrFiles, nrFields);
    in.setFileName(wFilenameList.getItems(0));
    in.setFileMask(wFilenameList.getItems(1));
    in.setExcludeFileMask(wFilenameList.getItems(2));
    in.setFileRequired(wFilenameList.getItems(3));
    in.setIncludeSubFolders(wFilenameList.getItems(4));
    for (int i = 0; i < nrFields; i++) {
        GetXMLDataField field = new GetXMLDataField();
        TableItem item = wFields.getNonEmpty(i);
        field.setName(item.getText(1));
        field.setXPath(item.getText(2));
        field.setElementType(GetXMLDataField.getElementTypeByDesc(item.getText(3)));
        field.setResultType(GetXMLDataField.getResultTypeByDesc(item.getText(4)));
        field.setType(ValueMeta.getType(item.getText(5)));
        field.setFormat(item.getText(6));
        field.setLength(Const.toInt(item.getText(7), -1));
        field.setPrecision(Const.toInt(item.getText(8), -1));
        field.setCurrencySymbol(item.getText(9));
        field.setDecimalSymbol(item.getText(10));
        field.setGroupSymbol(item.getText(11));
        field.setTrimType(GetXMLDataField.getTrimTypeByDesc(item.getText(12)));
        field.setRepeated(BaseMessages.getString(PKG, "System.Combo.Yes").equalsIgnoreCase(item.getText(13)));
        // CHECKSTYLE:Indentation:OFF
        in.getInputFields()[i] = field;
    }
    in.setShortFileNameField(wShortFileFieldName.getText());
    in.setPathField(wPathFieldName.getText());
    in.setIsHiddenField(wIsHiddenName.getText());
    in.setLastModificationDateField(wLastModificationTimeName.getText());
    in.setUriField(wUriName.getText());
    in.setRootUriField(wRootUriName.getText());
    in.setExtensionField(wExtensionFieldName.getText());
    in.setSizeField(wSizeFieldName.getText());
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) GetXMLDataField(org.pentaho.di.trans.steps.getxmldata.GetXMLDataField)

Example 3 with GetXMLDataField

use of org.pentaho.di.trans.steps.getxmldata.GetXMLDataField in project pentaho-kettle by pentaho.

the class GetXMLDataDialog method getData.

/**
 * Read the data from the TextFileInputMeta object and show it in this dialog.
 *
 * @param in
 *          The TextFileInputMeta object to obtain the data from.
 */
public void getData(GetXMLDataMeta in) {
    if (in.getFileName() != null) {
        wFilenameList.removeAll();
        for (int i = 0; i < in.getFileName().length; i++) {
            wFilenameList.add(new String[] { in.getFileName()[i], in.getFileMask()[i], in.getExludeFileMask()[i], in.getRequiredFilesDesc(in.getFileRequired()[i]), in.getRequiredFilesDesc(in.getIncludeSubFolders()[i]) });
        }
        wFilenameList.removeEmptyRows();
        wFilenameList.setRowNums();
        wFilenameList.optWidth(true);
    }
    wInclFilename.setSelection(in.includeFilename());
    wInclRownum.setSelection(in.includeRowNumber());
    wAddResult.setSelection(in.addResultFile());
    wNameSpaceAware.setSelection(in.isNamespaceAware());
    wreadUrl.setSelection(in.isReadUrl());
    wIgnoreComment.setSelection(in.isIgnoreComments());
    wValidating.setSelection(in.isValidating());
    wuseToken.setSelection(in.isuseToken());
    wIgnoreEmptyFile.setSelection(in.isIgnoreEmptyFile());
    wdoNotFailIfNoFile.setSelection(in.isdoNotFailIfNoFile());
    wXMLStreamField.setSelection(in.isInFields());
    wXMLIsAFile.setSelection(in.getIsAFile());
    if (in.getXMLField() != null) {
        wXMLField.setText(in.getXMLField());
    }
    if (in.getFilenameField() != null) {
        wInclFilenameField.setText(in.getFilenameField());
    }
    if (in.getRowNumberField() != null) {
        wInclRownumField.setText(in.getRowNumberField());
    }
    wLimit.setText("" + in.getRowLimit());
    if (in.getPrunePath() != null) {
        wPrunePath.setText(in.getPrunePath());
    }
    if (in.getLoopXPath() != null) {
        wLoopXPath.setText(in.getLoopXPath());
    }
    if (in.getEncoding() != null) {
        wEncoding.setText("" + in.getEncoding());
    } else {
        wEncoding.setText("UTF-8");
    }
    logDebug(BaseMessages.getString(PKG, "GetXMLDataDialog.Log.GettingFieldsInfo"));
    for (int i = 0; i < in.getInputFields().length; i++) {
        GetXMLDataField field = in.getInputFields()[i];
        if (field != null) {
            TableItem item = wFields.table.getItem(i);
            String name = field.getName();
            String xpath = field.getXPath();
            String element = field.getElementTypeDesc();
            String resulttype = field.getResultTypeDesc();
            String type = field.getTypeDesc();
            String format = field.getFormat();
            String length = "" + field.getLength();
            String prec = "" + field.getPrecision();
            String curr = field.getCurrencySymbol();
            String group = field.getGroupSymbol();
            String decim = field.getDecimalSymbol();
            String trim = field.getTrimTypeDesc();
            String rep = field.isRepeated() ? BaseMessages.getString(PKG, "System.Combo.Yes") : BaseMessages.getString(PKG, "System.Combo.No");
            if (name != null) {
                item.setText(1, name);
            }
            if (xpath != null) {
                item.setText(2, xpath);
            }
            if (element != null) {
                item.setText(3, element);
            }
            if (resulttype != null) {
                item.setText(4, resulttype);
            }
            if (type != null) {
                item.setText(5, type);
            }
            if (format != null) {
                item.setText(6, format);
            }
            if (length != null && !"-1".equals(length)) {
                item.setText(7, length);
            }
            if (prec != null && !"-1".equals(prec)) {
                item.setText(8, prec);
            }
            if (curr != null) {
                item.setText(9, curr);
            }
            if (decim != null) {
                item.setText(10, decim);
            }
            if (group != null) {
                item.setText(11, group);
            }
            if (trim != null) {
                item.setText(12, trim);
            }
            if (rep != null) {
                item.setText(13, rep);
            }
        }
    }
    wFields.removeEmptyRows();
    wFields.setRowNums();
    wFields.optWidth(true);
    if (in.getShortFileNameField() != null) {
        wShortFileFieldName.setText(in.getShortFileNameField());
    }
    if (in.getPathField() != null) {
        wPathFieldName.setText(in.getPathField());
    }
    if (in.isHiddenField() != null) {
        wIsHiddenName.setText(in.isHiddenField());
    }
    if (in.getLastModificationDateField() != null) {
        wLastModificationTimeName.setText(in.getLastModificationDateField());
    }
    if (in.getUriField() != null) {
        wUriName.setText(in.getUriField());
    }
    if (in.getRootUriField() != null) {
        wRootUriName.setText(in.getRootUriField());
    }
    if (in.getExtensionField() != null) {
        wExtensionFieldName.setText(in.getExtensionField());
    }
    if (in.getSizeField() != null) {
        wSizeFieldName.setText(in.getSizeField());
    }
    wStepname.selectAll();
    wStepname.setFocus();
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) GetXMLDataField(org.pentaho.di.trans.steps.getxmldata.GetXMLDataField)

Aggregations

GetXMLDataField (org.pentaho.di.trans.steps.getxmldata.GetXMLDataField)3 TableItem (org.eclipse.swt.widgets.TableItem)2 Test (org.junit.Test)1 KettleException (org.pentaho.di.core.exception.KettleException)1 TransMeta (org.pentaho.di.trans.TransMeta)1 StepMeta (org.pentaho.di.trans.step.StepMeta)1 GetXMLDataMeta (org.pentaho.di.trans.steps.getxmldata.GetXMLDataMeta)1 MemoryMetaStore (org.pentaho.metastore.stores.memory.MemoryMetaStore)1