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.

lepe
  • 22,543
  • 9
  • 85
  • 99
Sukhen_sql
  • 41
  • 4

1 Answers1

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.

lepe
  • 22,543
  • 9
  • 85
  • 99
  • 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 – Sukhen_sql Dec 26 '19 at 08:10
  • My Odi version is 12.1.3 & im using odi groovy editor to write & run the code – Sukhen_sql Dec 26 '19 at 16:30
  • @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](https://docs.oracle.com/middleware/1213/odi/reference-java-api/oracle/odi/domain/mapping/Mapping.html) and so far is all I get. – lepe Dec 27 '19 at 03:13
  • @Sukhen_sql : Are both servers running 12.1.3 ? – lepe Dec 27 '19 at 03:24
  • Have you checked `OdiModel.getReverseContext()` and `OdiModel.setReverseContext(OdiContext pContext)` ? [documentation](https://docs.oracle.com/middleware/1213/odi/reference-java-api/oracle/odi/domain/model/OdiModel.html#getReverseContext()) – lepe Dec 27 '19 at 03:47
  • mappingList.each { print (it.name) def OdiContext context2 = it.getReverseContext() // it.getDefaultContext () neither of the method working Lepe- No signature of method: oracle.odi.domain.mapping.Mapping.getReverseContext() is applicable for argument types: () values: []. Also it.setDefaultContext( context as IContext) , i think is not working as expected as this context object is from OdiContext, but setDefaultContext() needs an obj. of IContext :-( .... Like unix ,is there any way in groovy to check the excn status of last command ? – Sukhen_sql Dec 30 '19 at 13:01
  • @Sukhen_sql: I see. You need to find a way to convert `oracle.odi.domain.mapping.Mapping` (is what mappingList returns) into `oracle.odi.domain.model.OdiModel` which has the `getReverseContext` method. I think it may work if you use `.setReverseContext` (not `setDefaultContext`). About your question, read [how to check the exit status of last command](https://stackoverflow.com/questions/55655206/how-to-execute-shell-command-in-groovy-and-get-the-return-code). Unless you are doing a system call, I don't see how it can be useful though. – lepe Dec 30 '19 at 14:21