Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugs importing text columns containing commas or newlines, added MysqlLogger #7

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions .classpath
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry excluding="spring/" kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/conf/spring"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/i18n"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="grails-app/utils"/>
<classpathentry kind="src" path="grails-app/views"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.grails.ide.eclipse.core.CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/eclipseclasses"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/java"/>
<classpathentry kind="src" path="src/groovy"/>
<classpathentry kind="src" path="grails-app/conf"/>
<classpathentry kind="src" path="grails-app/controllers"/>
<classpathentry kind="src" path="grails-app/domain"/>
<classpathentry kind="src" path="grails-app/services"/>
<classpathentry kind="src" path="grails-app/taglib"/>
<classpathentry kind="src" path="grails-app/utils"/>
<classpathentry kind="src" path="test/integration"/>
<classpathentry kind="src" path="test/unit"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path=".link_to_grails_plugins/release-3.1.0/src/groovy">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path=".link_to_grails_plugins/release-3.1.0/src/java">
<attributes>
<attribute name="org.grails.ide.eclipse.core.SOURCE_FOLDER" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.grails.ide.eclipse.core.CLASSPATH_CONTAINER"/>
<classpathentry exported="true" kind="con" path="GROOVY_DSL_SUPPORT"/>
<classpathentry kind="output" path="target-eclipse/classes"/>
</classpath>
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
/target
plugin.xml
*.log
*.zip
*.zip.sha1
/web-app
/data
cobertura.ser
*.idea/**
*.iml
/conf
9 changes: 8 additions & 1 deletion .project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>imports</name>
<name>bulk-data-imports</name>
<comment></comment>
<projects>
</projects>
Expand All @@ -16,4 +16,11 @@
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>.link_to_grails_plugins</name>
<type>2</type>
<locationURI>GRAILS_ROOT/2.4.5/projects/bulk-data-imports/plugins</locationURI>
</link>
</linkedResources>
</projectDescription>
2 changes: 2 additions & 0 deletions .settings/org.eclipse.core.resources.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding//grails-app/i18n=UTF-8
2 changes: 2 additions & 0 deletions .settings/org.eclipse.jdt.groovy.core.prefs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=23
12 changes: 6 additions & 6 deletions BulkDataImportsGrailsPlugin.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import grails.plugins.imports.logging.MongoLogger
import grails.plugins.imports.logging.InMemoryLogger

class BulkDataImportsGrailsPlugin {
def version = "0.1.3"
def version = "0.1.4"
def grailsVersion = "2.0 > *"
def title = "Bulk Data Imports Plugin"
def author = "Jeremy Leng"
def authorEmail = "jleng@bcap.com"
def author = "Andy Coulson"
def authorEmail = "acoulson@practical-apps.com"
def description = '''\
Bulk Data Imports Plugin simplifies importing of bulk data via file uploads
Default support for CSV and domain classes
Expand All @@ -22,11 +22,11 @@ Default support for CSV and domain classes
"grails-app/views/importsTest/index.gsp"
]
def loadBefore = ['rabbitmq','rabbit-amqp']
def documentation = "http://github.com/bertramdev/imports"
def documentation = "https://github.com/acoulson2000/imports"
def watchedResources = "file:./grails-app/services/*Service.groovy"
def organization = [ name: "BertramLabs", url: "http://www.bertramlabs.com/" ]
def organization = [ name: "Original author: BertramLabs", url: "http://www.bertramlabs.com/" ]
def license = "APACHE"
def issueManagement = [ system: "GITHUB", url: "http://github.com/bertramdev/imports/issues" ]
def issueManagement = [ system: "GITHUB", url: "https://github.com/acoulson2000/imports" ]
def scm = [ url: "http://github.com/bertramdev/imports" ]

def doWithSpring = {
Expand Down
61 changes: 60 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
**Bulk Data Imports Grails Plugin**
=====================

**NOTE**

THIS PLUGIN IS A FORK OF http://github.com/bertramdev/imports - available in the Grails Plugins as
"Bulk Data Imports" plugin. The original had major issues with parsing CSV files that include
either commas or quoted text. They have not merged my fork, but I am making it available here. It
also includes a "logger" that logs to MySql, which is convenient if you want to persist the logs of
your imports, but don't want to do it in Mongo DB. It would probably also work with other ANSI SQL
DB's, although you might need to tweek the ImportLog Domain Object. See new section at the bottom of this
README for info on how to enable that. I recommend you build this project and install it locally in
your local repo via "grails maven-install" then include it in your project via:
```runtime ":bulk-data-imports:0.1.4"```

**~END NOTE~**

This plugin provides support for importing bulk data, typically via CSV file upload.

**Included features:**
Expand All @@ -14,7 +28,7 @@ This plugin provides support for importing bulk data, typically via CSV file upl
- Optional support for distributed processing (via optional RabbitMQ plugin)
- Optional support for confirmation and summary email notification (via optional Mail Plugin)
- All aspects of import processing can be overridden
- Pluggable import logging framework (includes in-memory and Mongo logging implementations)
- Pluggable import logging framework (includes in-memory, MySQL and Mongo logging implementations)
- Support for canceling asynchronous and queue-based import processing
- Support in customized import instructions
- Support for archiving imported file
Expand Down Expand Up @@ -574,6 +588,51 @@ Sample Log structure in JSON:

Custom logger classes should implement the `com.grails.plugins.imports.logging.ImportLogger` interface that defines the methods above.

MySql Logger
--------------------------

One such custom logger has been added - the MysqlLogger. This logger will log the JSON content to a table via a Domain Object. This is very usefull for retaining an audit trail of imports and retaining logs over reboots, without requiring a MongoDb installation.

To use Mysql Logging:

Create a Domain Object called ImportLog with a package name of grails.plugins.imports:
```
package grails.plugins.imports

import java.util.Date;

class ImportLog {

String id
String document
Date dateCreated

static mapping = {
version false
id name: "id", generator: "assigned"
document sqlType:"longtext"
}
}
```

If you create your tables manually, create a table called Import_Log using this SQL:
```
CREATE TABLE import_log (
id varchar(45) NOT NULL,
document longtext,
date_created datetime DEFAULT NULL,
PRIMARY KEY (`id`)
);
```
Add this entry to your application's Config.groovy class to tell the Importer to use the MysqlLogger implementation:
```
grails.plugins.imports.loggingProvider = 'grails.plugins.imports.MysqlLogger'
```

The JSON result of an import attempt will now be logged to the "document" column of Import_Log. The import id (GUID) will be used as the primary key.

**NOTE** You could adapt the Domain Class to work with other database types, but you will probably need to change the sqlType fo the document property to be whatever very long text type is supported by your database.

Import actions
--------------------------

Expand Down
9 changes: 4 additions & 5 deletions application.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#Grails Metadata file
#Wed Mar 19 18:12:44 PDT 2014
app.grails.version=2.3.6
app.name=bulk-data-imports
app.servlet.version=2.5
#Grails Metadata file
#Mon Oct 29 09:08:53 CDT 2018
app.grails.version=2.4.5
app.name=bulk-data-imports
27 changes: 15 additions & 12 deletions grails-app/conf/BuildConfig.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,27 @@ grails.project.dependency.resolution = {
}
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes eg.
runtime('mysql:mysql-connector-java:5.1.13') {
runtime('mysql:mysql-connector-java:5.1.27') {
export = false
}
}

plugins {
build(":release:3.0.1",
":rest-client-builder:1.0.3",
":tomcat:7.0.52.1") {
export = false
}
build ':release:3.0.1', ':rest-client-builder:1.0.3', {
export = false
}
// build(":release:3.0.1",
// ":rest-client-builder:1.0.3",
// ":tomcat:7.0.52.1") {
// export = false
// }
compile ":executor:0.3"
runtime(//':mongodb:1.3.3',
':rabbitmq:1.0.0',
':mail:1.0.1',
':hibernate:3.6.10.9') {
export = false
}
// runtime(//':mongodb:1.3.3',
// //':rabbitmq:1.0.0',
// ':mail:1.0.1',
// 'runtime ":hibernate4:4.3.5.2"') {
// export = false
// }

}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

16 changes: 16 additions & 0 deletions grails-app/domain/grails/plugins/imports/ImportLog.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package grails.plugins.imports

import java.util.Date;

class ImportLog {

String id
String document
Date dateCreated

static mapping = {
version false
id name: "id", generator: "assigned"
document sqlType:"longtext"
}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading