public RepositoryImportProgressDialog( Shell parent, int style, Repository rep, String fileDirectory, String[] filenames, RepositoryDirectoryInterface baseDirectory, String versionComment ) { this( parent, style, rep, fileDirectory, filenames, baseDirectory, versionComment, new ImportRules() ); }
@Override public void setImportRulesToValidate( ImportRules importRules ) { this.importRules = importRules; hasRules = ( importRules != null && !importRules.getRules().isEmpty() ); }
/** * Perform a deep clone * * @return a deep copy of the all the import rules. */ @Override public ImportRules clone() { ImportRules importRules = new ImportRules(); for ( ImportRuleInterface rule : rules ) { importRules.getRules().add( rule.clone() ); } return importRules; }
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; }
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() ); } } }
private boolean toExport( AbstractMeta meta ) { boolean shouldExport = true; List<ImportValidationFeedback> feedback = importRules.verifyRules( meta ); List<ImportValidationFeedback> errors = ImportValidationFeedback.getErrors( feedback ); if ( !errors.isEmpty() ) { shouldExport = false; log.logError( BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM", meta.getName() ) ); //$NON-NLS-1$ for ( ImportValidationFeedback error : errors ) { log.logError( BaseMessages.getString( PKG, "PurRepositoryExporter.ERROR_EXPORT_ITEM_RULE", error.toString() ) ); //$NON-NLS-1$ } } return shouldExport; }
public String getXML() { StringBuilder xml = new StringBuilder(); xml.append( XMLHandler.openTag( XML_TAG ) ).append( Const.CR ).append( Const.CR ); for ( ImportRuleInterface rule : getRules() ) { PluginInterface plugin = PluginRegistry.getInstance().getPlugin( ImportRulePluginType.class, rule.getId() ); xml.append( "<!-- " ).append( plugin.getName() ).append( " : " ).append( plugin.getDescription() ).append( Const.CR ).append( " -->" ).append( Const.CR ); xml.append( rule.getXML() ); xml.append( Const.CR ).append( Const.CR ); } xml.append( XMLHandler.closeTag( XML_TAG ) ); return xml.toString(); }
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 ); } }
private List<ImportValidationFeedback> validateObject( Object subject, boolean boolFeedback ) throws KettleException { if ( !hasRules ) { return Collections.emptyList(); } if ( !boolFeedback ) { // this is call from Pan, job Executor or somthing else - we should throw // exception if one or more export rules is viloated. RepositoryImporter.validateImportedElement( importRules, subject ); } List<ImportValidationFeedback> feedback = importRules.verifyRules( subject ); List<ImportValidationFeedback> errors = new ArrayList<ImportValidationFeedback>( feedback.size() ); for ( ImportValidationFeedback res : feedback ) { if ( res.isError() ) { errors.add( res ); } } return errors; }
public void loadXML( Node rulesNode ) throws KettleException { List<Node> ruleNodes = XMLHandler.getNodes( rulesNode, BaseImportRule.XML_TAG ); for ( Node ruleNode : ruleNodes ) { String id = XMLHandler.getTagValue( ruleNode, "id" ); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, id ); if ( plugin == null ) { throw new KettleException( "The import rule of type '" + id + "' could not be found in the plugin registry." ); } ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass( plugin ); rule.loadXML( ruleNode ); getRules().add( rule ); } }
public ImportRulesDialog( Shell parentShell, ImportRules importRules ) { super( parentShell ); this.parentShell = parentShell; this.originalRules = importRules; this.importRules = importRules.clone(); this.props = PropsUI.getInstance(); this.display = parentShell.getDisplay(); }
/** * Save the rules to an XML file */ protected void exportRules() { syncUIWithData(); FileDialog dialog = new FileDialog( shell, SWT.SAVE ); 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(); FileWriter fileWriter = null; try { fileWriter = new FileWriter( filename ); fileWriter.write( XMLHandler.getXMLHeader() ); fileWriter.write( importRules.getXML() ); } catch ( Exception e ) { new ErrorDialog( shell, "Error", "There was an error while exporting to file '" + filename + "'", e ); } finally { try { fileWriter.close(); } catch ( Exception e ) { new ErrorDialog( shell, "Error", "There was an error closing file '" + filename + "'", e ); } } } }
public RepositoryExportProgressDialog( Shell shell, Repository rep, RepositoryDirectoryInterface dir, String filename ) { this( shell, rep, dir, filename, new ImportRules() ); }
/** * Validates the repository element that is about to get imported against the list of import rules. * * @param importRules * import rules to validate against. * @param subject * @throws KettleException */ public static void validateImportedElement( ImportRules importRules, Object subject ) throws KettleException { List<ImportValidationFeedback> feedback = importRules.verifyRules( subject ); List<ImportValidationFeedback> errors = ImportValidationFeedback.getErrors( feedback ); if ( !errors.isEmpty() ) { StringBuilder message = new StringBuilder( BaseMessages.getString( PKG, "RepositoryImporter.ValidationFailed.Message", subject .toString() ) ); message.append( Const.CR ); for ( ImportValidationFeedback error : errors ) { message.append( " - " ); message.append( error.toString() ); message.append( Const.CR ); } throw new KettleException( message.toString() ); } }
public void removeRule() { 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 remove the selected rules from the list?" ); int answer = box.open(); if ( answer != SWT.YES ) { return; } int[] indices = table.getSelectionIndices(); Arrays.sort( indices ); for ( int i = indices.length - 1; i >= 0; i-- ) { importRules.getRules().remove( indices[i] ); } // Refresh the whole list.. // getCompositesData(); }
public RepositoryImporter( Repository repository, LogChannelInterface log ) { this( repository, new ImportRules(), Collections.<String>emptyList(), log ); }
public RepositoryImporter( Repository repository ) { this( repository, new ImportRules(), new ArrayList<String>() ); }
public PurRepositoryExporter( PurRepository repository ) { this.repository = repository; this.importRules = new ImportRules(); this.log = repository.getLog(); }
/** * @param repository */ public RepositoryExporter( Repository repository ) { this.log = repository.getLog(); this.repository = repository; this.importRules = new ImportRules(); }
protected void syncUIWithData() { ImportRules newRules = new ImportRules(); getInfo( newRules ); importRules = newRules; getCompositesData(); }