use of org.pentaho.di.imp.rule.ImportRuleInterface in project pentaho-kettle by pentaho.
the class PurRepositoryIT method testExportWithRules.
@Test
public void testExportWithRules() throws Exception {
String fileName = "testExportWithRuled.xml";
// $NON-NLS-1$
final String exportFileName = new File(fileName).getAbsolutePath();
RepositoryDirectoryInterface rootDir = initRepo();
String transWithoutNoteName = "2" + EXP_DBMETA_NAME;
TransMeta transWithoutNote = createTransMeta(transWithoutNoteName);
String transUniqueName = EXP_TRANS_NAME.concat(transWithoutNoteName);
RepositoryDirectoryInterface transDir = rootDir.findDirectory(DIR_TRANSFORMATIONS);
repository.save(transWithoutNote, VERSION_COMMENT_V1, null);
// So this transformation is cleaned up afterward
deleteStack.push(transWithoutNote);
assertNotNull(transWithoutNote.getObjectId());
assertTrue(hasVersionWithComment(transWithoutNote, VERSION_COMMENT_V1));
assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
// Second transformation (contained note)
String transWithNoteName = "1" + EXP_DBMETA_NAME;
TransMeta transWithNote = createTransMeta(transWithNoteName);
transUniqueName = EXP_TRANS_NAME.concat(EXP_DBMETA_NAME);
TransMeta transWithRules = createTransMeta(EXP_DBMETA_NAME);
NotePadMeta note = new NotePadMeta("Note Message", 1, 1, 100, 5);
transWithRules.addNote(note);
repository.save(transWithRules, VERSION_COMMENT_V1, null);
// So this transformation is cleaned up afterward
deleteStack.push(transWithRules);
assertNotNull(transWithRules.getObjectId());
assertTrue(hasVersionWithComment(transWithRules, VERSION_COMMENT_V1));
assertTrue(repository.exists(transUniqueName, transDir, RepositoryObjectType.TRANSFORMATION));
// create rules for export to .xml file
List<ImportRuleInterface> rules = new AbstractList<ImportRuleInterface>() {
@Override
public ImportRuleInterface get(int index) {
TransformationHasANoteImportRule rule = new TransformationHasANoteImportRule();
rule.setEnabled(true);
return rule;
}
@Override
public int size() {
return 1;
}
};
ImportRules importRules = new ImportRules();
importRules.setRules(rules);
// create exporter
IRepositoryExporter exporter = repository.getExporter();
exporter.setImportRulesToValidate(importRules);
// export itself
try {
// $NON-NLS-1$
exporter.exportAllObjects(new MockProgressMonitorListener(), exportFileName, null, "all");
FileObject exportFile = KettleVFS.getFileObject(exportFileName);
assertNotNull(exportFile);
MockRepositoryExportParser parser = new MockRepositoryExportParser();
SAXParserFactory.newInstance().newSAXParser().parse(KettleVFS.getInputStream(exportFile), parser);
if (parser.getFatalError() != null) {
throw parser.getFatalError();
}
// assumed transformation with note will be here and only it
assertEquals("Incorrect number of transformations", 1, parser.getNodesWithName(RepositoryObjectType.TRANSFORMATION.getTypeDescription()).size());
} finally {
KettleVFS.getFileObject(exportFileName).delete();
}
}
use of org.pentaho.di.imp.rule.ImportRuleInterface in project pentaho-kettle by pentaho.
the class ImportRulesDialog method addRule.
public void addRule() {
PluginRegistry registry = PluginRegistry.getInstance();
List<PluginInterface> plugins = registry.getPlugins(ImportRulePluginType.class);
//
for (ImportRuleInterface rule : importRules.getRules()) {
if (rule.isUnique()) {
int removeIndex = -1;
for (int i = 0; i < plugins.size(); i++) {
PluginInterface plugin = plugins.get(i);
if (Const.indexOfString(rule.getId(), plugin.getIds()) >= 0) {
removeIndex = i;
break;
}
}
if (removeIndex >= 0) {
plugins.remove(removeIndex);
}
}
}
//
if (plugins.size() > 0) {
String[] names = new String[plugins.size()];
for (int i = 0; i < plugins.size(); i++) {
names[i] = plugins.get(i).getName() + " : " + plugins.get(i).getDescription();
}
EnterSelectionDialog esd = new EnterSelectionDialog(shell, names, "Select a rule", "Select a new rule to add to the list:");
String name = esd.open();
if (name != null) {
try {
int index = Const.indexOfString(name, names);
PluginInterface plugin = plugins.get(index);
ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass(plugin);
rule.setEnabled(true);
rule.setId(plugin.getIds()[0]);
ImportRules newRules = new ImportRules();
getInfo(newRules);
newRules.getRules().add(rule);
importRules = newRules;
// Refresh the whole list..
//
getCompositesData();
} catch (Exception e) {
new ErrorDialog(shell, "Error", "Error loading rule class", e);
}
}
}
}
use of org.pentaho.di.imp.rule.ImportRuleInterface in project pentaho-kettle by pentaho.
the class ImportRulesDialog method getInfo.
protected void getInfo(ImportRules ir) {
ir.getRules().clear();
for (int i = 0; i < importRules.getRules().size(); i++) {
ImportRuleInterface rule = importRules.getRules().get(i);
ImportRuleCompositeInterface importRuleComposite = compositesList.get(i);
TableItem tableItem = table.getItem(i);
importRuleComposite.getCompositeData(rule);
rule.setEnabled(tableItem.getChecked());
ir.getRules().add(rule);
}
}
use of org.pentaho.di.imp.rule.ImportRuleInterface in project pentaho-kettle by pentaho.
the class ImportRulesDialog method main.
public static void main(String[] args) throws Exception {
Display display = new Display();
KettleEnvironment.init();
PropsUI.init(display, PropsUI.TYPE_PROPERTIES_SPOON);
Shell shell = new Shell(display);
ImportRules importRules = new ImportRules();
importRules.loadXML(XMLHandler.getSubNode(XMLHandler.loadXMLFile("bin/import-rules.xml"), ImportRules.XML_TAG));
ImportRulesDialog dialog = new ImportRulesDialog(shell, importRules);
if (dialog.open()) {
for (ImportRuleInterface rule : importRules.getRules()) {
System.out.println(" - " + rule.toString());
}
}
}
Aggregations