Wednesday, November 9, 2016

Git clone with user name and password

1. Use: 
git clone https://user:password@server.org/username/repo.git

2. Or (It will prompt you for your password):
git clone https://user@server.org/username/repo.git

Git: How to checkout a file from another git branch


1. First go to your project location using git bash

2. Use below command to go to project location:

3. Command:: cd /c/User/pritom/Git_Project/my_project

3. Now go to the branch from where you want to update file to 
current branch

3.1 You have to update the branch from which you want to 
checkout file

4. Command:: git checkout another_branch

5. Command:: git pull

6. Command:: git diff --name-only another_branch~1 
(It will list files changed last 1 commit)

7. Now go to working branch using:

8. Command:: git checkout current_branch

9. First pull to update current branch using:

10. Command:: git pull 

11. Now checkout files from another_branch using:

12. Command:: git checkout another_branch app/data/some_data.name

13. Now you file updated with another_branch

14. Command:: git status (It will show files changes)

Tuesday, November 8, 2016

Grails get retrieve GrailsParameterMap params from service class or util class

Have to import:
import org.springframework.web.context.request.RequestContextHolder

and use following:
def params = RequestContextHolder.getRequestAttributes().params

Reload refresh current url or redirect to another url using php script

Refresh/reload current page:
header("Refresh:0");

Or you can redirected to another page using:
header("Refresh:0; url=another-page.php");

Monday, November 7, 2016

Grails Hibernate check if and object is initialized

Hibernate.isInitialized(object)

Hooking into or extends the GormStaticApi methods of the GORM API for Grails

Main class defination

package com.autobill.enhancer

import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
import org.codehaus.groovy.grails.orm.hibernate.HibernateDatastore
import org.codehaus.groovy.grails.orm.hibernate.HibernateGormStaticApi
/**
 * Created by pritom on 17/10/2016.
 */
class MyCustomStaticApi<D> extends HibernateGormStaticApi<D> {
    private HibernateGormStaticApi gormStaticApi

    MyCustomStaticApi(HibernateGormStaticApi gormStaticApi) {
        super(gormStaticApi.persistentClass, gormStaticApi.datastore as HibernateDatastore, gormStaticApi.gormDynamicFinders, gormStaticApi.classLoader, gormStaticApi.transactionManager)
        this.gormStaticApi = gormStaticApi
    }

    @Override
    D read(Serializable id) {
        println("Reading-${id}")
        super.read(id)
    }

    static void init(servletContext) {
        servletContext.grailsApplication.domainClasses.each { DefaultGrailsDomainClass domainClass ->
            def gormStaticApi = domainClass.clazz.currentGormStaticApi()
            domainClass.clazz.setStaticGormStaticApi(new MyCustomStaticApi(gormStaticApi))
        }
    }
}

And invoke MyCustomStaticApi.init(servletContext) from Bootstrap.groovy


Hooking into or extends the GormInstanceApi methods of the GORM API for Grails

Main class defination


package com.autobill.enhancer

import org.codehaus.groovy.grails.commons.DefaultGrailsDomainClass
import org.codehaus.groovy.grails.orm.hibernate.HibernateDatastore
import org.codehaus.groovy.grails.orm.hibernate.HibernateGormInstanceApi
/**
 * Created by pritom on 17/10/2016.
 */
class MyCustomInstanceApi<D> extends HibernateGormInstanceApi<D> {
    private HibernateGormInstanceApi gormInstanceApi

    MyCustomInstanceApi(HibernateGormInstanceApi gormInstanceApi) {
        super(gormInstanceApi.persistentClass, gormInstanceApi.datastore as HibernateDatastore, gormInstanceApi.classLoader)
        this.gormInstanceApi = gormInstanceApi
    }

    @Override
    D save(D instance) {
        println("Saving-${instance}")
        super.save(instance)
    }

    static void init(servletContext) {
        servletContext.grailsApplication.domainClasses.each { DefaultGrailsDomainClass domainClass ->
            def gormInstanceApi = domainClass.clazz.currentGormInstanceApi()
            domainClass.clazz.setInstanceGormInstanceApi(new MyCustomInstanceApi(gormInstanceApi))
        }
    }
}

And invoke MyCustomInstanceApi.init(servletContext) from Bootstrap.groovy