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; }
/** * 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() ); } }
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; }