Java Code Examples for org.pentaho.di.core.plugins.PluginRegistry#loadClass()
The following examples show how to use
org.pentaho.di.core.plugins.PluginRegistry#loadClass() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Encr.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public static void init( String encoderPluginId ) throws KettleException { if ( Utils.isEmpty( encoderPluginId ) ) { throw new KettleException( "Unable to initialize the two way password encoder: No encoder plugin type specified." ); } PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( TwoWayPasswordEncoderPluginType.class, encoderPluginId ); if ( plugin == null ) { throw new KettleException( "Unable to find plugin with ID '" + encoderPluginId + "'. If this is a test, make sure" + " kettle-core tests jar is a dependency. If this is live make sure a kettle-password-encoder-plugins.xml" + " exits in the classpath" ); } encoder = (TwoWayPasswordEncoderInterface) registry.loadClass( plugin ); // Load encoder specific options... // try { encoder.init(); } catch ( PasswordEncoderException e ) { throw new KettleException( e ); } }
Example 2
Source File: SpoonUiExtenderPluginType.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public List<SpoonUiExtenderPluginInterface> getRelevantExtenders( Class<?> clazz, String uiEvent ) { PluginRegistry instance = PluginRegistry.getInstance(); List<PluginInterface> pluginInterfaces = instance.getPlugins( SpoonUiExtenderPluginType.class ); List<SpoonUiExtenderPluginInterface> relevantPluginInterfaces = new ArrayList<SpoonUiExtenderPluginInterface>( ); if ( pluginInterfaces != null ) { for ( PluginInterface pluginInterface : pluginInterfaces ) { try { Object loadClass = instance.loadClass( pluginInterface ); SpoonUiExtenderPluginInterface spoonUiExtenderPluginInterface = (SpoonUiExtenderPluginInterface) loadClass; Set<String> events = spoonUiExtenderPluginInterface.respondsTo().get( clazz ); if ( events != null && events.contains( uiEvent ) ) { relevantPluginInterfaces.add( spoonUiExtenderPluginInterface ); } } catch ( KettlePluginException e ) { e.printStackTrace(); } } } return relevantPluginInterfaces; }
Example 3
Source File: StepPartitioningMeta.java From pentaho-kettle with Apache License 2.0 | 6 votes |
public void createPartitioner( String method ) throws KettlePluginException { methodType = getMethodType( method ); switch ( methodType ) { case PARTITIONING_METHOD_SPECIAL: { PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( PartitionerPluginType.class, method ); partitioner = (Partitioner) registry.loadClass( plugin ); partitioner.setId( plugin.getIds()[0] ); break; } case PARTITIONING_METHOD_NONE: default: partitioner = null; } if ( partitioner != null ) { partitioner.setMeta( this ); } }
Example 4
Source File: ImportRules.java From pentaho-kettle with Apache License 2.0 | 6 votes |
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 ); } }
Example 5
Source File: ExecuteTransServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private Repository openRepository( String repositoryName, String user, String pass ) throws KettleException { if ( Utils.isEmpty( repositoryName ) ) { return null; } RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.readData(); RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { throw new KettleException( "Unable to find repository: " + repositoryName ); } PluginRegistry registry = PluginRegistry.getInstance(); Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); repository.init( repositoryMeta ); repository.connect( user, pass ); return repository; }
Example 6
Source File: ExecuteJobServlet.java From pentaho-kettle with Apache License 2.0 | 6 votes |
@VisibleForTesting Repository openRepository( String repositoryName, String user, String pass ) throws KettleException { if ( Utils.isEmpty( repositoryName ) ) { return null; } RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.readData(); RepositoryMeta repositoryMeta = repositoriesMeta.findRepository( repositoryName ); if ( repositoryMeta == null ) { String message = BaseMessages.getString( PKG, "ExecuteJobServlet.Error.UnableToFindRepository", repositoryName ); throw new KettleRepositoryNotFoundException( message ); } PluginRegistry registry = PluginRegistry.getInstance(); Repository repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); repository.init( repositoryMeta ); repository.connect( user, pass ); return repository; }
Example 7
Source File: SlaveServerConfig.java From pentaho-kettle with Apache License 2.0 | 5 votes |
private void openRepository( String repositoryId ) throws KettleException { try { RepositoriesMeta repositoriesMeta = new RepositoriesMeta(); repositoriesMeta.readData(); repositoryMeta = repositoriesMeta.findRepository( repositoryId ); if ( repositoryMeta == null ) { throw new KettleException( "Unable to find repository: " + repositoryId ); } PluginRegistry registry = PluginRegistry.getInstance(); repository = registry.loadClass( RepositoryPluginType.class, repositoryMeta, Repository.class ); repository.init( repositoryMeta ); repository.connect( repositoryUsername, repositoryPassword ); // Add the repository MetaStore to the delegation as well. // Set this one as active with the highest priority // if ( repository.getMetaStore() != null ) { metaStore.addMetaStore( 0, repository.getMetaStore() ); metaStore.setActiveMetaStoreName( repository.getMetaStore().getName() ); } LogChannel.GENERAL.logBasic( "Connected to repository '" + repository.getName() + "'" ); } catch ( Exception e ) { throw new KettleException( "Unable to open repository connection", e ); } }
Example 8
Source File: JobHasDescriptionImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void testRule() throws Exception { JobMeta jobMeta = new JobMeta(); jobMeta.setDescription( "This job is used for testing an import rule" ); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "JobHasDescription" ); assertNotNull( "The 'job has description' rule could not be found in the plugin registry!", plugin ); JobHasDescriptionImportRule rule = (JobHasDescriptionImportRule) registry.loadClass( plugin ); assertNotNull( "The 'job has description rule' class could not be loaded by the plugin registry!", plugin ); rule.setMinLength( 20 ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); rule.setMinLength( 2000 ); rule.setEnabled( true ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't expect any feedback from the 'job has description rule' while disabled", feedback .isEmpty() ); }
Example 9
Source File: JobHasANoteImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void testRule() throws Exception { // Create a job to test. // JobMeta jobMeta = new JobMeta(); NotePadMeta note = new NotePadMeta( "A note documenting the transformation", 50, 50, 200, 50 ); jobMeta.addNote( note ); // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "JobHasANote" ); assertNotNull( "The 'job has a note' rule could not be found in the plugin registry!", plugin ); JobHasANoteImportRule rule = (JobHasANoteImportRule) registry.loadClass( plugin ); assertNotNull( "The 'job has a note' rule class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has a note'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); jobMeta.removeNote( 0 ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has a note' rule", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't expect any feedback from the 'job has no note' rule while disabled", feedback.isEmpty() ); }
Example 10
Source File: TransformationHasANoteImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public void testRule() throws Exception { // Create a transformation to test. // TransMeta transMeta = new TransMeta(); NotePadMeta note = new NotePadMeta( "A note documenting the transformation", 50, 50, 200, 50 ); transMeta.addNote( note ); // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasANote" ); assertNotNull( "The 'transformation has a note' rule could not be found in the plugin registry!", plugin ); TransformationHasANoteImportRule rule = (TransformationHasANoteImportRule) registry.loadClass( plugin ); assertNotNull( "The 'transformation has a note' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); transMeta.removeNote( 0 ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has a note' rule", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has a note' rule while disabled", feedback .isEmpty() ); }
Example 11
Source File: DatabaseConfigurationImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { // Assemble a new database. // String DBNAME = "test"; String HOSTNAME = "localhost"; String PORT = "3306"; String USERNAME = "foo"; String PASSWORD = "bar"; DatabaseMeta verifyMeta = new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", HOSTNAME, DBNAME, PORT, USERNAME, PASSWORD ); // Create a transformation to test. // TransMeta transMeta = new TransMeta(); transMeta.addDatabase( (DatabaseMeta) verifyMeta.clone() ); // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "DatabaseConfiguration" ); assertNotNull( "The 'database configuration' rule could not be found in the plugin registry!", plugin ); DatabaseConfigurationImportRule rule = (DatabaseConfigurationImportRule) registry.loadClass( plugin ); assertNotNull( "The 'database configuration' class could not be loaded by the plugin registry!", plugin ); // Set the appropriate rule.. // rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'database configuration'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setDatabaseMeta( verifyMeta ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Create some errors... // verifyMeta.setDBName( "incorrect-test" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db name", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setDBName( DBNAME ); verifyMeta.setHostname( "incorrect-hostname" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db hostname", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setHostname( HOSTNAME ); verifyMeta.setDBPort( "incorrect-port" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db port", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setDBPort( PORT ); verifyMeta.setUsername( "incorrect-username" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db username", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setUsername( USERNAME ); verifyMeta.setPassword( "incorrect-password" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected validating the db password", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); verifyMeta.setPassword( PASSWORD ); // No feedback expected! // rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has trans log table configured' since disabled", feedback.isEmpty() ); }
Example 12
Source File: TransformationHasDescriptionImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { TransMeta transMeta = new TransMeta(); transMeta.setDescription( "This transformation is used for testing an import rule" ); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasDescription" ); assertNotNull( "The 'transformation has description' rule could not be found in the plugin registry!", plugin ); TransformationHasDescriptionImportRule rule = (TransformationHasDescriptionImportRule) registry.loadClass( plugin ); assertNotNull( "The 'transformation has description rule' class could not be loaded by the plugin registry!", plugin ); rule.setMinLength( 20 ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); rule.setMinLength( 2000 ); rule.setEnabled( true ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has description rule' while disabled", feedback .isEmpty() ); }
Example 13
Source File: JobHasNoDisabledHopsImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { // Create a job to test. // JobMeta jobMeta = new JobMeta(); // Add 3 dummy steps connected with hops. // JobEntryCopy lastCopy = null; for ( int i = 0; i < 3; i++ ) { JobEntrySpecial dummy = new JobEntrySpecial(); dummy.setDummy( true ); dummy.setName( "dummy" + ( i + 1 ) ); JobEntryCopy copy = new JobEntryCopy( dummy ); copy.setLocation( 50 + i * 50, 50 ); copy.setDrawn(); jobMeta.addJobEntry( copy ); if ( lastCopy != null ) { JobHopMeta hop = new JobHopMeta( lastCopy, copy ); jobMeta.addJobHop( hop ); } lastCopy = copy; } // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "JobHasNoDisabledHops" ); assertNotNull( "The 'job has no disabled hops' rule could not be found in the plugin registry!", plugin ); JobHasNoDisabledHopsImportRule rule = (JobHasNoDisabledHopsImportRule) registry.loadClass( plugin ); assertNotNull( "The 'job has no disabled hops' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has no disabled hops'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); jobMeta.getJobHop( 0 ).setEnabled( false ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has no disabled hops'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't expect any feedback from the 'job has no disabled hops' while disabled", feedback .isEmpty() ); }
Example 14
Source File: JobEntryCopy.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public JobEntryCopy( Node entrynode, List<DatabaseMeta> databases, List<SlaveServer> slaveServers, Repository rep, IMetaStore metaStore ) throws KettleXMLException { try { String stype = XMLHandler.getTagValue( entrynode, "type" ); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface jobPlugin = registry.findPluginWithId( JobEntryPluginType.class, stype, true ); if ( jobPlugin == null ) { String name = XMLHandler.getTagValue( entrynode, "name" ); entry = new MissingEntry( name, stype ); } else { entry = registry.loadClass( jobPlugin, JobEntryInterface.class ); } // Get an empty JobEntry of the appropriate class... if ( entry != null ) { if ( jobPlugin != null ) { entry.setPluginId( jobPlugin.getIds()[0] ); } entry.setMetaStore( metaStore ); // inject metastore entry.loadXML( entrynode, databases, slaveServers, rep, metaStore ); compatibleLoadXml( entrynode, databases, slaveServers, rep ); // Handle GUI information: nr & location? setNr( Const.toInt( XMLHandler.getTagValue( entrynode, "nr" ), 0 ) ); setLaunchingInParallel( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "parallel" ) ) ); setDrawn( "Y".equalsIgnoreCase( XMLHandler.getTagValue( entrynode, "draw" ) ) ); int x = Const.toInt( XMLHandler.getTagValue( entrynode, "xloc" ), 0 ); int y = Const.toInt( XMLHandler.getTagValue( entrynode, "yloc" ), 0 ); setLocation( x, y ); Node jobEntryCopyAttributesNode = XMLHandler.getSubNode( entrynode, XML_ATTRIBUTE_JOB_ENTRY_COPY ); if ( jobEntryCopyAttributesNode != null ) { attributesMap = AttributesUtil.loadAttributes( jobEntryCopyAttributesNode ); } else { // [PDI-17345] If the appropriate attributes node wasn't found, this must be an old file (prior to this fix). // Before this fix it was very probable to exist two attributes groups. While this is not very valid, in some // scenarios the Job worked as expected; so by trying to load the LAST one into the JobEntryCopy, we // simulate that behaviour. attributesMap = AttributesUtil.loadAttributes( XMLHandler.getLastSubNode( entrynode, AttributesUtil.XML_TAG ) ); } setDeprecationAndSuggestedJobEntry(); } } catch ( Throwable e ) { String message = "Unable to read Job Entry copy info from XML node : " + e.toString(); throw new KettleXMLException( message, e ); } }
Example 15
Source File: TransformationHasNoDisabledHopsImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { // Create a transformation to test. // TransMeta transMeta = new TransMeta(); // Add 3 dummy steps connected with hops. // StepMeta lastStep = null; for ( int i = 0; i < 3; i++ ) { DummyTransMeta dummyTransMeta = new DummyTransMeta(); StepMeta stepMeta = new StepMeta( "dummy" + ( i + 1 ), dummyTransMeta ); stepMeta.setLocation( 50 + i * 50, 50 ); stepMeta.setDraw( true ); transMeta.addStep( stepMeta ); if ( lastStep != null ) { TransHopMeta hop = new TransHopMeta( lastStep, stepMeta ); transMeta.addTransHop( hop ); } lastStep = stepMeta; } // Load the plugin to test from the registry. // PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasNoDisabledHops" ); assertNotNull( "The 'transformation has no disabled hops' rule could not be found in the plugin registry!", plugin ); TransformationHasNoDisabledHopsImportRule rule = (TransformationHasNoDisabledHopsImportRule) registry.loadClass( plugin ); assertNotNull( "The 'transformation has no disabled hops' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has no disabled hops'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); transMeta.getTransHop( 0 ).setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has no disabled hops'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has no disabled hops' while disabled", feedback .isEmpty() ); }
Example 16
Source File: TransformationHasTransLogConfiguredImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { TransMeta transMeta = new TransMeta(); DatabaseMeta logDbMeta = new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", "localhost", "test", "3306", "foo", "bar" ); transMeta.addDatabase( logDbMeta ); TransLogTable logTable = transMeta.getTransLogTable(); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "TransformationHasTransLogConfigured" ); assertNotNull( "The 'transformation has trans log table configured' rule could not be found in the plugin registry!", plugin ); TransformationHasTransLogConfiguredImportRule rule = (TransformationHasTransLogConfiguredImportRule) registry.loadClass( plugin ); assertNotNull( "The 'transformation has trans log table configured' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has trans log table configured'", !feedback .isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); logTable.setTableName( "SCHEMA" ); logTable.setTableName( "LOGTABLE" ); logTable.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Make the rules stricter! // rule.setTableName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Break the rule // rule.setSchemaName( "INCORRECT_SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "INCORRECT_LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( "INCORRECT_DATABASE" ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't get any feedback from the 'transformation has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); // No feedback expected! // rule.setEnabled( false ); feedback = rule.verifyRule( transMeta ); assertTrue( "We didn't expect any feedback from the 'transformation has trans " + "log table configured' since the rule is not enabled", feedback.isEmpty() ); }
Example 17
Source File: BaseSerializingMeta.java From pentaho-kettle with Apache License 2.0 | 4 votes |
private StepMetaInterface getNewMeta() throws KettleException { PluginRegistry pluginRegistry = PluginRegistry.getInstance(); String id = pluginRegistry.getPluginId( StepPluginType.class, this ); PluginInterface plugin = pluginRegistry.getPlugin( StepPluginType.class, id ); return (StepMetaInterface) pluginRegistry.loadClass( plugin ); }
Example 18
Source File: PropsUI.java From pentaho-kettle with Apache License 2.0 | 4 votes |
@SuppressWarnings( "unchecked" ) protected synchronized void init() { super.createLogChannel(); properties = new Properties(); pluginHistory = new ArrayList<ObjectUsageCount>(); setDefault(); loadProps(); addDefaultEntries(); loadPluginHistory(); loadScreens(); loadLastUsedFiles(); loadLastUsedRepoFiles(); loadOpenTabFiles(); resetRecentSearches(); PluginRegistry registry = PluginRegistry.getInstance(); List<PluginInterface> plugins = registry.getPlugins( LifecyclePluginType.class ); List<GUIOption<Object>> leditables = new ArrayList<GUIOption<Object>>(); for ( PluginInterface plugin : plugins ) { if ( !plugin.getClassMap().keySet().contains( GUIOption.class ) ) { continue; } try { GUIOption<Object> loaded = registry.loadClass( plugin, GUIOption.class ); if ( loaded != null ) { leditables.add( loaded ); } } catch ( ClassCastException cce ) { // Not all Lifecycle plugins implement GUIOption, keep calm and carry on LogChannel.GENERAL.logDebug( "Plugin " + plugin.getIds()[ 0 ] + " does not implement GUIOption, it will not be editable" ); } catch ( Exception e ) { LogChannel.GENERAL.logError( "Unexpected error loading class for plugin " + plugin.getName(), e ); } } editables = Collections.unmodifiableList( leditables ); }
Example 19
Source File: JobHasJobLogConfiguredImportRuleIT.java From pentaho-kettle with Apache License 2.0 | 4 votes |
public void testRule() throws Exception { JobMeta jobMeta = new JobMeta(); DatabaseMeta logDbMeta = new DatabaseMeta( "LOGDB", "MYSQL", "JDBC", "localhost", "test", "3306", "foo", "bar" ); jobMeta.addDatabase( logDbMeta ); JobLogTable logTable = jobMeta.getJobLogTable(); PluginRegistry registry = PluginRegistry.getInstance(); PluginInterface plugin = registry.findPluginWithId( ImportRulePluginType.class, "JobHasJobLogConfigured" ); assertNotNull( "The 'job has job log table configured' rule could not be found in the plugin registry!", plugin ); JobHasJobLogConfiguredImportRule rule = (JobHasJobLogConfiguredImportRule) registry.loadClass( plugin ); assertNotNull( "The 'job has job log table configured' class could not be loaded by the plugin registry!", plugin ); rule.setEnabled( true ); List<ImportValidationFeedback> feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has job log table configured'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); logTable.setTableName( "SCHEMA" ); logTable.setTableName( "LOGTABLE" ); logTable.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Make the rules stricter! // rule.setTableName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An approval ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.APPROVAL ); // Break the rule // rule.setSchemaName( "INCORRECT_SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "INCORRECT_LOGTABLE" ); rule.setConnectionName( logDbMeta.getName() ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); rule.setSchemaName( "SCHEMA" ); rule.setTableName( "LOGTABLE" ); rule.setConnectionName( "INCORRECT_DATABASE" ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't get any feedback from the 'job has description rule'", !feedback.isEmpty() ); assertTrue( "An error ruling was expected", feedback.get( 0 ).getResultType() == ImportValidationResultType.ERROR ); // No feedback expected! // rule.setEnabled( false ); feedback = rule.verifyRule( jobMeta ); assertTrue( "We didn't expect any feedback from the 'job has job log table configured' since the rule is not enabled", feedback.isEmpty() ); }