ODI Groovy Script to AutoMap Source to Target

173 Views Asked by At

I have already created script to create mapping which is able to do this :

enter image description here

But my Issue is , if Column names are same i should be able to autoMap , Please suggest how to do this.

https://blogs.oracle.com/dataintegration/entry/odi_12c_mapping_builder : Did not Help.

//name of the project
projectName = "TEST"
//name of the folder
ordnerName = "First Folder"
//name of the mapping
mappingName = "MAP_SRC_TO_TRG"
//name of the model
modelName = "SAP"
//trg model"SAP_INV10", "ODSSTAGE"
modelName_trg="ODSSTAGE"
//name of the source datastore
sourceDatastoreName = "INV10"
//name of the target datastore
targetDatastoreName = "SAP_INV10"
import oracle.odi.domain.model.OdiColumn
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.project.finder.IOdiKMFinder
import oracle.odi.domain.mapping.finder.IMappingFinder
import oracle.odi.domain.adapter.project.IKnowledgeModule.ProcessingType
import oracle.odi.domain.model.OdiDataStore
import  oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition

//set expression to the component
def createExp(comp, tgtTable, propertyName, expressionText) { 
 DatastoreComponent.findAttributeForColumn(comp,tgtTable.getColumn(propertyName))    .setExpressionText(expressionText)
}

//delete mapping with the same name
def removeMapping(folder, map_name) {
 txnDef = new DefaultTransactionDefinition()
 tm = odiInstance.getTransactionManager()
 tme = odiInstance.getTransactionalEntityManager()
 txnStatus = tm.getTransaction(txnDef)
 try {
   Mapping map = ((IMappingFinder)     tme.getFinder(Mapping.class)).findByName(folder, map_name)
   if (map != null) {
     odiInstance.getTransactionalEntityManager().remove(map);
   }
 } catch (Exception e) {e.printStackTrace();}
 tm.commit(txnStatus)
}

//looking for a project and folder
def find_folder(project_code, folder_name) {
 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)
 project = pf.findByCode(project_code)

//if there is no project, create new one
 if (project == null) {
    project = new OdiProject(project_code, project_code) 
    tme.persist(project)
 }
//if there is no folder, create new one
 folderColl = ff.findByName(folder_name, project_code)
 OdiFolder folder = null
 if (folderColl.size() == 1)
   folder = folderColl.iterator().next()
 if (folder == null) {
    folder = new OdiFolder(project, folder_name) 
    tme.persist(folder)
 }
 tm.commit(txnStatus)
 return folder
}

//name of the project and the folder
 folder = find_folder(projectName,ordnerName)
//delete old mapping
 removeMapping(folder, mappingName)

 txnDef = new DefaultTransactionDefinition()
 tm = odiInstance.getTransactionManager()
 tme = odiInstance.getTransactionalEntityManager()
 txnStatus = tm.getTransaction(txnDef)

 dsf = (IOdiDataStoreFinder)tme.getFinder(OdiDataStore.class)
 mapf = (IMappingFinder) tme.getFinder(Mapping.class)

//create new mapping
 map = new Mapping(mappingName, folder);
 tme.persist(map)

//insert source table
 boundTo_emp = dsf.findByName(sourceDatastoreName, modelName)
 comp_emp = new DatastoreComponent(map, boundTo_emp)

//insert target table
 boundTo_tgtemp = dsf.findByName(targetDatastoreName, modelName_trg)
 comp_tgtemp = new DatastoreComponent(map, boundTo_tgtemp)

//link source table with expression
//  comp_emp.connectTo(comp_expression)

//link expression with target table
 comp_emp.connectTo(comp_tgtemp)
// map.autoMap( boundTo_emp, boundTo_tgtemp);  

 tme.persist(map)
 tm.commit(txnStatus)

// After linking the source and target components

Do we have something like map.autoMap(sourceDatastoreName, targetDatastoreName)

Any help would be appreciated. ODI : 12c

1

There are 1 best solutions below

0
JeromeFr On

There is no direct method in the SDK to do the auto mapping.

However, David Allan wrote a blog post about how to implement it : ODI 12c - Mapping SDK Auto Mapping.