Search in sources :

Example 1 with EditRowsDialog

use of org.apache.hop.ui.testing.EditRowsDialog in project hop by apache.

the class TestingGuiPlugin method setInputDataSetOnTransform.

private boolean setInputDataSetOnTransform(IVariables variables, IHopMetadataProvider metadataProvider, PipelineMeta pipelineMeta, TransformMeta transformMeta, PipelineUnitTest unitTest, DataSet dataSet) throws HopPluginException, HopValueException, HopException {
    HopGui hopGui = HopGui.getInstance();
    // Now we need to map the fields from the input data set to the transform...
    // 
    IRowMeta setFields = dataSet.getSetRowMeta();
    IRowMeta transformFields;
    try {
        transformFields = pipelineMeta.getTransformFields(variables, transformMeta);
    } catch (HopTransformException e) {
        // Driver or input problems...
        // 
        transformFields = new RowMeta();
    }
    if (transformFields.isEmpty()) {
        transformFields = setFields.clone();
    }
    String[] transformFieldNames = transformFields.getFieldNames();
    String[] setFieldNames = setFields.getFieldNames();
    EnterMappingDialog mappingDialog = new EnterMappingDialog(hopGui.getShell(), setFieldNames, transformFieldNames);
    List<SourceToTargetMapping> mappings = mappingDialog.open();
    if (mappings == null) {
        return false;
    }
    // Ask about the sort order...
    // Show the mapping as well as an order column
    // 
    IRowMeta sortMeta = new RowMeta();
    sortMeta.addValueMeta(new ValueMetaString(BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Column.SetField")));
    List<Object[]> sortData = new ArrayList<>();
    for (String setFieldName : setFieldNames) {
        sortData.add(new Object[] { setFieldName });
    }
    EditRowsDialog orderDialog = new EditRowsDialog(hopGui.getShell(), SWT.NONE, BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Title"), BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Message"), sortMeta, sortData);
    List<Object[]> orderMappings = orderDialog.open();
    if (orderMappings == null) {
        return false;
    }
    // Modify the test
    // 
    // Remove other crap on the transform...
    // 
    unitTest.removeInputAndGoldenDataSets(transformMeta.getName());
    PipelineUnitTestSetLocation inputLocation = new PipelineUnitTestSetLocation();
    unitTest.getInputDataSets().add(inputLocation);
    inputLocation.setTransformName(transformMeta.getName());
    inputLocation.setDataSetName(dataSet.getName());
    List<PipelineUnitTestFieldMapping> fieldMappings = inputLocation.getFieldMappings();
    fieldMappings.clear();
    for (SourceToTargetMapping mapping : mappings) {
        String transformFieldName = mapping.getTargetString(transformFieldNames);
        String setFieldName = mapping.getSourceString(setFieldNames);
        fieldMappings.add(new PipelineUnitTestFieldMapping(transformFieldName, setFieldName));
    }
    List<String> setFieldOrder = new ArrayList<>();
    for (Object[] orderMapping : orderMappings) {
        String setFieldName = sortMeta.getString(orderMapping, 0);
        setFieldOrder.add(setFieldName);
    }
    inputLocation.setFieldOrder(setFieldOrder);
    // Save the unit test...
    // 
    saveUnitTest(variables, metadataProvider, unitTest, pipelineMeta);
    transformMeta.setChanged();
    return true;
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) EnterMappingDialog(org.apache.hop.ui.core.dialog.EnterMappingDialog) ArrayList(java.util.ArrayList) HopTransformException(org.apache.hop.core.exception.HopTransformException) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) EditRowsDialog(org.apache.hop.ui.testing.EditRowsDialog) SourceToTargetMapping(org.apache.hop.core.SourceToTargetMapping) HopGui(org.apache.hop.ui.hopgui.HopGui)

Example 2 with EditRowsDialog

use of org.apache.hop.ui.testing.EditRowsDialog in project hop by apache.

the class TestingGuiPlugin method setGoldenDataSetOnTransform.

private boolean setGoldenDataSetOnTransform(IVariables variables, IHopMetadataProvider metadataProvider, PipelineMeta pipelineMeta, TransformMeta transformMeta, PipelineUnitTest unitTest, DataSet dataSet) throws HopPluginException, HopValueException, HopException {
    // Now we need to map the fields from the transform to golden data set fields...
    // 
    IRowMeta transformFields;
    try {
        transformFields = pipelineMeta.getPrevTransformFields(variables, transformMeta);
    } catch (HopTransformException e) {
        // Ignore error: issues with not being able to get fields because of the unit test
        // running in a different environment.
        // 
        transformFields = new RowMeta();
    }
    IRowMeta setFields = dataSet.getSetRowMeta();
    String[] transformFieldNames = transformFields.getFieldNames();
    String[] setFieldNames = setFields.getFieldNames();
    EnterMappingDialog mappingDialog = new EnterMappingDialog(HopGui.getInstance().getShell(), transformFieldNames, setFieldNames);
    List<SourceToTargetMapping> mappings = mappingDialog.open();
    if (mappings == null) {
        return false;
    }
    // Ask about the sort order...
    // Show the mapping as well as an order column
    // 
    IRowMeta sortMeta = new RowMeta();
    sortMeta.addValueMeta(new ValueMetaString(BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Column.SetField")));
    List<Object[]> sortData = new ArrayList<>();
    for (String setFieldName : setFieldNames) {
        sortData.add(new Object[] { setFieldName });
    }
    EditRowsDialog orderDialog = new EditRowsDialog(HopGui.getInstance().getShell(), SWT.NONE, BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Title"), BaseMessages.getString(PKG, "TestingGuiPlugin.SortOrder.Message"), sortMeta, sortData);
    List<Object[]> orderMappings = orderDialog.open();
    if (orderMappings == null) {
        return false;
    }
    // Modify the test
    // 
    // Remove golden locations and input locations on the transform to avoid duplicates
    // 
    unitTest.removeInputAndGoldenDataSets(transformMeta.getName());
    PipelineUnitTestSetLocation goldenLocation = new PipelineUnitTestSetLocation();
    unitTest.getGoldenDataSets().add(goldenLocation);
    goldenLocation.setTransformName(transformMeta.getName());
    goldenLocation.setDataSetName(dataSet.getName());
    List<PipelineUnitTestFieldMapping> fieldMappings = goldenLocation.getFieldMappings();
    fieldMappings.clear();
    for (SourceToTargetMapping mapping : mappings) {
        fieldMappings.add(new PipelineUnitTestFieldMapping(mapping.getSourceString(transformFieldNames), mapping.getTargetString(setFieldNames)));
    }
    List<String> setFieldOrder = new ArrayList<>();
    for (Object[] orderMapping : orderMappings) {
        setFieldOrder.add(sortMeta.getString(orderMapping, 0));
    }
    goldenLocation.setFieldOrder(setFieldOrder);
    // Save the unit test...
    // 
    saveUnitTest(variables, metadataProvider, unitTest, pipelineMeta);
    transformMeta.setChanged();
    return true;
}
Also used : ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) RowMeta(org.apache.hop.core.row.RowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) IRowMeta(org.apache.hop.core.row.IRowMeta) EnterMappingDialog(org.apache.hop.ui.core.dialog.EnterMappingDialog) ArrayList(java.util.ArrayList) HopTransformException(org.apache.hop.core.exception.HopTransformException) ValueMetaString(org.apache.hop.core.row.value.ValueMetaString) EditRowsDialog(org.apache.hop.ui.testing.EditRowsDialog) SourceToTargetMapping(org.apache.hop.core.SourceToTargetMapping)

Aggregations

ArrayList (java.util.ArrayList)2 SourceToTargetMapping (org.apache.hop.core.SourceToTargetMapping)2 HopTransformException (org.apache.hop.core.exception.HopTransformException)2 IRowMeta (org.apache.hop.core.row.IRowMeta)2 RowMeta (org.apache.hop.core.row.RowMeta)2 ValueMetaString (org.apache.hop.core.row.value.ValueMetaString)2 EnterMappingDialog (org.apache.hop.ui.core.dialog.EnterMappingDialog)2 EditRowsDialog (org.apache.hop.ui.testing.EditRowsDialog)2 HopGui (org.apache.hop.ui.hopgui.HopGui)1