1. Introduction

GR8 CRM is a set of Grails Web Application Framework plugins that makes it easy to develop web applications with CRM functionality.

You can find more information about GR8 CRM on the main documentation site http://gr8crm.github.io.

1.1. Customer Relationship Management

Customer relationship management (CRM) is a system for managing a company’s interactions with current and future customers. It involves using technology to organize, automate and synchronize sales, marketing, customer service, and technical support. Wikipedia

The GR8 CRM "Ecosystem" currently contains over 40 Grails plugins. For a complete list of plugins see http://gr8crm.github.io.

Each GR8 CRM plugin defines a Bounded Context that focus on one specific domain, for example contact, project or document.

2. AWS Content Plugin

This Grails plugin extends the crm-content plugin to store all content in Amazon S3 buckets instead of in the local server file system.

This plugin is quite thin thanks to two great plugins, aws-sdk, and crm-content. The AWS plugin makes it easy to store objects in Amazon S3 and the crm-content plugin has support for "storage providers". So this plugin just adds the AwsContentProvider implementation that leverages aws-sdk for object storage. All standard GR8 CRM content management features works the same was as the default implementation that stores object in local file system.

3. Installation

Declare the plugin dependency in the BuildConfig.groovy file, as shown here:

grails.project.dependency.resolution = {
    inherits "global"
    log "info"
    repositories {
        // your repositories
    }
    dependencies {
        // Workaround to resolve dependency issue with aws-java-sdk and http-builder (dependent on httpcore:4.0)
        build 'org.apache.httpcomponents:httpcore:4.4.5'
        build 'org.apache.httpcomponents:httpclient:4.5.2'
        runtime 'org.apache.httpcomponents:httpcore:4.4.5'
        runtime 'org.apache.httpcomponents:httpclient:4.5.2'
    }
    plugins {
        // here go your plugin dependencies
        runtime ':crm-content-aws:2.4.2'
    }
}

4. Configuration

This plugin uses the excellent aws-sdk plugin to communicate with Amazon S3, so all configuration options for aws-sdk apply.

grails.plugin.awssdk.accessKey = '<aws key>'
grails.plugin.awssdk.secretKey = '<aws secret>'
grails.plugin.awssdk.region = '<aws region>'

Currently all GR8 CRM content are stored in the same bucket, configured with:

crm.content.s3.bucket = '<bucket name>' // default 'grails'

5. Extensions

You can write business logic that decides what content provider to use. You do this by replacing the bean named crmContentRouter with an implementation that can use content name, content length, domain instance that the content is attached to, or the current user to decide what content provider to route to.

The following example route all images to Amazon S3 and all other content to the default crmFileContentProvider that store files in the local file system.

src/groovy/my/package/ImageContentRouter.groovy
package my.package

import grails.plugins.crm.content.CrmContentProvider
import grails.plugins.crm.content.CrmContentRouter

/**
 * Route all images to Amazon S3.
 */
class ImageContentRouter implements CrmContentRouter {

    def crmFileContentProvider
    def awsContentProvider

    @Override
    CrmContentProvider getProvider(String filename, long length, Object reference, String username) {
        isImage(filename) ? awsContentProvider : crmFileContentProvider
    }

    private boolean isImage(String filename) {
        for (ext in [".png", ".jpg", ".jpeg", ".gif"]) {
            if (filename.toLowerCase().endsWith(ext)) {
                return true
            }
        }
        return false
    }
}
grails-app/conf/spring/resources.groovy
beans = {
    crmContentRouter(my.package.ImageContentRouter) { bean ->
        bean.autowire = 'byName'
    }
}

6. Changes

2.4.2

Make sure S3Object is closed after use. Adds method withObjects(Closure).

2.4.1

First public release

7. License

This plugin is licensed with Apache License version 2.0

8. Source Code

The source code for this plugin is available at https://github.com/technipelago/grails-crm-content-aws

9. Contributing

Please report issues or suggestions.

Want to improve the plugin: Fork the repository and send a pull request.