lunedì 5 dicembre 2016

ODI 11g-12c - Groovy Come creare un utente ODI ed assegnazione profili

Di seguito due script per la creazione di un utente ODI con relativa assegnazione di profili. Di seguito due versioni una per ODI 11g e una per ODI 12c, la seconda utilizza delle funzioni che possono essere richiamata all'interno di un main.
  • ODI 11g
// 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;
// Secutity class:
import oracle.odi.domain.security.finder.IOdiUserFinder
import oracle.odi.domain.security.OdiUserCreationServiceImpl
import oracle.odi.domain.security.OdiUser
import oracle.odi.domain.security.OdiProfile;
import oracle.odi.domain.security.finder.IOdiProfileFinder
// Variabili
def txnDef = new DefaultTransactionDefinition()
def tm = odiInstance.getTransactionManager()
def txnStatus = tm.getTransaction(txnDef)
String  username="PIPPO";
String  pwd="PIPPO1";
String  supervisor="false";
        expirationDate=null;

try {
         odiUser = ((IOdiUserFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiUser.class)).findByName(username);
     
           println("  User              :-->"+odiUser.getName());
           println("  User Note         :-->"+odiUser.getNotes());
           println("  Pwd Date Expire   :-->"+odiUser.getPasswordExpiracyDate());
           println("  Expiracy Date     :-->"+odiUser.getAccountExpiracyDate());
          
           Collection odiUserPro =(odiUser.getOdiProfileList())
            for (Object kk : odiUserPro) {
              OdiProfile odiPro =(OdiProfile)kk ;
              println("  Profile           :-->"+odiPro.getOdiProfileList().getProfileName());
              println("  Profile           :-->"+odiPro.getOdiProfileList().getInternalId());
            }
           
}catch(NullPointerException e_101){

        // obtaining the generic profiles
        genericprofile_connect = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("CONNECT") ;
        genericprofile_designer = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("DESIGNER") ;
        genericprofile_topology_admin = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("TOPOLOGY ADMIN") ;    

        // creating user
    OdiUserCreationServiceImpl service = new OdiUserCreationServiceImpl(odiInstance)
    OdiUser newUser = service.createOdiUser(username, pwd.toCharArray(), supervisor.toBoolean(), expirationDate );

        // adding profiles to the user
        newUser.addOdiProfile(genericprofile_connect);
        newUser.addOdiProfile(genericprofile_designer);
        newUser.addOdiProfile(genericprofile_topology_admin);

        NewodiUser = ((IOdiUserFinder) odiInstance.getTransactionalEntityManager().getFinder(OdiUser.class)).findByName(username);
           println("  User              :-->"+NewodiUser.getName());
           println("  User Note         :-->"+NewodiUser.getNotes());
           println("  Pwd Date Expire   :-->"+NewodiUser.getPasswordExpiracyDate());
           println("  Expiracy Date     :-->"+NewodiUser.getAccountExpiracyDate());
          
 }

tm.commit(txnStatus) 



  • ODI 12c
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
import oracle.odi.domain.security.finder.IOdiUserFinder
import oracle.odi.domain.security.OdiUserCreationServiceImpl
import oracle.odi.domain.security.OdiUser
import oracle.odi.core.OdiInstance
import oracle.odi.domain.security.OdiProfile;


// creating  user (Pippo)

def new_user(user, pwd, supervisor ) {
     expirationDate = null

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

    // checking if whether user exists
    userf = (IOdiUserFinder) tme.getFinder(OdiUser.class)

    // creating user
    OdiUserCreationServiceImpl service = new OdiUserCreationServiceImpl(odiInstance)
    OdiUser newUser = service.createOdiUser(user, pwd.toCharArray(), supervisor.toBoolean(), expirationDate );
   
    tm.commit(txnStatus)
    return newUser
}

def adding_profiles(username) {

    txnDef    = new DefaultTransactionDefinition()
    tm        = odiInstance.getTransactionManager()
    tme       = odiInstance.getTransactionalEntityManager()
    txnStatus = tm.getTransaction(txnDef)
        
        // finding the user
        user = odiInstance.getTransactionalEntityManager().getFinder(OdiUser.class).findByName(username) ;
        // obtaining the generic profiles
        genericprofile_connect = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("CONNECT") ;
        genericprofile_designer = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("DESIGNER") ;
        genericprofile_topology_admin = odiInstance.getTransactionalEntityManager().getFinder(OdiProfile.class).findByName("TOPOLOGY ADMIN") ;
        // adding profiles to the user
        user.addOdiProfile(genericprofile_connect);
        user.addOdiProfile(genericprofile_designer);
        user.addOdiProfile(genericprofile_topology_admin);
    tm.commit(txnStatus)
    return user;
}

//  add odi user "Pippo " and grant profiles like CONNECT, DESIGNER, TOPOLOGY ADMIN
FirstUser1 = new_user("Pippo", "1234abcd5678","false")
FirstUser1Profiles = adding_profiles("Pippo")


Provate e fatemi sapere

Nessun commento:

Posta un commento