Migrate SortingConfig to Jackson
This commit is contained in:
parent
25aa076836
commit
d311810c2c
@ -42,9 +42,6 @@ import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
@ -168,14 +165,12 @@ public class GetRowsCommand extends Command {
|
||||
RowWritingVisitor rwv = new RowWritingVisitor(start, limit);
|
||||
|
||||
SortingConfig sortingConfig = null;
|
||||
try{
|
||||
String json = request.getParameter("sorting");
|
||||
JSONObject sortingJson = (json == null) ? null :
|
||||
ParsingUtilities.evaluateJsonStringToObject(json);
|
||||
try {
|
||||
String sortingJson = request.getParameter("sorting");
|
||||
if (sortingJson != null) {
|
||||
sortingConfig = SortingConfig.reconstruct(sortingJson);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
if (engine.getMode() == Mode.RowBased) {
|
||||
|
@ -33,10 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
package com.google.refine.commands.row;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import com.google.refine.browsing.Engine;
|
||||
import com.google.refine.browsing.EngineConfig;
|
||||
@ -45,7 +44,6 @@ import com.google.refine.model.AbstractOperation;
|
||||
import com.google.refine.model.Project;
|
||||
import com.google.refine.operations.row.RowReorderOperation;
|
||||
import com.google.refine.sorting.SortingConfig;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
public class ReorderRowsCommand extends EngineDependentCommand {
|
||||
|
||||
@ -59,9 +57,8 @@ public class ReorderRowsCommand extends EngineDependentCommand {
|
||||
try{
|
||||
String json = request.getParameter("sorting");
|
||||
|
||||
JSONObject sortingJson = (json == null) ? null : ParsingUtilities.evaluateJsonStringToObject(json);
|
||||
sorting = (sortingJson == null) ? null : SortingConfig.reconstruct(sortingJson);
|
||||
} catch (JSONException e) {
|
||||
sorting = (json == null) ? null : SortingConfig.reconstruct(json);
|
||||
} catch (IOException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,6 @@ import java.io.Writer;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.refine.browsing.Engine;
|
||||
@ -88,13 +87,7 @@ public class TemplatingExporter implements WriterExporter {
|
||||
String limitString = options.getProperty("limit");
|
||||
int limit = limitString != null ? Integer.parseInt(limitString) : -1;
|
||||
|
||||
JSONObject sortingJson = null;
|
||||
try{
|
||||
String json = options.getProperty("sorting");
|
||||
sortingJson = (json == null) ? null :
|
||||
ParsingUtilities.evaluateJsonStringToObject(json);
|
||||
} catch (JSONException e) {
|
||||
}
|
||||
String sortingJson = options.getProperty("sorting");
|
||||
|
||||
String templateString = options.getProperty("template");
|
||||
String prefixString = options.getProperty("prefix");
|
||||
|
@ -2,8 +2,6 @@ package com.google.refine.sorting;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonCreator;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
@ -30,7 +28,7 @@ public final class SortingConfig {
|
||||
return _criteria;
|
||||
}
|
||||
|
||||
public static SortingConfig reconstruct(JSONObject obj) throws IOException {
|
||||
return ParsingUtilities.mapper.readValue(obj.toString(), SortingConfig.class);
|
||||
public static SortingConfig reconstruct(String obj) throws IOException {
|
||||
return ParsingUtilities.mapper.readValue(obj, SortingConfig.class);
|
||||
}
|
||||
}
|
@ -1,11 +1,8 @@
|
||||
package com.google.refine.tests.operations.row;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
@ -52,7 +49,7 @@ public class RowReorderOperationTests extends RefineTest {
|
||||
@Test
|
||||
public void testSortEmptyString() throws Exception {
|
||||
String sortingJson = "{\"criteria\":[{\"column\":\"key\",\"valueType\":\"number\",\"reverse\":false,\"blankPosition\":2,\"errorPosition\":1}]}";
|
||||
SortingConfig sortingConfig = SortingConfig.reconstruct(new JSONObject(sortingJson));
|
||||
SortingConfig sortingConfig = SortingConfig.reconstruct(sortingJson);
|
||||
project.rows.get(1).cells.set(0, new Cell("", null));
|
||||
AbstractOperation op = new RowReorderOperation(
|
||||
Mode.RowBased, sortingConfig
|
||||
@ -69,7 +66,6 @@ public class RowReorderOperationTests extends RefineTest {
|
||||
|
||||
@Test
|
||||
public void serializeRowReorderOperation() throws JSONException, Exception {
|
||||
Project project = mock(Project.class);
|
||||
String json = " {\n" +
|
||||
" \"op\": \"core/row-reorder\",\n" +
|
||||
" \"description\": \"Reorder rows\",\n" +
|
||||
|
@ -2,8 +2,6 @@ package com.google.refine.tests.sorting;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.refine.sorting.SortingConfig;
|
||||
@ -11,7 +9,7 @@ import com.google.refine.tests.util.TestUtils;
|
||||
|
||||
public class SortingConfigTests {
|
||||
@Test
|
||||
public void serializeSortingConfig() throws JSONException, IOException {
|
||||
public void serializeSortingConfig() throws IOException {
|
||||
String json = "{\n" +
|
||||
" \"criteria\": [\n" +
|
||||
" {\n" +
|
||||
@ -23,6 +21,6 @@ public class SortingConfigTests {
|
||||
" }\n" +
|
||||
" ]\n" +
|
||||
" }";
|
||||
TestUtils.isSerializedTo(SortingConfig.reconstruct(new JSONObject(json)), json);
|
||||
TestUtils.isSerializedTo(SortingConfig.reconstruct(json), json);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user