Skip to content
This repository was archived by the owner on Mar 18, 2020. It is now read-only.

Commit 733474a

Browse files
lsitumcritchlow
authored andcommitted
Fixes #317 - Add spaces surrounding pipe as multi-values delimiter.
1 parent 61028ab commit 733474a

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

src/edu/ucsd/library/xdre/tab/RDFExcelConvertor.java

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,13 @@ private void updateFieldCounts(Map<String, Integer> fieldCounts, Map<String, Int
351351
}
352352
}
353353

354-
private void appendValues(StringBuilder line, int fieldCount, String fieldValues, boolean mutiValuesField) {
354+
private void appendValues(StringBuilder line, int fieldCount, String fieldValues, boolean multiValuesField) {
355355
if (StringUtils.isNotBlank(fieldValues)) {
356-
String[] values = mutiValuesField ? new String[] { fieldValues } : fieldValues.split("\\|");
356+
String[] values = fieldValues.split("\\" + TabularRecord.DELIMITER);
357+
if (multiValuesField) {
358+
String strVal = concatValues(values, " " + TabularRecord.DELIMITER + " ");
359+
values = new String[]{ strVal };
360+
}
357361

358362
Arrays.sort(values);
359363
for (String value : values) {
@@ -364,7 +368,7 @@ private void appendValues(StringBuilder line, int fieldCount, String fieldValues
364368
}
365369

366370
// append commas for extra fields
367-
if (!mutiValuesField && fieldCount > values.length) {
371+
if (!multiValuesField && fieldCount > values.length) {
368372
for (int i= values.length; i< fieldCount; i++) {
369373
line.append(",");
370374
}
@@ -375,6 +379,22 @@ private void appendValues(StringBuilder line, int fieldCount, String fieldValues
375379
}
376380
}
377381

382+
/*
383+
* Join array elements into string with delimiter.
384+
* @param values
385+
* @param delimiter
386+
* @return
387+
*/
388+
private static String concatValues(String[] values, String delimiter) {
389+
StringBuilder builder = new StringBuilder();
390+
for (String v : values) {
391+
if (builder.length() > 0)
392+
builder.append(delimiter);
393+
builder.append(v);
394+
}
395+
return builder.toString();
396+
}
397+
378398
private void appendFlatColumnNames(StringBuilder line, int fieldCount, String columnName) {
379399
for (int i=0; i< fieldCount; i++) {
380400
if (line.length() > 1)

test/edu/ucsd/library/xdre/harvesting/CilHavestingTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,9 @@ public void testCsvExportMultiple() throws Exception {
273273

274274
@Test
275275
public void testCsvExportWithMultiValues() throws Exception {
276-
String personResearsher = "\"W. Stoeckenius|Wolfgang Bettighofer|Buchanan, JoAnn|Richard Allen\"";
277-
String subjectAnatomy = "artificial phospholipid membrane|membrane";
278-
String subjectTopic = "free text for response to chemical stimulus|response to chemical stimulus";
276+
String personResearsher = "\"W. Stoeckenius | Wolfgang Bettighofer | Buchanan, JoAnn | Richard Allen\"";
277+
String subjectAnatomy = "artificial phospholipid membrane | membrane";
278+
String subjectTopic = "free text for response to chemical stimulus | response to chemical stimulus";
279279

280280
String[] files = {createJsonDataFile("test123.json").getAbsolutePath()};
281281
CilHarvesting cilHarvesting = new CilHarvesting(fieldMappings, constantFields, Arrays.asList(files));

0 commit comments

Comments
 (0)