import oracle.odi.core.OdiInstance import oracle.odi.core.config.OdiInstanceConfig import oracle.odi.core.config.MasterRepositoryDbInfo import oracle.odi.core.config.WorkRepositoryDbInfo import oracle.odi.core.security.Authentication import oracle.odi.core.config.PoolingAttributes import oracle.odi.domain.project.OdiProject import oracle.odi.domain.project.finder.IOdiProjectFinder import oracle.odi.domain.project.finder.IOdiFolderFinder import oracle.odi.domain.project.finder.IOdiInterfaceFinder import oracle.odi.domain.model.finder.IOdiDataStoreFinder import oracle.odi.domain.topology.finder.IOdiContextFinder import oracle.odi.domain.topology.finder.IOdiTechnologyFinder import oracle.odi.domain.topology.OdiTechnology import oracle.odi.domain.project.OdiFolder import oracle.odi.domain.project.OdiInterface import oracle.odi.domain.project.interfaces.DataSet import oracle.odi.domain.model.OdiDataStore import oracle.odi.domain.topology.OdiContext import oracle.odi.core.persistence.transaction.ITransactionStatus import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition import oracle.odi.domain.project.OdiPackage import oracle.odi.domain.project.StepOdiCommand import oracle.odi.domain.xrefs.expression.ExpressionStringBuilder import oracle.odi.languages.ILanguageProvider import oracle.odi.languages.support.LanguageProviderImpl import oracle.odi.generation.support.OdiScenarioGeneratorImpl import oracle.odi.runtime.agent.invocation.RemoteRuntimeAgentInvoker import oracle.odi.runtime.agent.invocation.StartupParams import java.util.Collection import java.io.* /* ----------------------------------------------------------------------------------------- Describe code here ----------------------------------------------------------------------------------------- */ /* -------- Begin update section Replace the follwing values with your connectivity information. Alternatively, you can use ODI substitution APIs to fill in these parameters dynamically ----------- */ def url = "jdbc:oracle:thin:@localhost:1521:orcl" /*Master Repository: JDBC URL */ def driver = "oracle.jdbc.OracleDriver" /*Master Repository: JDBC driver */ def schema = "ODIM1115" /*Master Repository: Database user for schema access*/ def schemapwd = "ODIM1115PWD" /*Master Repository JDBC URL */ def workrep = "WORKREP1" /*Name of the Work Repository */ def odiuser= "SUPERVISOR" /* ODI User name used to connect to the repositories */ def odiuserpwd = "SUNOPSIS" /* ODI User password to connect to the repositories */ def projectCode = "RF" /*Project Code*/ def folder ="First Folder" /*Folder Name*/ /* -------- End of update section ----------- */ def masterInfo = new MasterRepositoryDbInfo(url, driver, schema, schemapwd.toCharArray(), new PoolingAttributes()) def workInfo = new WorkRepositoryDbInfo(workrep, new PoolingAttributes()) def odiInstance = OdiInstance.createInstance(new OdiInstanceConfig(masterInfo, workInfo)) def auth = odiInstance.getSecurityManager().createAuthentication(odiuser, odiuserpwd.toCharArray()) odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth) def txnDef = new DefaultTransactionDefinition() def tm = odiInstance.getTransactionManager() def txnStatus = tm.getTransaction(txnDef) /* To create the package, we first need the odiFolder object where the package will be created - we can retrieve this from the project Code and Folder name */ def odiFolders = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(folder,projectCode) if (odiFolders.size() == 0) { System.err.println("Error: cannot find folder "+folder+" in project "+project); return } def odiFolder = (OdiFolder) (odiFolders.toArray()[0]) /* ---- Create a new, empty package ---- */ def odiPackage = new OdiPackage(odiFolder, "RunODICommand") /* ---- Now we need to add an ODI Tool as a step in the package ---- */ def odiTechnology = ((IOdiTechnologyFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiTechnology.class)).findByCode("SUNOPSIS_API") lp = new LanguageProviderImpl(odiInstance); stepLanguage = lp.getSnpsLanguageByTechnologyName("SUNOPSIS_API") /* Hint: Check out the "Technology Code" for "ODI Tools" in Topology's Physical Architecture. This is where the internal name for the technology can be found*/ def stepOdiCommand = new StepOdiCommand(odiPackage, "SendMail") /* ---- Now we have a step, but no expression for that step (we need the equivalent of what would be in the "command" tab of the step in the ODI Studio ---- */ def expressionStringBuilder = new ExpressionStringBuilder(stepLanguage) expressionStringBuilder.append("OdiSendMail \"-MAILHOST=mail.oracle.com\" \"-FROM=foo@foo.com\" \"-SUBJECT=You've Got Mail\" \"-TO=foo@foo.com\" \n This code was generated, compiled and Executed with the ODI SDK\n. Thanks for your help!.") stepOdiCommand.setCommandExpression(expressionStringBuilder.toExpression() ) /* ---- The step is now complete. We can now generate a scenario form the package WARNING: if you've already generated this scenario, you have to remove it manually before you generate it again... or you have to improve the code to do so ;) ---- */ odiInstance.getTransactionalEntityManager().persist(odiPackage) def scen=new oracle.odi.generation.support.OdiScenarioGeneratorImpl(odiInstance) scen.generateScenario(odiPackage, "RUNCOMMAND", "001") /* ---- Now we have to commit our operations - or the agent will not find the scenario in the repository ---- */ tm.commit(txnStatus) /* ---- Connect to the agent and run the scenario ---- */ agent = new RemoteRuntimeAgentInvoker("http://localhost:20910/oraclediagent", "SUPERVISOR", "SUNOPSIS".toCharArray()) startupParams = new StartupParams() agent.invokeStartScenario("RUNCOMMAND", "001", startupParams, "", "DEV", 5, "Dynamic", true, "WORKREP1")