Exportar e importar Scenarios por projeto ou pasta
Olá a todos.
Keeping our “java series” we have one more piece of code to share.
I hope you “enjoy” it!
O código abaixo é usado para exportar e importar todo o Scenario do trabalho de desenvolvimento Rep para execução Work Rep .
Para exportação existem 3 opções diferentes ou Exportar todo o scenario
- Para um projeto (ou)
- Para uma pasta (ou)
- Scenarios correspondente a um determinado período de tempo .
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;
}
}
É bom ver-te por aqui e, por favor, continua a visitar-nos!
fevereiro 22, 2018 at 11:26 PM
I am trying to automate ODI ,can anyone share the shell/bat script to export and import ODI scenarios.
dezembro 21, 2016 at 7:56 AM
Hi,
Could anyone help me with creating the Generate DDL utility using ODI SDK?
What I am looking for is, for each model it should loop through all the datastores and create a single procedure for each model.
Thanks
setembro 2, 2016 at 10:58 AM
Hi,
I’m using the same approach for odi 12.1.3 to automate smart export for mapping. But it’s not responding and getting hunged.. Could you please help and advice
Thanks
Indra
setembro 2, 2016 at 10:55 AM
Hi,
I’m using the same approach for odi 12c and trying to smart export the mapping using SmartExportServiceImpl . But it’s getting hunged and not responding.. Could you please help and advice..
fevereiro 29, 2016 at 6:56 AM
I am using SDk 11.1.1.9, in this release I find that in the class, the 3rd parameter is the root object of a folder where i want to import in
So my code is
import_service = ImportServiceImpl (odiInstance)
import_service.importObjectFromXml (import_service.IMPORT_MODE_SYNONYM_INSERT_UPDATE,
‘/u02/export/SCEN_INFA_2_HC_CUSTOM_SDE_ORA11510_ADAPTOR_SDE_ORA_SALESORDERLINESFACT_FULL_101.xml’,
customfolder, True)
I get this error
====
Feb 29, 2016 1:50:47 AM oracle.security.jps.internal.common.util.XmlSchemaValidationUtil$StrictErrorHandler warning
WARNING: Invalid xml content was found. SchemaLocation: schemaLocation value = ‘http://xmlns.oracle.com/oracleas/schema/11/jps-config-11_1.xsd’ must have even number of URI’s. Location: line 1 column 310.
(‘custom folder ‘, oracle.odi.domain.project.OdiFolder Custom)
Traceback (most recent call last):
File “/u02/Upgrade/smartexport1.py”, line 932, in
import_service.importObjectFromXml (import_service.IMPORT_MODE_SYNONYM_INSERT_UPDATE,
at oracle.odi.impexp.support.ImportServiceImpl.importObjectFromXml(ImportServiceImpl.java:460)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
oracle.odi.impexp.OdiImportNotSupportedException: oracle.odi.impexp.OdiImportNotSupportedException: This parent object doesn’t support this imported object.
Any input?
dezembro 18, 2014 at 2:57 PM
Hi,
When i am exporting the project using smart export, i am getting the below error
ODI-10207: uncategorized exceptional during transaction system usage.
Internal Exception:java.sql.SQLException: Protocal violation Error Code:17401
This ODI project that i am exporting is very huge. Any help would be appreciated.
Thanks,
Ram Mohan V
abril 18, 2014 at 6:14 AM
I have recenlty imported data from one env. to another. While running the Load plan, some of the mapping failed with following error:
Caused By: com.sunopsis.tools.core.exception.SnpsSimpleMessageException: ODI-17517: Error during task interpretation.
Task: 9
java.lang.Exception: BeanShell script error: Sourced file: inline evaluation of: “ if (sUseDbLink.equals(“Y”) && (!sIsSDSDeployed.equals(“Y”))) { out.print(“\n\n . . . ” : Attempt to resolve method: equals() on undefined variable or class name: sUseDbLink : at Line: 1 : in file: inline evaluation of: “ if (sUseDbLink.equals(“Y”) && (!sIsSDSDeployed.equals(“Y”))) { out.print(“\n\n . . . ” : sUseDbLink .equals ( “Y” )
BSF info: Create view on source at line: 0 column: columnNo
at com.sunopsis.dwg.codeinterpretor.SnpTaskNameCodeInterpretor.transform(SnpTaskNameCodeInterpretor.java:570)
at com.sunopsis.dwg.dbobj.SnpSessStep.createTaskLogs(SnpSessStep.java:819)
at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:468)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:2093)
at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1896)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$2.doAction(StartScenRequestProcessor.java:580)
at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:216)
at oracle.odi.runtime.agent.processor.impl.StartScenRequestProcessor$StartScenTask.doExecute(StartScenRequestProcessor.java:1068)
at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:137)
at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:83)
at java.lang.Thread.run(Thread.java:662)
Caused by: org.apache.bsf.BSFException: BeanShell script error: Sourced file: inline evaluation of: “ if (sUseDbLink.equals(“Y”) && (!sIsSDSDeployed.equals(“Y”))) { out.print(“\n\n . . . ” : Attempt to resolve method: equals() on undefined variable or class name: sUseDbLink : at Line: 1 : in file: inline evaluation of: “ if (sUseDbLink.equals(“Y”) && (!sIsSDSDeployed.equals(“Y”))) { out.print(“\n\n . . . ” : sUseDbLink .equals ( “Y” )
BSF info: Create view on source at line: 0 column: columnNo
at bsh.util.BeanShellBSFEngine.eval(Unknown Source)
at bsh.util.BeanShellBSFEngine.exec(Unknown Source)
at com.sunopsis.dwg.codeinterpretor.SnpTaskNameCodeInterpretor.transform(SnpTaskNameCodeInterpretor.java:556)
… 10 more
Text:
After a reasearch I found out that only those scenario’s which have been regenarated after importing to odi are failing… please reply….
dezembro 21, 2011 at 11:03 AM
Hi Kshitiz,
That works, it’s the solution I’m using presently, but to reduce complexity I’d prefer to export the folder. It’s strange that there’s no obvious implementation for this because the functionality is available in ODI Studio already. I’ve decompiled the ExportServiceImpl class and looking at the decompiled code, by playing with some snp classes I could export an array of odi scenarios but I’d prefer not to go down that road 🙂
Cheers,
Alex
dezembro 21, 2011 at 9:29 AM
Hi Kshitiz,
Thanks for your reply, unfortunatelly that package refers to load plans and i couldnt find anything related to Scenario Folders in there. I’ve looked in oracle.odi.domain.runtime.scenario and there’s a OdiScenarioFolder there. Playing with it i could enumerate my Load Plans/Scenarios contained in a Scenario Folder. Still the provided ExportServiceImpl.exportAllScenarii wont accept a OdiScenarioFolder as container. So maybe my initial question is a bit more clear now, do you know of any way to use a OdiScenarioFolder as the container for exportAllScenarii ?
Cheers,
Alex
dezembro 21, 2011 at 9:55 AM
Alex,
I think we can loop through each scenario in the ScenarioFolder and export individual XML .
Please find a sample code which i believe should solve your requirement. If i am able to figure out ExportAllScenario method i will let you ,but i highly doubt so it will work ,since Exportall takes Project or Folder as input .
Any way please try this and let me know if this works .
Boolean RecursiveExport = true;
Boolean OverWriteFile = true;
String ExportFolderPath="/home/oracle/Documents/ODIExport";
ExportServiceImpl export=new ExportServiceImpl(odiInstance);
EncodingOptions EncdOption = new EncodingOptions();
OdiScenarioFolder Scenfolder=OdiScenarioFolder("FOLDER_NAME");
Collection odiscen=Scenfolder.getScenarios();
for (Object scen : odiscen) {
OdiScenario odiscenario =(OdiScenario)scen ;
export.exportToXml(odiscenario, ExportFolderPath, OverWriteFile, RecursiveExport, EncdOption);
}
Thanks
Kshitiz
dezembro 21, 2011 at 6:02 AM
Hi,
First of all, thatnks for the great intros to the ODI Java SDK.
Atm I’m trying to automate our export/deploy processes so we can avoid a lot of problems when the client deploys our ODI solution to their environment. Your example of exporting/importing scenarios from a project/folder is a great start but i was curious (and couldn’t find) on how to export a Scenario/LoadPlan folder (so mimic the ODI studio functionality to export a Load Plan and Scenario folder from the Load Plans and Scenarios section of the Designer accordion). Th reason is that sometimes we do incremental releases with a folder of selected scenarios load plans and we don’t want to use solutions for this. So any idea how? My current feeling is that there’s no built functionality to do this in the API and that i will just have to build my own exporter for this (the scenario folders are AbstractOdiEntity…)
Appreciate your work,
Alex
dezembro 21, 2011 at 8:02 AM
Hi Alex ,
Thanks for your comments and visiting us.
For ODI 11.1.1.5 there are API for Load Plan . you can find them here
http://docs.oracle.com/cd/E21764_01/apirefs.1111/e17060/toc.htm
Package oracle.odi.domain.runtime.loadplan
Hope this helps.
Thanks
Kshitiz Devendra