Skip to content

Commit

Permalink
Added support for fieldParent
Browse files Browse the repository at this point in the history
  • Loading branch information
Flavian committed Jul 31, 2014
1 parent 8c5c65e commit 1a80d84
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The CSV river import data from CSV files and index it.
"escape_character" : ";",
"quote_character" : "'",
"field_id" : "id",
"field_parent" : "id_parent",
"concurrent_requests" : "1",
"charset" : "UTF-8",
"script_before_all": "/path/to/before_all.sh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Configuration {
int bulkThreshold
int concurrentRequests
String idField
String idParent

String scriptBeforeAll
String scriptAfterAll
Expand All @@ -55,6 +56,7 @@ class Configuration {
separator = nodeStringValue(csvSettings.get(Constants.CSV.FIELD_SEPARATOR), String.valueOf(',')).charAt(0)
quoteCharacter = nodeStringValue(csvSettings.get(Constants.CSV.QUOTE_CHARACTER), String.valueOf('\"')).charAt(0)
idField = nodeStringValue(csvSettings.get(Constants.CSV.FIELD_ID), 'id')
parentField = nodeStringValue(csvSettings.get(Constants.CSV.FIELD_PARENT), '')
concurrentRequests = nodeIntegerValue(csvSettings.get(Constants.CSV.CONCURRENT_REQUESTS), 1)

String charsetName = nodeStringValue(csvSettings.get(Constants.CSV.CHARSET), 'UTF-8')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class Constants {
static final String FIELD_SEPARATOR = 'field_separator'
static final String QUOTE_CHARACTER = 'quote_character'
static final String FIELD_ID = 'field_id'
statif final String FIELD_PARENT = 'field_parent'

static final String CHARSET = 'charset'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ class OpenCSVFileProcessor implements FileProcessor {
request.id(UUID.randomUUID().toString())
}

if (csvContainsParentColumn()) {
request.parent(getParent(line))
}

request.create(false).source(builder)

listener.onLineProcessed(request)
Expand All @@ -86,10 +90,21 @@ class OpenCSVFileProcessor implements FileProcessor {
return config.csvFields.find { it == config.idField }
}

boolean csvContainsParentColumn() {
return config.csvFields.find { it == config.idParent }
}

String getId(String[] line) {

int index = config.csvFields.indexOf(config.idField)

return line[index]
}

String getParent(String[] line) {

int index = config.csvFields.indexOf(config.idParent)

return line[index]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class ConfigurationTest extends Specification {
config.filenamePattern
!config.folderName
config.idField
config.idParent
config.indexName
config.poll
config.quoteCharacter
Expand Down

0 comments on commit 1a80d84

Please sign in to comment.