use of org.apache.hop.core.action.GuiContextAction in project hop by apache.
the class TestingGuiPlugin method clearGoldenDataSet.
/**
* We set an golden data set on the selected unit test
*/
@GuiContextAction(id = ACTION_ID_PIPELINE_GRAPH_TRANSFORM_CLEAR_GOLDEN_DATA_SET, parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Delete, name = "i18n::TestingGuiPlugin.ContextAction.ClearGoldenDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.ClearGoldenDataset.Tooltip", image = "clear-golden-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void clearGoldenDataSet(HopGuiPipelineTransformContext context) {
HopGui hopGui = HopGui.getInstance();
PipelineMeta pipelineMeta = context.getPipelineMeta();
TransformMeta transformMeta = context.getTransformMeta();
IVariables variables = context.getPipelineGraph().getVariables();
if (checkTestPresent(hopGui, pipelineMeta)) {
return;
}
try {
PipelineUnitTest currentUnitTest = getCurrentUnitTest(pipelineMeta);
PipelineUnitTestSetLocation goldenLocation = currentUnitTest.findGoldenLocation(transformMeta.getName());
if (goldenLocation != null) {
currentUnitTest.getGoldenDataSets().remove(goldenLocation);
}
saveUnitTest(variables, hopGui.getMetadataProvider(), currentUnitTest, pipelineMeta);
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.ClearGoldenDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.ClearGoldenDataset.Error.Message"), e);
}
pipelineMeta.setChanged();
context.getPipelineGraph().updateGui();
}
use of org.apache.hop.core.action.GuiContextAction in project hop by apache.
the class TestingGuiPlugin method setGoldenDataSet.
/**
* We set an golden data set on the selected unit test
*/
@GuiContextAction(id = ACTION_ID_PIPELINE_GRAPH_TRANSFORM_DEFINE_GOLDEN_DATA_SET, parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Modify, name = "i18n::TestingGuiPlugin.ContextAction.SetGoldenDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.SetGoldenDataset.Tooltip", image = "set-golden-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void setGoldenDataSet(HopGuiPipelineTransformContext context) {
PipelineMeta sourcePipelineMeta = context.getPipelineMeta();
TransformMeta transformMeta = context.getTransformMeta();
HopGuiPipelineGraph pipelineGraph = context.getPipelineGraph();
IVariables variables = pipelineGraph.getVariables();
HopGui hopGui = HopGui.getInstance();
IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
if (checkTestPresent(hopGui, sourcePipelineMeta)) {
return;
}
PipelineUnitTest unitTest = getCurrentUnitTest(sourcePipelineMeta);
try {
// Create a copy and modify the pipeline
// This way we have
PipelineMetaModifier modifier = new PipelineMetaModifier(variables, sourcePipelineMeta, unitTest);
PipelineMeta pipelineMeta = modifier.getTestPipeline(LogChannel.UI, variables, metadataProvider);
IHopMetadataSerializer<DataSet> setSerializer = metadataProvider.getSerializer(DataSet.class);
List<String> setNames = setSerializer.listObjectNames();
Collections.sort(setNames);
EnterSelectionDialog esd = new EnterSelectionDialog(hopGui.getShell(), setNames.toArray(new String[setNames.size()]), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Message"));
String setName = esd.open();
if (setName != null) {
DataSet dataSet = setSerializer.load(setName);
boolean changed = setGoldenDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
if (changed) {
pipelineGraph.updateGui();
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.SetGoldenDataset.Error.Message"), e);
}
}
use of org.apache.hop.core.action.GuiContextAction in project hop by apache.
the class TestingGuiPlugin method createDataSetFromTransform.
/**
* Create a new data set with the output from
*/
@GuiContextAction(id = "pipeline-graph-transform-20400-create-data-set-from-transform", parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Delete, name = "i18n::TestingGuiPlugin.ContextAction.CreateDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.CreateDataset.Tooltip", image = "create-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void createDataSetFromTransform(HopGuiPipelineTransformContext context) {
HopGui hopGui = HopGui.getInstance();
IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
IVariables variables = context.getPipelineGraph().getVariables();
TransformMeta transformMeta = context.getTransformMeta();
PipelineMeta pipelineMeta = context.getPipelineMeta();
try {
DataSet dataSet = new DataSet();
IRowMeta rowMeta = pipelineMeta.getTransformFields(variables, transformMeta);
for (int i = 0; i < rowMeta.size(); i++) {
IValueMeta valueMeta = rowMeta.getValueMeta(i);
String setFieldName = valueMeta.getName();
DataSetField field = new DataSetField(setFieldName, valueMeta.getType(), valueMeta.getLength(), valueMeta.getPrecision(), valueMeta.getComments(), valueMeta.getFormatMask());
dataSet.getFields().add(field);
}
MetadataManager<DataSet> manager = new MetadataManager<>(hopGui.getVariables(), hopGui.getMetadataProvider(), DataSet.class);
if (manager.newMetadata(dataSet) != null) {
PipelineUnitTest unitTest = getCurrentUnitTest(pipelineMeta);
if (unitTest == null) {
return;
}
// Now that the data set is created and we have an active unit test, perhaps the user wants
// to use it on the transform?
//
MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.CANCEL | SWT.ICON_QUESTION);
box.setText(BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Header"));
box.setMessage(BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Message", dataSet.getName(), transformMeta.getName()) + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer1") + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer2") + Const.CR + BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.DatasetType.Answer3") + Const.CR);
int answer = box.open();
if ((answer & SWT.YES) != 0) {
// set the new data set as an input
//
setInputDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
}
if ((answer & SWT.NO) != 0) {
setGoldenDataSetOnTransform(variables, metadataProvider, pipelineMeta, transformMeta, unitTest, dataSet);
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.CreateDataset.Error.Message"), e);
}
}
use of org.apache.hop.core.action.GuiContextAction in project hop by apache.
the class TestingGuiPlugin method clearInputDataSet.
/**
* We set an golden data set on the selected unit test
*/
@GuiContextAction(id = ACTION_ID_PIPELINE_GRAPH_TRANSFORM_CLEAR_INPUT_DATA_SET, parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Delete, name = "i18n::TestingGuiPlugin.ContextAction.ClearInputDataset.Name", tooltip = "i18n::TestingGuiPlugin.ContextAction.ClearInputDataset.Message", image = "clear-input-dataset.svg", category = "i18n::TestingGuiPlugin.Category", categoryOrder = "8")
public void clearInputDataSet(HopGuiPipelineTransformContext context) {
HopGui hopGui = ((HopGui) HopGui.getInstance());
PipelineMeta pipelineMeta = context.getPipelineMeta();
TransformMeta transformMeta = context.getTransformMeta();
IVariables variables = context.getPipelineGraph().getVariables();
if (checkTestPresent(hopGui, pipelineMeta)) {
return;
}
try {
PipelineUnitTest currentUnitTest = getCurrentUnitTest(pipelineMeta);
PipelineUnitTestSetLocation inputLocation = currentUnitTest.findInputLocation(transformMeta.getName());
if (inputLocation != null) {
currentUnitTest.getInputDataSets().remove(inputLocation);
}
saveUnitTest(variables, hopGui.getMetadataProvider(), currentUnitTest, pipelineMeta);
context.getPipelineGraph().updateGui();
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.ClearInputDataset.Error.Header"), BaseMessages.getString(PKG, "TestingGuiPlugin.ContextAction.ClearInputDataset.Error.Message"), e);
}
}
use of org.apache.hop.core.action.GuiContextAction in project hop by apache.
the class DataProbeGuiPlugin method addDataProbeForTransform.
@GuiContextAction(id = "pipeline-graph-transform-9000-add-probe", parentId = HopGuiPipelineTransformContext.CONTEXT_ID, type = GuiActionType.Info, name = "Add data probe", tooltip = "Streams the rows to a pipeline defined in a selected pipeline probe", image = "probe.svg", category = "Preview", categoryOrder = "3")
public void addDataProbeForTransform(HopGuiPipelineTransformContext context) {
PipelineMeta pipelineMeta = context.getPipelineMeta();
TransformMeta transformMeta = context.getTransformMeta();
HopGui hopGui = HopGui.getInstance();
try {
// Present the user with a list of pipeline probes...
//
IHopMetadataProvider metadataProvider = hopGui.getMetadataProvider();
IHopMetadataSerializer<PipelineProbe> serializer = metadataProvider.getSerializer(PipelineProbe.class);
MetadataManager<PipelineProbe> manager = new MetadataManager<>(hopGui.getVariables(), metadataProvider, PipelineProbe.class);
PipelineProbe pipelineProbe = null;
List<String> pipelineProbeNames = serializer.listObjectNames();
if (pipelineProbeNames.isEmpty()) {
MessageBox box = new MessageBox(hopGui.getShell(), SWT.YES | SWT.NO | SWT.ICON_QUESTION);
box.setText("No probes available");
box.setMessage("There are no pipeline probe objects defined yet. Do you want to create one?");
int answer = box.open();
if ((answer & SWT.YES) != 0) {
// Create a new pipeline probe...
//
pipelineProbe = new PipelineProbe();
addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
manager.newMetadata(pipelineProbe);
return;
} else {
return;
}
} else {
EnterSelectionDialog dialog = new EnterSelectionDialog(hopGui.getShell(), pipelineProbeNames.toArray(new String[0]), "Select pipeline probe", "Select the pipeline probe to add this pipeline transform to");
String pipelineProbeName = dialog.open();
if (pipelineProbeName != null) {
pipelineProbe = serializer.load(pipelineProbeName);
}
}
if (pipelineProbe != null) {
// See if it's open in the metadata perspective...
//
MetadataPerspective perspective = (MetadataPerspective) hopGui.getPerspectiveManager().findPerspective(MetadataPerspective.class);
String key = PipelineProbe.class.getAnnotation(HopMetadata.class).key();
PipelineProbeEditor editor = (PipelineProbeEditor) perspective.findEditor(key, pipelineProbe.getName());
if (editor != null) {
// We're going to change the current metadata and flag it as changed...
//
pipelineProbe = new PipelineProbe();
editor.getWidgetsContent(pipelineProbe);
// Add the location
//
addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
// Replace and refresh the dialog
//
editor.setMetadata(pipelineProbe);
editor.setWidgetsContent();
// Set changed...
//
editor.setChanged();
// Switch to the editor...
//
perspective.activate();
perspective.setActiveEditor(editor);
return;
} else {
// Not opened in the perspective, simply add the data probe location...
//
addLocation(hopGui.getVariables(), pipelineProbe, pipelineMeta, transformMeta);
// ... and save the pipeline probe
//
serializer.save(pipelineProbe);
}
}
} catch (Exception e) {
new ErrorDialog(hopGui.getShell(), "Error", "Error adding pipeline probe to transform '" + transformMeta.getName() + "'", e);
}
}
Aggregations