use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testExport.
@Test
public void testExport() throws Exception {
// $NON-NLS-1$
final String exportFileName = new File("test.export").getAbsolutePath();
RepositoryDirectoryInterface rootDir = initRepo();
String uniqueTransName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
TransMeta transMeta = createTransMeta(EXP_DBMETA_NAME);
// Create a database association
DatabaseMeta dbMeta = createDatabaseMeta(EXP_DBMETA_NAME);
repository.save(dbMeta, VERSION_COMMENT_V1, null);
TableInputMeta tableInputMeta = new TableInputMeta();
tableInputMeta.setDatabaseMeta(dbMeta);
transMeta.addStep(new StepMeta(EXP_TRANS_STEP_1_NAME, tableInputMeta));
RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
repository.save(transMeta, VERSION_COMMENT_V1, null);
// So this transformation is cleaned up afterward
deleteStack.push(transMeta);
assertNotNull(transMeta.getObjectId());
ObjectRevision version = transMeta.getObjectRevision();
assertNotNull(version);
assertTrue(hasVersionWithComment(transMeta, VERSION_COMMENT_V1));
assertTrue(repository.exists(uniqueTransName, transDir, RepositoryObjectType.TRANSFORMATION));
JobMeta jobMeta = createJobMeta(EXP_JOB_NAME);
RepositoryDirectoryInterface jobsDir = rootDir.findDirectory(DIR_JOBS);
repository.save(jobMeta, VERSION_COMMENT_V1, null);
deleteStack.push(jobMeta);
assertNotNull(jobMeta.getObjectId());
version = jobMeta.getObjectRevision();
assertNotNull(version);
assertTrue(hasVersionWithComment(jobMeta, VERSION_COMMENT_V1));
assertTrue(repository.exists(EXP_JOB_NAME, jobsDir, RepositoryObjectType.JOB));
LogListener errorLogListener = new LogListener(LogLevel.ERROR);
KettleLogStore.getAppender().addLoggingEventListener(errorLogListener);
try {
// $NON-NLS-1$
repository.getExporter().exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
FileObject exportFile = KettleVFS.getFileObject(exportFileName);
assertFalse("file left open", exportFile.getContent().isOpen());
assertNotNull(exportFile);
MockRepositoryExportParser parser = new MockRepositoryExportParser();
SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
if (parser.getFatalError() != null) {
throw parser.getFatalError();
}
// $NON-NLS-1$
assertNotNull("No nodes found in export", parser.getNodeNames());
// $NON-NLS-1$
assertTrue("No nodes found in export", !parser.getNodeNames().isEmpty());
// $NON-NLS-1$
assertEquals("Incorrect number of nodes", 5, parser.getNodeNames().size());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName("transformation").size());
// $NON-NLS-1$ //$NON-NLS-2$
assertEquals("Incorrect number of jobs", 1, parser.getNodesWithName("job").size());
assertTrue("log error", errorLogListener.getEvents().isEmpty());
} finally {
KettleVFS.getFileObject(exportFileName).delete();
KettleLogStore.getAppender().removeLoggingEventListener(errorLogListener);
}
}
use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.
the class TableInputDialog method preview.
/**
* Preview the data generated by this step. This generates a transformation using this step & a dummy and previews it.
*/
private void preview() {
// Create the table input reader step...
TableInputMeta oneMeta = new TableInputMeta();
getInfo(oneMeta, true);
TransMeta previewMeta = TransPreviewFactory.generatePreviewTransformation(transMeta, oneMeta, wStepname.getText());
EnterNumberDialog numberDialog = new EnterNumberDialog(shell, props.getDefaultPreviewSize(), BaseMessages.getString(PKG, "TableInputDialog.EnterPreviewSize"), BaseMessages.getString(PKG, "TableInputDialog.NumberOfRowsToPreview"));
int previewSize = numberDialog.open();
if (previewSize > 0) {
TransPreviewProgressDialog progressDialog = new TransPreviewProgressDialog(shell, previewMeta, new String[] { wStepname.getText() }, new int[] { previewSize });
progressDialog.open();
Trans trans = progressDialog.getTrans();
String loggingText = progressDialog.getLoggingText();
if (!progressDialog.isCancelled()) {
if (trans.getResult() != null && trans.getResult().getNrErrors() > 0) {
EnterTextDialog etd = new EnterTextDialog(shell, BaseMessages.getString(PKG, "System.Dialog.PreviewError.Title"), BaseMessages.getString(PKG, "System.Dialog.PreviewError.Message"), loggingText, true);
etd.setReadOnly();
etd.open();
} else {
PreviewRowsDialog prd = new PreviewRowsDialog(shell, transMeta, SWT.NONE, wStepname.getText(), progressDialog.getPreviewRowsMeta(wStepname.getText()), progressDialog.getPreviewRows(wStepname.getText()), loggingText);
prd.open();
}
}
}
}
use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.
the class TransDialog method get.
// Get the dependencies
private void get() {
Table table = wFields.table;
for (int i = 0; i < transMeta.nrSteps(); i++) {
StepMeta stepMeta = transMeta.getStep(i);
String con = null;
String tab = null;
TableItem item = null;
StepMetaInterface sii = stepMeta.getStepMetaInterface();
if (sii instanceof TableInputMeta) {
TableInputMeta tii = (TableInputMeta) stepMeta.getStepMetaInterface();
if (tii.getDatabaseMeta() == null) {
MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
mb.setMessage(BaseMessages.getString(PKG, "TransDialog.DatabaseMetaNotSet.Text"));
mb.open();
return;
}
con = tii.getDatabaseMeta().getName();
tab = getTableFromSQL(tii.getSQL());
if (tab == null) {
tab = stepMeta.getName();
}
}
if (sii instanceof DatabaseLookupMeta) {
DatabaseLookupMeta dvli = (DatabaseLookupMeta) stepMeta.getStepMetaInterface();
con = dvli.getDatabaseMeta().getName();
tab = dvli.getTablename();
if (tab == null) {
tab = stepMeta.getName();
}
break;
}
if (tab != null || con != null) {
item = new TableItem(table, SWT.NONE);
if (con != null) {
item.setText(1, con);
}
if (tab != null) {
item.setText(2, tab);
}
}
}
wFields.setRowNums();
}
use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.
the class PluginRegistryIT method testPluginRegistry.
public void testPluginRegistry() throws KettlePluginException {
PluginRegistry registry = PluginRegistry.getInstance();
assertNotNull("Registry singleton was not found!", registry);
// PluginRegistry.init() may have already been called, our test path will be different
// for each case. If it has not been called, try to register the type and plugin. If
// it has been called, simply verify the plugin type and plugin have been registered.
Class<? extends PluginTypeInterface> pluginTypeClass = StepPluginType.class;
Object pluginClass = new TableInputMeta();
List<PluginInterface> inputPluginsAtTestStart = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_INPUT_CATEGORY);
int numInputPluginsAtStart = inputPluginsAtTestStart.size();
List<PluginInterface> outputPluginsAtTestStart = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_OUTPUT_CATEGORY);
int numOutputPluginsAtStart = outputPluginsAtTestStart.size();
try {
registry.getPluginType(pluginTypeClass);
} catch (KettlePluginException kpe) {
// Register a new plugin type...
registry.registerPluginType(pluginTypeClass);
}
// See if the plugin is there...
try {
registry.getPluginType(pluginTypeClass);
} catch (KettlePluginException kpe) {
fail(pluginTypeClass.getName() + " expected in the PluginRegistry but was not found!");
}
PluginInterface plugin = registry.getPlugin(pluginTypeClass, pluginClass);
Map<Class<?>, String> classMap = new HashMap<Class<?>, String>();
PluginInterface tableInputPlugin = plugin;
int numInputPluginsRegistered = 0;
if (plugin == null) {
// Register a single step plugin
//
classMap.put(StepMetaInterface.class, "org.pentaho.di.trans.steps.tableinput.TableInputMeta");
tableInputPlugin = new Plugin(new String[] { TABLE_INPUT_PLUGIN_ID }, pluginTypeClass, StepMetaInterface.class, PLUGIN_INPUT_CATEGORY, TABLE_INPUT_PLUGIN_NAME, TABLE_INPUT_PLUGIN_DESCRIPTION, TABLE_INPUT_PLUGIN_IMAGE_FILE_NAME, false, true, classMap, new ArrayList<String>(), // No error help file
null, // pluginFolder
null, // documentation URL
null, // cases URL
null, // forum URL
null);
registry.registerPlugin(pluginTypeClass, tableInputPlugin);
numInputPluginsRegistered++;
}
// Verify the plugin has been registered
PluginInterface verify = registry.getPlugin(pluginTypeClass, TABLE_INPUT_PLUGIN_ID);
assertNotNull("A plugin was not found in the plugin registry", verify);
assertEquals("A different plugin then expected was retrieved from the plugin registry", verify, tableInputPlugin);
pluginClass = new TableOutputMeta();
plugin = registry.getPlugin(pluginTypeClass, pluginClass);
PluginInterface tableOutputPlugin = plugin;
int numOutputPluginsRegistered = 0;
if (plugin == null) {
// Register a second step plugin
//
classMap = new HashMap<Class<?>, String>();
classMap.put(StepMetaInterface.class, "org.pentaho.di.trans.steps.tableoutput.TableOutputMeta");
tableOutputPlugin = new Plugin(new String[] { TABLE_OUTPUT_PLUGIN_ID }, pluginTypeClass, StepMetaInterface.class, PLUGIN_OUTPUT_CATEGORY, TABLE_OUTPUT_PLUGIN_NAME, TABLE_OUTPUT_PLUGIN_DESCRIPTION, TABLE_OUTPUT_PLUGIN_IMAGE_FILE_NAME, false, true, classMap, new ArrayList<String>(), // No error help file
null, // pluginFolder
null, // documentation URL
null, // cases URL
null, // forum URL
null);
registry.registerPlugin(pluginTypeClass, tableOutputPlugin);
numOutputPluginsRegistered++;
}
// Verify the plugin has been registered
verify = registry.getPlugin(pluginTypeClass, TABLE_OUTPUT_PLUGIN_ID);
assertNotNull("A plugin was not found in the plugin registry", verify);
assertEquals("A different plugin then expected was retrieved from the plugin registry", verify, tableOutputPlugin);
// Get a list by category...
//
List<PluginInterface> inputPlugins = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_INPUT_CATEGORY);
assertEquals("Exactly one plugin expected in the step plugin input category", numInputPluginsAtStart + numInputPluginsRegistered, inputPlugins.size());
assertTrue("Input plugins list should contain the table input step", inputPlugins.contains(tableInputPlugin));
assertFalse("Input plugins list should not contain the table output step", inputPlugins.contains(tableOutputPlugin));
List<PluginInterface> outputPlugins = registry.getPluginsByCategory(pluginTypeClass, PLUGIN_OUTPUT_CATEGORY);
assertEquals("Exactly one plugin expected in the step plugin output category", numOutputPluginsAtStart + numOutputPluginsRegistered, outputPlugins.size());
assertTrue("Output plugins list should contain the table output step", outputPlugins.contains(tableOutputPlugin));
assertFalse("Output plugins list should not contain the table input step", outputPlugins.contains(tableInputPlugin));
// List the categories...
//
List<String> categories = registry.getCategories(pluginTypeClass);
assertTrue("The input category was expected in the categories list", categories.contains(PLUGIN_INPUT_CATEGORY));
assertTrue("The output category was expected in the categories list", categories.contains(PLUGIN_OUTPUT_CATEGORY));
// Now have a little bit of class loading fun: load the main class of the plugin
//
Object object = registry.loadClass(tableInputPlugin, StepMetaInterface.class);
assertNotNull(object);
// The same but now explicitly asking for the main class
//
Object object2 = registry.loadClass(tableOutputPlugin, StepMetaInterface.class);
assertNotNull(object2);
try {
registry.loadClass(tableInputPlugin, String.class);
fail("A String class type can't be used when loading a step class");
} catch (Exception e) {
// OK!
}
}
use of org.pentaho.di.trans.steps.tableinput.TableInputMeta in project pentaho-kettle by pentaho.
the class CombinationLookupIT method testCombinationLookup.
/**
* Test case for Combination lookup/update.
*/
public void testCombinationLookup() throws Exception {
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("transname");
// Add the database connections
for (int i = 0; i < databasesXML.length; i++) {
DatabaseMeta databaseMeta = new DatabaseMeta(databasesXML[i]);
transMeta.addDatabase(databaseMeta);
}
DatabaseMeta lookupDBInfo = transMeta.findDatabase("lookup");
// Execute our setup SQLs in the database.
Database lookupDatabase = new Database(transMeta, lookupDBInfo);
lookupDatabase.connect();
createTables(lookupDatabase);
createData(lookupDatabase);
PluginRegistry registry = PluginRegistry.getInstance();
//
// create the source step...
//
String fromstepname = "read from [" + source_table + "]";
TableInputMeta tii = new TableInputMeta();
tii.setDatabaseMeta(transMeta.findDatabase("lookup"));
String selectSQL = "SELECT " + Const.CR;
selectSQL += "DLR_CD, DLR_NM, DLR_DESC ";
selectSQL += "FROM " + source_table + " ORDER BY ORDNO;";
tii.setSQL(selectSQL);
String fromstepid = registry.getPluginId(StepPluginType.class, tii);
StepMeta fromstep = new StepMeta(fromstepid, fromstepname, tii);
fromstep.setLocation(150, 100);
fromstep.setDraw(true);
fromstep.setDescription("Reads information from table [" + source_table + "] on database [" + lookupDBInfo + "]");
transMeta.addStep(fromstep);
//
// create the combination lookup/update step...
//
String lookupstepname = "lookup from [lookup]";
CombinationLookupMeta clm = new CombinationLookupMeta();
String[] lookupKey = { "DLR_CD" };
clm.setTablename(target_table);
clm.setKeyField(lookupKey);
clm.setKeyLookup(lookupKey);
clm.setTechnicalKeyField("ID");
clm.setTechKeyCreation(CombinationLookupMeta.CREATION_METHOD_TABLEMAX);
clm.setDatabaseMeta(lookupDBInfo);
String lookupstepid = registry.getPluginId(StepPluginType.class, clm);
StepMeta lookupstep = new StepMeta(lookupstepid, lookupstepname, clm);
lookupstep.setDescription("Looks up information from table [lookup] on database [" + lookupDBInfo + "]");
transMeta.addStep(lookupstep);
TransHopMeta hi = new TransHopMeta(fromstep, lookupstep);
transMeta.addTransHop(hi);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.execute(null);
trans.waitUntilFinished();
checkResults(lookupDatabase);
}
Aggregations