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