7 Replies Latest reply on Feb 19, 2013 4:55 AM by VIB

    ODI Groovy Script to create an interface


      I'm working on ODI 11.1.16 and trying to create an interface using Groovy Scripts. It throws me an error "java.lang.IllegalArgumentException: DataStore shouldn't be null "
      Below are my assumptions

      Source datastore : Groovy_Source
      Target datastore : Groovy_Trgt
      Context : Global
      Stndrd conn: localhost,1521,orcl

      def file = new File('c:/interfaces.txt')
      def s = 0


      DataSet dataSet = odiInterface.getDataSets().get(0);
      OdiDataStore odiDatastore1 = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName(DUMMY_GROOVY_SOURCE,Oracle);
      OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName(DUMMY_GROOVY_TRGT,Oracle);

      It throws an error here any help is appreciated

        • 1. Re: ODI Groovy Script to create an interface
          Hi VIB,

          What are the variables DUMMY_GROOVY_SOURCE and DUMMY_GROOVY_TRGT assigned to in your script? How about Oracle, is this assigned to the correct Model code? I think some more of your code would provide a better context for determining the cause of the error.

          You can always debug using out.print, as follows:

          out.print DUMMY_GROOVY_SOURCE

          This will allow you to determine if objects are being set correctly in the code.

          Michael Rainey
          • 2. Re: ODI Groovy Script to create an interface
            Hi Michael,

            Below is my entire code.. Picked it up from one of the blogs just trying to fine tune it. Thanks for your reply.

            //Created by ODI Studio
            // Context operators:
            import oracle.odi.domain.topology.OdiContext
            import oracle.odi.domain.topology.finder.IOdiContextFinder

            // Folder operators:
            import oracle.odi.domain.project.OdiFolder
            import oracle.odi.domain.project.finder.IOdiFolderFinder

            // Interface operators:
            import oracle.odi.domain.project.OdiInterface

            // Interface helpers:
            import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions
            import oracle.odi.interfaces.interactive.support.targetkeychoosers.TargetKeyChooserPrimaryKey
            import oracle.odi.interfaces.interactive.support.mapping.automap.AutoMappingComputerLazy
            import oracle.odi.interfaces.interactive.support.mapping.matchpolicy.MappingMatchPolicyLazy
            import oracle.odi.interfaces.interactive.support.actions.InterfaceActionSetTargetDataStore
            import oracle.odi.interfaces.interactive.support.aliascomputers.AliasComputerDoubleChecker
            import oracle.odi.interfaces.interactive.support.clauseimporters.ClauseImporterLazy
            import oracle.odi.interfaces.interactive.support.actions.InterfaceActionAddSourceDataStore
            import oracle.odi.interfaces.interactive.support.actions.InterfaceActionOnTargetDataStoreComputeAutoMapping;

            // Transaction operators:
            import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
            import oracle.odi.core.persistence.transaction.ITransactionDefinition;
            import oracle.odi.core.persistence.transaction.ITransactionManager;
            import oracle.odi.core.persistence.transaction.ITransactionStatus;

            // Data set:
            import oracle.odi.domain.project.interfaces.DataSet;

            // Data store:
            import oracle.odi.domain.model.OdiDataStore;
            import oracle.odi.domain.model.finder.IOdiDataStoreFinder;

            // Define VARS:
            def project = new String("Test") // What is the target project?
            def folder = new String("Test Subfolder") // Which folder in target project?

            def file = new File('c:/interfaces.txt')
            def s = 0

            // Get default context:
            OdiContext context = ((IOdiContextFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiContext.class)).findDefaultContext();

            // Get Folder:
            Collection odiFolders = ((IOdiFolderFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiFolder.class)).findByName(folder);
            if (odiFolders.size() == 0)
            println("Error: cannot find folder "+folder+" in project "+project)
            OdiFolder odiFolder = (OdiFolder) (odiFolders.toArray()[0]);

            // Print default settings:
            println ("Context used = " + context.getName())
            println ("Folder for interface = " + odiFolder.getName())

            file.eachLine { line ->
            toks = line.split(",")

            if (toks.length != 5)
            println("Error in input, line: "+s)
            iname = toks[0]
            Oracle = toks[1]
            DUMMY_GROOVT_SOURCE = toks[2]
            Oracle = toks[3]
            DUMMY_GROOVY_TRGT = toks[4]

            // Transactie:
            ITransactionDefinition txnDef = new DefaultTransactionDefinition()
            ITransactionManager tm = odiInstance.getTransactionManager()
            ITransactionStatus txnStatus = tm.getTransaction(txnDef)

            OdiInterface odiInterface = new OdiInterface(odiFolder, iname, context);

            InteractiveInterfaceHelperWithActions interactiveHelper = new InteractiveInterfaceHelperWithActions(odiInterface, odiInstance, odiInstance.getTransactionalEntityManager());

            DataSet dataSet = odiInterface.getDataSets().get(0);
            OdiDataStore odiDatastore1 = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName("DUMMY_GROOVY_SOURCE", Oracle);
            OdiDataStore targetDatastore = ((IOdiDataStoreFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiDataStore.class)).findByName("DUMMY_GROOVY_TRGT", Oracle);

            interactiveHelper.performAction(new InterfaceActionAddSourceDataStore(odiDatastore1, dataSet, new AliasComputerDoubleChecker(), new ClauseImporterLazy(), new AutoMappingComputerLazy()));
            interactiveHelper.performAction(new InterfaceActionSetTargetDataStore(targetDatastore, new MappingMatchPolicyLazy(), new AutoMappingComputerLazy(), new AutoMappingComputerLazy(), new TargetKeyChooserPrimaryKey()));

            interactiveHelper.performAction(new InterfaceActionOnTargetDataStoreComputeAutoMapping())


            Edited by: VIB on Feb 18, 2013 10:46 AM
            • 3. Re: ODI Groovy Script to create an interface
              First glance, I noticed a typo.

              name = toks[0]
              Oracle = toks[1]
              DUMMY_GROOVT_SOURCE = toks[2]
              Oracle = toks[3]
              DUMMY_GROOVY_TRGT = toks[4]

              Should that be DUMMY_GROOVY_SOURCE?

              Please let me know if that fixes the issue.

              Michael Rainey
              • 4. Re: ODI Groovy Script to create an interface
                David Allan-Oracle
                Sounds like your search for the datastore in the model failed.

                There are a few posts on this kind of accelerator below;

                Interface accelerator;

                Groovy version - Getting Groovy with ODI

                Extending the interface accelerator example (auto mapping extensions);
                More interface accelerator options around auto mapping;

                Interface Builder (explicit interface definition driven from a file);

                • 5. Re: ODI Groovy Script to create an interface
                  Yes it's a Typo but did not change much still throws up the same error.

                  • 6. Re: ODI Groovy Script to create an interface
                    Hi VIB,

                    I agree with David. Take a look at all of the other resources available. Plus, you can use the process I mentioned to print out the object value for debugging to ensure the text file is being read correctly.

                    Unfortunately, without having your full environment in front of me it's tough to offer you further advice.

                    Michael Rainey
                    • 7. Re: ODI Groovy Script to create an interface
                      Thank you Michael and David, I will try and hopefully one of them should work.