Migrate PreviewExtendDataCommand to Jackson

This commit is contained in:
Antonin Delpeuch 2018-11-20 16:42:11 +00:00
parent c80001a642
commit c98ae0dcf6

View File

@ -45,9 +45,8 @@ 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.JSONArray;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.refine.commands.Command; import com.google.refine.commands.Command;
import com.google.refine.model.Cell; import com.google.refine.model.Cell;
import com.google.refine.model.Column; import com.google.refine.model.Column;
@ -94,8 +93,8 @@ public class PreviewExtendDataCommand extends Command {
String jsonString = request.getParameter("extension"); String jsonString = request.getParameter("extension");
DataExtensionConfig config = DataExtensionConfig.reconstruct(jsonString); DataExtensionConfig config = DataExtensionConfig.reconstruct(jsonString);
JSONArray rowIndices = ParsingUtilities.evaluateJsonStringToArray(rowIndicesString); List<Integer> rowIndices = ParsingUtilities.mapper.readValue(rowIndicesString, new TypeReference<List<Integer>>() {});
int length = rowIndices.length(); int length = rowIndices.size();
Column column = project.columnModel.getColumnByName(columnName); Column column = project.columnModel.getColumnByName(columnName);
int cellIndex = column.getCellIndex(); int cellIndex = column.getCellIndex();
@ -116,7 +115,7 @@ public class PreviewExtendDataCommand extends Command {
List<String> topicIds = new ArrayList<String>(); List<String> topicIds = new ArrayList<String>();
Set<String> ids = new HashSet<String>(); Set<String> ids = new HashSet<String>();
for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) {
int rowIndex = rowIndices.getInt(i); int rowIndex = rowIndices.get(i);
if (rowIndex >= 0 && rowIndex < project.rows.size()) { if (rowIndex >= 0 && rowIndex < project.rows.size()) {
Row row = project.rows.get(rowIndex); Row row = project.rows.get(rowIndex);
Cell cell = row.getCell(cellIndex); Cell cell = row.getCell(cellIndex);