I was playing with multi tenancy setup with grails.
While there were some examples I found most them were old and werent updated for recent grails versions
Ran into a bunch of errors when I tried to use multitenancy plugin with spring security.
Had to try out a few things before i was able to correct all the errors and get this working.
I try here to give a step by step guide to setting up multitenancy for grails based apps.
Create a simple domain class
grails create-domain-class com.helloworld.Message
install spring security plugin
>grails install-plugin spring-security-core
Create the user and roles
grails s2-quickstart org.racetrack User Role
Install multitenant plugin
grails install-plugin multi-tenant
install Multi-Tenant Spring Security Integration
grails install-plugin multi-tenant-spring-security
Add to config.groovy
tenant {
mode = "multiTenant" // "singleTenant" OR "multiTenant"
datasourceResolver.type = "db"
resolver {
type = "request"
resolver.request.dns.type = "db"
request.dns.type = "db"
}
}
Annotate domain classes that are to be shared after importing Multitenat annotation
import com.infusion.tenant.groovy.compiler.MultiTenant;
@MultiTenant
Add to the User Class
/** for multi-tenant-acegi plugin **/
Integer userTenantId
Add the following constraints
// Existing constraints
userTenantId(min: 0)
Create a dns map table
grails create-dns-map
I installed drools plugin to work with my grails app.
When I started the application, I got a SAXParseException.
Issue turns out to be a jar installed.
Navigate to
Delete this jar - Restart the application and all is well. .grails\1.3.4\projects\<your-project>\plugins\drools-0.3\lib
NOTE:your grails version will dictate the directory
xml-apis-1.0.b2.jar
Jasperreports complains with utf-8 issue when it tries to render the report.
Problem can be solved adding parameter -Dfile.encoding=UTF-8 to the VM.
To add parameter edit etc/ireport.conf,
Modify 'default_options' parameter it should look like this:
default_options="-J-Dfile.encoding=UTF-8 -J-Xms256M -J-Xmx512M"
Now the reports render perfectly - Enjoy!
In this post I will walk through how to configure email using mail plugin.
1. Install mail plugin in your project.
grails install-plugin mail
Grails application: Scheduling with Quartz
In this post I will discuss how to Install and configure quartz with jobs persistent in a database( mysql)
1.
Get quartz distribution.
Unzip to a directory.
Run the table-creation SQL scripts in the "docs/dbTables" directory of the Quartz distribution
2.Install quartz plugin
grails install-plugin quartzCreate a file, QuartzConfig.groovy in grails-app\conf
Specify quartz startup and storage options here like this:
In resources.groovy in grails-app\conf\spring
add the imports:6.
Create a service class(or where you would prefer to do this) with grails create-service
Enable the service class to be injeced with a scheduler by declaring like this
def quartzScheduler
define a method which will do the scheduling for you.
In this eg I put in a domain object for later retrieval during job execution.
Create a quartz job using
grails create-job fully-qualified-job-name
If you job uses a domain class (like in example above) you need to create a jar with all the domain class used by quartz and add this to your lib directory
NOTE: This is at best a hack solution. Better option is doing this through classloader. But I wont go into it.
Thats it.
Enjoy and email me at trbala attherateof yahoo.com if you need an exmaple source or if you can offer me a good paying job in siliconvalley!!!