Search in sources :

Example 6 with ImportRuleInterface

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();
    }
}
Also used : AbstractList(java.util.AbstractList) RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) TransMeta(org.pentaho.di.trans.TransMeta) Matchers.anyString(org.mockito.Matchers.anyString) ImportRules(org.pentaho.di.imp.ImportRules) TransformationHasANoteImportRule(org.pentaho.di.imp.rules.TransformationHasANoteImportRule) NotePadMeta(org.pentaho.di.core.NotePadMeta) FileObject(org.apache.commons.vfs2.FileObject) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IRepositoryExporter(org.pentaho.di.repository.IRepositoryExporter) Test(org.junit.Test)

Example 7 with ImportRuleInterface

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);
            }
        }
    }
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) EnterSelectionDialog(org.pentaho.di.ui.core.dialog.EnterSelectionDialog) KettleException(org.pentaho.di.core.exception.KettleException)

Example 8 with ImportRuleInterface

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);
    }
}
Also used : ImportRuleCompositeInterface(org.pentaho.di.ui.imp.rule.ImportRuleCompositeInterface) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) TableItem(org.eclipse.swt.widgets.TableItem)

Example 9 with ImportRuleInterface

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());
        }
    }
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) Shell(org.eclipse.swt.widgets.Shell) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) Display(org.eclipse.swt.widgets.Display)

Aggregations

ImportRuleInterface (org.pentaho.di.imp.rule.ImportRuleInterface)9 KettleException (org.pentaho.di.core.exception.KettleException)4 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)4 ImportRules (org.pentaho.di.imp.ImportRules)4 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)3 ArrayList (java.util.ArrayList)2 TableItem (org.eclipse.swt.widgets.TableItem)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 ImportRuleCompositeInterface (org.pentaho.di.ui.imp.rule.ImportRuleCompositeInterface)2 Node (org.w3c.dom.Node)2 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 SimpleDateFormat (java.text.SimpleDateFormat)1 AbstractList (java.util.AbstractList)1 Date (java.util.Date)1 FileObject (org.apache.commons.vfs2.FileObject)1 TableEditor (org.eclipse.swt.custom.TableEditor)1