Search in sources :

Example 1 with ImportRules

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();
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules)

Example 2 with ImportRules

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;
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) JobHasDescriptionImportRule(org.pentaho.di.imp.rules.JobHasDescriptionImportRule) ImportRuleInterface(org.pentaho.di.imp.rule.ImportRuleInterface) ArrayList(java.util.ArrayList) TransformationHasDescriptionImportRule(org.pentaho.di.imp.rules.TransformationHasDescriptionImportRule)

Example 3 with ImportRules

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();
    }
}
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 4 with ImportRules

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);
        }
    }
}
Also used : ImportRules(org.pentaho.di.imp.ImportRules) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) FileDialog(org.eclipse.swt.widgets.FileDialog) KettleException(org.pentaho.di.core.exception.KettleException) MessageBox(org.eclipse.swt.widgets.MessageBox)

Example 5 with ImportRules

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);
            }
        }
    }
}
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)

Aggregations

ImportRules (org.pentaho.di.imp.ImportRules)8 ImportRuleInterface (org.pentaho.di.imp.rule.ImportRuleInterface)4 FileDialog (org.eclipse.swt.widgets.FileDialog)3 MessageBox (org.eclipse.swt.widgets.MessageBox)3 KettleException (org.pentaho.di.core.exception.KettleException)2 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)2 Point (org.pentaho.di.core.gui.Point)2 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)2 KettlePropertiesFileDialog (org.pentaho.di.ui.core.dialog.KettlePropertiesFileDialog)2 ImportRulesDialog (org.pentaho.di.ui.imp.ImportRulesDialog)2 File (java.io.File)1 AbstractList (java.util.AbstractList)1 ArrayList (java.util.ArrayList)1 FileObject (org.apache.commons.vfs2.FileObject)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1