How to create scenario of odi mapping using groovy script

2.2k views Asked by At

I have created thousands of mapping using groovy script but I am unable to run them.

I can iterate the mapping but now wanted to run the mapping using groovy script. How do I create scenarios of mappings and then run scenarios using groovy script?

1

There are 1 answers

0
Santosh Kadam On
//Created by DI Studio
//Created by DI Studio
//Created by DI Studio
//Created by DI Studio

//Created by DI Studio
//Created by DI Studio
//Created by DI Studio
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.model.finder.IOdiDataStoreFinder;
import oracle.odi.domain.project.finder.IOdiFolderFinder; 
import oracle.odi.domain.mapping.finder.IMappingFinder;
import oracle.odi.domain.model.OdiDataStore;
import oracle.odi.domain.model.OdiModel;
import oracle.odi.domain.model.finder.IOdiModelFinder;
import  oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
import oracle.odi.generation.support.OdiScenarioGeneratorImpl;
import oracle.odi.generation.IOdiScenarioGenerator;
import oracle.odi.domain.runtime.scenario.OdiScenario;
import oracle.odi.domain.mapping.Mapping;
import oracle.odi.domain.mapping.finder.IMappingFinder;
import oracle.odi.domain.runtime.scenario.finder.IOdiScenarioFinder;
import oracle.odi.domain.project.OdiProject;



  //txnDef = new DefaultTransactionDefinition()
  //tm = odiInstance.getTransactionManager()
  //tme = odiInstance.getTransactionalEntityManager()
  //txnStatus = tm.getTransaction(txnDef)
  //pf = (IOdiProjectFinder)tme.getFinder(OdiProject.class)
  //ff = (IOdiFolderFinder)tme.getFinder(OdiFolder.class)

//Variables 
//projectName = "Project Name" 
//folderName = "Folder Name" 
//sourcemodelName = "Source Name"
//targetmodelName = "Target name"  
//find project and the folder

/*
def mappingList = ((IMappingFinder) odiInstance.getTransactionalEntityManager().getFinder(Mapping.class)).findByProject("STOO3", "STO3")
ms=mapplingList.iterator()
while(ms.hasNext()){
println ms.getName()
}

*/

txnDef = new DefaultTransactionDefinition()
tm = odiInstance.getTransactionManager()
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef)
def fm = ((IMappingFinder) tme.getFinder(Mapping.class))         // shorcut to Find Mapping
def mappingList = fm.findAll().findAll{w -> w.getProject().getCode() == 'CUSTDBN'}
//def mappingList = ((IMappingFinder) odiInstance.getTransactionalEntityManager().getFinder(Mapping.class)).findByProject("SOCAIRO", "STO")
if (mappingList == null){
  println "Map is null"
}
ms=mappingList.iterator()
while(ms.hasNext()){
              ms_i = ms.next()
              println ms_i.getName()
              scenName = ms_i.getName();

              //IIOdiScenarioGenerator gene = new OdiScenarioGeneratorImpl((odiInstance)
              //OdiScenario newScen = gene.generateScenario(ms_i, scenName,newVersion)}
              //odiInstance.getTransactionalEntityManager().persist(ms_i);
              //OdiScenarioGenerator gene = new OdiScenarioGeneratorImpl((odiInstance)
            //gene.generateScenario(ms_i, scenName,"001")

            stxnDef = new DefaultTransactionDefinition()
            stm = odiInstance.getTransactionManager()
            stme = odiInstance.getTransactionalEntityManager()
            stxnStatus = stm.getTransaction(stxnDef)

            OdiScenario sc = ((IOdiScenarioFinder)     stme.getFinder(OdiScenario.class)).findLatestByName(scenName)
            if (sc != null){
              println "Scenario already exist"
              println sc
            }
            IOdiScenarioGenerator gene = new OdiScenarioGeneratorImpl(odiInstance);
            OdiScenario newScen = gene.generateScenario(ms_i, scenName, "001")
            println newScen 
            //tme.persist(newScen)
            stm.commit(stxnStatus)
            println "Created"
            //odiInstance.close()

            }
tm.commit(txnStatus)

//println ((IMappingFinder) odiInstance.getTransactionalEntityManager().getFinder(Mapping.class)).findByProject("STOO3", "STO3")

              //ms_i.validate()
              //ms_i.submit()