use of org.pentaho.di.imp.ImportRules in project pentaho-kettle by pentaho.
the class ImportRulesDialog method syncUIWithData.
protected void syncUIWithData() {
ImportRules newRules = new ImportRules();
getInfo(newRules);
importRules = newRules;
getCompositesData();
}
use of org.pentaho.di.imp.ImportRules in project pentaho-kettle by pentaho.
the class RepositoryExporterTest method getImportRules.
private ImportRules getImportRules() {
ImportRules imp = new ImportRules();
List<ImportRuleInterface> impRules = new ArrayList<ImportRuleInterface>(1);
JobHasDescriptionImportRule rule = new JobHasDescriptionImportRule();
rule.setEnabled(true);
rule.setMinLength(19000);
impRules.add(rule);
TransformationHasDescriptionImportRule trRule = new TransformationHasDescriptionImportRule() {
public String toString() {
return "stub to avoid call to Plugin registry";
}
};
trRule.setEnabled(true);
trRule.setMinLength(19001);
impRules.add(trRule);
imp.setRules(impRules);
return imp;
}
use of org.pentaho.di.imp.ImportRules 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.ImportRules in project pentaho-kettle by pentaho.
the class ImportRulesDialog method importRules.
/**
* Import the rules from an XML rules file...
*/
protected void importRules() {
if (!importRules.getRules().isEmpty()) {
MessageBox box = new MessageBox(shell, SWT.ICON_WARNING | SWT.APPLICATION_MODAL | SWT.SHEET | SWT.YES | SWT.NO);
box.setText("Warning");
box.setMessage("Are you sure you want to load a new set of rules, replacing the current list?");
int answer = box.open();
if (answer != SWT.YES) {
return;
}
}
FileDialog dialog = new FileDialog(shell, SWT.OPEN);
dialog.setFilterExtensions(new String[] { "*.xml;*.XML", "*" });
dialog.setFilterNames(new String[] { BaseMessages.getString(PKG, "System.FileType.XMLFiles"), BaseMessages.getString(PKG, "System.FileType.AllFiles") });
if (dialog.open() != null) {
String filename = dialog.getFilterPath() + System.getProperty("file.separator") + dialog.getFileName();
ImportRules newRules = new ImportRules();
try {
newRules.loadXML(XMLHandler.getSubNode(XMLHandler.loadXMLFile(filename), ImportRules.XML_TAG));
importRules = newRules;
// Re-load the dialog.
//
getCompositesData();
} catch (Exception e) {
new ErrorDialog(shell, "Error", "There was an error during the import of the import rules file, verify the XML format.", e);
}
}
}
use of org.pentaho.di.imp.ImportRules 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);
}
}
}
}
Aggregations