commitToGit.groovy

import com.sunopsis.dwg.DwgObject
import oracle.odi.core.service.vcs.generic.OdiObjectInfo
import oracle.odi.core.service.vcs.generic.adapter.OdiVcsAdapterType
import oracle.odi.core.service.vcs.generic.adapter.impl.OdiVcsAdapterFactory
import oracle.odi.core.service.vcs.generic.delegate.OdiVcsDelegate
import oracle.odi.core.service.vcs.generic.utils.OdiVcsUtils
import oracle.odi.core.service.vcs.git.adapter.impl.OdiGitRepositoryInfo

def commitToGit() {

    def wrl = null //?
    def walletPwd = 'xxxxxx'.toCharArray()
    def includeDependencies = false
    def regenerateScen = true

    def repositoryUrl = 'ssh://git@gitrepo:999/dv.git'
    def privateKeyFile = '/home/odi/.ssh/id_rsa'
    def gitDirectory = '/home/odi/git/dwh/odi'

    OdiGitRepositoryInfo repoInfo = new OdiGitRepositoryInfo();
    repoInfo.setAuthenticationType(OdiGitRepositoryInfo.GIT_AUTH_TYPE.GIT_SSH);
/*
        HTTP_BASIC("basic", "http://<host>[:<port>]/<git-repository>", "Http Basic"),
        HTTPS_SSL("ssl", "https://<host>[:<port>]/<git-repository>", "SSL"),
        GIT_BASIC("git", "git://<host>[:<port>]/<git-repository>", "Git Basic"),
        GIT_SSH("ssh", "ssh://<username>@<host>[:<port>]/<disk-path-of-git-repo>", "SSH"),
        FILE("file", "file://<disk-path-of-git-repo>", "File based"),
 */
    repoInfo.setRepositoryUrl(repositoryUrl);
    //repoInfo.setUserName(this.getUserName());
    //repoInfo.setUserPassword(this.getUserPassword());
    repoInfo.setPrivateKeyFile(new File(privateKeyFile))
     //repoInfo.setPassPhrase(this.getPassPhrase());
    repoInfo.gitDirectory = new File(gitDirectory);
    //repoInfo.setConnectionName(this.getConnectionName());
    //repoInfo.setCertificatePath(this.getCertificatePath());
    //repoInfo.setCertPassPhrase(this.getCertPassPhrase());
    //repoInfo.setProxyUrl(this.getProxyUrl());
    //repoInfo.setProxyPort(this.getProxyPort());
    //repoInfo.setProxyUserName(this.getProxyUserName());
    //repoInfo.setProxyUserPassword(this.getProxyUserPassword());
    boolean isSaveLoginCredPwd = true

    OdiVcsAdapterFactory odiVcsAdapterFactory = OdiVcsAdapterFactory.getInstance()
    oracle.odi.core.service.vcs.git.adapter.impl.OdiJGitAdapter odiVcsAdapter = odiVcsAdapterFactory.createVcsAdapter(OdiVcsAdapterType.Git_Jgit)
    odiVcsAdapter.init()
    odiVcsAdapter.pullFromRemoteRepository(repoInfo)
    OdiVcsDelegate odiVcsDelegate = new OdiVcsDelegate(odiInstance);
    odiVcsDelegate.createConnection(wrl, walletPwd, repoInfo, isSaveLoginCredPwd)

    List<OdiObjectInfo> modified = odiVcsDelegate.getAllPendingChangesInRepository(repoInfo)
    modified.stream().each {  ooi ->
        if(ooi.dwgObject != null){
            def msg = "modified: $ooi.dwgObject.objectInstanceName $ooi.dwgObject.lastUser $ooi.dwgObject.lastDate"
            println msg
            odiVcsDelegate.createVersion( ooi.dwgObject, msg)
        }
    }
    odiVcsAdapter.pushToRemoteRepository(repoInfo , "master")
    Collection<com.sunopsis.dwg.DwgObject> nonVersioned = OdiVcsUtils.getNonVersionControlledObjects(odiInstance)
    nonVersioned.each {
        dwgObject ->
                def msg = "created: $dwgObject.objectInstanceName $dwgObject.lastUser $dwgObject.lastDate"
                println msg
                List<DwgObject> o = new ArrayList<DwgObject>()
                o.add(dwgObject)
                odiVcsDelegate.addToVcs( repoInfo, o , msg,  includeDependencies, regenerateScen) // this matches
    }
    odiVcsAdapter.pushToRemoteRepository(repoInfo , "master")
}

commitToGit()