Jackson deserialization for ExtendDataOperation

This commit is contained in:
Antonin Delpeuch 2018-10-22 10:11:23 +01:00
parent 393eec1586
commit eb66619840
5 changed files with 21 additions and 24 deletions

View File

@ -41,7 +41,6 @@ import com.google.refine.model.AbstractOperation;
import com.google.refine.model.Project;
import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig;
import com.google.refine.operations.recon.ExtendDataOperation;
import com.google.refine.util.ParsingUtilities;
public class ExtendDataCommand extends EngineDependentCommand {
@Override
@ -55,7 +54,7 @@ public class ExtendDataCommand extends EngineDependentCommand {
String schemaSpace = request.getParameter("schemaSpace");
String jsonString = request.getParameter("extension");
DataExtensionConfig extension = DataExtensionConfig.reconstruct(ParsingUtilities.evaluateJsonStringToObject(jsonString));
DataExtensionConfig extension = DataExtensionConfig.reconstruct(jsonString);
return new ExtendDataOperation(
engineConfig,

View File

@ -93,7 +93,7 @@ public class PreviewExtendDataCommand extends Command {
}
String jsonString = request.getParameter("extension");
DataExtensionConfig config = DataExtensionConfig.reconstruct(ParsingUtilities.evaluateJsonStringToObject(jsonString));
DataExtensionConfig config = DataExtensionConfig.reconstruct(jsonString);
JSONArray rowIndices = ParsingUtilities.evaluateJsonStringToArray(rowIndicesString);
int length = rowIndices.length();

View File

@ -107,10 +107,10 @@ public class ReconciledDataExtensionJob {
this.properties = properties;
}
public static DataExtensionConfig reconstruct(JSONObject obj) throws JSONException {
public static DataExtensionConfig reconstruct(String json) throws JSONException {
ObjectMapper mapper = new ObjectMapper();
try {
return mapper.readValue(obj.toString(), DataExtensionConfig.class);
return mapper.readValue(json, DataExtensionConfig.class);
} catch(IOException e) {
throw new JSONException(e.toString());
}

View File

@ -44,6 +44,7 @@ import java.util.Set;
import org.json.JSONException;
import org.json.JSONObject;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.refine.browsing.Engine;
@ -67,6 +68,7 @@ import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionCon
import com.google.refine.operations.EngineDependentOperation;
import com.google.refine.process.LongRunningProcess;
import com.google.refine.process.Process;
import com.google.refine.util.ParsingUtilities;
public class ExtendDataOperation extends EngineDependentOperation {
@JsonProperty("baseColumnName")
@ -84,28 +86,24 @@ public class ExtendDataOperation extends EngineDependentOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
JSONObject engineConfig = obj.getJSONObject("engineConfig");
DataExtensionConfig dataExtensionConfig = DataExtensionConfig.reconstruct(obj.getJSONObject("extension"));
return new ExtendDataOperation(
EngineConfig.reconstruct(engineConfig),
obj.getString("baseColumnName"),
obj.getString("endpoint"),
obj.getString("identifierSpace"),
obj.getString("schemaSpace"),
dataExtensionConfig,
obj.getInt("columnInsertIndex")
);
return ParsingUtilities.mapper.readValue(obj.toString(), ExtendDataOperation.class);
}
@JsonCreator
public ExtendDataOperation(
@JsonProperty("engineConfig")
EngineConfig engineConfig,
@JsonProperty("baseColumnName")
String baseColumnName,
@JsonProperty("endpoint")
String endpoint,
@JsonProperty("identifierSpace")
String identifierSpace,
@JsonProperty("schemaSpace")
String schemaSpace,
@JsonProperty("extension")
DataExtensionConfig extension,
@JsonProperty("columnInsertIndex")
int columnInsertIndex
) {
super(engineConfig);

View File

@ -177,12 +177,12 @@ public class ExtendDataOperationTests extends RefineTest {
@Test
public void serializeDataExtensionConfig() {
TestUtils.isSerializedTo(DataExtensionConfig.reconstruct(new JSONObject(dataExtensionConfigJson)), dataExtensionConfigJson);
TestUtils.isSerializedTo(DataExtensionConfig.reconstruct(dataExtensionConfigJson), dataExtensionConfigJson);
}
@Test
public void testFormulateQuery() throws IOException {
DataExtensionConfig config = DataExtensionConfig.reconstruct(new JSONObject(dataExtensionConfigJson));
DataExtensionConfig config = DataExtensionConfig.reconstruct(dataExtensionConfigJson);
Set<String> ids = Collections.singleton("Q2");
String json = "{\"ids\":[\"Q2\"],\"properties\":[{\"id\":\"P571\"},{\"id\":\"P159\"},{\"id\":\"P625\"}]}";
ReconciledDataExtensionJobStub stub = new ReconciledDataExtensionJobStub(config, "http://endpoint");
@ -214,7 +214,7 @@ public class ExtendDataOperationTests extends RefineTest {
@Test
public void testFetchStrings() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct(new JSONObject("{\"properties\":[{\"id\":\"P297\",\"name\":\"ISO 3166-1 alpha-2 code\"}]}"));
DataExtensionConfig extension = DataExtensionConfig.reconstruct("{\"properties\":[{\"id\":\"P297\",\"name\":\"ISO 3166-1 alpha-2 code\"}]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config,
"country",
@ -252,7 +252,7 @@ public class ExtendDataOperationTests extends RefineTest {
@Test
public void testFetchCounts() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct(
new JSONObject("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}"));
"{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"count\":\"on\",\"rank\":\"any\"}}]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config,
"country",
@ -287,7 +287,7 @@ public class ExtendDataOperationTests extends RefineTest {
@Test
public void testFetchCurrent() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct(
new JSONObject("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"best\"}}]}"));
"{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"best\"}}]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config,
"country",
@ -328,7 +328,7 @@ public class ExtendDataOperationTests extends RefineTest {
@Test
public void testFetchRecord() throws Exception {
DataExtensionConfig extension = DataExtensionConfig.reconstruct(
new JSONObject("{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"any\"}}]}"));
"{\"properties\":[{\"id\":\"P38\",\"name\":\"currency\",\"settings\":{\"rank\":\"any\"}}]}");
EngineDependentOperation op = new ExtendDataOperation(engine_config,
"country",