Hi Friends!
First of all HAPPY NEW YEAR!
We, from ODI Experts, hope that 2012 be a fantastic year for all of you!
Continuing our “Java code series” take a look on this new one.
The below code is used to Generate/Regenerate All Scenario and depending on the options the appropriate ODI Objects scenario will be generated/regenerated.
Also make sure you use the appropriate Generating option i.e INCREMENTAL_MODE (OR) REGENERATE_MODE (OR) REPLACE_MODE
GenerationOptions options=new GenerationOptions(GenerationOptions.INCREMENTAL_MODE, GenerateFromPackage, GenerateFromInterface, GenerateFromProcedure, GenerateFromVariable);
package odi.sdk;
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.OdiProject;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.generation.GenerationOptions;
import oracle.odi.generation.support.OdiScenarioGeneratorImpl;
import oracle.odi.impexp.EncodingOptions;
import oracle.odi.impexp.support.ExportServiceImpl;
public class RegenrateAllScen {
private static String Project_Code;
private static OdiProject project;
private static String Folder_Name;
private static OdiFolder folder;
/**
* @param args
*/
public static void main(String[] args) {
/****** Please change these Parameters *********/
/** Development Repository ****/
String Url = "jdbc:oracle:thin:@localhost:1521:xe";
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";
// Generating ODI Objects options
Boolean GenerateFromInterface = true;
Boolean GenerateFromPackage = true;
Boolean GenerateFromProcedure = true;
Boolean GenerateFromVariable = true;
Project_Code ="XMT";
/********************************************/
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());
//Regenerating All Scenario by Project
// Get Project
project = ((IOdiProjectFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).findByCode(Project_Code);
OdiScenarioGeneratorImpl generatescen=new OdiScenarioGeneratorImpl(odiInstance);
//
// Please change your Generating Option ie INCREMENTAL (or) REGENERATE (or) REPLACE
//
GenerationOptions options=new GenerationOptions(GenerationOptions.INCREMENTAL_MODE, GenerateFromPackage, GenerateFromInterface, GenerateFromProcedure, GenerateFromVariable);
OdiScenario[] scen =generatescen.generateAllScenarios(project, options);
for (OdiScenario odiScenario : scen) {
System.out.println( options.getMode()+" Generating Scenario " +odiScenario.getName()+"\t"+odiScenario.getVersion());
}
odiInstance.getTransactionManager().commit(trans);
System.out.println("Commiting Changes \n Process Completed");
odiInstance.close();
}
}
Keeping visiting us!
Posted: January 5th, 2012 |
Author: Kshitiz Devendra |
Filed under: How to,
ODI,
SDK,
Tips and Tricks |
Tags: ODI SDK,
PROJECT,
REGENERATE,
scenario,
SDK |
Comments: No Comments »
Hi Everyone,
Keeping our “java series” we have one more piece of code to share.
I hope you “enjoy” it!
The below code is used to Export and Import all the Scenario from Development Work Rep to Execution Work Rep .
For Export there are 3 different options either Export all the scenario
- For a Project (or)
- For a Folder (or)
- Scenarios matching a particular Time period .
Note : – Make sure you either delete the folder or delete all the scenario inside the Export Folder once successful import is done .
package odi.sdk;
import java.io.File;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collection;
import java.util.Date;
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.IOdiScenarioSourceContainer;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder;
import oracle.odi.impexp.EncodingOptions;
import oracle.odi.impexp.OdiImportException;
import oracle.odi.impexp.support.ExportServiceImpl;
import oracle.odi.impexp.support.ImportServiceImpl;
public class ExportImport {
private static String Project_Code;
private static OdiProject project;
private static String Folder_Name;
private static OdiFolder folder;
/**
* @param args
* @throws IOException
* @throws OdiImportException
* @throws ParseException
*/
public static void main(String[] args) throws IOException, OdiImportException, ParseException {
/****** Please change these Parameters *********/
/** Development Repository ****/
String Url = "jdbc:oracle:thin:@localhost:1521:xe";
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";
/*** Execution Repository ***/
// In case if your Execution rep is linked to a different Master repository please appropriately create new variables
// The present codes assumes that Development and Execution are linked to the same Master Repository.
String WorkRep_Execution="WORKREP_EXECUTION";
/***************************************************/
//Exporting Scenario Options
String ExportFolderPath="/home/oracle/Documents/ODIExport";
// While providing path in windows make sure you use \\
Boolean ExportPackageScen = true;
Boolean ExportInterfaceScen = true;
Boolean ExportProcedureScen = true;
Boolean ExportVariableScen = false;
Boolean RecursiveExport = true;
Boolean OverWriteFile = true;
Project_Code ="XMT";
Folder_Name ="FOLDER2";
// Date based on which the scenario is compared
SimpleDateFormat df = new SimpleDateFormat("MM-dd-yyyy");
Date date =df.parse("11-23-2011");
/********************************************/
MasterRepositoryDbInfo masterInfo = new MasterRepositoryDbInfo(Url, Driver, Master_User,Master_Pass.toCharArray(), new PoolingAttributes());
/// Development Repository
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());
//Execution Repository
WorkRepositoryDbInfo workInfo_exec = new WorkRepositoryDbInfo(WorkRep_Execution, new PoolingAttributes());
OdiInstance odiInstance_exec=OdiInstance.createInstance(new OdiInstanceConfig(masterInfo,workInfo_exec));
Authentication auth_exec = odiInstance_exec.getSecurityManager().createAuthentication(Odi_User,Odi_Pass.toCharArray());
odiInstance_exec.getSecurityManager().setCurrentThreadAuthentication(auth_exec);
ITransactionStatus trans_exec = odiInstance_exec.getTransactionManager().getTransaction(new DefaultTransactionDefinition());
//Export All Scenario by Project
// Get Project
project = ((IOdiProjectFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiProject.class)).findByCode(Project_Code);
ExportServiceImpl export=new ExportServiceImpl(odiInstance);
EncodingOptions EncdOption = new EncodingOptions();
System.out.println( " Exporting all Scenario for the Project " +Project_Code);
export.exportAllScenarii(project, ExportFolderPath, ExportPackageScen, ExportInterfaceScen, ExportProcedureScen, ExportVariableScen, EncdOption, RecursiveExport, OverWriteFile);
// ( or )
// Export All Scenario by Folder
// Find the folder
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();
}
ExportServiceImpl export=new ExportServiceImpl(odiInstance);
EncodingOptions EncdOption = new EncodingOptions();
System.out.println( " Exporting all Scenario for the Project " +Project_Code+ " and Folder "+Folder_Name);
export.exportAllScenarii(folder, ExportFolderPath, ExportPackageScen, ExportInterfaceScen, ExportProcedureScen, ExportVariableScen, EncdOption, RecursiveExport, OverWriteFile);
// ( or )
// Export Selected Scenario based on date
ExportServiceImpl export=new ExportServiceImpl(odiInstance);
EncodingOptions EncdOption = new EncodingOptions();
//Reading all scenario
Collection odiscen= ((IOdiScenarioFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiScenario.class)).findAll();
for (Object scen : odiscen) {
OdiScenario odiscenario =(OdiScenario)scen ;
if (odiscenario.getLastDate().before(date)) {
System.out.println(" Exporting scenario "+odiscenario.getName());
export.exportToXml(odiscenario, ExportFolderPath, OverWriteFile, RecursiveExport, EncdOption);
}
}
//Importing Scenarios in INSERT_UPDATE Mode
// The below code import all the scenarios present in the Exported Folder path , so make sure older files are deleted
ImportServiceImpl importsrvc=new ImportServiceImpl(odiInstance_exec);
String[] XMLFiles=getXMLFiles(ExportFolderPath).split("\n");
for (String xmlfile : XMLFiles) {
System.out.println(" Importing scenario XML "+xmlfile);
importsrvc.importObjectFromXml(importsrvc.IMPORT_MODE_SYNONYM_INSERT_UPDATE, xmlfile, true);
}
// Commit and Close Transaction
odiInstance.close();
odiInstance_exec.getTransactionManager().commit(trans_exec);
odiInstance_exec.close();
}
//Reading all the XML Files
public static String getXMLFiles(String DirectoryName){
String xmlfiles="";
String files;
File folder = new File(DirectoryName);
File[] listOfFiles = folder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
files = listOfFiles[i].getName();
if (files.endsWith(".xml") || files.endsWith(".XML"))
{
xmlfiles+=DirectoryName+"/"+files+"\n";
}
}}
return xmlfiles;
}
}
Good to see you around and please, keep visiting us!
Posted: November 27th, 2011 |
Author: Kshitiz Devendra |
Filed under: How to,
Logic,
ODI,
Others,
SDK,
SQL,
Tips and Tricks |
Tags: Export,
FOLDER,
Import,
ODI,
ODI Scenario,
ODI_SDK,
PROJECT,
scenario |
Comments: 5 Comments »
Hi Everyone!
First I wish to all of you a really Happy New Year! I hope that 2011 can be the best year ever to all of us!
Second, sorry, sorry and sorry. We “abandoned” our blog this last few weeks. I got a lot of new responsibilities on my formal job and Dev was in vacation with his family. We are going to try to be more present from now forward.
Third (and last) let’s talk about scenarios!
I created this title “Scenarios, a lot in the first delivery makes maintenance very simple!” in the hope of a full understanding about what this post is in just one phrase once I would like that after we finish to discuss it you can tell me if the title is right or not…
I Oracle Data Integrator, our famous ODI, is very common to develop all objects that you need to your integration and, at end of the development, add all of these at a package, create a scenario and that is it. Test and go to production.
That is the common way in all ODI environments that I saw until today… let’s discuss this.
When we are developing a it’s normal to have several tables to load in some order (parents, children, etc), procedures to performs some “not interfaceble” task and variables that uses code (refreshing type). Then, all we do is add all of this in a package, generate de scenario and our development is done.
OK, now let’s think about it from the Software Development Life Cycle (SDLC) perspective, I mean, everything that is developed will get some maintenance in one of his “pieces” some day.
As we change just one piece from all our package, of course we should test just that piece right?
NO! And here is the problem!
Who can guarantee that none of the others pieces (or ODI objects) was changed? In fact, using a trusted SDLC, you need to execute the complete test plan (the same that allows the first delivery) once all code was “compiled”, I mean, regenerated (in ODI terms).
Do you agree?
And if we split the development in small pieces of scenarios, as small as possible, even at object level (as we can generate scenarios from objects ) and then create a package (or packages) that orchestrate the execution of this small pieces????
Of course that the first delivery will have a lot of scenarios to be imported at production but when some change is necessary you can update only the relevant code and, too, test only it.
In this way your SDLC will get less errors and the cost (HR, Financial, Hardware, etc) of tests will decrease substantially and plus, you can always re-use any of the object scenario.
If you pay attention, you will see that we are talking about the old concept of Object Orientation, nothing new.
And now, what do you think? Is the title right?
A tip to use this approach is to have the Operator (scenarios tab) organized in folders. This will avoid the endless list of scenarios and brings organization to the environment.
Well friends, that’s all for now. I hope you keep traking us!
Once again, Happy 2011!!!!
Cezar Santos
Posted: January 10th, 2011 |
Author: Cezar Santos |
Filed under: Administration,
Architecture,
How to,
ODI,
Tips and Tricks |
Tags: ODI,
ODI 11g,
ODI Experts,
ODI Scenario,
Oracle Data Integrator,
scenario,
Sunopsis |
Comments: 6 Comments »