-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathBulkDataImportsGrailsPlugin.groovy
79 lines (75 loc) · 3.8 KB
/
BulkDataImportsGrailsPlugin.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import grails.util.GrailsNameUtils as NU
import grails.plugins.imports.DefaultImporter as DF
import grails.plugins.imports.ImportsService as IS
import grails.plugins.imports.logging.DefaultLogger
import grails.plugins.imports.logging.MongoLogger
import grails.plugins.imports.logging.InMemoryLogger
class BulkDataImportsGrailsPlugin {
def version = "0.1.3"
def grailsVersion = "2.0 > *"
def title = "Bulk Data Imports Plugin"
def author = "Jeremy Leng"
def authorEmail = "jleng@bcap.com"
def description = '''\
Bulk Data Imports Plugin simplifies importing of bulk data via file uploads
Default support for CSV and domain classes
'''
def pluginExcludes = [
"grails-app/controllers/grails/plugins/imports/test/*",
"grails-app/domain/grails/plugins/imports/test/*",
"grails-app/services/grails/plugins/imports/test/*",
"grails-app/views/importsTest/index.gsp"
]
def loadBefore = ['rabbitmq','rabbit-amqp']
def documentation = "http://github.com/bertramdev/imports"
def watchedResources = "file:./grails-app/services/*Service.groovy"
def organization = [ name: "BertramLabs", url: "http://www.bertramlabs.com/" ]
def license = "APACHE"
def issueManagement = [ system: "GITHUB", url: "http://github.com/bertramdev/imports/issues" ]
def scm = [ url: "http://github.com/bertramdev/imports" ]
def doWithSpring = {
def loggingProvider = application.config.grails.plugins.imports.containsKey('loggingProvider') ? application.config.grails.plugins.imports.loggingProvider : 'default'
if (loggingProvider == 'mongo') {
importsLogger(MongoLogger)
} else if (loggingProvider == 'mem') {
importsLogger(InMemoryLogger)
} else if (loggingProvider == 'default') {
importsLogger(DefaultLogger)
} else {
Class clazz = Class.forName(loggingProvider, true, Thread.currentThread().contextClassLoader)
importsLogger(clazz)
}
for(service in application.serviceClasses) {
if (service.hasProperty('imports')) {
def entityName,
imports = service.getPropertyValue('imports')
if (imports instanceof Class || imports instanceof String) {
entityName = NU.getPropertyName(imports)
}
if (entityName) {
def found = application.domainClasses?.find { NU.getPropertyName(it.name) == entityName} != null
if (!found && !service.hasMetaMethod('processRow', getArgs(5)) ) {
log.warn('\n BulkDataImports: could not configure importer '+service.shortName+'... no domain class found and missing processRow method')
} else {
DF.SERVICE_METHODS.each {k,v->
if (!service.hasMetaMethod(k, getArgs(v))) service.metaClass."${k}" = DF."${k}"
}
def props = DF.SERVICE_PROPERTIES.clone()
props.entityName = entityName
props.each {k, v->
if (!service.hasMetaMethod(k)) service.metaClass."${k}" = { -> v }
}
IS.IMPORT_CONFIGURATIONS[entityName] = NU.getPropertyNameRepresentation(service.shortName)
}
} else {
log.warn('\n BulkDataImports: invalid imports configuration for '+service.shortName+' :'+imports)
}
}
}
IS.IMPORT_CONFIGURATIONS.each {k,v-> log.info('\n BulkDataImports:'+ k + ' imported by '+v) }
}
def onChange = { event -> if (event.source) doWithSpring() }
private getArgs(ct) {
(1..ct).collect { Object.class }.toArray()
}
}