Merge pull request #1387 from tiagofernandez/save-import-options
Options metadata
This commit is contained in:
commit
5311b48a6b
@ -1005,16 +1005,7 @@ public class ImportingUtilities {
|
|||||||
final Format record,
|
final Format record,
|
||||||
final Project project
|
final Project project
|
||||||
) {
|
) {
|
||||||
ProjectMetadata pm = new ProjectMetadata();
|
ProjectMetadata pm = createProjectMetadata(optionObj);
|
||||||
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
|
|
||||||
pm.setTags(JSONUtilities.getStringArray(optionObj, "projectTags"));
|
|
||||||
String encoding = JSONUtilities.getString(optionObj, "encoding", "UTF-8");
|
|
||||||
if ("".equals(encoding)) {
|
|
||||||
// encoding can be present, but empty, which won't trigger JSONUtilities default processing
|
|
||||||
encoding = "UTF-8";
|
|
||||||
}
|
|
||||||
pm.setEncoding(encoding);
|
|
||||||
|
|
||||||
record.parser.parse(
|
record.parser.parse(
|
||||||
project,
|
project,
|
||||||
pm,
|
pm,
|
||||||
@ -1042,5 +1033,18 @@ public class ImportingUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static public ProjectMetadata createProjectMetadata(JSONObject optionObj) {
|
||||||
|
ProjectMetadata pm = new ProjectMetadata();
|
||||||
|
pm.setName(JSONUtilities.getString(optionObj, "projectName", "Untitled"));
|
||||||
|
pm.setTags(JSONUtilities.getStringArray(optionObj, "projectTags"));
|
||||||
|
pm.appendImportOptionMetadata(optionObj);
|
||||||
|
|
||||||
|
String encoding = JSONUtilities.getString(optionObj, "encoding", "UTF-8");
|
||||||
|
if ("".equals(encoding)) {
|
||||||
|
// encoding can be present, but empty, which won't trigger JSONUtilities default processing
|
||||||
|
encoding = "UTF-8";
|
||||||
|
}
|
||||||
|
pm.setEncoding(encoding);
|
||||||
|
return pm;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.google.refine.tests.importing;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.testng.Assert;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.refine.ProjectMetadata;
|
||||||
|
import com.google.refine.importing.ImportingUtilities;
|
||||||
|
import com.google.refine.tests.RefineTest;
|
||||||
|
|
||||||
|
public class ImportingUtilitiesTests extends RefineTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void createProjectMetadataTest() throws Exception {
|
||||||
|
JSONObject optionObj = new JSONObject("{\"projectName\":\"acme\",\"projectTags\":[],\"created\":\"2017-12-18T13:28:40.659\",\"modified\":\"2017-12-20T09:28:06.654\",\"creator\":\"\",\"contributors\":\"\",\"subject\":\"\",\"description\":\"\",\"rowCount\":50,\"customMetadata\":{},\"importOptionMetadata\":[{\"guessCellValueTypes\":false,\"projectTags\":[\"\"],\"ignoreLines\":-1,\"processQuotes\":true,\"fileSource\":\"acme.txt\",\"encoding\":\"\",\"separator\":\"|\",\"storeBlankCellsAsNulls\":true,\"storeBlankRows\":true,\"skipDataLines\":0,\"includeFileSources\":false,\"headerLines\":1,\"limit\":-1,\"projectName\":\"acme\"},{\"guessCellValueTypes\":false,\"projectTags\":[\"\"],\"ignoreLines\":-1,\"processQuotes\":true,\"fileSource\":\"acme.txt\",\"encoding\":\"\",\"separator\":\"|\",\"storeBlankCellsAsNulls\":true,\"storeBlankRows\":true,\"skipDataLines\":0,\"includeFileSources\":false,\"headerLines\":1,\"limit\":-1,\"projectName\":\"acme\"}]}");
|
||||||
|
ProjectMetadata pm = ImportingUtilities.createProjectMetadata(optionObj);
|
||||||
|
Assert.assertEquals(pm.getName(), "acme");
|
||||||
|
Assert.assertEquals(pm.getEncoding(), "UTF-8");
|
||||||
|
Assert.assertTrue(pm.getTags().length == 0);
|
||||||
|
Assert.assertTrue(pm.getImportOptionMetadata().length() > 0);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user