public static List<ImportValidationFeedback> getErrors( List<ImportValidationFeedback> feedback ) { List<ImportValidationFeedback> errors = new ArrayList<ImportValidationFeedback>(); for ( ImportValidationFeedback error : feedback ) { if ( error.isError() ) { errors.add( error ); } } return errors; }
public List<ImportValidationFeedback> verifyRules( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); for ( ImportRuleInterface rule : rules ) { feedback.addAll( rule.verifyRule( subject ) ); } return feedback; }
@Override public String toString() { StringBuilder string = new StringBuilder(); string.append( resultType.name() ).append( " : " ); string.append( comment ).append( " - " ); string.append( importRule.toString() ); return string.toString(); }
/** * 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() ); } }
if ( rule.isUnique() ) { PluginInterface plugin = plugins.get( i ); if ( Const.indexOfString( rule.getId(), plugin.getIds() ) >= 0 ) { removeIndex = i; break; PluginInterface plugin = plugins.get( index ); ImportRuleInterface rule = (ImportRuleInterface) registry.loadClass( plugin ); rule.setEnabled( true ); rule.setId( plugin.getIds()[0] );
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(); }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof JobMeta ) ) { return feedback; } JobMeta jobMeta = (JobMeta) subject; if ( jobMeta.nrNotes() == 0 ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "There is not even a single note in the job." ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "At least one not is present in the job." ) ); } return feedback; }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof TransMeta ) ) { return feedback; } TransMeta transMeta = (TransMeta) subject; if ( transMeta.nrNotes() == 0 ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "There is not even a single note in the transformation." ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "At least one not is present in the transformation." ) ); } return feedback; }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof JobMeta ) ) { return feedback; } JobMeta transMeta = (JobMeta) subject; String description = transMeta.getDescription(); if ( description != null && description.length() > minLength ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "A description is present" ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "A description is not present or too short" ) ); } return feedback; }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof TransMeta ) ) { return feedback; } TransMeta transMeta = (TransMeta) subject; String description = transMeta.getDescription(); if ( Utils.isEmpty( description ) || ( minLength > 0 && description.length() < minLength ) ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "A description is not present or is too short." ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "A description is present" ) ); } return feedback; }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof TransMeta ) ) { return feedback; } TransMeta transMeta = (TransMeta) subject; for ( int i = 0; i < transMeta.nrTransHops(); i++ ) { TransHopMeta hop = transMeta.getTransHop( i ); if ( !hop.isEnabled() ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "There is a disabled hop in the transformation." ) ); } } if ( feedback.isEmpty() ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "All hops are enabled in this transformation." ) ); } return feedback; }
@Override public List<ImportValidationFeedback> verifyRule( Object subject ) { List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>(); if ( !isEnabled() ) { return feedback; } if ( !( subject instanceof JobMeta ) ) { return feedback; } JobMeta jobMeta = (JobMeta) subject; for ( int i = 0; i < jobMeta.nrJobHops(); i++ ) { JobHopMeta hop = jobMeta.getJobHop( i ); if ( !hop.isEnabled() ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "There is a disabled hop in the job." ) ); } } if ( feedback.isEmpty() ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "All hops are enabled in this job." ) ); } return feedback; }
feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "The logging table is not defined" ) ); } else { if ( !Utils.isEmpty( schemaName ) ) { if ( schemaName.equals( transLogTable.getSchemaName() ) ) { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "The schema name is set to: " + schemaName ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "The schema name is not set to: " + schemaName ) ); feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "The table name is set to: " + tableName ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "The table name is not set to: " + tableName ) ); feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "The database connection used for logging is: " + connectionName ) ); } else { feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.ERROR, "The database connection used for logging is not: " + connectionName ) ); feedback.add( new ImportValidationFeedback( this, ImportValidationResultType.APPROVAL, "The logging table is correctly defined" ) );
/** * 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; }
public ImportRuleCompositeInterface getImportRuleComposite( ImportRuleInterface rule ) throws KettleException { String compositeClassName = rule.getCompositeClassName(); Class<?> compositeClass; Class<?>[] paramClasses = new Class<?>[] {}; Object[] paramArgs = new Object[] {}; Constructor<?> compositeConstructor; try { compositeClass = rule.getClass().getClassLoader().loadClass( compositeClassName ); compositeConstructor = compositeClass.getConstructor( paramClasses ); return (ImportRuleCompositeInterface) compositeConstructor.newInstance( paramArgs ); } catch ( Exception e ) { throw new KettleException( e ); } }
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 ); } }
List<ImportValidationFeedback> fList = this.getResult(); for ( ImportValidationFeedback res : fList ) { message = BaseMessages.getString( PKG, "ExportFeedback.Message.RuleViolated", res.getComment() ); sb.append( message ); sb.append( Const.CR );
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 ); } }
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; }
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; }