Search in sources :

Example 1 with PipelineUnitTestSetLocationDialog

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

the class LocationMouseDoubleClickExtensionPoint method callExtensionPoint.

@Override
public void callExtensionPoint(ILogChannel log, IVariables variables, HopGuiPipelineGraphExtension pipelineGraphExtension) throws HopException {
    HopGuiPipelineGraph pipelineGraph = pipelineGraphExtension.getPipelineGraph();
    PipelineMeta pipelineMeta = pipelineGraph.getPipelineMeta();
    PipelineUnitTest unitTest = TestingGuiPlugin.getCurrentUnitTest(pipelineMeta);
    if (unitTest == null) {
        return;
    }
    HopGui hopGui = HopGui.getInstance();
    try {
        List<DataSet> dataSets = hopGui.getMetadataProvider().getSerializer(DataSet.class).loadAll();
        Map<String, IRowMeta> transformFieldsMap = new HashMap<>();
        for (TransformMeta transformMeta : pipelineMeta.getTransforms()) {
            try {
                IRowMeta transformFields = pipelineMeta.getTransformFields(pipelineGraph.getVariables(), transformMeta);
                transformFieldsMap.put(transformMeta.getName(), transformFields);
            } catch (Exception e) {
            // Ignore GUI errors...
            }
        }
        // Find the location that was double clicked on...
        // 
        MouseEvent e = pipelineGraphExtension.getEvent();
        Point point = pipelineGraphExtension.getPoint();
        if (e.button == 1 || e.button == 2) {
            AreaOwner areaOwner = pipelineGraph.getVisibleAreaOwner(point.x, point.y);
            if (areaOwner != null && areaOwner.getAreaType() != null) {
                // 
                if (DataSetConst.AREA_DRAWN_INPUT_DATA_SET.equals(areaOwner.getParent())) {
                    // Open the dataset double clicked on...
                    // 
                    String transformName = (String) areaOwner.getOwner();
                    PipelineUnitTestSetLocation inputLocation = unitTest.findInputLocation(transformName);
                    if (inputLocation != null) {
                        PipelineUnitTestSetLocationDialog dialog = new PipelineUnitTestSetLocationDialog(hopGui.getShell(), variables, hopGui.getMetadataProvider(), inputLocation, dataSets, transformFieldsMap);
                        if (dialog.open()) {
                            hopGui.getMetadataProvider().getSerializer(PipelineUnitTest.class).save(unitTest);
                            pipelineGraph.updateGui();
                        }
                    }
                } else if (DataSetConst.AREA_DRAWN_GOLDEN_DATA_SET.equals(areaOwner.getParent())) {
                    // Open the dataset double clicked on...
                    // 
                    String transformName = (String) areaOwner.getOwner();
                    PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
                    if (goldenLocation != null) {
                        PipelineUnitTestSetLocationDialog dialog = new PipelineUnitTestSetLocationDialog(hopGui.getShell(), variables, hopGui.getMetadataProvider(), goldenLocation, dataSets, transformFieldsMap);
                        if (dialog.open()) {
                            // Save the unit test
                            hopGui.getMetadataProvider().getSerializer(PipelineUnitTest.class).save(unitTest);
                            pipelineGraph.updateGui();
                        }
                    }
                } else if (DataSetConst.AREA_DRAWN_GOLDEN_DATA_RESULT.equals(areaOwner.getParent())) {
                    // Open the dataset double clicked on...
                    // 
                    String transformName = (String) areaOwner.getOwner();
                    PipelineUnitTestSetLocation goldenLocation = unitTest.findGoldenLocation(transformName);
                    if (goldenLocation != null) {
                        // Find the errors list of the unit test...
                        // 
                        IPipelineEngine<PipelineMeta> pipeline = pipelineGraph.getPipeline();
                        if (pipeline == null) {
                            return;
                        }
                        List<UnitTestResult> results = (List<UnitTestResult>) pipeline.getExtensionDataMap().get(DataSetConst.UNIT_TEST_RESULTS);
                        if (results == null || results.isEmpty()) {
                            return;
                        }
                        ValidatePipelineUnitTestExtensionPoint.showUnitTestErrors(pipeline, results, hopGui);
                    }
                }
            }
        }
    } catch (Exception e) {
        new ErrorDialog(hopGui.getShell(), "Error", "Error editing location", e);
    }
}
Also used : PipelineUnitTestSetLocation(org.apache.hop.testing.PipelineUnitTestSetLocation) MouseEvent(org.eclipse.swt.events.MouseEvent) DataSet(org.apache.hop.testing.DataSet) HashMap(java.util.HashMap) IRowMeta(org.apache.hop.core.row.IRowMeta) UnitTestResult(org.apache.hop.testing.UnitTestResult) ErrorDialog(org.apache.hop.ui.core.dialog.ErrorDialog) ExtensionPoint(org.apache.hop.core.extension.ExtensionPoint) IExtensionPoint(org.apache.hop.core.extension.IExtensionPoint) Point(org.apache.hop.core.gui.Point) HopException(org.apache.hop.core.exception.HopException) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) AreaOwner(org.apache.hop.core.gui.AreaOwner) TransformMeta(org.apache.hop.pipeline.transform.TransformMeta) List(java.util.List) PipelineUnitTest(org.apache.hop.testing.PipelineUnitTest) HopGuiPipelineGraph(org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph) PipelineUnitTestSetLocationDialog(org.apache.hop.ui.testing.PipelineUnitTestSetLocationDialog) HopGui(org.apache.hop.ui.hopgui.HopGui)

Aggregations

HashMap (java.util.HashMap)1 List (java.util.List)1 HopException (org.apache.hop.core.exception.HopException)1 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)1 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)1 AreaOwner (org.apache.hop.core.gui.AreaOwner)1 Point (org.apache.hop.core.gui.Point)1 IRowMeta (org.apache.hop.core.row.IRowMeta)1 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)1 TransformMeta (org.apache.hop.pipeline.transform.TransformMeta)1 DataSet (org.apache.hop.testing.DataSet)1 PipelineUnitTest (org.apache.hop.testing.PipelineUnitTest)1 PipelineUnitTestSetLocation (org.apache.hop.testing.PipelineUnitTestSetLocation)1 UnitTestResult (org.apache.hop.testing.UnitTestResult)1 ErrorDialog (org.apache.hop.ui.core.dialog.ErrorDialog)1 HopGui (org.apache.hop.ui.hopgui.HopGui)1 HopGuiPipelineGraph (org.apache.hop.ui.hopgui.file.pipeline.HopGuiPipelineGraph)1 PipelineUnitTestSetLocationDialog (org.apache.hop.ui.testing.PipelineUnitTestSetLocationDialog)1 MouseEvent (org.eclipse.swt.events.MouseEvent)1