3

Due to project requirement we need to import the project mappings & other objects from a different server. But we found that all the mapping context becomes undefined.

I am trying to write a groovy program to set the context at a bulk. I have written the below code but somehow the interfaceList is empty and thus unable to perform odiInterface.setOptimizationContext(context);.

Below is my code. For brevity I haven't mentioned the packages stmt.

def all the variables like url,driver,schema etc
def all variables like MasterInfo, auth, transaction, etc 

def OdiContext context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode("CTX_ANN1_S4")
for (p in odiProjectList) {
    if (p.getName() == "PrjDemo_TA") {
        def OdiFolderList = p.getFolders()
        for (f in OdiFolderList) {
            if (f.getName() == "TrgDemoMod_Comn_TA_S4") {
                // def OdiInterfaceList2 = f.getInterfaces()                
                // def OdiMappingList = odiInstance.getTransactionalEntityManager().findAll( Mapping.class)
                def OdiInterfaceList = ((IOdiInterfaceFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiInterface.class)).findByProject(projectCode, folderName)

                for (m in OdiInterfaceList2) {
                    println(m.getName() + "|" + m.getClass()) //+ "|" + m.getParent()   + "|" + m.getFolder() )
                    m.setOptimizationContext(context)
                }
                tm.commit(txnStatus)
            }
        }
    }
}

The line which initializes OdiInterfaceList is not throwing any error nor populating desired interface lists of all the interfaces within a folder. So m.setOptimizationContext(context) is not executed.

If i substitute that line with:

def OdiMappingList = odiInstance.getTransactionalEntityManager().findAll( Mapping.class)

within a for ... loop i can able to access the mappings but I don't know how to set its context OdiMappingList as setOptimizationContext is an interface's method.

1 Answer 1

4

I'm unable to reproduce your case as I don't have the environment to test it, but I still think I can help.

First, I refactored your code so its more groovy:

def OdiContext context = ((IOdiContextFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findByCode("CTX_ANN1_S4")

// Looking for the project
def prjDemo = odiProjectList.find { it.name == "PrjDemo_TA" }
assert prjDemo : "Unable to find ODI project"

//Getting the Mappings
def mappingList = odiInstance.getTransactionalEntityManager().findAll( Mapping.class)
assert ! mappingList.toList().empty : "Mappings not found"

// Printing interfaces
mappingList.each {
    it.setDefaultContext(context as IContext)
}

With those asserts, you may be able to know more in detail where your code may be really failing.

I noticed that IOdiInterfaceFinder is marked as deprecated, so it might not play well with Oracle 12c. Check your versions.

Probably it would be better if you try to replace that deprecated code with a more updated version. I found some similar code to yours in this page, so it might be useful.

UPDATE: Updated the code to use Mapping class. As it has setDefaultContext(IContext ctx) method and OdiContext implements IContext, maybe it might work.

Sign up to request clarification or add additional context in comments.

7 Comments

Heartiest thanks Lepe that you hv modified code in a marvelous way that i could get 2 know things like toList(), assert etc.But still interfaceList is empty & assert becomes true: def OdiInterfaceList = finder.findByProject(projectCode, folderName) . Now if I use Mapping objects i cn able 2 access it but as it does not have any setOptimizationContext(), im again on ground-0 seeking resolutions for 2 open qstns. 1.how to set context for all mappings? 2.regenerate all scenarios in a batch frm mappings
My Odi version is 12.1.3 & im using odi groovy editor to write & run the code
@Sukhen_sql : I have modified the code using Mapping objects instead of OdiInterface objects. I don't have any way to test it, but it might help in any way. I have checked the documentation and so far is all I get.
@Sukhen_sql : Are both servers running 12.1.3 ?
Have you checked OdiModel.getReverseContext() and OdiModel.setReverseContext(OdiContext pContext) ? documentation
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.