import groovy.swing.SwingBuilder import java.awt.FlowLayout as FL import javax.swing.DefaultComboBoxModel import javax.swing.BoxLayout as BXL import groovy.beans.Bindable; import oracle.odi.domain.topology.finder.IOdiTechnologyFinder; import oracle.odi.domain.topology.finder.IOdiContextFinder; import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition; import oracle.odi.domain.topology.OdiTechnology; import oracle.odi.domain.topology.OdiContext; import oracle.odi.domain.util.ObfuscatedString; import oracle.odi.domain.model.OdiModel; import oracle.odi.domain.topology.OdiLogicalSchema; import oracle.odi.domain.topology.OdiPhysicalSchema; import oracle.odi.domain.topology.OdiDataServer; import oracle.odi.domain.topology.OdiContextualSchemaMapping; import oracle.odi.domain.topology.AbstractOdiDataServer; class Model{ @Bindable DefaultComboBoxModel toItems } def captureInput(defaultTech, defaultUrl, defaultDriver, defaultUser) { txnDef = new DefaultTransactionDefinition(); tm = odiInstance.getTransactionManager() txnStatus = tm.getTransaction(txnDef) contexts = [] technos = [] contextFinder = (IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class); contextc = contextFinder.findAll(); conItr = contextc.iterator() while (conItr.hasNext()) { con = (OdiContext) conItr.next() contexts.add(con.getCode()) } techFinder = (IOdiTechnologyFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiTechnology.class); techs = techFinder.findAll() techItr = techs.iterator() while (techItr.hasNext()) { tech = (OdiTechnology) techItr.next() technos.add(tech.getInternalName()) } tm.commit(txnStatus) Model m=new Model() Model t=new Model() d = new java.awt.Dimension(205,20) m.toItems = new DefaultComboBoxModel(contexts as Object[]) t.toItems = new DefaultComboBoxModel(technos as Object[]) def s = new SwingBuilder() s.setVariable('myDialog-properties',[:]) def vars = s.variables def dial = s.dialog(title:'Create ODI Model',id:'myDialog',modal:true) { panel() { boxLayout(axis:BXL.Y_AXIS) panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Technology Code:') comboBox(id:'techcode', 'model': bind {t.toItems}, selectedItem:defaultTech, preferredSize:d) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Context Code:') comboBox(id:'contextcode', 'model': bind {m.toItems}, preferredSize:d) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Model Name:') textField(id:'name',columns:25) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Logical Schema Name:') textField(id:'logschema',columns:25) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Dataserver Name:') textField(id:'dataservername',columns:25) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Driver:') textField(id:'driver',columns:25, text:defaultDriver) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('URL:') textField(id:'url',columns:25, text:defaultUrl) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('User:') textField(id:'user',columns:25, text:defaultUser) } panel(alignmentX:0f) { flowLayout(alignment:FL.RIGHT) label('Password:') passwordField(id:'password',columns:25) } panel(alignmentX:0f) { flowLayout(alignment:FL.LEFT) button('OK',preferredSize:[80,24], actionPerformed:{ vars.dialogResult = 'OK' dispose() }) button('Cancel',preferredSize:[80,24], actionPerformed:{ vars.dialogResult = 'cancel' dispose() }) } } } dial.pack() dial.show() return vars } def createLogicalSchema(contextCode, techCode, schName, dataserverName, userName, password, url, driver, schema) { txnDef = new DefaultTransactionDefinition(); tm = odiInstance.getTransactionManager() txnStatus = tm.getTransaction(txnDef) contextFinder = (IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class); context = contextFinder.findByCode(contextCode); techFinder = (IOdiTechnologyFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiTechnology.class); tech = techFinder.findByCode(techCode); lschema = new OdiLogicalSchema(tech, schName) dserver = new OdiDataServer(tech, dataserverName) con = new AbstractOdiDataServer.JdbcSettings(url, driver) dserver.setConnectionSettings(con) dserver.setUsername(userName) dserver.setPassword(password) pschema = new OdiPhysicalSchema(dserver) pschema.setSchemaName(schema) pschema.setWorkSchemaName(schema) cschema = new OdiContextualSchemaMapping(context, lschema, pschema) odiInstance.getTransactionalEntityManager().persist(lschema) odiInstance.getTransactionalEntityManager().persist(dserver) tm.commit(txnStatus) return lschema } def createModel(lschema, contextCode, modName, modCode) { txnDef = new DefaultTransactionDefinition(); tm = odiInstance.getTransactionManager() txnStatus = tm.getTransaction(txnDef) contextFinder = (IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class); context = contextFinder.findByCode(contextCode); mod = new OdiModel(lschema, modName, modCode) mod.setReverseContext(context) odiInstance.getTransactionalEntityManager().persist(mod) tm.commit(txnStatus) return mod } // // // 1. Capture User Input, results returned in vars // // vars= captureInput('ORACLE', 'jdbc:oracle:thin:@localhost:1521:orcl', 'oracle.jdbc.OracleDriver', 'SCOTT') // // // 2. If OK was pressed, then create Logical Schema and then Model // // if (vars.dialogResult == 'OK') { lschema = createLogicalSchema(vars.contextcode.selectedItem, vars.techcode.selectedItem, vars.logschema.text, vars.dataservername.text, vars.user.text, ObfuscatedString.obfuscate(vars.password.text), vars.url.text, vars.driver.text, vars.user.text) createModel(lschema, vars.contextcode.selectedItem, vars.name.text, vars.name.text) }