Monday, September 12, 2011

Two Things

I decided to use the programmatic properties file reading for a more 'sensible' solution to my last implementation:


applicationContext.groovy (via spring-grails DSL/BeanBuiler) in the src/webapp/WEB-INF directory

...
Properties properties = loadProperties(logger)
...

Properties loadProperties(logger) {
    String baseFilename = "overrides.properties"
    String defaultBaseFilename = "default.properties"
    def contextClassLoader = Thread.currentThread().getContextClassLoader()
    String defaultFilename = contextClassLoader.getResource(defaultBaseFilename).getFile()
    String overrideFileName = contextClassLoader.getResource(baseFilename)?.getFile()

    File defaultPropertyFile = new File(defaultFilename)

    Properties properties = new Properties()
    properties.load(new FileReader(defaultPropertyFile))

    if(overrideFileName) {
        File overridePropertyFile = new File(overrideFileName)
        if(overridePropertyFile.exists()) {
            logger.info "Loading overrides..."
            properties.load(new FileReader(overridePropertyFile))
        }
    }
    else {
        logger.warn "No override properties file was found, using project defaults ONLY."
    }
   
    logger.info "Properties"
    properties.each {k,v -> logger.info "$k=$v"}

    return properties
}

The throughout the 'beans' closure, I can say 'properties[property]' at load time rather than getting a proxy as the last implementation returned.  This means I can use properties to conditionally configure
beans based on environment.  It also allows a 'default.properties' file that will hopefully cover 90% of
what will be done and then the 'overrides.properties' can cover the few things that will likely be
different but can be loaded via that environment (e.g. tomcat/lib).

The other thing is I did very basic implementation with full CRUD for an EclipsePhase character tracker with a Flex front-end and a Gaelyk back-end.

http://ep-tools.appspot.com/epui.html

Slow services on app engine, but free.  Using the app engine Entity for persistence is easy but I still thing I'll look at doing it with Grails and deploying to CloudFoundry as long as it is 'cheap enough'.

Code is nothing exciting but on github.

https://github.com/twcrone/eclpsephase-character-tracker-services
https://github.com/twcrone/eclipsephase-character-tracker-ui

No guarantees that the code will stick around or stay the same as the base site.  Cool thing is...with Flex (and my skills), the back-end can change.  Not embedded in any particular environment (e.g. Gaelyk, Grails, Rails, Spring).


No comments:

Post a Comment