The below codes automatically adds all the interface/Scenarios of a Folder into a New Package .
The below codes are written in such a way so that minimal changes are required .
All you would need to change is the parameters . Also in the Scenarios we have mentioned only Scenario name and version as -1 so please change accordingly or add more parameters according to your requirement.
Add all the interface of the Folder into Package
package odi_sdk; import java.util.Collection; import java.util.Iterator; import oracle.odi.core.OdiInstance; import oracle.odi.core.config.MasterRepositoryDbInfo; import oracle.odi.core.config.OdiInstanceConfig; import oracle.odi.core.config.PoolingAttributes; import oracle.odi.core.config.WorkRepositoryDbInfo; import oracle.odi.core.persistence.transaction.ITransactionStatus; import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition; import oracle.odi.core.security.Authentication; import oracle.odi.domain.project.OdiFolder; import oracle.odi.domain.project.OdiInterface; import oracle.odi.domain.project.OdiPackage; import oracle.odi.domain.project.StepInterface; import oracle.odi.domain.project.finder.IOdiFolderFinder; import oracle.odi.domain.project.finder.IOdiInterfaceFinder; public class AddIntfNewPackage { private static String Project_Code; private static String Folder_Name; private static OdiInterface odiInterface; private static StepInterface step_prevscen; private static OdiPackage pkg; private static StepInterface step_intf; private static OdiFolder folder; private static String Package_Name; /** * @param args */ public static void main(String[] args) { /****** Please change these Parameters *********/ String Url = "jdbc:oracle:thin:@localhost:1521:orcl"; String Driver="oracle.jdbc.OracleDriver"; String Master_User="ODI_MASTER_11G"; String Master_Pass="ODI_MASTER_11G"; String WorkRep="WORKREP1"; String Odi_User="SUPERVISOR"; String Odi_Pass="SUNOPSIS"; Project_Code="XMT"; Folder_Name ="FOLDER"; Package_Name=""; //Provide Package Name /********************************************/ MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes()); WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(WorkRep, new PoolingAttributes()); OdiInstance odiInstance=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo)); Authentication auth = odiInstance.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray()); odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth); ITransactionStatus trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition()); Collection<OdiFolder> fold = ((IOdiFolderFinder) odiInstance .getTransactionalEntityManager().getFinder(OdiFolder.class)). findByName(Folder_Name,Project_Code); for (Iterator<OdiFolder> it = fold.iterator(); it.hasNext();) { folder = (OdiFolder) it.next(); } // New Package pkg = new OdiPackage(folder, Package_Name); int i=0; Collection<OdiInterface> intf_find = ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)). findByProject(Project_Code, Folder_Name); for (Iterator<OdiInterface> iterator = intf_find.iterator(); iterator.hasNext();) { odiInterface = (OdiInterface) iterator.next(); System.out.println("Interface Name is " + odiInterface.getName()); step_intf = new StepInterface(pkg,odiInterface,odiInterface.getName()); if (i==0) { step_prevscen = new StepInterface(pkg,odiInterface,odiInterface.getName()); pkg.setFirstStep(step_prevscen); pkg.removeStep(step_intf); i+=1; }else{ step_prevscen.setNextStepAfterSuccess(step_intf); step_prevscen = step_intf; }} // Persisting the Package odiInstance.getTransactionalEntityManager().persist(pkg); odiInstance.getTransactionManager().commit(trans); odiInstance.close(); System.out.println("Process Completed"); } }
Add all the scenario of the Folder into the Package.
package odi_sdk; import java.util.Collection; import java.util.Iterator; import oracle.odi.core.OdiInstance; import oracle.odi.core.config.MasterRepositoryDbInfo; import oracle.odi.core.config.OdiInstanceConfig; import oracle.odi.core.config.PoolingAttributes; import oracle.odi.core.config.WorkRepositoryDbInfo; import oracle.odi.core.persistence.transaction.ITransactionStatus; import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition; import oracle.odi.core.security.Authentication; import oracle.odi.domain.project.OdiFolder; import oracle.odi.domain.project.OdiInterface; import oracle.odi.domain.project.OdiPackage; import oracle.odi.domain.project.StepOdiCommand; import oracle.odi.domain.project.finder.IOdiFolderFinder; import oracle.odi.domain.project.finder.IOdiInterfaceFinder; import oracle.odi.domain.runtime.scenario.OdiScenario; import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder; import oracle.odi.domain.xrefs.expression.Expression; public class AddScenNewPackage { private static String Project_Code; private static String Folder_Name; private static OdiInterface odiInterface; private static StepOdiCommand step_prevscen; private static OdiPackage pkg; private static StepOdiCommand step_scen; private static OdiFolder folder; private static String Package_Name; /** * @param args */ public static void main(String[] args) { /****** Please change these Parameters *********/ String Url = "jdbc:oracle:thin:@localhost:1521:orcl"; String Driver="oracle.jdbc.OracleDriver"; String Master_User="ODI_MASTER_11G"; String Master_Pass="ODI_MASTER_11G"; String WorkRep="WORKREP1"; String Odi_User="SUPERVISOR"; String Odi_Pass="SUNOPSIS"; Project_Code="XMT"; Folder_Name ="FOLDER"; Package_Name="TESTING"; //Provide Package Name /********************************************/ MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes()); WorkRepositoryDbInfo workInfo = new WorkRepositoryDbInfo(WorkRep, new PoolingAttributes()); OdiInstance odiInstance=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo)); Authentication auth = odiInstance.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray()); odiInstance.getSecurityManager().setCurrentThreadAuthentication(auth); ITransactionStatus trans = odiInstance.getTransactionManager().getTransaction(new DefaultTransactionDefinition()); Collection<OdiFolder> fold = ((IOdiFolderFinder) odiInstance .getTransactionalEntityManager().getFinder(OdiFolder.class)). findByName(Folder_Name,Project_Code); for (Iterator<OdiFolder> it = fold.iterator(); it.hasNext();) { folder = (OdiFolder) it.next(); } // New Package pkg = new OdiPackage(folder, Package_Name); int i=0; Collection<OdiInterface> intf_find = ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)). findByProject(Project_Code, Folder_Name); for (Iterator<OdiInterface> iterator = intf_find.iterator(); iterator.hasNext();) { odiInterface = (OdiInterface) iterator.next(); Collection<OdiScenario> scen = ((IOdiScenarioFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiScenario.class)). findBySourceInterface(odiInterface.getInterfaceId()); for (Iterator<OdiScenario> iterator2 = scen.iterator(); iterator2.hasNext();) { OdiScenario odiScenario = (OdiScenario) iterator2.next(); System.out.println(odiScenario.getName()); step_scen = new StepOdiCommand(pkg,odiScenario.getName().toUpperCase()); step_scen.setCommandExpression(new Expression("OdiStartScen -SCEN_NAME="+odiScenario.getName()+" -SCEN_VERSION=-1", null, Expression.SqlGroupType.NONE)); System.out.println(i); if (i==0) { step_prevscen = step_scen; pkg.setFirstStep(step_prevscen); step_prevscen = step_scen; i+=1; }else{ step_prevscen.setNextStepAfterSuccess(step_scen); step_prevscen = step_scen; }} } odiInstance.getTransactionalEntityManager().persist(pkg); odiInstance.getTransactionManager().commit(trans); odiInstance.close(); System.out.println("Process Completed"); } }
2 Comments
Leave a reply →