From 1790799bfe4fb4345354b797435045f3037c3ecd Mon Sep 17 00:00:00 2001 From: Antonin Delpeuch Date: Wed, 3 Oct 2018 21:33:37 +0100 Subject: [PATCH] Remove Jsonizable interface and write methods --- .../database/DatabaseModuleImpl.java | 1 - .../PreviewWikibaseSchemaCommand.java | 92 +++++----- .../commands/SaveWikibaseSchemaCommand.java | 3 +- .../wikidata/editing/WikibaseCredentials.java | 26 +-- .../PerformWikibaseEditsOperation.java | 17 +- .../SaveWikibaseSchemaOperation.java | 25 +-- .../org/openrefine/wikidata/qa/QAWarning.java | 3 +- .../wikidata/schema/WbItemDocumentExpr.java | 3 +- .../wikidata/schema/WikibaseSchema.java | 14 +- .../wikidata/utils/JacksonJsonizable.java | 79 -------- .../wikidata/operations/OperationTest.java | 5 +- .../wikidata/schema/WikibaseSchemaTest.java | 14 +- main/src/com/google/refine/Jsonizable.java | 49 ----- .../refine/browsing/DecoratedValue.java | 16 +- .../com/google/refine/browsing/Engine.java | 20 +-- .../google/refine/browsing/EngineConfig.java | 21 +-- .../google/refine/browsing/facets/Facet.java | 3 +- .../refine/browsing/facets/FacetConfig.java | 3 +- .../refine/browsing/facets/ListFacet.java | 36 +--- .../browsing/facets/NominalFacetChoice.java | 18 +- .../refine/browsing/facets/RangeFacet.java | 74 +------- .../browsing/facets/ScatterplotFacet.java | 75 -------- .../browsing/facets/TextSearchFacet.java | 32 +--- .../browsing/facets/TimeRangeFacet.java | 65 ------- .../google/refine/clustering/Clusterer.java | 3 +- .../refine/clustering/ClustererConfig.java | 3 +- .../clustering/binning/BinningClusterer.java | 50 +----- .../refine/clustering/knn/kNNClusterer.java | 58 +----- .../com/google/refine/commands/Command.java | 33 ++-- .../refine/commands/GetPreferenceCommand.java | 25 +-- .../google/refine/commands/HttpUtilities.java | 9 +- .../commands/cell/EditOneCellCommand.java | 46 +++-- .../expr/GetExpressionHistoryCommand.java | 32 +--- .../GetExpressionLanguageInfoCommand.java | 37 +--- .../expr/GetStarredExpressionsCommand.java | 28 +-- .../expr/PreviewExpressionCommand.java | 43 +---- .../history/GetOperationsCommand.java | 37 +--- .../GetImportingJobStatusCommand.java | 44 +++-- .../project/CreateProjectCommand.java | 2 +- .../commands/project/ExportRowsCommand.java | 1 - .../commands/project/GetMetadataCommand.java | 2 +- .../commands/project/GetModelsCommand.java | 90 +++++----- .../recon/ReconClearOneCellCommand.java | 34 ++-- .../recon/ReconJudgeOneCellCommand.java | 13 +- .../refine/commands/row/GetRowsCommand.java | 61 ++----- .../GetAllProjectMetadataCommand.java | 31 +--- .../workspace/GetAllProjectTagsCommand.java | 22 +-- .../src/com/google/refine/expr/EvalError.java | 17 +- .../com/google/refine/expr/MetaParser.java | 4 +- main/src/com/google/refine/grel/Control.java | 19 +- .../refine/grel/ControlFunctionRegistry.java | 6 +- main/src/com/google/refine/grel/Function.java | 16 +- .../src/com/google/refine/history/Change.java | 1 + .../com/google/refine/history/History.java | 27 +-- .../google/refine/history/HistoryEntry.java | 21 +-- .../google/refine/history/HistoryProcess.java | 16 -- .../importing/DefaultImportingController.java | 30 ++-- .../google/refine/importing/ImportingJob.java | 17 +- .../refine/io/FileHistoryEntryManager.java | 12 +- .../google/refine/io/FileProjectManager.java | 32 +--- .../refine/io/ProjectMetadataUtilities.java | 5 +- .../refine/model/AbstractOperation.java | 3 +- main/src/com/google/refine/model/Cell.java | 42 +---- main/src/com/google/refine/model/Column.java | 37 +--- .../com/google/refine/model/ColumnGroup.java | 32 +--- .../com/google/refine/model/ColumnModel.java | 34 +--- .../com/google/refine/model/OverlayModel.java | 3 +- main/src/com/google/refine/model/Project.java | 10 +- main/src/com/google/refine/model/Recon.java | 56 +----- .../google/refine/model/ReconCandidate.java | 27 +-- .../com/google/refine/model/ReconStats.java | 24 +-- .../com/google/refine/model/ReconType.java | 17 +- .../com/google/refine/model/RecordModel.java | 16 +- main/src/com/google/refine/model/Row.java | 71 ++------ .../refine/model/changes/ColumnChange.java | 13 +- .../model/changes/DataExtensionChange.java | 9 +- .../refine/model/changes/MassReconChange.java | 8 +- .../model/metadata/AbstractMetadata.java | 23 --- .../model/metadata/DataPackageMetadata.java | 42 +---- .../refine/model/metadata/IMetadata.java | 16 +- .../model/metadata/ProjectMetadata.java | 168 ++++++------------ .../metadata/validator/ValidateOperation.java | 11 -- .../model/recon/DataExtensionReconConfig.java | 9 +- .../refine/model/recon/ReconConfig.java | 15 +- .../recon/ReconciledDataExtensionJob.java | 88 ++------- .../model/recon/StandardReconConfig.java | 44 +---- .../operations/cell/BlankDownOperation.java | 16 -- .../operations/cell/FillDownOperation.java | 16 -- .../cell/KeyValueColumnizeOperation.java | 20 --- .../operations/cell/MassEditOperation.java | 42 +---- .../cell/MultiValuedCellJoinOperation.java | 17 -- .../cell/MultiValuedCellSplitOperation.java | 27 --- .../cell/TextTransformOperation.java | 19 -- .../TransposeColumnsIntoRowsOperation.java | 26 --- .../TransposeRowsIntoColumnsOperation.java | 16 -- ...ColumnAdditionByFetchingURLsOperation.java | 40 +---- .../column/ColumnAdditionOperation.java | 19 -- .../column/ColumnMoveOperation.java | 17 -- .../column/ColumnRemovalOperation.java | 16 -- .../column/ColumnRenameOperation.java | 17 -- .../column/ColumnReorderOperation.java | 19 -- .../column/ColumnSplitOperation.java | 30 ---- .../operations/recon/ExtendDataOperation.java | 19 -- .../ReconClearSimilarCellsOperation.java | 18 -- .../ReconCopyAcrossColumnsOperation.java | 29 --- .../recon/ReconDiscardJudgmentsOperation.java | 17 -- .../ReconJudgeSimilarCellsOperation.java | 26 +-- .../recon/ReconMarkNewTopicsOperation.java | 17 -- .../ReconMatchBestCandidatesOperation.java | 16 -- .../ReconMatchSpecificTopicOperation.java | 29 --- .../operations/recon/ReconOperation.java | 61 ------- .../operations/row/DenormalizeOperation.java | 15 -- .../operations/row/RowFlagOperation.java | 16 -- .../operations/row/RowRemovalOperation.java | 15 -- .../operations/row/RowReorderOperation.java | 16 -- .../operations/row/RowStarOperation.java | 16 -- .../refine/preference/PreferenceStore.java | 29 +-- .../com/google/refine/preference/TopList.java | 20 +-- .../refine/process/LongRunningProcess.java | 18 -- .../com/google/refine/process/Process.java | 3 +- .../google/refine/process/ProcessManager.java | 35 +--- .../process/QuickHistoryEntryProcess.java | 17 -- .../com/google/refine/sorting/Criterion.java | 19 +- .../google/refine/sorting/DateCriterion.java | 4 - .../google/refine/sorting/SortingConfig.java | 20 +-- .../com/google/refine/util/JSONUtilities.java | 18 +- .../google/refine/util/ParsingUtilities.java | 11 +- main/src/com/google/refine/util/Pool.java | 37 +--- .../google/refine/tests/model/CellTests.java | 5 +- .../google/refine/tests/model/RowTests.java | 9 +- .../recon/ExtendDataOperationTests.java | 4 +- .../ReconJudgeSimilarCellsOperationTests.java | 4 +- .../recon/ReconJudgeSimilarCellsTests.java | 3 +- .../tests/process/ProcessManagerTests.java | 4 +- .../google/refine/tests/util/TestUtils.java | 42 +---- 135 files changed, 508 insertions(+), 2900 deletions(-) delete mode 100644 extensions/wikidata/src/org/openrefine/wikidata/utils/JacksonJsonizable.java delete mode 100644 main/src/com/google/refine/Jsonizable.java diff --git a/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java b/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java index d26fefcf8..3d821f4d4 100644 --- a/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java +++ b/extensions/database/src/com/google/refine/extension/database/DatabaseModuleImpl.java @@ -40,7 +40,6 @@ import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.refine.Jsonizable; import edu.mit.simile.butterfly.ButterflyModuleImpl; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java index eb3749133..ce496df4b 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/commands/PreviewWikibaseSchemaCommand.java @@ -27,31 +27,55 @@ package org.openrefine.wikidata.commands; import static org.openrefine.wikidata.commands.CommandUtilities.respondError; import java.io.IOException; -import java.io.StringWriter; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import org.openrefine.wikidata.qa.EditInspector; import org.openrefine.wikidata.qa.QAWarning; +import org.openrefine.wikidata.qa.QAWarning.Severity; import org.openrefine.wikidata.qa.QAWarningStore; import org.openrefine.wikidata.schema.WikibaseSchema; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.scheduler.WikibaseAPIUpdateScheduler; import com.fasterxml.jackson.databind.ObjectMapper; + import com.google.refine.browsing.Engine; import com.google.refine.commands.Command; import com.google.refine.model.Project; public class PreviewWikibaseSchemaCommand extends Command { + + protected static class PreviewResults { + @JsonProperty("warnings") + List warnings; + @JsonProperty("max_severity") + Severity maxSeverity; + @JsonProperty("nb_warnings") + int nbWarnings; + @JsonProperty("edit_count") + int editCount; + @JsonProperty("edits_preview") + List editsPreview; + + protected PreviewResults( + List warnings, + Severity maxSeverity, + int nbWarnings, + int editCount, + List editsPreview) { + this.warnings = warnings; + this.maxSeverity = maxSeverity; + this.nbWarnings = nbWarnings; + this.editCount = editCount; + this.editsPreview = editsPreview; + } + } @Override public void doPost(HttpServletRequest request, HttpServletResponse response) @@ -87,50 +111,24 @@ public class PreviewWikibaseSchemaCommand extends Command { Engine engine = getEngine(request, project); List editBatch = schema.evaluate(project, engine, warningStore); - StringWriter sb = new StringWriter(2048); - JSONWriter writer = new JSONWriter(sb); - writer.object(); + // Inspect the edits and generate warnings + EditInspector inspector = new EditInspector(warningStore); + inspector.inspect(editBatch); + + // Dump the first 10 edits, scheduled with the default scheduler + WikibaseAPIUpdateScheduler scheduler = new WikibaseAPIUpdateScheduler(); + List nonNullEdits = scheduler.schedule(editBatch).stream() + .filter(e -> !e.isNull()) + .collect(Collectors.toList()); + List firstEdits = nonNullEdits.stream() + .limit(10) + .collect(Collectors.toList()); - { - // Inspect the edits and generate warnings - EditInspector inspector = new EditInspector(warningStore); - inspector.inspect(editBatch); - writer.key("warnings"); - writer.array(); - for (QAWarning warning : warningStore.getWarnings()) { - warning.write(writer, new Properties()); - } - writer.endArray(); - - // Add max warning level - writer.key("max_severity"); - writer.value(warningStore.getMaxSeverity().toString()); - - // this is not the length of the warnings array written before, - // but the total number of issues raised (before deduplication) - writer.key("nb_warnings"); - writer.value(warningStore.getNbWarnings()); - - // Dump the first 10 edits, scheduled with the default scheduler - WikibaseAPIUpdateScheduler scheduler = new WikibaseAPIUpdateScheduler(); - List nonNullEdits = scheduler.schedule(editBatch).stream() - .filter(e -> !e.isNull()) - .collect(Collectors.toList()); - writer.key("edit_count"); - writer.value(nonNullEdits.size()); - List firstEdits = nonNullEdits.stream() - .limit(10) - .collect(Collectors.toList()); - ObjectMapper mapper = new ObjectMapper(); - String firstEditsJson = mapper.writeValueAsString(firstEdits); - - writer.key("edits_preview"); - writer.value(new JSONArray(firstEditsJson)); - } - - writer.endObject(); - - respond(response, sb.toString()); + respondJSON(response, new PreviewResults( + warningStore.getWarnings(), + warningStore.getMaxSeverity(), + warningStore.getNbWarnings(), + nonNullEdits.size(), firstEdits)); } catch (Exception e) { respondException(response, e); } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/commands/SaveWikibaseSchemaCommand.java b/extensions/wikidata/src/org/openrefine/wikidata/commands/SaveWikibaseSchemaCommand.java index 9196fcef5..2dc44a39e 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/commands/SaveWikibaseSchemaCommand.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/commands/SaveWikibaseSchemaCommand.java @@ -23,6 +23,8 @@ ******************************************************************************/ package org.openrefine.wikidata.commands; +import static org.openrefine.wikidata.commands.CommandUtilities.respondError; + import java.io.IOException; import java.util.Properties; @@ -34,7 +36,6 @@ import org.json.JSONException; import org.json.JSONObject; import org.openrefine.wikidata.operations.SaveWikibaseSchemaOperation; import org.openrefine.wikidata.schema.WikibaseSchema; -import static org.openrefine.wikidata.commands.CommandUtilities.respondError; import com.google.refine.commands.Command; import com.google.refine.model.AbstractOperation; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/editing/WikibaseCredentials.java b/extensions/wikidata/src/org/openrefine/wikidata/editing/WikibaseCredentials.java index b8de3581f..c8645dcd3 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/editing/WikibaseCredentials.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/editing/WikibaseCredentials.java @@ -23,13 +23,11 @@ ******************************************************************************/ package org.openrefine.wikidata.editing; -import java.util.Properties; - import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; -import com.google.refine.Jsonizable; +import com.fasterxml.jackson.annotation.JsonProperty; + /** * This is just the necessary bits to store Wikidata credentials in OpenRefine's @@ -38,9 +36,11 @@ import com.google.refine.Jsonizable; * @author Antonin Delpeuch * */ -class WikibaseCredentials implements Jsonizable { +class WikibaseCredentials { + @JsonProperty("username") private String username; + @JsonProperty("password") private String password; public WikibaseCredentials() { @@ -64,18 +64,10 @@ class WikibaseCredentials implements Jsonizable { public boolean isNonNull() { return username != null && password != null && !"null".equals(username) && !"null".equals(password); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("class"); - writer.value(this.getClass().getName()); - writer.key("username"); - writer.value(username); - writer.key("password"); - writer.value(password); - writer.endObject(); + + @JsonProperty("class") + public String getClassName() { + return getClass().getName(); } public static WikibaseCredentials load(JSONObject obj) diff --git a/extensions/wikidata/src/org/openrefine/wikidata/operations/PerformWikibaseEditsOperation.java b/extensions/wikidata/src/org/openrefine/wikidata/operations/PerformWikibaseEditsOperation.java index d45c08709..86f0129e1 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/operations/PerformWikibaseEditsOperation.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/operations/PerformWikibaseEditsOperation.java @@ -46,6 +46,7 @@ import org.wikidata.wdtk.wikibaseapi.ApiConnection; import org.wikidata.wdtk.wikibaseapi.WikibaseDataEditor; import org.wikidata.wdtk.wikibaseapi.WikibaseDataFetcher; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.ObjectMapper; import com.google.refine.browsing.Engine; @@ -64,6 +65,7 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation { static final Logger logger = LoggerFactory.getLogger(PerformWikibaseEditsOperation.class); + @JsonProperty("summary") private String summary; public PerformWikibaseEditsOperation(EngineConfig engineConfig, String summary) { @@ -84,21 +86,6 @@ public class PerformWikibaseEditsOperation extends EngineDependentOperation { EngineConfig.reconstruct(engineConfig), summary); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("op"); - writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); - writer.value("Perform Wikibase edits"); - writer.key("summary"); - writer.value(summary); - writer.key("engineConfig"); - getEngineConfig().write(writer, options); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Peform edits on Wikidata"; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/operations/SaveWikibaseSchemaOperation.java b/extensions/wikidata/src/org/openrefine/wikidata/operations/SaveWikibaseSchemaOperation.java index 8303469c6..7eccbbafd 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/operations/SaveWikibaseSchemaOperation.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/operations/SaveWikibaseSchemaOperation.java @@ -33,6 +33,8 @@ import org.json.JSONObject; import org.json.JSONWriter; import org.openrefine.wikidata.schema.WikibaseSchema; +import com.fasterxml.jackson.annotation.JsonProperty; + import com.google.refine.history.Change; import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; @@ -44,6 +46,7 @@ import com.google.refine.util.Pool; public class SaveWikibaseSchemaOperation extends AbstractOperation { final public String operationDescription = "Save Wikibase schema"; + @JsonProperty("schema") final protected WikibaseSchema _schema; public SaveWikibaseSchemaOperation(WikibaseSchema schema) { @@ -56,22 +59,9 @@ public class SaveWikibaseSchemaOperation extends AbstractOperation { return new SaveWikibaseSchemaOperation(WikibaseSchema.reconstruct(obj.getJSONObject("schema"))); } - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("op"); - writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); - writer.value(operationDescription); - writer.key("schema"); - _schema.write(writer, options); - writer.endObject(); - - } - @Override protected String getBriefDescription(Project project) { - return "Save Wikibase schema skelton"; + return operationDescription; } @Override @@ -149,12 +139,7 @@ public class SaveWikibaseSchemaOperation extends AbstractOperation { static protected void writeWikibaseSchema(WikibaseSchema s, Writer writer) throws IOException { if (s != null) { - JSONWriter jsonWriter = new JSONWriter(writer); - try { - s.write(jsonWriter, new Properties()); - } catch (JSONException e) { - e.printStackTrace(); - } + ParsingUtilities.defaultWriter.writeValue(writer, s); } } } diff --git a/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java b/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java index a5b98dd09..0b58a42f5 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/qa/QAWarning.java @@ -28,7 +28,6 @@ import java.util.Map; import java.util.Map.Entry; import org.jsoup.helper.Validate; -import org.openrefine.wikidata.utils.JacksonJsonizable; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -42,7 +41,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; * @author Antonin Delpeuch * */ -public class QAWarning extends JacksonJsonizable implements Comparable { +public class QAWarning implements Comparable { public enum Severity { INFO, // We just report something to the user but it is probably fine diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java index dc198adba..3ecbca5cd 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WbItemDocumentExpr.java @@ -30,7 +30,6 @@ import org.jsoup.helper.Validate; import org.openrefine.wikidata.schema.exceptions.SkipSchemaExpressionException; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; -import org.openrefine.wikidata.utils.JacksonJsonizable; import org.wikidata.wdtk.datamodel.interfaces.ItemIdValue; import org.wikidata.wdtk.datamodel.interfaces.Statement; @@ -48,7 +47,7 @@ import com.fasterxml.jackson.annotation.JsonTypeInfo; */ @JsonIgnoreProperties(ignoreUnknown = true) @JsonTypeInfo(use = JsonTypeInfo.Id.NONE) -public class WbItemDocumentExpr extends JacksonJsonizable implements WbExpression { +public class WbItemDocumentExpr implements WbExpression { private WbExpression subject; private List nameDescs; diff --git a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java index 6c5d98c45..5f25306a7 100644 --- a/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java +++ b/extensions/wikidata/src/org/openrefine/wikidata/schema/WikibaseSchema.java @@ -63,6 +63,7 @@ public class WikibaseSchema implements OverlayModel { final static Logger logger = LoggerFactory.getLogger("RdfSchema"); + @JsonProperty("itemDocuments") protected List itemDocumentExprs = new ArrayList(); protected String baseIri = "http://www.wikidata.org/entity/"; @@ -198,19 +199,6 @@ public class WikibaseSchema implements OverlayModel { throw new JSONException(e.toString()); } } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("itemDocuments"); - writer.array(); - for (WbItemDocumentExpr changeExpr : itemDocumentExprs) { - changeExpr.write(writer, options); - } - writer.endArray(); - writer.endObject(); - } static public WikibaseSchema load(Project project, JSONObject obj) throws Exception { diff --git a/extensions/wikidata/src/org/openrefine/wikidata/utils/JacksonJsonizable.java b/extensions/wikidata/src/org/openrefine/wikidata/utils/JacksonJsonizable.java deleted file mode 100644 index b84c79b7d..000000000 --- a/extensions/wikidata/src/org/openrefine/wikidata/utils/JacksonJsonizable.java +++ /dev/null @@ -1,79 +0,0 @@ -/******************************************************************************* - * MIT License - * - * Copyright (c) 2018 Antonin Delpeuch - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - ******************************************************************************/ -package org.openrefine.wikidata.utils; - -import java.io.IOException; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONObject; -import org.json.JSONWriter; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.ObjectMapper; - -import com.google.refine.Jsonizable; - -/** - * This class is inefficient because it serializes the object to string and then - * deserializes it back. Unfortunately, this is the only simple way to bridge - * Jackson to org.json. This conversion should be removed when (if ?) we migrate - * OpenRefine a better JSON library. - * - * @author Antonin Delpeuch - * - */ -@JsonIgnoreProperties(ignoreUnknown = true) -public abstract class JacksonJsonizable implements Jsonizable { - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - ObjectMapper mapper = new ObjectMapper(); - try { - writer.value(new JSONObject(mapper.writeValueAsString(this))); - } catch (JsonProcessingException e) { - throw new JSONException(e.toString()); - } - } - - public static T fromJSONClass(JSONObject obj, Class klass) - throws JSONException { - ObjectMapper mapper = new ObjectMapper(); - String json = obj.toString(); - try { - return mapper.readValue(json, klass); - } catch (JsonParseException e) { - throw new JSONException(e.toString()); - } catch (JsonMappingException e) { - throw new JSONException(e.toString()); - } catch (IOException e) { - throw new JSONException(e.toString()); - } - } - -} diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java index edd29a260..cfc04fb4e 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/operations/OperationTest.java @@ -33,7 +33,6 @@ import java.io.StringWriter; import java.util.Properties; import org.json.JSONObject; -import org.json.JSONWriter; import org.openrefine.wikidata.testing.JacksonSerializationTest; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -43,6 +42,7 @@ import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; import com.google.refine.operations.OperationRegistry; import com.google.refine.tests.RefineTest; +import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; import edu.mit.simile.butterfly.ButterflyModule; @@ -77,8 +77,7 @@ public abstract class OperationTest extends RefineTest { JSONObject json = getJson(); AbstractOperation op = reconstruct(); StringWriter writer = new StringWriter(); - JSONWriter jsonWriter = new JSONWriter(writer); - op.write(jsonWriter, new Properties()); + ParsingUtilities.defaultWriter.writeValue(writer, op); JacksonSerializationTest.assertJsonEquals(json.toString(), writer.toString()); } diff --git a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java index 72bd2d941..42ba06c8d 100644 --- a/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java +++ b/extensions/wikidata/tests/src/org/openrefine/wikidata/schema/WikibaseSchemaTest.java @@ -26,16 +26,13 @@ package org.openrefine.wikidata.schema; import static org.junit.Assert.assertEquals; import java.io.IOException; -import java.io.StringWriter; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Properties; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.openrefine.wikidata.testing.TestingData; import org.openrefine.wikidata.updates.ItemUpdate; import org.openrefine.wikidata.updates.ItemUpdateBuilder; @@ -58,7 +55,7 @@ import com.google.refine.browsing.Engine; import com.google.refine.browsing.EngineConfig; import com.google.refine.model.Project; import com.google.refine.tests.RefineTest; -import com.google.refine.util.ParsingUtilities; +import com.google.refine.tests.util.TestUtils; public class WikibaseSchemaTest extends RefineTest { @@ -103,14 +100,7 @@ public class WikibaseSchemaTest extends RefineTest { throws JSONException, IOException { JSONObject serialized = TestingData.jsonFromFile("schema/history_of_medicine.json"); WikibaseSchema parsed = WikibaseSchema.reconstruct(serialized); - StringWriter writer = new StringWriter(); - JSONWriter jsonWriter = new JSONWriter(writer); - parsed.write(jsonWriter, new Properties()); - writer.close(); - JSONObject newSerialized = ParsingUtilities.evaluateJsonStringToObject(writer.toString()); - // toString because it looks like JSONObject equality isn't great… - assertEquals(TestingData.jsonFromFile("schema/history_of_medicine_normalized.json").toString(), - newSerialized.toString()); + TestUtils.isSerializedTo(parsed, TestingData.jsonFromFile("data/schema/history_of_medicine_normalized.json").toString()); } @Test diff --git a/main/src/com/google/refine/Jsonizable.java b/main/src/com/google/refine/Jsonizable.java deleted file mode 100644 index 630631d96..000000000 --- a/main/src/com/google/refine/Jsonizable.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - -Copyright 2010, Google Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are -met: - - * Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above -copyright notice, this list of conditions and the following disclaimer -in the documentation and/or other materials provided with the -distribution. - * Neither the name of Google Inc. nor the names of its -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -package com.google.refine; - -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; - -/** - * Interface for streaming out JSON, either into HTTP responses or - * serialization files. - * - * @author dfhuynh - */ -public interface Jsonizable { - public void write(JSONWriter writer, Properties options) throws JSONException; -} diff --git a/main/src/com/google/refine/browsing/DecoratedValue.java b/main/src/com/google/refine/browsing/DecoratedValue.java index 31c617a97..fc8ef95e7 100644 --- a/main/src/com/google/refine/browsing/DecoratedValue.java +++ b/main/src/com/google/refine/browsing/DecoratedValue.java @@ -34,14 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing; import java.time.OffsetDateTime; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.util.StringUtils; /** @@ -51,7 +46,7 @@ import com.google.refine.util.StringUtils; * * Facet choices that are presented to the user as text are stored as decorated values. */ -public class DecoratedValue implements Jsonizable { +public class DecoratedValue { @JsonProperty("v") final public Object value; @JsonProperty("l") @@ -65,13 +60,4 @@ public class DecoratedValue implements Jsonizable { } this.label = label; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("v"); writer.value(value); - writer.key("l"); writer.value(label); - writer.endObject(); - } } diff --git a/main/src/com/google/refine/browsing/Engine.java b/main/src/com/google/refine/browsing/Engine.java index 4fa193fe1..4feb97ec8 100644 --- a/main/src/com/google/refine/browsing/Engine.java +++ b/main/src/com/google/refine/browsing/Engine.java @@ -36,17 +36,14 @@ package com.google.refine.browsing; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.refine.Jsonizable; import com.google.refine.browsing.facets.Facet; import com.google.refine.browsing.util.ConjunctiveFilteredRecords; import com.google.refine.browsing.util.ConjunctiveFilteredRows; @@ -57,7 +54,7 @@ import com.google.refine.model.Row; /** * Faceted browsing engine. */ -public class Engine implements Jsonizable { +public class Engine { static public enum Mode { @JsonProperty("row-based") RowBased, @@ -205,19 +202,4 @@ public class Engine implements Jsonizable { throw new InternalError("Unknown mode."); } } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("facets"); - writer.array(); - for (Facet facet : _facets) { - facet.write(writer, options); - } - writer.endArray(); - writer.key(MODE); writer.value(_config.getMode().equals(Mode.RowBased) ? MODE_ROW_BASED : MODE_RECORD_BASED); - writer.endObject(); - } } diff --git a/main/src/com/google/refine/browsing/EngineConfig.java b/main/src/com/google/refine/browsing/EngineConfig.java index 6a058a29f..b0af26097 100644 --- a/main/src/com/google/refine/browsing/EngineConfig.java +++ b/main/src/com/google/refine/browsing/EngineConfig.java @@ -3,16 +3,12 @@ package com.google.refine.browsing; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine.Mode; import com.google.refine.browsing.facets.FacetConfig; import com.google.refine.browsing.facets.ListFacet.ListFacetConfig; @@ -22,7 +18,7 @@ import com.google.refine.browsing.facets.TextSearchFacet.TextSearchFacetConfig; import com.google.refine.browsing.facets.TimeRangeFacet.TimeRangeFacetConfig; -public class EngineConfig implements Jsonizable { +public class EngineConfig { protected final List _facets; protected final Mode _mode; @@ -88,19 +84,4 @@ public class EngineConfig implements Jsonizable { return new EngineConfig(facets, mode); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("facets"); - writer.array(); - for (FacetConfig facet : _facets) { - facet.write(writer, options); - } - writer.endArray(); - writer.key(Engine.MODE); writer.value(_mode == Mode.RowBased ? Engine.MODE_ROW_BASED : Engine.MODE_RECORD_BASED); - writer.endObject(); - } - } diff --git a/main/src/com/google/refine/browsing/facets/Facet.java b/main/src/com/google/refine/browsing/facets/Facet.java index 5720806ca..34476870e 100644 --- a/main/src/com/google/refine/browsing/facets/Facet.java +++ b/main/src/com/google/refine/browsing/facets/Facet.java @@ -33,7 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing.facets; -import com.google.refine.Jsonizable; import com.google.refine.browsing.FilteredRecords; import com.google.refine.browsing.FilteredRows; import com.google.refine.browsing.RecordFilter; @@ -43,7 +42,7 @@ import com.google.refine.model.Project; /** * Interface of facets. */ -public interface Facet extends Jsonizable { +public interface Facet { public RowFilter getRowFilter(Project project); public RecordFilter getRecordFilter(Project project); diff --git a/main/src/com/google/refine/browsing/facets/FacetConfig.java b/main/src/com/google/refine/browsing/facets/FacetConfig.java index 3971b66d4..22f07e39c 100644 --- a/main/src/com/google/refine/browsing/facets/FacetConfig.java +++ b/main/src/com/google/refine/browsing/facets/FacetConfig.java @@ -4,7 +4,6 @@ import org.json.JSONObject; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.model.Project; @@ -17,7 +16,7 @@ import com.google.refine.model.Project; * @author antonin * */ -public interface FacetConfig extends Jsonizable { +public interface FacetConfig { /** * Reads the facet configuration from a JSON object (will be removed once we migrate to Jackson) * @param fo diff --git a/main/src/com/google/refine/browsing/facets/ListFacet.java b/main/src/com/google/refine/browsing/facets/ListFacet.java index 780e73f80..07ecf61f0 100644 --- a/main/src/com/google/refine/browsing/facets/ListFacet.java +++ b/main/src/com/google/refine/browsing/facets/ListFacet.java @@ -35,20 +35,16 @@ package com.google.refine.browsing.facets; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.ProjectManager; import com.google.refine.browsing.DecoratedValue; @@ -115,33 +111,6 @@ public class ListFacet implements Facet { @JsonProperty("selectError") public boolean selectError; - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("type"); writer.value("list"); - writer.key("name"); writer.value(name); - writer.key("expression"); writer.value(expression); - writer.key("columnName"); writer.value(columnName); - writer.key("invert"); writer.value(invert); - writer.key("selection"); writer.array(); - for (DecoratedValue choice : selection) { - writer.object(); - writer.key("v"); - choice.write(writer, options); - writer.endObject(); - } - writer.endArray(); - writer.key("selectNumber"); writer.value(selectNumber); - writer.key("selectDateTime"); writer.value(selectDateTime); - writer.key("selectBoolean"); writer.value(selectBoolean); - writer.key("omitBlank"); writer.value(omitBlank); - writer.key("selectBlank"); writer.value(selectBlank); - writer.key("omitError"); writer.value(omitError); - writer.key("selectError"); writer.value(selectError); - writer.endObject(); - } - @JsonProperty("selection") public List getWrappedSelection() { return selection.stream() @@ -292,6 +261,7 @@ public class ListFacet implements Facet { } return null; } +<<<<<<< HEAD @Override public void write(JSONWriter writer, Properties options) @@ -353,6 +323,8 @@ public class ListFacet implements Facet { writer.endObject(); } +======= +>>>>>>> Remove Jsonizable interface and write methods protected int getLimit() { Object v = ProjectManager.singleton.getPreferenceStore().get("ui.browsing.listFacet.limit"); diff --git a/main/src/com/google/refine/browsing/facets/NominalFacetChoice.java b/main/src/com/google/refine/browsing/facets/NominalFacetChoice.java index ad59ff61a..f29a6ae96 100644 --- a/main/src/com/google/refine/browsing/facets/NominalFacetChoice.java +++ b/main/src/com/google/refine/browsing/facets/NominalFacetChoice.java @@ -33,21 +33,15 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing.facets; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.browsing.DecoratedValue; /** * Store a facet choice that has a decorated value, a count of matched rows, * and a flag of whether it has been selected. */ -public class NominalFacetChoice implements Jsonizable { +public class NominalFacetChoice { @JsonProperty("v") final public DecoratedValue decoratedValue; @JsonProperty("c") @@ -58,14 +52,4 @@ public class NominalFacetChoice implements Jsonizable { public NominalFacetChoice(DecoratedValue decoratedValue) { this.decoratedValue = decoratedValue; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("v"); decoratedValue.write(writer, options); - writer.key("c"); writer.value(count); - writer.key("s"); writer.value(selected); - writer.endObject(); - } } diff --git a/main/src/com/google/refine/browsing/facets/RangeFacet.java b/main/src/com/google/refine/browsing/facets/RangeFacet.java index 48621873b..ce0c68161 100644 --- a/main/src/com/google/refine/browsing/facets/RangeFacet.java +++ b/main/src/com/google/refine/browsing/facets/RangeFacet.java @@ -33,11 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing.facets; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -96,24 +92,6 @@ public class RangeFacet implements Facet { protected boolean _selected; // false if we're certain that all rows will match // and there isn't any filtering to do - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("type"); writer.value("range"); - writer.key("name"); writer.value(_name); - writer.key("expression"); writer.value(_expression); - writer.key("columnName"); writer.value(_columnName); - writer.key(FROM); writer.value(_from); - writer.key(TO); writer.value(_to); - writer.key("selectNumeric"); writer.value(_selectNumeric); - writer.key("selectNonNumeric"); writer.value(_selectNonNumeric); - writer.key("selectError"); writer.value(_selectError); - writer.key("selectBlank"); writer.value(_selectBlank); - writer.endObject(); - - } - @Override public void initializeFromJSON(JSONObject o) { _name = o.getString("name"); @@ -282,56 +260,8 @@ public class RangeFacet implements Facet { return _config._to; } return null; - } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("name"); writer.value(_config._name); - writer.key("expression"); writer.value(_config._expression); - writer.key("columnName"); writer.value(_config._columnName); - - if (_errorMessage != null) { - writer.key("error"); writer.value(_errorMessage); - } else { - if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) { - writer.key(MIN); writer.value(_min); - writer.key(MAX); writer.value(_max); - writer.key("step"); writer.value(_step); - - writer.key("bins"); writer.array(); - for (int b : _bins) { - writer.value(b); - } - writer.endArray(); - - writer.key("baseBins"); writer.array(); - for (int b : _baseBins) { - writer.value(b); - } - writer.endArray(); - - writer.key(FROM); writer.value(_config._from); - writer.key(TO); writer.value(_config._to); - } else { - writer.key("error"); writer.value(ERR_NO_NUMERIC_VALUE_PRESENT); - } - - writer.key("baseNumericCount"); writer.value(_baseNumericCount); - writer.key("baseNonNumericCount"); writer.value(_baseNonNumericCount); - writer.key("baseBlankCount"); writer.value(_baseBlankCount); - writer.key("baseErrorCount"); writer.value(_baseErrorCount); - - writer.key("numericCount"); writer.value(_numericCount); - writer.key("nonNumericCount"); writer.value(_nonNumericCount); - writer.key("blankCount"); writer.value(_blankCount); - writer.key("errorCount"); writer.value(_errorCount); - } - writer.endObject(); - } - + } + public void initializeFromConfig(RangeFacetConfig config, Project project) { _config = config; diff --git a/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java b/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java index 3945251d7..202a04606 100644 --- a/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java +++ b/main/src/com/google/refine/browsing/facets/ScatterplotFacet.java @@ -40,14 +40,11 @@ import java.awt.image.BufferedImage; import java.awt.image.RenderedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.util.Properties; import javax.imageio.ImageIO; import org.apache.commons.codec.binary.Base64; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -140,36 +137,6 @@ public class ScatterplotFacet implements Facet { return dim_y == LIN ? "lin" : "log"; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - - writer.key("type"); writer.value("scatterplot"); - writer.key(NAME); writer.value(name); - writer.key(X_COLUMN_NAME); writer.value(columnName_x); - writer.key(X_EXPRESSION); writer.value(expression_x); - writer.key(Y_COLUMN_NAME); writer.value(columnName_y); - writer.key(Y_EXPRESSION); writer.value(expression_y); - writer.key(SIZE); writer.value(size); - writer.key(DOT); writer.value(dot); - if(!rotation_str.isEmpty()) { - writer.key(ROTATION); writer.value(rotation_str); - } - writer.key(DIM_X); writer.value(dim_x == LIN ? "lin" : "log"); - writer.key(DIM_Y); writer.value(dim_y == LIN ? "lin" : "log"); - if(!"000000".equals(color_str)) { - writer.key(COLOR); writer.value(color_str); - } - writer.key(FROM_X); writer.value(from_x); - writer.key(TO_X); writer.value(to_x); - writer.key(FROM_Y); writer.value(from_y); - writer.key(TO_Y); writer.value(to_y); - - writer.endObject(); - - } - @Override public ScatterplotFacet apply(Project project) { ScatterplotFacet facet = new ScatterplotFacet(); @@ -404,48 +371,6 @@ public class ScatterplotFacet implements Facet { } return null; } - - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - - writer.object(); - - writer.key(NAME); writer.value(config.name); - writer.key(X_COLUMN_NAME); writer.value(config.columnName_x); - writer.key(X_EXPRESSION); writer.value(config.expression_x); - writer.key(Y_COLUMN_NAME); writer.value(config.columnName_y); - writer.key(Y_EXPRESSION); writer.value(config.expression_y); - writer.key(SIZE); writer.value(config.size); - writer.key(DOT); writer.value(config.dot); - writer.key(ROTATION); writer.value(config.rotation); - writer.key(DIM_X); writer.value(config.dim_x); - writer.key(DIM_Y); writer.value(config.dim_y); - writer.key(COLOR); writer.value(config.color_str); - - if (IMAGE_URI) { - writer.key(IMAGE); writer.value(image); - } - - if (errorMessage_x != null) { - writer.key(ERROR_X); writer.value(errorMessage_x); - } else { - if (!Double.isInfinite(min_x) && !Double.isInfinite(max_x)) { - writer.key(FROM_X); writer.value(config.from_x); - writer.key(TO_X); writer.value(config.to_x); - } - } - - if (errorMessage_y != null) { - writer.key(ERROR_Y); writer.value(errorMessage_y); - } else { - if (!Double.isInfinite(min_y) && !Double.isInfinite(max_y)) { - writer.key(FROM_Y); writer.value(config.from_y); - writer.key(TO_Y); writer.value(config.to_y); - } - } - - writer.endObject(); - } public void initializeFromConfig(ScatterplotFacetConfig configuration, Project project) { config = configuration; diff --git a/main/src/com/google/refine/browsing/facets/TextSearchFacet.java b/main/src/com/google/refine/browsing/facets/TextSearchFacet.java index c627f8258..5e3780e2a 100644 --- a/main/src/com/google/refine/browsing/facets/TextSearchFacet.java +++ b/main/src/com/google/refine/browsing/facets/TextSearchFacet.java @@ -33,12 +33,10 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing.facets; -import java.util.Properties; import java.util.regex.Pattern; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -73,20 +71,6 @@ public class TextSearchFacet implements Facet { @JsonProperty("invert") protected boolean _invert; - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("name"); writer.value(_name); - writer.key("columnName"); writer.value(_columnName); - writer.key("query"); writer.value(_query); - writer.key("mode"); writer.value(_mode); - writer.key("caseSensitive"); writer.value(_caseSensitive); - writer.key("invert"); writer.value(_invert); - writer.key("type"); writer.value("text"); - writer.endObject(); - } - @Override public TextSearchFacet apply(Project project) { TextSearchFacet facet = new TextSearchFacet(); @@ -152,21 +136,7 @@ public class TextSearchFacet implements Facet { public boolean isInverted() { return _config._invert; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("name"); writer.value(_config._name); - writer.key("columnName"); writer.value(_config._columnName); - writer.key("query"); writer.value(_config._query); - writer.key("mode"); writer.value(_config._mode); - writer.key("caseSensitive"); writer.value(_config._caseSensitive); - writer.key("invert"); writer.value(_config._invert); - writer.endObject(); - } - + public void initializeFromConfig(TextSearchFacetConfig config, Project project) { _config = config; diff --git a/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java b/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java index 98cd0d1ee..c1042f116 100644 --- a/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java +++ b/main/src/com/google/refine/browsing/facets/TimeRangeFacet.java @@ -33,11 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.browsing.facets; -import java.util.Properties; - import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -93,23 +90,6 @@ public class TimeRangeFacet implements Facet { protected boolean _selected; // false if we're certain that all rows will match // and there isn't any filtering to do - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("type"); writer.value("timerange"); - writer.key("name"); writer.value(_name); - writer.key("expression"); writer.value(_expression); - writer.key("columnName"); writer.value(_columnName); - writer.key("selectTime"); writer.value(_selectTime); - writer.key("selectNonTime"); writer.value(_selectNonTime); - writer.key("selectBlank"); writer.value(_selectBlank); - writer.key("selectError"); writer.value(_selectError); - writer.key(FROM); writer.value((long)_from); - writer.key(TO); writer.value((long)_to); - writer.endObject(); - } - @Override public void initializeFromJSON(JSONObject o) throws JSONException { _name = o.getString("name"); @@ -266,51 +246,6 @@ public class TimeRangeFacet implements Facet { return null; } - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - - writer.object(); - writer.key("name"); writer.value(_config._name); - writer.key("expression"); writer.value(_config._expression); - writer.key("columnName"); writer.value(_config._columnName); - - if (_errorMessage != null) { - writer.key("error"); writer.value(_errorMessage); - } else { - if (!Double.isInfinite(_min) && !Double.isInfinite(_max)) { - writer.key(MIN); writer.value((long)_min); - writer.key(MAX); writer.value((long)_max); - writer.key("step"); writer.value((long)_step); - - writer.key("bins"); writer.array(); - for (int b : _bins) { - writer.value(b); - } - writer.endArray(); - - writer.key("baseBins"); writer.array(); - for (int b : _baseBins) { - writer.value(b); - } - writer.endArray(); - - writer.key(FROM); writer.value((long)_config._from); - writer.key(TO); writer.value((long)_config._to); - } - - writer.key("baseTimeCount"); writer.value(_baseTimeCount); - writer.key("baseNonTimeCount"); writer.value(_baseNonTimeCount); - writer.key("baseBlankCount"); writer.value(_baseBlankCount); - writer.key("baseErrorCount"); writer.value(_baseErrorCount); - - writer.key("timeCount"); writer.value(_timeCount); - writer.key("nonTimeCount"); writer.value(_nonTimeCount); - writer.key("blankCount"); writer.value(_blankCount); - writer.key("errorCount"); writer.value(_errorCount); - } - writer.endObject(); - } - public void initializeFromConfig(TimeRangeFacetConfig config, Project project) { _config = config; if (_config._columnName.length() > 0) { diff --git a/main/src/com/google/refine/clustering/Clusterer.java b/main/src/com/google/refine/clustering/Clusterer.java index a18e42c81..bfb149498 100644 --- a/main/src/com/google/refine/clustering/Clusterer.java +++ b/main/src/com/google/refine/clustering/Clusterer.java @@ -33,12 +33,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.clustering; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine; import com.google.refine.model.Column; import com.google.refine.model.Project; -public abstract class Clusterer implements Jsonizable { +public abstract class Clusterer { protected Project _project; protected int _colindex; diff --git a/main/src/com/google/refine/clustering/ClustererConfig.java b/main/src/com/google/refine/clustering/ClustererConfig.java index 95930fd99..5ac10369f 100644 --- a/main/src/com/google/refine/clustering/ClustererConfig.java +++ b/main/src/com/google/refine/clustering/ClustererConfig.java @@ -4,7 +4,6 @@ import org.json.JSONObject; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.model.Project; /** @@ -12,7 +11,7 @@ import com.google.refine.model.Project; * @author Antonin Delpeuch * */ -public abstract class ClustererConfig implements Jsonizable { +public abstract class ClustererConfig { protected String columnName; diff --git a/main/src/com/google/refine/clustering/binning/BinningClusterer.java b/main/src/com/google/refine/clustering/binning/BinningClusterer.java index 7e93013d1..589f610ca 100644 --- a/main/src/com/google/refine/clustering/binning/BinningClusterer.java +++ b/main/src/com/google/refine/clustering/binning/BinningClusterer.java @@ -57,7 +57,6 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine; import com.google.refine.browsing.FilteredRows; import com.google.refine.browsing.RowVisitor; @@ -99,20 +98,6 @@ public class BinningClusterer extends Clusterer { public BinningParameters getParameters() { return _parameters; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("function"); writer.value(_keyerName); - writer.key("type"); writer.value("binning"); - writer.key("column"); writer.value(getColumnName()); - if(_parameters != null) { - writer.key("params"); - _parameters.write(writer, options); - } - writer.endObject(); - } @Override public BinningClusterer apply(Project project) { @@ -128,21 +113,10 @@ public class BinningClusterer extends Clusterer { } - public static class BinningParameters implements Jsonizable { + public static class BinningParameters { @JsonProperty("ngram-size") @JsonInclude(Include.NON_DEFAULT) public int ngramSize; - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - if(ngramSize > 0) { - writer.key("ngram-size"); - writer.value(ngramSize); - } - writer.endObject(); - } public static BinningParameters reconstruct(JSONObject o) { BinningParameters parameters = new BinningParameters(); @@ -274,28 +248,6 @@ public class BinningClusterer extends Clusterer { Collections.sort(_clusters, new SizeComparator()); } - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - EntriesComparator c = new EntriesComparator(); - - writer.array(); - for (Map m : _clusters) { - if (m.size() > 1) { - writer.array(); - List> entries = new ArrayList>(m.entrySet()); - Collections.sort(entries,c); - for (Entry e : entries) { - writer.object(); - writer.key("v"); writer.value(e.getKey()); - writer.key("c"); writer.value(e.getValue()); - writer.endObject(); - } - writer.endArray(); - } - } - writer.endArray(); - } - protected static Map entryToMap(Entry entry) { Map map = new HashMap<>(); map.put("v", entry.getKey()); diff --git a/main/src/com/google/refine/clustering/knn/kNNClusterer.java b/main/src/com/google/refine/clustering/knn/kNNClusterer.java index 10db49280..da0a502d8 100644 --- a/main/src/com/google/refine/clustering/knn/kNNClusterer.java +++ b/main/src/com/google/refine/clustering/knn/kNNClusterer.java @@ -34,21 +34,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.clustering.knn; import java.io.Serializable; -import java.util.ArrayList; -import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +51,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine; import com.google.refine.browsing.FilteredRows; import com.google.refine.browsing.RowVisitor; @@ -86,21 +80,7 @@ public class kNNClusterer extends Clusterer { private String _distanceStr; private Distance _distance; private kNNClustererConfigParameters _parameters; - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("function"); writer.value(_distanceStr); - writer.key("type"); writer.value("knn"); - writer.key("column"); writer.value(getColumnName()); - if(_parameters != null) { - writer.key("params"); - _parameters.write(writer, options); - } - writer.endObject(); - } - + public void initializeFromJSON(JSONObject o) { super.initializeFromJSON(o); _distanceStr = o.getString("function"); @@ -136,7 +116,7 @@ public class kNNClusterer extends Clusterer { } - public static class kNNClustererConfigParameters implements Jsonizable { + public static class kNNClustererConfigParameters { public static final double defaultRadius = 1.0d; public static final int defaultBlockingNgramSize = 6; @JsonProperty("radius") @@ -144,16 +124,6 @@ public class kNNClusterer extends Clusterer { @JsonProperty("blocking-ngram-size") public int blockingNgramSize = defaultBlockingNgramSize; - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("radius"); writer.value(radius); - writer.key("blocking-ngram-size"); - writer.value(blockingNgramSize); - writer.endObject(); - } - public static kNNClustererConfigParameters reconstruct(JSONObject o) { kNNClustererConfigParameters params = new kNNClustererConfigParameters(); if(o.has("radius")) { @@ -294,30 +264,6 @@ public class kNNClusterer extends Clusterer { } } - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.array(); - for (Set m : _clusters) { - if (m.size() > 1) { - Map internal_counts = new HashMap(); - for (Serializable s : m) { - internal_counts.put(s,_counts.get(s)); - } - List> values = new ArrayList>(internal_counts.entrySet()); - Collections.sort(values, new ValuesComparator()); - writer.array(); - for (Entry e : values) { - writer.object(); - writer.key("v"); writer.value(e.getKey()); - writer.key("c"); writer.value(e.getValue()); - writer.endObject(); - } - writer.endArray(); - } - } - writer.endArray(); - } - protected List getClusteredEntries(Set s) { return s.stream() .map(e -> new ClusteredEntry(e, _counts.get(e))) diff --git a/main/src/com/google/refine/commands/Command.java b/main/src/com/google/refine/commands/Command.java index 9c685e447..39415f4d9 100644 --- a/main/src/com/google/refine/commands/Command.java +++ b/main/src/com/google/refine/commands/Command.java @@ -50,7 +50,8 @@ import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.refine.Jsonizable; +import com.fasterxml.jackson.annotation.JsonProperty; + import com.google.refine.ProjectManager; import com.google.refine.RefineServlet; import com.google.refine.browsing.Engine; @@ -237,6 +238,16 @@ public abstract class Command { } return null; } + + protected static class HistoryEntryResponse { + @JsonProperty("code") + protected String getCode() { return "ok"; } + @JsonProperty("historyEntry") + protected HistoryEntry historyEntry; + protected HistoryEntryResponse(HistoryEntry entry) { + historyEntry = entry; + } + } static protected void performProcessAndRespond( HttpServletRequest request, @@ -244,23 +255,18 @@ public abstract class Command { Project project, Process process ) throws Exception { - response.setCharacterEncoding("UTF-8"); - response.setHeader("Content-Type", "application/json"); + HistoryEntry historyEntry = project.processManager.queueProcess(process); if (historyEntry != null) { Writer w = response.getWriter(); - JSONWriter writer = new JSONWriter(w); - Properties options = new Properties(); - - writer.object(); - writer.key("code"); writer.value("ok"); - writer.key("historyEntry"); historyEntry.write(writer, options); - writer.endObject(); + ParsingUtilities.defaultWriter.writeValue(w, new HistoryEntryResponse(historyEntry)); w.flush(); w.close(); } else { + response.setCharacterEncoding("UTF-8"); + response.setHeader("Content-Type", "application/json"); respond(response, "{ \"code\" : \"pending\" }"); } } @@ -293,14 +299,14 @@ public abstract class Command { w.close(); } - static protected void respondJSON(HttpServletResponse response, Jsonizable o) + static protected void respondJSON(HttpServletResponse response, Object o) throws IOException, JSONException { respondJSON(response, o, new Properties()); } static protected void respondJSON( - HttpServletResponse response, Jsonizable o, Properties options) + HttpServletResponse response, Object o, Properties options) throws IOException, JSONException { response.setCharacterEncoding("UTF-8"); @@ -308,9 +314,8 @@ public abstract class Command { response.setHeader("Cache-Control", "no-cache"); Writer w = response.getWriter(); - JSONWriter writer = new JSONWriter(w); + ParsingUtilities.defaultWriter.writeValue(w, o); - o.write(writer, options); w.flush(); w.close(); } diff --git a/main/src/com/google/refine/commands/GetPreferenceCommand.java b/main/src/com/google/refine/commands/GetPreferenceCommand.java index 9f26daadc..cd1681b99 100644 --- a/main/src/com/google/refine/commands/GetPreferenceCommand.java +++ b/main/src/com/google/refine/commands/GetPreferenceCommand.java @@ -34,47 +34,24 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.commands; import java.io.IOException; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.preference.PreferenceStore; -import com.google.refine.preference.TopList; public class GetPreferenceCommand extends Command { - protected static class PreferenceValue implements Jsonizable { + protected static class PreferenceValue { @JsonProperty("value") protected Object pref; protected PreferenceValue(Object o) { pref = o; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("value"); - if (pref == null || pref instanceof String || pref instanceof Number || pref instanceof Boolean) { - writer.value(pref); - } else if (pref instanceof TopList) { - TopList tl = (TopList) pref; - tl.write(writer, new Properties()); - } else { - writer.value(pref.toString()); - } - - writer.endObject(); - } } @Override diff --git a/main/src/com/google/refine/commands/HttpUtilities.java b/main/src/com/google/refine/commands/HttpUtilities.java index 604fa9af9..97d9cc7e2 100644 --- a/main/src/com/google/refine/commands/HttpUtilities.java +++ b/main/src/com/google/refine/commands/HttpUtilities.java @@ -17,7 +17,6 @@ import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.google.refine.Jsonizable; import com.google.refine.RefineServlet; import com.google.refine.util.ParsingUtilities; @@ -56,23 +55,21 @@ abstract public class HttpUtilities { } } - static public void respondJSON(HttpServletResponse response, Jsonizable o) + static public void respondJSON(HttpServletResponse response, Object o) throws IOException, JSONException { respondJSON(response, o, new Properties()); } static public void respondJSON( - HttpServletResponse response, Jsonizable o, Properties options) + HttpServletResponse response, Object o, Properties options) throws IOException, JSONException { response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Type", "application/json"); Writer w = response.getWriter(); - JSONWriter writer = new JSONWriter(w); - - o.write(writer, options); + ParsingUtilities.defaultWriter.writeValue(w, o); w.flush(); w.close(); } diff --git a/main/src/com/google/refine/commands/cell/EditOneCellCommand.java b/main/src/com/google/refine/commands/cell/EditOneCellCommand.java index 266319947..41c7ab0b3 100644 --- a/main/src/com/google/refine/commands/cell/EditOneCellCommand.java +++ b/main/src/com/google/refine/commands/cell/EditOneCellCommand.java @@ -35,13 +35,14 @@ package com.google.refine.commands.cell; import java.io.IOException; import java.io.Serializable; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.commands.Command; import com.google.refine.history.Change; @@ -55,6 +56,32 @@ import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; public class EditOneCellCommand extends Command { + + protected static class EditResult { + @JsonProperty("code") + protected String code; + @JsonProperty("historyEntry") + @JsonInclude(Include.NON_NULL) + protected HistoryEntry historyEntry; + @JsonProperty("cell") + @JsonInclude(Include.NON_NULL) + protected Cell cell; + @JsonProperty("pool") + @JsonInclude(Include.NON_NULL) + protected Pool pool; + + protected EditResult( + String code, + HistoryEntry historyEntry, + Cell cell, + Pool pool) { + this.code = code; + this.historyEntry = historyEntry; + this.cell = cell; + this.pool = pool; + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -96,18 +123,11 @@ public class EditOneCellCommand extends Command { * If the operation has been done, return the new cell's data * so the client side can update the cell's rendering right away. */ - JSONWriter writer = new JSONWriter(response.getWriter()); - Pool pool = new Pool(); - Properties options = new Properties(); - options.put("pool", pool); - - writer.object(); - writer.key("code"); writer.value("ok"); - writer.key("historyEntry"); historyEntry.write(writer, options); - writer.key("cell"); process.newCell.write(writer, options); - writer.key("pool"); pool.write(writer, options); - writer.endObject(); + if(process.newCell != null && process.newCell.recon != null) { + pool.pool(process.newCell.recon); + } + respondJSON(response, new EditResult("ok", historyEntry, process.newCell, pool)); } else { respond(response, "{ \"code\" : \"pending\" }"); } diff --git a/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java b/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java index 18385f579..b4f229be9 100644 --- a/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java +++ b/main/src/com/google/refine/commands/expr/GetExpressionHistoryCommand.java @@ -37,7 +37,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; @@ -45,19 +44,15 @@ import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.commands.Command; import com.google.refine.preference.TopList; public class GetExpressionHistoryCommand extends Command { - public static class ExpressionState implements Jsonizable { + public static class ExpressionState { @JsonProperty("code") protected String code; @JsonProperty("global") @@ -69,38 +64,15 @@ public class GetExpressionHistoryCommand extends Command { this.code = code; this.starred = starred; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("code"); writer.value(code); - writer.key("global"); writer.value(false); - writer.key("starred"); writer.value(starred); - writer.endObject(); - } } - public static class ExpressionsList implements Jsonizable { + public static class ExpressionsList { @JsonProperty("expressions") List expressions; protected ExpressionsList(List states) { this.expressions = states; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("expressions"); - writer.array(); - for (ExpressionState e : expressions) { - e.write(writer, options); - } - writer.endArray(); - writer.endObject(); - } } static protected List toExpressionList(Object o) { diff --git a/main/src/com/google/refine/commands/expr/GetExpressionLanguageInfoCommand.java b/main/src/com/google/refine/commands/expr/GetExpressionLanguageInfoCommand.java index b5400d909..a47f7b62b 100644 --- a/main/src/com/google/refine/commands/expr/GetExpressionLanguageInfoCommand.java +++ b/main/src/com/google/refine/commands/expr/GetExpressionLanguageInfoCommand.java @@ -35,19 +35,13 @@ package com.google.refine.commands.expr; import java.io.IOException; import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.commands.Command; import com.google.refine.grel.Control; import com.google.refine.grel.ControlFunctionRegistry; @@ -55,7 +49,7 @@ import com.google.refine.grel.Function; public class GetExpressionLanguageInfoCommand extends Command { - public static class LanguageInfo implements Jsonizable { + public static class LanguageInfo { @JsonProperty("functions") Map functions; @@ -66,35 +60,6 @@ public class GetExpressionLanguageInfoCommand extends Command { functions = ControlFunctionRegistry.getFunctionMap(); controls = ControlFunctionRegistry.getControlMap(); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - - writer.key("functions"); - writer.object(); - { - for (Entry entry : functions.entrySet()) { - writer.key(entry.getKey()); - entry.getValue().write(writer, options); - } - } - writer.endObject(); - - writer.key("controls"); - writer.object(); - { - for (Entry entry : controls.entrySet()) { - writer.key(entry.getKey()); - entry.getValue().write(writer, options); - } - } - writer.endObject(); - - writer.endObject(); - } - } @Override diff --git a/main/src/com/google/refine/commands/expr/GetStarredExpressionsCommand.java b/main/src/com/google/refine/commands/expr/GetStarredExpressionsCommand.java index acad51a5c..60635c399 100644 --- a/main/src/com/google/refine/commands/expr/GetStarredExpressionsCommand.java +++ b/main/src/com/google/refine/commands/expr/GetStarredExpressionsCommand.java @@ -2,19 +2,14 @@ package com.google.refine.commands.expr; import java.io.IOException; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.commands.Command; import com.google.refine.preference.TopList; @@ -22,39 +17,20 @@ import com.google.refine.preference.TopList; public class GetStarredExpressionsCommand extends Command { - protected static class Expression implements Jsonizable { + protected static class Expression { @JsonProperty("code") protected String code; protected Expression(String c) { code = c; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("code"); writer.value(code); - writer.endObject(); - } } - protected static class ExpressionList implements Jsonizable { + protected static class ExpressionList { @JsonProperty("expressions") protected List expressions; protected ExpressionList(List e) { expressions = e; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("expressions"); - writer.array(); - for (Expression s : expressions) { - s.write(writer, options); - } - writer.endArray(); - writer.endObject(); - } } public static ExpressionList getExpressionsList() { diff --git a/main/src/com/google/refine/commands/expr/PreviewExpressionCommand.java b/main/src/com/google/refine/commands/expr/PreviewExpressionCommand.java index 2f5941a6f..e59ad8b5b 100644 --- a/main/src/com/google/refine/commands/expr/PreviewExpressionCommand.java +++ b/main/src/com/google/refine/commands/expr/PreviewExpressionCommand.java @@ -47,14 +47,12 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonValue; -import com.google.refine.Jsonizable; import com.google.refine.commands.Command; import com.google.refine.expr.EvalError; import com.google.refine.expr.Evaluable; @@ -71,21 +69,13 @@ import com.google.refine.util.ParsingUtilities; public class PreviewExpressionCommand extends Command { - protected static interface ExpressionValue extends Jsonizable { } + protected static interface ExpressionValue { } protected static class ErrorMessage implements ExpressionValue { @JsonProperty("message") protected String message; public ErrorMessage(String m) { message = m; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("message"); writer.value(message); - writer.endObject(); - } - } protected static class SuccessfulEvaluation implements ExpressionValue { @JsonValue @@ -93,15 +83,9 @@ public class PreviewExpressionCommand extends Command { protected SuccessfulEvaluation(String value) { this.value = value; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.value(value); - } - } - protected static class PreviewResult implements Jsonizable { + protected static class PreviewResult { @JsonProperty("code") protected String code; @JsonProperty("message") @@ -111,6 +95,7 @@ public class PreviewExpressionCommand extends Command { @JsonInclude(Include.NON_NULL) protected String type; @JsonProperty("results") + @JsonInclude(Include.NON_NULL) List results; public PreviewResult(String code, String message, String type) { @@ -126,28 +111,6 @@ public class PreviewExpressionCommand extends Command { this.type = null; this.results = evaluated; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("code"); writer.value(code); - if(message != null) { - writer.key("message"); writer.value(message); - } - if(type != null) { - writer.key("type"); writer.value(type); - } - if(results != null) { - writer.key("results"); - writer.array(); - for(ExpressionValue v : results) { - v.write(writer, options); - } - writer.endArray(); - } - writer.endObject(); - } } @Override diff --git a/main/src/com/google/refine/commands/history/GetOperationsCommand.java b/main/src/com/google/refine/commands/history/GetOperationsCommand.java index f03f9aabc..9b3c88829 100644 --- a/main/src/com/google/refine/commands/history/GetOperationsCommand.java +++ b/main/src/com/google/refine/commands/history/GetOperationsCommand.java @@ -35,28 +35,23 @@ package com.google.refine.commands.history; import java.io.IOException; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; - -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.commands.Command; import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; public class GetOperationsCommand extends Command { - protected static class SimpleHistoryEntry implements Jsonizable { + protected static class SimpleHistoryEntry { protected HistoryEntry entry; public SimpleHistoryEntry(HistoryEntry e) { @@ -73,22 +68,9 @@ public class GetOperationsCommand extends Command { public AbstractOperation getOperation() { return entry.operation; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("description"); writer.value(entry.description); - if (entry.operation != null) { - writer.key("operation"); - entry.operation.write(writer, options); - } - writer.endObject(); - } - } - protected static class HistoryEntries implements Jsonizable { + protected static class HistoryEntries { @JsonProperty("entries") List entries; @@ -97,19 +79,6 @@ public class GetOperationsCommand extends Command { .map(e -> new SimpleHistoryEntry(e)) .collect(Collectors.toList()); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("entries"); writer.array(); - - for (SimpleHistoryEntry entry : entries) { - entry.write(writer, options); - } - writer.endArray(); - writer.endObject(); - } } @Override diff --git a/main/src/com/google/refine/commands/importing/GetImportingJobStatusCommand.java b/main/src/com/google/refine/commands/importing/GetImportingJobStatusCommand.java index 7c982c35a..4a06556b1 100644 --- a/main/src/com/google/refine/commands/importing/GetImportingJobStatusCommand.java +++ b/main/src/com/google/refine/commands/importing/GetImportingJobStatusCommand.java @@ -35,20 +35,38 @@ package com.google.refine.commands.importing; import java.io.IOException; import java.io.Writer; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONException; -import org.json.JSONWriter; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.commands.Command; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; +import com.google.refine.util.ParsingUtilities; public class GetImportingJobStatusCommand extends Command { + protected static class JobStatusResponse { + @JsonProperty("code") + protected String code; + @JsonProperty("message") + @JsonInclude(Include.NON_NULL) + protected String message; + @JsonProperty("job") + @JsonInclude(Include.NON_NULL) + protected ImportingJob job; + + protected JobStatusResponse(String code, String message, ImportingJob job) { + this.code = code; + this.message = message; + this.job = job; + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -57,22 +75,10 @@ public class GetImportingJobStatusCommand extends Command { ImportingJob job = ImportingManager.getJob(jobID); Writer w = response.getWriter(); - JSONWriter writer = new JSONWriter(w); - try { - writer.object(); - if (job == null) { - writer.key("code"); writer.value("error"); - writer.key("message"); writer.value("No such import job"); - } else { - writer.key("code"); writer.value("ok"); - writer.key("job"); job.write(writer, new Properties()); - } - writer.endObject(); - } catch (JSONException e) { - throw new ServletException(e); - } finally { - w.flush(); - w.close(); + if (job == null) { + ParsingUtilities.defaultWriter.writeValue(w, new JobStatusResponse("error", "No such import job", null)); + } else { + ParsingUtilities.defaultWriter.writeValue(w, new JobStatusResponse("ok", null, job)); } } } diff --git a/main/src/com/google/refine/commands/project/CreateProjectCommand.java b/main/src/com/google/refine/commands/project/CreateProjectCommand.java index ece7ef28f..0d5020fe1 100644 --- a/main/src/com/google/refine/commands/project/CreateProjectCommand.java +++ b/main/src/com/google/refine/commands/project/CreateProjectCommand.java @@ -52,8 +52,8 @@ import com.google.refine.commands.Command; import com.google.refine.commands.HttpUtilities; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; -import com.google.refine.importing.ImportingUtilities; import com.google.refine.importing.ImportingManager.Format; +import com.google.refine.importing.ImportingUtilities; import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities; diff --git a/main/src/com/google/refine/commands/project/ExportRowsCommand.java b/main/src/com/google/refine/commands/project/ExportRowsCommand.java index 3270c671c..44c031da4 100644 --- a/main/src/com/google/refine/commands/project/ExportRowsCommand.java +++ b/main/src/com/google/refine/commands/project/ExportRowsCommand.java @@ -57,7 +57,6 @@ import com.google.refine.exporters.ExporterRegistry; import com.google.refine.exporters.StreamExporter; import com.google.refine.exporters.WriterExporter; import com.google.refine.exporters.sql.SqlExporterException; - import com.google.refine.model.Project; public class ExportRowsCommand extends Command { diff --git a/main/src/com/google/refine/commands/project/GetMetadataCommand.java b/main/src/com/google/refine/commands/project/GetMetadataCommand.java index 9a7b21de1..a448505e3 100644 --- a/main/src/com/google/refine/commands/project/GetMetadataCommand.java +++ b/main/src/com/google/refine/commands/project/GetMetadataCommand.java @@ -38,7 +38,7 @@ public class GetMetadataCommand extends Command { } IMetadata metadata = MetadataFactory.buildDataPackageMetadata(project); - respondJSONObject(response, metadata.getJSON()); + respondJSON(response, metadata); } catch (JSONException e) { respondException(response, e); } catch (ValidationException e) { diff --git a/main/src/com/google/refine/commands/project/GetModelsCommand.java b/main/src/com/google/refine/commands/project/GetModelsCommand.java index ea433fa9c..876f5fa76 100644 --- a/main/src/com/google/refine/commands/project/GetModelsCommand.java +++ b/main/src/com/google/refine/commands/project/GetModelsCommand.java @@ -34,26 +34,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.commands.project; import java.io.IOException; -import java.util.Properties; +import java.util.HashMap; +import java.util.Map; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONException; -import org.json.JSONWriter; + +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.commands.Command; -import com.google.refine.commands.HttpUtilities; import com.google.refine.commands.HttpHeadersSupport; import com.google.refine.commands.HttpHeadersSupport.HttpHeaderInfo; - +import com.google.refine.commands.HttpUtilities; import com.google.refine.expr.MetaParser; import com.google.refine.expr.MetaParser.LanguageInfo; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; +import com.google.refine.model.ColumnModel; import com.google.refine.model.OverlayModel; import com.google.refine.model.Project; +import com.google.refine.model.RecordModel; public class GetModelsCommand extends Command { @Override @@ -67,6 +70,32 @@ public class GetModelsCommand extends Command { internalRespond(request, response); } + protected static class ModelsResponse { + @JsonProperty("columnModel") + protected ColumnModel columnModel; + @JsonProperty("recordModel") + protected RecordModel recordModel; + @JsonProperty("overlayModels") + protected Map overlayModels; + @JsonProperty("scripting") + protected Map scripting; + @JsonProperty("httpHeaders") + protected Map httpHeaders; + + protected ModelsResponse( + ColumnModel columns, + RecordModel records, + Map overlays, + Map languageInfos, + Map headers) { + columnModel = columns; + recordModel = records; + overlayModels = overlays; + scripting = languageInfos; + httpHeaders = headers; + } + } + protected void internalRespond(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -86,53 +115,26 @@ public class GetModelsCommand extends Command { } try { - response.setCharacterEncoding("UTF-8"); - response.setHeader("Content-Type", "application/json"); response.setHeader("Cache-Control", "no-cache"); - - Properties options = new Properties(); - JSONWriter writer = new JSONWriter(response.getWriter()); - - writer.object(); - writer.key("columnModel"); project.columnModel.write(writer, options); - writer.key("recordModel"); project.recordModel.write(writer, options); - - writer.key("overlayModels"); writer.object(); - for (String modelName : project.overlayModels.keySet()) { - OverlayModel overlayModel = project.overlayModels.get(modelName); - if (overlayModel != null) { - writer.key(modelName); - - project.overlayModels.get(modelName).write(writer, options); - } - } - writer.endObject(); - - writer.key("scripting"); writer.object(); + + Map prefixesMap = new HashMap<>(); for (String languagePrefix : MetaParser.getLanguagePrefixes()) { LanguageInfo info = MetaParser.getLanguageInfo(languagePrefix); - - writer.key(languagePrefix); - writer.object(); - writer.key("name"); writer.value(info.name); - writer.key("defaultExpression"); writer.value(info.defaultExpression); - writer.endObject(); + prefixesMap.put(languagePrefix, info); } - writer.endObject(); - - writer.key("httpHeaders"); - writer.object(); + + Map headersMap = new HashMap<>(); for (String headerLabel : HttpHeadersSupport.getHttpHeaderLabels()) { HttpHeaderInfo info = HttpHeadersSupport.getHttpHeaderInfo(headerLabel); - writer.key(headerLabel); - writer.object(); - writer.key("header"); writer.value(info.header); - writer.key("defaultValue"); writer.value(info.defaultValue); - writer.endObject(); + headersMap.put(headerLabel, info); } - writer.endObject(); - - writer.endObject(); + + respondJSON(response, new ModelsResponse( + project.columnModel, + project.recordModel, + project.overlayModels, + prefixesMap, + headersMap)); } catch (JSONException e) { HttpUtilities.respondException(response, e); } diff --git a/main/src/com/google/refine/commands/recon/ReconClearOneCellCommand.java b/main/src/com/google/refine/commands/recon/ReconClearOneCellCommand.java index e028d90b2..39682064e 100644 --- a/main/src/com/google/refine/commands/recon/ReconClearOneCellCommand.java +++ b/main/src/com/google/refine/commands/recon/ReconClearOneCellCommand.java @@ -42,6 +42,8 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONWriter; +import com.fasterxml.jackson.annotation.JsonProperty; + import com.google.refine.commands.Command; import com.google.refine.expr.ExpressionUtils; import com.google.refine.history.Change; @@ -57,6 +59,23 @@ import com.google.refine.process.QuickHistoryEntryProcess; import com.google.refine.util.Pool; public class ReconClearOneCellCommand extends Command { + protected static class CellResponse { + @JsonProperty("code") + protected String code = "ok"; + @JsonProperty("historyEntry") + protected HistoryEntry entry; + @JsonProperty("cell") + Cell cell; + @JsonProperty("pool") + Pool pool; + + protected CellResponse(HistoryEntry historyEntry, Cell newCell, Pool newPool) { + entry = historyEntry; + cell = newCell; + pool = newPool; + } + } + @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { @@ -80,18 +99,13 @@ public class ReconClearOneCellCommand extends Command { * If the process is done, write back the cell's data so that the * client side can update its UI right away. */ - JSONWriter writer = new JSONWriter(response.getWriter()); - Pool pool = new Pool(); - Properties options = new Properties(); - options.put("pool", pool); + + if(process.newCell != null && process.newCell.recon != null) { + pool.pool(process.newCell.recon); + } - writer.object(); - writer.key("code"); writer.value("ok"); - writer.key("historyEntry"); historyEntry.write(writer, options); - writer.key("cell"); process.newCell.write(writer, options); - writer.key("pool"); pool.write(writer, options); - writer.endObject(); + respondJSON(response, new CellResponse(historyEntry, process.newCell, pool)); } else { respond(response, "{ \"code\" : \"pending\" }"); } diff --git a/main/src/com/google/refine/commands/recon/ReconJudgeOneCellCommand.java b/main/src/com/google/refine/commands/recon/ReconJudgeOneCellCommand.java index 7297fdeea..aceaf4e57 100644 --- a/main/src/com/google/refine/commands/recon/ReconJudgeOneCellCommand.java +++ b/main/src/com/google/refine/commands/recon/ReconJudgeOneCellCommand.java @@ -103,18 +103,13 @@ public class ReconJudgeOneCellCommand extends Command { * If the process is done, write back the cell's data so that the * client side can update its UI right away. */ - JSONWriter writer = new JSONWriter(response.getWriter()); Pool pool = new Pool(); - Properties options = new Properties(); - options.put("pool", pool); + if (process.newCell != null && process.newCell.recon != null) { + pool.pool(process.newCell.recon); + } - writer.object(); - writer.key("code"); writer.value("ok"); - writer.key("historyEntry"); historyEntry.write(writer, options); - writer.key("cell"); process.newCell.write(writer, options); - writer.key("pool"); pool.write(writer, options); - writer.endObject(); + respondJSON(response, new ReconClearOneCellCommand.CellResponse(historyEntry, process.newCell, pool)); } else { respond(response, "{ \"code\" : \"pending\" }"); } diff --git a/main/src/com/google/refine/commands/row/GetRowsCommand.java b/main/src/com/google/refine/commands/row/GetRowsCommand.java index 60d3bf366..9e11f9be7 100644 --- a/main/src/com/google/refine/commands/row/GetRowsCommand.java +++ b/main/src/com/google/refine/commands/row/GetRowsCommand.java @@ -37,7 +37,6 @@ import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; @@ -45,14 +44,12 @@ import javax.servlet.http.HttpServletResponse; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonUnwrapped; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine.Mode; import com.google.refine.browsing.FilteredRecords; @@ -62,6 +59,7 @@ import com.google.refine.browsing.RowVisitor; import com.google.refine.commands.Command; import com.google.refine.importing.ImportingJob; import com.google.refine.importing.ImportingManager; +import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Record; import com.google.refine.model.Row; @@ -73,12 +71,12 @@ import com.google.refine.util.Pool; public class GetRowsCommand extends Command { - protected static class WrappedRow implements Jsonizable { + protected static class WrappedRow { @JsonUnwrapped protected final Row row; - @JsonProperty("rowIndex") + @JsonProperty("i") protected final int rowIndex; - @JsonProperty("recordIndex") + @JsonProperty("j") @JsonInclude(Include.NON_NULL) protected final Integer recordIndex; @@ -87,23 +85,9 @@ public class GetRowsCommand extends Command { this.rowIndex = rowIndex; this.recordIndex = recordIndex; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - options.put("rowIndex", rowIndex); - if(recordIndex != null) { - options.put("recordIndex", recordIndex); - } - row.write(writer, options); - if(recordIndex != null) { - options.remove("recordIndex"); - } - } - } - protected static class JsonResult implements Jsonizable { + protected static class JsonResult { @JsonProperty("mode") protected final Mode mode; @JsonProperty("rows") @@ -129,24 +113,6 @@ public class GetRowsCommand extends Command { this.limit = limit; this.pool = pool; } - - @Override - public void write(JSONWriter jsonWriter, Properties options) - throws JSONException { - jsonWriter.object(); - jsonWriter.key("mode"); jsonWriter.value(mode == Mode.RowBased ? "row-based" : "record-based"); - jsonWriter.key("rows"); jsonWriter.array(); - for(WrappedRow row : rows) { - row.write(jsonWriter, options); - } - jsonWriter.endArray(); - jsonWriter.key("filtered"); jsonWriter.value(filtered); - jsonWriter.key("total"); jsonWriter.value(totalCount); - jsonWriter.key("start"); jsonWriter.value(start); - jsonWriter.key("limit"); jsonWriter.value(limit); - jsonWriter.key("pool"); pool.write(jsonWriter, options); - jsonWriter.endObject(); - } } @Override @@ -186,10 +152,10 @@ public class GetRowsCommand extends Command { int limit = Math.min(project.rows.size() - start, Math.max(0, getIntegerParameter(request, "limit", 20))); Pool pool = new Pool(); - Properties options = new Properties(); + /* Properties options = new Properties(); options.put("project", project); options.put("reconCandidateOmitTypes", true); - options.put("pool", pool); + options.put("pool", pool); */ response.setCharacterEncoding("UTF-8"); response.setHeader("Content-Type", callback == null ? "application/json" : "text/javascript"); @@ -200,8 +166,6 @@ public class GetRowsCommand extends Command { writer.write("("); } - JSONWriter jsonWriter = new JSONWriter(writer); - RowWritingVisitor rwv = new RowWritingVisitor(start, limit); SortingConfig sortingConfig = null; @@ -243,12 +207,21 @@ public class GetRowsCommand extends Command { filteredRecords.accept(project, visitor); } + // Pool all the recons occuring in the rows seen + for(WrappedRow wr : rwv.results) { + for(Cell c : wr.row.cells) { + if(c != null && c.recon != null) { + pool.pool(c.recon); + } + } + } JsonResult result = new JsonResult(engine.getMode(), rwv.results, rwv.total, engine.getMode() == Mode.RowBased ? project.rows.size() : project.recordModel.getRecordCount(), start, limit, pool); - result.write(jsonWriter, options); + + ParsingUtilities.defaultWriter.writeValue(writer, result); if (callback != null) { writer.write(")"); } diff --git a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java index e1f2cdf72..4968dffdd 100644 --- a/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java +++ b/main/src/com/google/refine/commands/workspace/GetAllProjectMetadataCommand.java @@ -35,29 +35,24 @@ package com.google.refine.commands.workspace; import java.io.IOException; import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.json.JSONArray; import org.json.JSONException; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonRawValue; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.commands.Command; import com.google.refine.model.metadata.ProjectMetadata; public class GetAllProjectMetadataCommand extends Command { - public static class AllProjectMetadata implements Jsonizable { + public static class AllProjectMetadata { @JsonProperty("projects") protected Map projects; @JsonProperty("customMetadataColumns") @@ -69,30 +64,6 @@ public class GetAllProjectMetadataCommand extends Command { projects = map; customMetadataColumns = json; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - - writer.key("projects"); - writer.object(); - for (Entry e : projects.entrySet()) { - ProjectMetadata pm = e.getValue(); - if (pm != null) { - writer.key(e.getKey().toString()); - pm.write(writer, options); - } - } - writer.endObject(); - - if (customMetadataColumns != null) { - writer.key("customMetadataColumns"); - writer.value(new JSONArray(customMetadataColumns)); - } - writer.endObject(); - } } @Override diff --git a/main/src/com/google/refine/commands/workspace/GetAllProjectTagsCommand.java b/main/src/com/google/refine/commands/workspace/GetAllProjectTagsCommand.java index 80fe2a3d1..49330e8bf 100644 --- a/main/src/com/google/refine/commands/workspace/GetAllProjectTagsCommand.java +++ b/main/src/com/google/refine/commands/workspace/GetAllProjectTagsCommand.java @@ -27,9 +27,7 @@ package com.google.refine.commands.workspace; import java.io.IOException; import java.util.Collections; -import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import javax.servlet.ServletException; @@ -37,17 +35,15 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.json.JSONException; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.commands.Command; public class GetAllProjectTagsCommand extends Command { - public static class AllProjectsTags implements Jsonizable { + public static class AllProjectsTags { @JsonProperty("tags") protected Set tags; @@ -55,22 +51,6 @@ public class GetAllProjectTagsCommand extends Command { protected AllProjectsTags(Set tags) { this.tags = tags; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("tags"); - writer.array(); - if (tags != null) { - for (String tag : tags) { - writer.value(tag); - } - } - writer.endArray(); - writer.endObject(); - } - } @Override diff --git a/main/src/com/google/refine/expr/EvalError.java b/main/src/com/google/refine/expr/EvalError.java index 34682cdfc..c87744c3e 100644 --- a/main/src/com/google/refine/expr/EvalError.java +++ b/main/src/com/google/refine/expr/EvalError.java @@ -34,14 +34,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.expr; import java.io.Serializable; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; /** * An error that occurs during the evaluation of an Evaluable. Errors are values, too @@ -49,7 +44,7 @@ import com.google.refine.Jsonizable; * thrown because an error might occupy just one element in an array and doesn't need * to make the whole array erroneous. */ -public class EvalError implements Serializable, Jsonizable { +public class EvalError implements Serializable { private static final long serialVersionUID = -102681220092874080L; @JsonProperty("message") @@ -69,16 +64,6 @@ public class EvalError implements Serializable, Jsonizable { return this.message; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("type"); writer.value("error"); - writer.key("message"); writer.value(message); - writer.endObject(); - } - @JsonProperty("type") public String getType() { return "error"; diff --git a/main/src/com/google/refine/expr/MetaParser.java b/main/src/com/google/refine/expr/MetaParser.java index a9d8d8ae5..274b8e0f8 100644 --- a/main/src/com/google/refine/expr/MetaParser.java +++ b/main/src/com/google/refine/expr/MetaParser.java @@ -39,11 +39,11 @@ import java.util.Map; import java.util.Properties; import java.util.Set; +import com.google.refine.grel.Parser; + import clojure.lang.IFn; import clojure.lang.RT; -import com.google.refine.grel.Parser; - abstract public class MetaParser { static public class LanguageInfo { diff --git a/main/src/com/google/refine/grel/Control.java b/main/src/com/google/refine/grel/Control.java index a4e475da1..392017e23 100644 --- a/main/src/com/google/refine/grel/Control.java +++ b/main/src/com/google/refine/grel/Control.java @@ -35,14 +35,10 @@ package com.google.refine.grel; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.expr.Evaluable; /** @@ -50,7 +46,7 @@ import com.google.refine.expr.Evaluable; * decide which part of the code to execute and can affect the environment bindings. * Functions, on the other hand, can't do either. */ -public interface Control extends Jsonizable { +public interface Control { public Object call(Properties bindings, Evaluable[] args); public String checkArguments(Evaluable[] args); @@ -66,17 +62,4 @@ public interface Control extends Jsonizable { @JsonProperty("returns") public String getReturns(); - - @Override - default public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value(getDescription()); - if (!getParams().isEmpty()) { - writer.key("params"); writer.value(getParams()); - } - writer.key("returns"); writer.value(getReturns()); - writer.endObject(); - } } diff --git a/main/src/com/google/refine/grel/ControlFunctionRegistry.java b/main/src/com/google/refine/grel/ControlFunctionRegistry.java index 8745832b9..1ef16e95c 100644 --- a/main/src/com/google/refine/grel/ControlFunctionRegistry.java +++ b/main/src/com/google/refine/grel/ControlFunctionRegistry.java @@ -108,19 +108,19 @@ import com.google.refine.expr.functions.strings.Contains; import com.google.refine.expr.functions.strings.Diff; import com.google.refine.expr.functions.strings.EndsWith; import com.google.refine.expr.functions.strings.Escape; +import com.google.refine.expr.functions.strings.Find; import com.google.refine.expr.functions.strings.Fingerprint; import com.google.refine.expr.functions.strings.IndexOf; import com.google.refine.expr.functions.strings.LastIndexOf; import com.google.refine.expr.functions.strings.MD5; import com.google.refine.expr.functions.strings.Match; -import com.google.refine.expr.functions.strings.Find; import com.google.refine.expr.functions.strings.NGram; import com.google.refine.expr.functions.strings.NGramFingerprint; import com.google.refine.expr.functions.strings.ParseJson; import com.google.refine.expr.functions.strings.Partition; import com.google.refine.expr.functions.strings.Phonetic; -import com.google.refine.expr.functions.strings.Range; import com.google.refine.expr.functions.strings.RPartition; +import com.google.refine.expr.functions.strings.Range; import com.google.refine.expr.functions.strings.Reinterpret; import com.google.refine.expr.functions.strings.Replace; import com.google.refine.expr.functions.strings.ReplaceChars; @@ -144,8 +144,8 @@ import com.google.refine.grel.controls.ForNonBlank; import com.google.refine.grel.controls.ForRange; import com.google.refine.grel.controls.If; import com.google.refine.grel.controls.IsBlank; -import com.google.refine.grel.controls.IsError; import com.google.refine.grel.controls.IsEmptyString; +import com.google.refine.grel.controls.IsError; import com.google.refine.grel.controls.IsNonBlank; import com.google.refine.grel.controls.IsNotNull; import com.google.refine.grel.controls.IsNull; diff --git a/main/src/com/google/refine/grel/Function.java b/main/src/com/google/refine/grel/Function.java index c3c346855..fb1d49482 100644 --- a/main/src/com/google/refine/grel/Function.java +++ b/main/src/com/google/refine/grel/Function.java @@ -35,18 +35,15 @@ package com.google.refine.grel; import java.util.Properties; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; /** * Interface for functions. When a function is called, its arguments have already * been evaluated down into non-error values. */ -public interface Function extends Jsonizable { +public interface Function { public Object call(Properties bindings, Object[] args); @JsonProperty("description") @@ -60,15 +57,4 @@ public interface Function extends Jsonizable { @JsonProperty("returns") public String getReturns(); - - @Override - default public void write(JSONWriter writer, Properties options) { - writer.object(); - writer.key("description"); writer.value(getDescription()); - if (!getParams().isEmpty()) { - writer.key("params"); writer.value(getParams()); - } - writer.key("returns"); writer.value(getReturns()); - writer.endObject(); - } } diff --git a/main/src/com/google/refine/history/Change.java b/main/src/com/google/refine/history/Change.java index d7812a1d6..cb3a9f4cd 100644 --- a/main/src/com/google/refine/history/Change.java +++ b/main/src/com/google/refine/history/Change.java @@ -50,5 +50,6 @@ public interface Change { public void apply(Project project); public void revert(Project project); + public void save(Writer writer, Properties options) throws IOException; } diff --git a/main/src/com/google/refine/history/History.java b/main/src/com/google/refine/history/History.java index f41ca0863..e667e3503 100644 --- a/main/src/com/google/refine/history/History.java +++ b/main/src/com/google/refine/history/History.java @@ -46,12 +46,8 @@ import java.util.LinkedList; import java.util.List; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.RefineServlet; import com.google.refine.model.Project; @@ -64,7 +60,7 @@ import com.google.refine.util.Pool; * the history entries are much smaller and can be kept in memory, while the change objects * are only loaded into memory on demand. */ -public class History implements Jsonizable { +public class History { static public Change readOneChange(InputStream in, Pool pool) throws Exception { LineNumberReader reader = new LineNumberReader(new InputStreamReader(in, "UTF-8")); try { @@ -263,27 +259,6 @@ public class History implements Jsonizable { } } - @Override - synchronized public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - - writer.key("past"); writer.array(); - for (HistoryEntry entry : _pastEntries) { - entry.write(writer, options); - } - writer.endArray(); - - writer.key("future"); writer.array(); - for (HistoryEntry entry : _futureEntries) { - entry.write(writer, options); - } - writer.endArray(); - - writer.endObject(); - } - /* * NOTE: this method is called from the autosave thread with the Project * lock already held, so no other synchronized method here can aquire that diff --git a/main/src/com/google/refine/history/HistoryEntry.java b/main/src/com/google/refine/history/HistoryEntry.java index 8c56fb885..f2c7f793d 100644 --- a/main/src/com/google/refine/history/HistoryEntry.java +++ b/main/src/com/google/refine/history/HistoryEntry.java @@ -34,13 +34,11 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.history; import java.io.Writer; -import java.time.ZoneId; import java.time.OffsetDateTime; +import java.time.ZoneId; import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -48,7 +46,6 @@ import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonView; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; @@ -60,7 +57,7 @@ import com.google.refine.util.ParsingUtilities; * This is the metadata of a Change. It's small, so we can load it in order to * obtain information about a change without actually loading the change. */ -public class HistoryEntry implements Jsonizable { +public class HistoryEntry { final static Logger logger = LoggerFactory.getLogger("HistoryEntry"); @JsonProperty("id") final public long id; @@ -117,20 +114,6 @@ public class HistoryEntry implements Jsonizable { } } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(id); - writer.key("description"); writer.value(description); - writer.key("time"); writer.value(ParsingUtilities.dateToString(time)); - if ("save".equals(options.getProperty("mode")) && operation != null) { - writer.key(OPERATION); operation.write(writer, options); - } - writer.endObject(); - } - public void save(Writer writer, Properties options){ _manager.save(this, writer, options); } diff --git a/main/src/com/google/refine/history/HistoryProcess.java b/main/src/com/google/refine/history/HistoryProcess.java index 19c8769cd..80a5ccbba 100644 --- a/main/src/com/google/refine/history/HistoryProcess.java +++ b/main/src/com/google/refine/history/HistoryProcess.java @@ -33,11 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.history; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -98,17 +93,6 @@ public class HistoryProcess extends Process { public void startPerforming(ProcessManager manager) { throw new RuntimeException(WARN); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("description"); writer.value(_description); - writer.key("immediate"); writer.value(true); - writer.key("status"); writer.value(getStatus()); - writer.endObject(); - } @JsonProperty("status") public String getStatus() { diff --git a/main/src/com/google/refine/importing/DefaultImportingController.java b/main/src/com/google/refine/importing/DefaultImportingController.java index c226097fb..b7b920dae 100644 --- a/main/src/com/google/refine/importing/DefaultImportingController.java +++ b/main/src/com/google/refine/importing/DefaultImportingController.java @@ -50,6 +50,8 @@ import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; +import com.fasterxml.jackson.annotation.JsonProperty; + import com.google.refine.RefineServlet; import com.google.refine.commands.HttpUtilities; import com.google.refine.importing.ImportingManager.Format; @@ -272,6 +274,19 @@ public class DefaultImportingController implements ImportingController { } } + protected static class JobResponse { + @JsonProperty("code") + protected String code; + @JsonProperty("job") + protected ImportingJob job; + + protected JobResponse(String code, ImportingJob job) { + this.code = code; + this.job = job; + } + + } + /** * return the job to the front end. * @param request @@ -284,18 +299,9 @@ public class DefaultImportingController implements ImportingController { throws ServletException, IOException { Writer w = response.getWriter(); - JSONWriter writer = new JSONWriter(w); - try { - writer.object(); - writer.key("code"); writer.value("ok"); - writer.key("job"); job.write(writer, new Properties()); - writer.endObject(); - } catch (JSONException e) { - throw new ServletException(e); - } finally { - w.flush(); - w.close(); - } + ParsingUtilities.defaultWriter.writeValue(w, job); + w.flush(); + w.close(); } static public void writeErrors(JSONWriter writer, List exceptions) throws JSONException { diff --git a/main/src/com/google/refine/importing/ImportingJob.java b/main/src/com/google/refine/importing/ImportingJob.java index 17d644d41..4f52f6c3b 100644 --- a/main/src/com/google/refine/importing/ImportingJob.java +++ b/main/src/com/google/refine/importing/ImportingJob.java @@ -37,22 +37,18 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import org.apache.commons.io.FileUtils; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.model.Project; import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.util.JSONUtilities; -public class ImportingJob implements Jsonizable { +public class ImportingJob { final public long id; final public File dir; // Temporary directory where the data about this job is stored @@ -205,15 +201,4 @@ public class ImportingJob implements Jsonizable { dir2.mkdirs(); return dir2; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - synchronized(lock) { - writer.object(); - writer.key("config"); writer.value(config); - writer.endObject(); - } - } } diff --git a/main/src/com/google/refine/io/FileHistoryEntryManager.java b/main/src/com/google/refine/io/FileHistoryEntryManager.java index 0094fca5d..9d8ce5f16 100644 --- a/main/src/com/google/refine/io/FileHistoryEntryManager.java +++ b/main/src/com/google/refine/io/FileHistoryEntryManager.java @@ -35,6 +35,7 @@ package com.google.refine.io; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStreamReader; import java.io.Writer; import java.util.Properties; @@ -42,13 +43,11 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import java.util.zip.ZipOutputStream; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.ProjectManager; import com.google.refine.history.History; import com.google.refine.history.HistoryEntry; import com.google.refine.history.HistoryEntryManager; +import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; @@ -64,10 +63,9 @@ public class FileHistoryEntryManager implements HistoryEntryManager{ @Override public void save(HistoryEntry historyEntry, Writer writer, Properties options) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - historyEntry.write(jsonWriter, options); - } catch (JSONException e) { + ParsingUtilities.defaultWriter.writeValue(writer, historyEntry); + } catch (IOException e) { e.printStackTrace(); } } @@ -116,6 +114,8 @@ public class FileHistoryEntryManager implements HistoryEntryManager{ out.putNextEntry(new ZipEntry("change.txt")); try { History.writeOneChange(out, historyEntry.getChange(), pool); + } catch(Exception e) { + e.printStackTrace(); } finally { out.closeEntry(); } diff --git a/main/src/com/google/refine/io/FileProjectManager.java b/main/src/com/google/refine/io/FileProjectManager.java index ac8f75829..2baa454fc 100644 --- a/main/src/com/google/refine/io/FileProjectManager.java +++ b/main/src/com/google/refine/io/FileProjectManager.java @@ -43,7 +43,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.HashMap; import java.util.Map.Entry; -import java.util.Properties; import java.util.Set; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; @@ -55,14 +54,12 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONTokener; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.ProjectManager; import com.google.refine.history.HistoryEntryManager; import com.google.refine.model.Project; @@ -71,9 +68,10 @@ import com.google.refine.model.metadata.IMetadata; import com.google.refine.model.metadata.MetadataFormat; import com.google.refine.model.metadata.ProjectMetadata; import com.google.refine.preference.TopList; +import com.google.refine.util.ParsingUtilities; -public class FileProjectManager extends ProjectManager implements Jsonizable { +public class FileProjectManager extends ProjectManager { final static protected String PROJECT_DIR_SUFFIX = ".project"; protected File _workspaceDir; @@ -251,7 +249,9 @@ public class FileProjectManager extends ProjectManager implements Jsonizable { ProjectMetadataUtilities.save(metadata, projectDir); } else if (metadata.getFormatName() == MetadataFormat.DATAPACKAGE_METADATA) { DataPackageMetadata dp = (DataPackageMetadata)metadata; - dp.writeToFile(new File(projectDir, DataPackageMetadata.DEFAULT_FILE_NAME)); + FileWriter writer = new FileWriter(new File(projectDir, DataPackageMetadata.DEFAULT_FILE_NAME)); + ParsingUtilities.defaultWriter.writeValue(writer, dp); + writer.close(); } logger.info("metadata saved in " + metadata.getFormatName()); @@ -326,8 +326,7 @@ public class FileProjectManager extends ProjectManager implements Jsonizable { FileWriter writer = new FileWriter(file); boolean saveWasNeeded = saveNeeded(); try { - JSONWriter jsonWriter = new JSONWriter(writer); - write(jsonWriter, new Properties()); + ParsingUtilities.defaultWriter.writeValue(writer, this); saveProjectMetadata(); } finally { writer.close(); @@ -486,25 +485,6 @@ public class FileProjectManager extends ProjectManager implements Jsonizable { gos.close(); } } - - @Override - public void write(JSONWriter jsonWriter, Properties options) - throws JSONException { - jsonWriter.object(); - jsonWriter.key("projectIDs"); - jsonWriter.array(); - for (Long id : _projectsMetadata.keySet()) { - ProjectMetadata metadata = _projectsMetadata.get(id); - if (metadata != null) { - jsonWriter.value(id); - } - } - jsonWriter.endArray(); - - jsonWriter.key("preferences"); - _preferenceStore.write(jsonWriter, new Properties()); - jsonWriter.endObject(); - } @JsonProperty("projectIDs") public Set getProjectIds() { diff --git a/main/src/com/google/refine/io/ProjectMetadataUtilities.java b/main/src/com/google/refine/io/ProjectMetadataUtilities.java index 6b5a77e94..e41fa500d 100644 --- a/main/src/com/google/refine/io/ProjectMetadataUtilities.java +++ b/main/src/com/google/refine/io/ProjectMetadataUtilities.java @@ -46,13 +46,13 @@ import java.util.List; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.json.JSONException; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.refine.model.Project; import com.google.refine.model.metadata.IMetadata; import com.google.refine.model.metadata.ProjectMetadata; +import com.google.refine.util.ParsingUtilities; public class ProjectMetadataUtilities { final static Logger logger = LoggerFactory.getLogger("project_metadata_utilities"); @@ -78,8 +78,7 @@ public class ProjectMetadataUtilities { protected static void saveToFile(IMetadata projectMeta, File metadataFile) throws JSONException, IOException { Writer writer = new OutputStreamWriter(new FileOutputStream(metadataFile)); try { - JSONWriter jsonWriter = new JSONWriter(writer); - projectMeta.write(jsonWriter, false); + ParsingUtilities.defaultWriter.writeValue(writer, projectMeta); } finally { writer.close(); } diff --git a/main/src/com/google/refine/model/AbstractOperation.java b/main/src/com/google/refine/model/AbstractOperation.java index f21c930d9..414bbe453 100644 --- a/main/src/com/google/refine/model/AbstractOperation.java +++ b/main/src/com/google/refine/model/AbstractOperation.java @@ -37,7 +37,6 @@ import java.util.Properties; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.history.HistoryEntry; import com.google.refine.operations.OperationRegistry; import com.google.refine.process.Process; @@ -47,7 +46,7 @@ import com.google.refine.process.QuickHistoryEntryProcess; * An abstract operation can be applied to different but similar * projects. */ -abstract public class AbstractOperation implements Jsonizable { +abstract public class AbstractOperation { public Process createProcess(Project project, Properties options) throws Exception { return new QuickHistoryEntryProcess(project, getBriefDescription(null)) { @Override diff --git a/main/src/com/google/refine/model/Cell.java b/main/src/com/google/refine/model/Cell.java index fcaa86b5e..33d71b922 100644 --- a/main/src/com/google/refine/model/Cell.java +++ b/main/src/com/google/refine/model/Cell.java @@ -33,6 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; +import java.io.IOException; import java.io.Serializable; import java.io.Writer; import java.time.Instant; @@ -41,9 +42,6 @@ import java.time.OffsetDateTime; import java.time.ZoneOffset; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -52,7 +50,6 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import com.google.refine.Jsonizable; import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; import com.google.refine.expr.HasFields; @@ -60,7 +57,7 @@ import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; import com.google.refine.util.StringUtils; -public class Cell implements HasFields, Jsonizable { +public class Cell implements HasFields { @JsonIgnore final public Serializable value; @JsonIgnore @@ -85,31 +82,6 @@ public class Cell implements HasFields, Jsonizable { public boolean fieldAlsoHasFields(String name) { return "recon".equals(name); } - - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - if (ExpressionUtils.isError(value)) { - writer.key("e"); - writer.value(((EvalError) value).message); - } else { - writer.key("v"); - writer.value(getValueAsString()); - String jsonType = getTypeString(); - if(jsonType != null) { - writer.key("t"); writer.value(jsonType); - } - } - - if (recon != null) { - writer.key("r"); - writer.value(Long.toString(recon.id)); - - Pool pool = (Pool) options.get("pool"); - pool.pool(recon); - } - writer.endObject(); - } @JsonProperty("e") @JsonInclude(Include.NON_NULL) @@ -171,15 +143,17 @@ public class Cell implements HasFields, Jsonizable { if (recon != null) { return Long.toString(recon.id); } - // TODO pool the recon?? return null; } public void save(Writer writer, Properties options) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - write(jsonWriter, options); - } catch (JSONException e) { + Pool pool = (Pool)options.get("pool"); + if(pool != null && recon != null) { + pool.pool(recon); + } + ParsingUtilities.saveWriter.writeValue(writer, this); + } catch (IOException e) { e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/Column.java b/main/src/com/google/refine/model/Column.java index e3cdf4538..171b7eda5 100644 --- a/main/src/com/google/refine/model/Column.java +++ b/main/src/com/google/refine/model/Column.java @@ -33,23 +33,20 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; +import java.io.IOException; import java.io.Writer; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; -import java.util.Properties; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.InterProjectModel; -import com.google.refine.Jsonizable; import com.google.refine.model.recon.ReconConfig; import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities; @@ -59,7 +56,7 @@ import io.frictionlessdata.tableschema.TypeInferrer; import io.frictionlessdata.tableschema.exceptions.ConstraintsException; import io.frictionlessdata.tableschema.exceptions.InvalidCastException; -public class Column implements Jsonizable { +public class Column { final private int _cellIndex; final private String _originalName; private String _name; @@ -118,31 +115,6 @@ public class Column implements Jsonizable { public ReconStats getReconStats() { return _reconStats; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("cellIndex"); writer.value(_cellIndex); - writer.key("originalName"); writer.value(_originalName); - writer.key("name"); writer.value(_name); - writer.key("type"); writer.value(type); - writer.key("format"); writer.value(format); - writer.key("title"); writer.value(title); - writer.key("description"); writer.value(description); - writer.key("constraints"); writer.value(new JSONObject(constraints).toString()); - if (_reconConfig != null) { - writer.key("reconConfig"); - _reconConfig.write(writer, options); - } - if (_reconStats != null) { - writer.key("reconStats"); - _reconStats.write(writer, options); - } - writer.endObject(); - } - /** * Clear all cached precomputed values. @@ -230,10 +202,9 @@ public class Column implements Jsonizable { } public void save(Writer writer) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - write(jsonWriter, new Properties()); - } catch (JSONException e) { + ParsingUtilities.defaultWriter.writeValue(writer, this); + } catch (IOException e) { e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/ColumnGroup.java b/main/src/com/google/refine/model/ColumnGroup.java index 1ba26d1ad..c8a261af2 100644 --- a/main/src/com/google/refine/model/ColumnGroup.java +++ b/main/src/com/google/refine/model/ColumnGroup.java @@ -33,25 +33,22 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; +import java.io.IOException; import java.io.Writer; import java.util.LinkedList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonView; -import com.google.refine.Jsonizable; import com.google.refine.util.JsonViews; import com.google.refine.util.ParsingUtilities; -public class ColumnGroup implements Jsonizable { +public class ColumnGroup { final public int startColumnIndex; final public int columnSpan; final public int keyColumnIndex; // could be -1 if there is no key cell @@ -66,26 +63,6 @@ public class ColumnGroup implements Jsonizable { internalInitialize(); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - - writer.key("startColumnIndex"); writer.value(startColumnIndex); - writer.key("columnSpan"); writer.value(columnSpan); - writer.key("keyColumnIndex"); writer.value(keyColumnIndex); - - if (!"save".equals(options.get("mode")) && (subgroups != null) && (subgroups.size() > 0)) { - writer.key("subgroups"); writer.array(); - for (ColumnGroup g : subgroups) { - g.write(writer, options); - } - writer.endArray(); - } - writer.endObject(); - } - @JsonProperty("startColumnIndex") public int getStartColumnIndex() { return startColumnIndex; @@ -114,10 +91,9 @@ public class ColumnGroup implements Jsonizable { } public void save(Writer writer) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - write(jsonWriter, new Properties()); - } catch (JSONException e) { + ParsingUtilities.defaultWriter.writeValue(writer, this); + } catch (IOException e) { e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/ColumnModel.java b/main/src/com/google/refine/model/ColumnModel.java index a4109c1b3..112ad97b3 100644 --- a/main/src/com/google/refine/model/ColumnModel.java +++ b/main/src/com/google/refine/model/ColumnModel.java @@ -45,17 +45,13 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; -public class ColumnModel implements Jsonizable { +public class ColumnModel { @JsonProperty("columns") final public List columns = new LinkedList(); @JsonProperty("columnGroups") @@ -179,34 +175,6 @@ public class ColumnModel implements Jsonizable { synchronized public List getColumnNames() { return _columnNames; } - - @Override - synchronized public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - - writer.key("columns"); - writer.array(); - for (Column column : columns) { - column.write(writer, options); - } - writer.endArray(); - - if (columns.size() > 0) { - writer.key("keyCellIndex"); writer.value(getKeyColumnIndex()); - writer.key("keyColumnName"); writer.value(columns.get(_keyColumnIndex).getName()); - } - - writer.key("columnGroups"); - writer.array(); - for (ColumnGroup g : _rootColumnGroups) { - g.write(writer, options); - } - writer.endArray(); - - writer.endObject(); - } @JsonProperty("keyCellIndex") @JsonInclude(Include.NON_NULL) diff --git a/main/src/com/google/refine/model/OverlayModel.java b/main/src/com/google/refine/model/OverlayModel.java index 1b1b184b9..7ca914173 100644 --- a/main/src/com/google/refine/model/OverlayModel.java +++ b/main/src/com/google/refine/model/OverlayModel.java @@ -33,9 +33,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; -import com.google.refine.Jsonizable; -public interface OverlayModel extends Jsonizable { +public interface OverlayModel { public void onBeforeSave(Project project); public void onAfterSave(Project project); diff --git a/main/src/com/google/refine/model/Project.java b/main/src/com/google/refine/model/Project.java index 4b4a511cf..113e591d9 100644 --- a/main/src/com/google/refine/model/Project.java +++ b/main/src/com/google/refine/model/Project.java @@ -48,9 +48,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -160,13 +158,7 @@ public class Project { writer.write(modelName); writer.write("="); - try { - JSONWriter jsonWriter = new JSONWriter(writer); - - overlayModels.get(modelName).write(jsonWriter, options); - } catch (JSONException e) { - e.printStackTrace(); - } + ParsingUtilities.saveWriter.writeValue(writer, overlayModels.get(modelName)); writer.write('\n'); } diff --git a/main/src/com/google/refine/model/Recon.java b/main/src/com/google/refine/model/Recon.java index a4b726708..f96125ed3 100644 --- a/main/src/com/google/refine/model/Recon.java +++ b/main/src/com/google/refine/model/Recon.java @@ -40,9 +40,6 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonFilter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; @@ -53,13 +50,12 @@ import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import com.google.refine.Jsonizable; import com.google.refine.expr.HasFields; import com.google.refine.util.JsonViews; import com.google.refine.util.Pool; @JsonFilter("reconCandidateFilter") -public class Recon implements HasFields, Jsonizable { +public class Recon implements HasFields { /** * Freebase schema URLs kept for compatibility with legacy reconciliation results @@ -366,56 +362,6 @@ public class Recon implements HasFields, Jsonizable { return null; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - boolean saveMode = "save".equals(options.getProperty("mode")); - - writer.object(); - writer.key("id"); writer.value(id); - if (saveMode) { - writer.key("judgmentHistoryEntry"); writer.value(judgmentHistoryEntry); - } - - writer.key("service"); writer.value(service); - writer.key("identifierSpace"); writer.value(identifierSpace); - writer.key("schemaSpace"); writer.value(schemaSpace); - - writer.key("j"); writer.value(judgmentToString()); - if (match != null) { - writer.key("m"); - match.write(writer, options); - } - if (match == null || saveMode) { - writer.key("c"); writer.array(); - if (candidates != null) { - for (ReconCandidate c : candidates) { - c.write(writer, options); - } - } - writer.endArray(); - } - - if (saveMode) { - writer.key("f"); - writer.array(); - for (Object o : features) { - writer.value(o); - } - writer.endArray(); - - writer.key("judgmentAction"); writer.value(judgmentAction); - writer.key("judgmentBatchSize"); writer.value(judgmentBatchSize); - - if (match != null) { - writer.key("matchRank"); writer.value(matchRank); - } - } - - writer.endObject(); - } - static public Recon loadStreaming(String s, Pool pool) throws Exception { JsonFactory jsonFactory = new JsonFactory(); JsonParser jp = jsonFactory.createJsonParser(s); diff --git a/main/src/com/google/refine/model/ReconCandidate.java b/main/src/com/google/refine/model/ReconCandidate.java index 7c3f4c9d0..6b2e86f3a 100644 --- a/main/src/com/google/refine/model/ReconCandidate.java +++ b/main/src/com/google/refine/model/ReconCandidate.java @@ -37,19 +37,14 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - -import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import com.google.refine.Jsonizable; import com.google.refine.expr.HasFields; -public class ReconCandidate implements HasFields, Jsonizable { +public class ReconCandidate implements HasFields { @JsonProperty("id") final public String id; @JsonProperty("name") @@ -84,26 +79,6 @@ public class ReconCandidate implements HasFields, Jsonizable { public boolean fieldAlsoHasFields(String name) { return false; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(id); - writer.key("name"); writer.value(name); - writer.key("score"); writer.value(score); - - /* if (!options.containsKey("reconCandidateOmitTypes")) */ { - writer.key("types"); writer.array(); - for (String typeID : types) { - writer.value(typeID); - } - writer.endArray(); - } - - writer.endObject(); - } static public ReconCandidate loadStreaming(String s) throws Exception { JsonFactory jsonFactory = new JsonFactory(); diff --git a/main/src/com/google/refine/model/ReconStats.java b/main/src/com/google/refine/model/ReconStats.java index 00f555e29..f9b887a19 100644 --- a/main/src/com/google/refine/model/ReconStats.java +++ b/main/src/com/google/refine/model/ReconStats.java @@ -33,20 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; +import java.io.IOException; import java.io.Writer; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.expr.ExpressionUtils; import com.google.refine.model.Recon.Judgment; +import com.google.refine.util.ParsingUtilities; -public class ReconStats implements Jsonizable { +public class ReconStats { static public ReconStats load(JSONObject obj) throws Exception { return new ReconStats( obj.getInt("nonBlanks"), @@ -67,17 +65,6 @@ public class ReconStats implements Jsonizable { this.newTopics = newTopics; this.matchedTopics = matchedTopics; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("nonBlanks"); writer.value(nonBlanks); - writer.key("newTopics"); writer.value(newTopics); - writer.key("matchedTopics"); writer.value(matchedTopics); - writer.endObject(); - } static public ReconStats create(Project project, int cellIndex) { int nonBlanks = 0; @@ -103,10 +90,9 @@ public class ReconStats implements Jsonizable { } public void save(Writer writer) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - write(jsonWriter, new Properties()); - } catch (JSONException e) { + ParsingUtilities.defaultWriter.writeValue(writer, this); + } catch (IOException e) { e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/ReconType.java b/main/src/com/google/refine/model/ReconType.java index 3f172bf28..ac023719a 100644 --- a/main/src/com/google/refine/model/ReconType.java +++ b/main/src/com/google/refine/model/ReconType.java @@ -33,22 +33,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; /** * This represents a type from the reconciliation * service. It is used when extending data to * store the (expected) types of new columns. */ -public class ReconType implements Jsonizable { +public class ReconType { @JsonProperty("id") public String id; @JsonProperty("name") @@ -59,16 +54,6 @@ public class ReconType implements Jsonizable { this.name = name; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(id); - writer.key("name"); writer.value(name); - writer.endObject(); - } - static public ReconType load(JSONObject obj) throws Exception { if (obj == null) { return null; diff --git a/main/src/com/google/refine/model/RecordModel.java b/main/src/com/google/refine/model/RecordModel.java index 2d1bf0569..fe9ccae13 100644 --- a/main/src/com/google/refine/model/RecordModel.java +++ b/main/src/com/google/refine/model/RecordModel.java @@ -38,20 +38,16 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; -import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.expr.ExpressionUtils; -public class RecordModel implements Jsonizable { +public class RecordModel { final static Logger logger = LoggerFactory.getLogger("RecordModel"); final static public class CellDependency { @@ -108,16 +104,6 @@ public class RecordModel implements Jsonizable { } return null; } - - @Override - synchronized public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("hasRecords"); - writer.value(hasRecords()); - writer.endObject(); - } @JsonProperty("hasRecords") public boolean hasRecords() { diff --git a/main/src/com/google/refine/model/Row.java b/main/src/com/google/refine/model/Row.java index 780f1fe92..bfa5f7db6 100644 --- a/main/src/com/google/refine/model/Row.java +++ b/main/src/com/google/refine/model/Row.java @@ -33,32 +33,28 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model; +import java.io.IOException; import java.io.Writer; import java.util.ArrayList; import java.util.List; -import java.util.Map.Entry; import java.util.Properties; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.core.JsonFactory; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; -import org.json.JSONException; -import org.json.JSONWriter; -import com.google.refine.Jsonizable; import com.google.refine.expr.CellTuple; import com.google.refine.expr.HasFields; -import com.google.refine.util.JsonViews; +import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; /** * Class representing a single Row which contains a list of {@link Cell}s. There may * be multiple rows in a {@link Record}. */ -public class Row implements HasFields, Jsonizable { +public class Row implements HasFields { public boolean flagged; public boolean starred; final public List cells; @@ -165,50 +161,6 @@ public class Row implements HasFields, Jsonizable { return new CellTuple(project, this); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key(FLAGGED); writer.value(flagged); - writer.key(STARRED); writer.value(starred); - - writer.key("cells"); writer.array(); - for (Cell cell : cells) { - if (cell != null) { - cell.write(writer, options); - } else { - writer.value(null); - } - } - writer.endArray(); - - if (!"save".equals(options.getProperty("mode"))) { - if (options.containsKey("rowIndex")) { - int rowIndex = (Integer) options.get("rowIndex"); - writer.key("i"); writer.value(rowIndex); - - if (options.containsKey("recordIndex")) { - int recordIndex = (Integer) options.get("recordIndex"); - - writer.key("j"); writer.value(recordIndex); - } - } - - if (options.containsKey("extra")) { - Properties extra = (Properties) options.get("extra"); - if (extra != null) { - for (Entry e : extra.entrySet()) { - writer.key((String) e.getKey()); - writer.value(e.getValue()); - } - } - } - } - - writer.endObject(); - } - @JsonProperty(FLAGGED) public boolean isFlagged() { return flagged; @@ -230,10 +182,21 @@ public class Row implements HasFields, Jsonizable { */ public void save(Writer writer, Properties options) { - JSONWriter jsonWriter = new JSONWriter(writer); + if (options.containsKey("rowIndex")) { + // See GetRowsCommand to serialize a row with indices + throw new IllegalArgumentException("Serializing with row indices is not supported anymore."); + } try { - write(jsonWriter, options); - } catch (JSONException e) { + ParsingUtilities.saveWriter.writeValue(writer, this); + Pool pool = (Pool)options.get("pool"); + if(pool != null) { + for(Cell c : cells) { + if (c != null && c.recon != null) { + pool.pool(c.recon); + } + } + } + } catch (IOException e) { e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/changes/ColumnChange.java b/main/src/com/google/refine/model/changes/ColumnChange.java index df2956865..55757e801 100644 --- a/main/src/com/google/refine/model/changes/ColumnChange.java +++ b/main/src/com/google/refine/model/changes/ColumnChange.java @@ -40,11 +40,9 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; - import com.google.refine.history.Change; import com.google.refine.model.ColumnGroup; +import com.google.refine.util.ParsingUtilities; abstract public class ColumnChange implements Change { @@ -52,13 +50,8 @@ abstract public class ColumnChange implements Change { List oldColumnGroups) throws IOException { writer.write("oldColumnGroupCount="); writer.write(Integer.toString(oldColumnGroups.size())); writer.write('\n'); - for (ColumnGroup cg : oldColumnGroups) { - JSONWriter jsonWriter = new JSONWriter(writer); - try { - cg.write(jsonWriter, options); - } catch (JSONException e) { - throw new IOException(e); - } + for (ColumnGroup cg : oldColumnGroups) { + ParsingUtilities.saveWriter.writeValue(writer, cg); writer.write('\n'); } } diff --git a/main/src/com/google/refine/model/changes/DataExtensionChange.java b/main/src/com/google/refine/model/changes/DataExtensionChange.java index a034c9ebc..31348540a 100644 --- a/main/src/com/google/refine/model/changes/DataExtensionChange.java +++ b/main/src/com/google/refine/model/changes/DataExtensionChange.java @@ -307,13 +307,8 @@ public class DataExtensionChange implements Change { } writer.write("columnTypeCount="); writer.write(Integer.toString(_columnTypes.size())); writer.write('\n'); for (ReconType type : _columnTypes) { - try { - if(type != null) { - JSONWriter jsonWriter = new JSONWriter(writer); - type.write(jsonWriter, options); - } - } catch (JSONException e) { - // ??? + if(type != null) { + ParsingUtilities.defaultWriter.writeValue(writer, type); } writer.write('\n'); } diff --git a/main/src/com/google/refine/model/changes/MassReconChange.java b/main/src/com/google/refine/model/changes/MassReconChange.java index 5e8eb2a13..0e4df55bb 100644 --- a/main/src/com/google/refine/model/changes/MassReconChange.java +++ b/main/src/com/google/refine/model/changes/MassReconChange.java @@ -50,6 +50,7 @@ import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Recon; import com.google.refine.model.Row; +import com.google.refine.util.ParsingUtilities; import com.google.refine.util.Pool; public class MassReconChange implements Change { @@ -110,12 +111,7 @@ public class MassReconChange implements Change { Pool pool = (Pool) options.get("pool"); pool.poolReconCandidates(recon); - JSONWriter jsonWriter = new JSONWriter(writer); - try { - recon.write(jsonWriter, options); - } catch (JSONException e) { - e.printStackTrace(); - } + ParsingUtilities.saveWriter.writeValue(writer, recon); writer.write("\n"); } } diff --git a/main/src/com/google/refine/model/metadata/AbstractMetadata.java b/main/src/com/google/refine/model/metadata/AbstractMetadata.java index 84b0f878e..43a5ac9b5 100644 --- a/main/src/com/google/refine/model/metadata/AbstractMetadata.java +++ b/main/src/com/google/refine/model/metadata/AbstractMetadata.java @@ -2,12 +2,9 @@ package com.google.refine.model.metadata; import java.io.File; import java.time.LocalDateTime; -import java.util.Properties; import org.apache.commons.beanutils.PropertyUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; public abstract class AbstractMetadata implements IMetadata { private MetadataFormat formatName = MetadataFormat.UNKNOWN; @@ -30,9 +27,6 @@ public abstract class AbstractMetadata implements IMetadata { @Override public abstract void loadFromFile(File metadataFile); - @Override - public abstract void writeToFile(File metadataFile); - @Override public boolean isDirty() { return written == null || _modified.isAfter(written); @@ -48,23 +42,6 @@ public abstract class AbstractMetadata implements IMetadata { _modified = LocalDateTime.now(); } - /** - * @param jsonWriter - * writer to save metadatea to - * @param onlyIfDirty - * true to not write unchanged metadata - * @throws JSONException - */ - @Override - public void write(JSONWriter jsonWriter, boolean onlyIfDirty) throws JSONException { - if (!onlyIfDirty || isDirty()) { - Properties options = new Properties(); - options.setProperty("mode", "save"); - - write(jsonWriter, options); - } - } - protected static boolean propertyExists(Object bean, String property) { return PropertyUtils.isReadable(bean, property) && PropertyUtils.isWriteable(bean, property); diff --git a/main/src/com/google/refine/model/metadata/DataPackageMetadata.java b/main/src/com/google/refine/model/metadata/DataPackageMetadata.java index 3ddac2f93..b314d6e74 100644 --- a/main/src/com/google/refine/model/metadata/DataPackageMetadata.java +++ b/main/src/com/google/refine/model/metadata/DataPackageMetadata.java @@ -3,21 +3,20 @@ package com.google.refine.model.metadata; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.StringWriter; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ExceptionUtils; import org.everit.json.schema.ValidationException; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonRawValue; +import com.fasterxml.jackson.annotation.JsonValue; + import io.frictionlessdata.datapackage.Package; import io.frictionlessdata.datapackage.Resource; import io.frictionlessdata.datapackage.exceptions.DataPackageException; @@ -30,6 +29,12 @@ public class DataPackageMetadata extends AbstractMetadata { private Package _pkg; + @JsonValue + @JsonRawValue + public String getJson() { + return _pkg.getJson().toString(); + } + public DataPackageMetadata() { setFormatName(MetadataFormat.DATAPACKAGE_METADATA); @@ -61,30 +66,6 @@ public class DataPackageMetadata extends AbstractMetadata { loadFromJSON(new JSONObject(jsonString)); } - /** - * Write the package to a json file. - */ - @Override - public void writeToFile(File metadataFile) { - try { - this._pkg.save(metadataFile.getAbsolutePath()); - } catch (IOException e) { - logger.error("IO exception when writing to file " + metadataFile.getAbsolutePath(), - ExceptionUtils.getStackTrace(e)); - } catch (DataPackageException e) { - logger.error("Data package exception when writing to file " + metadataFile.getAbsolutePath(), - ExceptionUtils.getStackTrace(e)); - } - } - - @Override - public void write(JSONWriter jsonWriter, Properties options) - throws JSONException { - StringWriter sw = new StringWriter(); - _pkg.getJson().write(sw); - jsonWriter = new JSONWriter(sw); - } - @Override public void loadFromStream(InputStream inputStream) { try { @@ -107,11 +88,6 @@ public class DataPackageMetadata extends AbstractMetadata { return listResources; } - - @Override - public JSONObject getJSON() { - return _pkg.getJson(); - } public Package getPackage() { return _pkg; diff --git a/main/src/com/google/refine/model/metadata/IMetadata.java b/main/src/com/google/refine/model/metadata/IMetadata.java index d3d4192d0..8f5f863fd 100644 --- a/main/src/com/google/refine/model/metadata/IMetadata.java +++ b/main/src/com/google/refine/model/metadata/IMetadata.java @@ -5,30 +5,18 @@ import java.io.InputStream; import java.time.LocalDateTime; import java.util.List; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; -import com.google.refine.Jsonizable; /** * Interface to import/export metadata */ -public interface IMetadata extends Jsonizable { +public interface IMetadata { public void loadFromJSON(JSONObject obj); public void loadFromFile(File metadataFile); public void loadFromStream(InputStream inputStream); - public void writeToFile(File metadataFile); - - /** - * @param jsonWriter writer to save metadatea to - * @param onlyIfDirty true to not write unchanged metadata - * @throws JSONException - */ - public void write(JSONWriter jsonWriter, boolean onlyIfDirty); - public MetadataFormat getFormatName(); public void setFormatName(MetadataFormat format); @@ -38,7 +26,5 @@ public interface IMetadata extends Jsonizable { public boolean isDirty(); - public JSONObject getJSON(); - public List validate(); } diff --git a/main/src/com/google/refine/model/metadata/ProjectMetadata.java b/main/src/com/google/refine/model/metadata/ProjectMetadata.java index d12806c3c..d81c1e611 100644 --- a/main/src/com/google/refine/model/metadata/ProjectMetadata.java +++ b/main/src/com/google/refine/model/metadata/ProjectMetadata.java @@ -64,10 +64,19 @@ import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonRawValue; +import com.fasterxml.jackson.annotation.JsonUnwrapped; +import com.fasterxml.jackson.annotation.JsonView; +import com.fasterxml.jackson.annotation.JsonInclude.Include; + import com.google.refine.ProjectManager; import com.google.refine.preference.PreferenceStore; import com.google.refine.preference.TopList; import com.google.refine.util.JSONUtilities; +import com.google.refine.util.JsonViews; import com.google.refine.util.ParsingUtilities; public class ProjectMetadata extends AbstractMetadata { @@ -75,36 +84,77 @@ public class ProjectMetadata extends AbstractMetadata { final public static String TEMP_FILE_NAME = "metadata.temp.json"; final public static String OLD_FILE_NAME = "metadata.old.json"; + @JsonProperty("created") private final LocalDateTime _created; + @JsonProperty("name") private String _name = ""; + @JsonProperty("password") + @JsonView(JsonViews.SaveMode.class) private String _password = ""; + @JsonProperty("encoding") + @JsonView(JsonViews.SaveMode.class) private String _encoding = ""; + @JsonProperty("encodingConfidence") + @JsonView(JsonViews.SaveMode.class) private int _encodingConfidence; + @JsonProperty("rowCount") private int _rowCount; // user metadata - private JSONArray _userMetadata = new JSONArray();; + private JSONArray _userMetadata = new JSONArray(); // _tags maps to keywords of the data package metadata + @JsonProperty("tags") private String[] _tags = new String[0]; + @JsonProperty("creator") private String _creator = ""; + @JsonProperty("contributors") private String _contributors = ""; + @JsonProperty("subject") private String _subject = ""; // Several refine projects may be linked + @JsonProperty("description") private String _description = ""; // free form of comment // import options is an array for 1-n data sources private JSONArray _importOptionMetadata = new JSONArray(); - + @JsonUnwrapped private Map _customMetadata = new HashMap(); + @JsonProperty("preferences") + @JsonView(JsonViews.SaveMode.class) private PreferenceStore _preferenceStore = new PreferenceStore(); // below 5 fields are from data package metadata: + @JsonProperty("title") private String title = ""; + @JsonProperty("homepage") private String homepage; + @JsonProperty("image") private String image = ""; + @JsonProperty("license") private String license = ""; + @JsonProperty("version") private String version = ""; + + @JsonProperty("userMetadata") + @JsonRawValue + @JsonInclude(Include.NON_NULL) + public String getJsonUserMetadata() { + if (_userMetadata.length() > 0) { + return _userMetadata.toString(); + } + return null; + } + + @JsonProperty("importOptionMetadata") + @JsonRawValue + @JsonInclude(Include.NON_NULL) + public String getJsonImportOptionMetadata() { + if (_importOptionMetadata.length() > 0) { + return _importOptionMetadata.toString(); + } + return null; + } private final static Logger logger = LoggerFactory.getLogger("project_metadata"); @@ -130,86 +180,12 @@ public class ProjectMetadata extends AbstractMetadata { updateModified(); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("name"); - writer.value(_name); - writer.key("tags"); - writer.array(); - for (String tag : _tags) { - writer.value(tag); - } - writer.endArray(); - writer.key("created"); writer.value(ParsingUtilities.localDateToString(_created)); - writer.key("modified"); writer.value(ParsingUtilities.localDateToString(_modified)); - writer.key("creator"); writer.value(_creator); - writer.key("contributors"); writer.value(_contributors); - writer.key("subject"); writer.value(_subject); - writer.key("description"); writer.value(_description); - writer.key("rowCount"); writer.value(_rowCount); - writer.key("title"); writer.value(title); - writer.key("homepage"); writer.value(homepage); - writer.key("image"); writer.value(image); - writer.key("license"); writer.value(license); - writer.key("version"); writer.value(version); - - writer.key("customMetadata"); - writer.object(); - - for (String key : _customMetadata.keySet()) { - Serializable value = _customMetadata.get(key); - writer.key(key); - writer.value(value); - } - writer.endObject(); - - // write JSONArray directly - if (_importOptionMetadata.length() > 0) { - writer.key("importOptionMetadata"); - writer.value(_importOptionMetadata); - } - - // write user metadata in {name, value, display} form: - if (_userMetadata.length() > 0) { - writer.key(PreferenceStore.USER_METADATA_KEY); - writer.value(_userMetadata); - } - - if (isSaveMode(options)) { - writer.key("password"); - writer.value(_password); - - writer.key("encoding"); - writer.value(_encoding); - writer.key("encodingConfidence"); - writer.value(_encodingConfidence); - - writer.key("preferences"); - _preferenceStore.write(writer, options); - } - - writer.endObject(); - - if (isSaveMode(options)) { - written = LocalDateTime.now(); - } - } - - public void writeWithoutOption(JSONWriter writer) - throws JSONException { - write(writer, new Properties()); - } - - private boolean isSaveMode(Properties options) { - return "save".equals(options.getProperty("mode")); - } - - public void write(JSONWriter jsonWriter) - throws JSONException { - write(jsonWriter, false); + @JsonProperty("saveModeWritten") + @JsonView(JsonViews.SaveMode.class) + @JsonInclude(Include.NON_NULL) + public String setSaveModeWritten() { + written = LocalDateTime.now(); + return null; } public void loadFromJSON(JSONObject obj) { @@ -555,25 +531,6 @@ public class ProjectMetadata extends AbstractMetadata { loadFromStream(targetStream); } - @Override - public void writeToFile(File metadataFile) { - Writer writer = null; - try { - writer = new OutputStreamWriter(new FileOutputStream(metadataFile)); - - JSONWriter jsonWriter = new JSONWriter(writer); - write(jsonWriter, false); - } catch (FileNotFoundException e) { - logger.error(ExceptionUtils.getStackTrace(e)); - } finally { - try { - writer.close(); - } catch (IOException e) { - logger.error(ExceptionUtils.getStackTrace(e)); - } - } - } - @Override public void loadFromStream(InputStream inputStream) { try (InputStreamReader reader = new InputStreamReader(inputStream)) { @@ -586,15 +543,6 @@ public class ProjectMetadata extends AbstractMetadata { } } - @Override - public JSONObject getJSON() { - StringWriter writer = new StringWriter(); - JSONWriter jsonWriter = new JSONWriter(writer); - writeWithoutOption(jsonWriter); - - return new JSONObject(jsonWriter.toString()); - } - @Override public List validate() { return null; diff --git a/main/src/com/google/refine/model/metadata/validator/ValidateOperation.java b/main/src/com/google/refine/model/metadata/validator/ValidateOperation.java index bb918712a..10d0f3a86 100644 --- a/main/src/com/google/refine/model/metadata/validator/ValidateOperation.java +++ b/main/src/com/google/refine/model/metadata/validator/ValidateOperation.java @@ -1,10 +1,6 @@ package com.google.refine.model.metadata.validator; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; @@ -22,11 +18,4 @@ public class ValidateOperation extends AbstractOperation { return ValidatorInspector.inspect(project, options); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - // TODO Auto-generated method stub - - } - } diff --git a/main/src/com/google/refine/model/recon/DataExtensionReconConfig.java b/main/src/com/google/refine/model/recon/DataExtensionReconConfig.java index 9c1eede9b..29c8c3590 100644 --- a/main/src/com/google/refine/model/recon/DataExtensionReconConfig.java +++ b/main/src/com/google/refine/model/recon/DataExtensionReconConfig.java @@ -33,21 +33,16 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model.recon; -import java.util.List; -import java.util.Properties; import java.util.ArrayList; +import java.util.List; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; -import com.google.refine.model.ReconType; import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Recon; +import com.google.refine.model.ReconType; import com.google.refine.model.Row; -import com.google.refine.model.recon.StandardReconConfig; -import com.google.refine.model.recon.ReconJob; public class DataExtensionReconConfig extends StandardReconConfig { final public ReconType type; diff --git a/main/src/com/google/refine/model/recon/ReconConfig.java b/main/src/com/google/refine/model/recon/ReconConfig.java index 7f11af0f8..063cc5e13 100644 --- a/main/src/com/google/refine/model/recon/ReconConfig.java +++ b/main/src/com/google/refine/model/recon/ReconConfig.java @@ -33,31 +33,29 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.model.recon; +import java.io.IOException; import java.io.Writer; import java.lang.reflect.Method; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.model.Cell; import com.google.refine.model.Project; import com.google.refine.model.Recon; import com.google.refine.model.Row; +import com.google.refine.util.ParsingUtilities; import edu.mit.simile.butterfly.ButterflyModule; -abstract public class ReconConfig implements Jsonizable { +abstract public class ReconConfig { final static protected Logger LOGGER = LoggerFactory.getLogger("recon-config"); static final public Map>> s_opNameToClass = @@ -125,11 +123,10 @@ abstract public class ReconConfig implements Jsonizable { abstract public Recon createNewRecon(long historyEntryID); public void save(Writer writer) { - JSONWriter jsonWriter = new JSONWriter(writer); try { - write(jsonWriter, new Properties()); - } catch (JSONException e) { - LOGGER.error("Save failed",e); + ParsingUtilities.defaultWriter.writeValue(writer, this); + } catch (IOException e) { + e.printStackTrace(); } } diff --git a/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java b/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java index 2d971a06d..83c78e538 100644 --- a/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java +++ b/main/src/com/google/refine/model/recon/ReconciledDataExtensionJob.java @@ -47,35 +47,35 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import java.util.stream.Collectors; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.annotation.JsonView; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.refine.Jsonizable; import com.google.refine.expr.functions.ToDate; import com.google.refine.model.ReconCandidate; import com.google.refine.model.ReconType; import com.google.refine.util.JSONUtilities; +import com.google.refine.util.JsonViews; import com.google.refine.util.ParsingUtilities; public class ReconciledDataExtensionJob { - static public class DataExtensionProperty implements Jsonizable { + static public class DataExtensionProperty { @JsonProperty("id") public final String id; @JsonProperty("name") + @JsonView(JsonViews.NonSaveMode.class) public final String name; @JsonProperty("settings") @JsonInclude(Include.NON_NULL) @@ -92,31 +92,10 @@ public class ReconciledDataExtensionJob { this.id = id; this.name = name; this.settings = settings; - } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("id"); writer.value(id); - if(!"query".equals(options.getProperty("mode"))) { - writer.key("name"); writer.value(name); - } - if (settings != null) { - writer.key("settings"); - writer.object(); - for(Map.Entry entry : settings.entrySet()) { - writer.key(entry.getKey()); - writer.value(entry.getValue()); - } - writer.endObject(); - } - writer.endObject(); - } - + } } - static public class DataExtensionConfig implements Jsonizable { + static public class DataExtensionConfig { @JsonProperty("properties") public final List properties; @@ -135,22 +114,7 @@ public class ReconciledDataExtensionJob { } catch(IOException e) { throw new JSONException(e.toString()); } - } - - @Override - public void write(JSONWriter jsonWriter, Properties options) - throws JSONException { - jsonWriter.object(); - jsonWriter.key("properties"); - jsonWriter.array(); - - for (DataExtensionProperty property : properties) { - property.write(jsonWriter, options); - } - jsonWriter.endArray(); - jsonWriter.endObject(); - } - + } } static public class DataExtensionQuery extends DataExtensionConfig { @@ -166,34 +130,7 @@ public class ReconciledDataExtensionJob { List properties) { super(properties); this.ids = ids; - } - - @Override - public void write(JSONWriter jsonWriter, Properties options) - throws JSONException { - jsonWriter.object(); - - if(ids != null) { - jsonWriter.key("ids"); - jsonWriter.array(); - for (String id : ids) { - if (id != null) { - jsonWriter.value(id); - } - } - jsonWriter.endArray(); - } - - jsonWriter.key("properties"); - jsonWriter.array(); - - for (DataExtensionProperty property : properties) { - property.write(jsonWriter, options); - } - jsonWriter.endArray(); - jsonWriter.endObject(); - } - + } } static public class DataExtension { @@ -382,12 +319,9 @@ public class ReconciledDataExtensionJob { } - static protected void formulateQuery(Set ids, DataExtensionConfig node, Writer writer) throws JSONException { - JSONWriter jsonWriter = new JSONWriter(writer); - Properties options = new Properties(); + static protected void formulateQuery(Set ids, DataExtensionConfig node, Writer writer) throws IOException { DataExtensionQuery query = new DataExtensionQuery(ids.stream().collect(Collectors.toList()), node.properties); - options.setProperty("mode", "query"); - query.write(jsonWriter, options); + ParsingUtilities.saveWriter.writeValue(writer, query); } static protected void gatherColumnInfo(JSONArray meta, List columns) throws JSONException { diff --git a/main/src/com/google/refine/model/recon/StandardReconConfig.java b/main/src/com/google/refine/model/recon/StandardReconConfig.java index 43e3754b8..068bd4b29 100644 --- a/main/src/com/google/refine/model/recon/StandardReconConfig.java +++ b/main/src/com/google/refine/model/recon/StandardReconConfig.java @@ -42,7 +42,6 @@ import java.time.OffsetDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; -import java.util.Properties; import java.util.Set; import org.apache.commons.lang3.StringUtils; @@ -56,7 +55,6 @@ import org.slf4j.LoggerFactory; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.expr.ExpressionUtils; import com.google.refine.model.Cell; import com.google.refine.model.Project; @@ -71,7 +69,7 @@ import com.google.refine.util.ParsingUtilities; public class StandardReconConfig extends ReconConfig { final static Logger logger = LoggerFactory.getLogger("refine-standard-recon"); - static public class ColumnDetail implements Jsonizable { + static public class ColumnDetail { @JsonProperty("column") final public String columnName; @JsonProperty("propertyName") @@ -84,17 +82,6 @@ public class StandardReconConfig extends ReconConfig { this.propertyName = propertyName; this.propertyID = propertyID; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("column"); writer.value(columnName); - writer.key("propertyName"); writer.value(propertyName); - writer.key("propertyID"); writer.value(propertyID); - writer.endObject(); - - } } static public ReconConfig reconstruct(JSONObject obj) throws Exception { @@ -214,35 +201,6 @@ public class StandardReconConfig extends ReconConfig { this.columnDetails = columnDetails; this.limit = limit; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("mode"); writer.value("standard-service"); - writer.key("service"); writer.value(service); - writer.key("identifierSpace"); writer.value(identifierSpace); - writer.key("schemaSpace"); writer.value(schemaSpace); - writer.key("type"); - if (typeID == null) { - writer.value(null); - } else { - writer.object(); - writer.key("id"); writer.value(typeID); - writer.key("name"); writer.value(typeName); - writer.endObject(); - } - writer.key("autoMatch"); writer.value(autoMatch); - writer.key("columnDetails"); - writer.array(); - for (ColumnDetail c : columnDetails) { - c.write(writer, options); - } - writer.endArray(); - writer.key("limit"); writer.value(limit); - writer.endObject(); - } @JsonProperty("type") public ReconType getReconType() { diff --git a/main/src/com/google/refine/operations/cell/BlankDownOperation.java b/main/src/com/google/refine/operations/cell/BlankDownOperation.java index 17d2f0b1a..0afda51b2 100644 --- a/main/src/com/google/refine/operations/cell/BlankDownOperation.java +++ b/main/src/com/google/refine/operations/cell/BlankDownOperation.java @@ -34,11 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.cell; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.browsing.Engine.Mode; import com.google.refine.browsing.EngineConfig; @@ -51,7 +48,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class BlankDownOperation extends EngineDependentMassCellOperation { @@ -71,18 +67,6 @@ public class BlankDownOperation extends EngineDependentMassCellOperation { super(engineConfig, columnName, true); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Blank down cells in column " + _columnName; diff --git a/main/src/com/google/refine/operations/cell/FillDownOperation.java b/main/src/com/google/refine/operations/cell/FillDownOperation.java index 23a42c5a3..1ecca6345 100644 --- a/main/src/com/google/refine/operations/cell/FillDownOperation.java +++ b/main/src/com/google/refine/operations/cell/FillDownOperation.java @@ -34,11 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.cell; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.browsing.Engine; import com.google.refine.browsing.Engine.Mode; @@ -52,7 +49,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class FillDownOperation extends EngineDependentMassCellOperation { @@ -72,18 +68,6 @@ public class FillDownOperation extends EngineDependentMassCellOperation { super(engineConfig, columnName, true); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Fill down cells in column " + _columnName; diff --git a/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java b/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java index 37ca3a7af..c4d29535d 100644 --- a/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java +++ b/main/src/com/google/refine/operations/cell/KeyValueColumnizeOperation.java @@ -37,11 +37,8 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -53,7 +50,6 @@ import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowColumnChange; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class KeyValueColumnizeOperation extends AbstractOperation { @@ -78,22 +74,6 @@ public class KeyValueColumnizeOperation extends AbstractOperation { _valueColumnName = valueColumnName; _noteColumnName = noteColumnName; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value( - "Columnize by key column " + - _keyColumnName + " and value column " + _valueColumnName + - (_noteColumnName != null ? (" with note column " + _noteColumnName) : "")); - writer.key("keyColumnName"); writer.value(_keyColumnName); - writer.key("valueColumnName"); writer.value(_valueColumnName); - writer.key("noteColumnName"); writer.value(_noteColumnName); - writer.endObject(); - } @JsonProperty("keyColumnName") public String getKeyColumnName() { diff --git a/main/src/com/google/refine/operations/cell/MassEditOperation.java b/main/src/com/google/refine/operations/cell/MassEditOperation.java index 3a288b2fe..d9388b8e1 100644 --- a/main/src/com/google/refine/operations/cell/MassEditOperation.java +++ b/main/src/com/google/refine/operations/cell/MassEditOperation.java @@ -41,13 +41,10 @@ import java.util.Map; import java.util.Properties; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.RowVisitor; import com.google.refine.expr.Evaluable; @@ -60,7 +57,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.ParsingUtilities; import com.google.refine.util.StringUtils; @@ -68,7 +64,7 @@ public class MassEditOperation extends EngineDependentMassCellOperation { final protected String _expression; final protected List _edits; - static public class Edit implements Jsonizable { + static public class Edit { @JsonProperty("from") final public List from; @JsonProperty("fromBlank") @@ -84,23 +80,6 @@ public class MassEditOperation extends EngineDependentMassCellOperation { this.fromError = fromError; this.to = to; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("fromBlank"); writer.value(fromBlank); - writer.key("fromError"); writer.value(fromError); - writer.key("from"); - writer.array(); - for (String s : from) { - writer.value(s); - } - writer.endArray(); - writer.key("to"); writer.value(to); - writer.endObject(); - } } static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { @@ -157,25 +136,6 @@ public class MassEditOperation extends EngineDependentMassCellOperation { _expression = expression; _edits = edits; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("expression"); writer.value(_expression); - writer.key("edits"); - writer.array(); - for (Edit edit : _edits) { - edit.write(writer, options); - } - writer.endArray(); - writer.endObject(); - } @JsonProperty("expression") public String getExpression() { diff --git a/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java b/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java index ba1b37a18..112214b14 100644 --- a/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java +++ b/main/src/com/google/refine/operations/cell/MultiValuedCellJoinOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.cell; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -51,7 +48,6 @@ import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowChange; -import com.google.refine.operations.OperationRegistry; public class MultiValuedCellJoinOperation extends AbstractOperation { final protected String _columnName; @@ -75,19 +71,6 @@ public class MultiValuedCellJoinOperation extends AbstractOperation { _keyColumnName = keyColumnName; _separator = separator; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("columnName"); writer.value(_columnName); - writer.key("keyColumnName"); writer.value(_keyColumnName); - writer.key("separator"); writer.value(_separator); - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java b/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java index d9537f941..180d2c864 100644 --- a/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java +++ b/main/src/com/google/refine/operations/cell/MultiValuedCellSplitOperation.java @@ -35,13 +35,10 @@ package com.google.refine.operations.cell; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -54,7 +51,6 @@ import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowChange; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class MultiValuedCellSplitOperation extends AbstractOperation { @@ -148,29 +144,6 @@ public class MultiValuedCellSplitOperation extends AbstractOperation { return _fieldLengths; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Split multi-valued cells in column " + _columnName); - writer.key("columnName"); writer.value(_columnName); - writer.key("keyColumnName"); writer.value(_keyColumnName); - writer.key("mode"); writer.value(_mode); - if ("separator".equals(_mode)) { - writer.key("separator"); writer.value(_separator); - writer.key("regex"); writer.value(_regex); - } else { - writer.key("fieldLengths"); writer.array(); - for (int l : _fieldLengths) { - writer.value(l); - } - writer.endArray(); - } - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Split multi-valued cells in column " + _columnName; diff --git a/main/src/com/google/refine/operations/cell/TextTransformOperation.java b/main/src/com/google/refine/operations/cell/TextTransformOperation.java index 6016cb92b..fa3a07c30 100644 --- a/main/src/com/google/refine/operations/cell/TextTransformOperation.java +++ b/main/src/com/google/refine/operations/cell/TextTransformOperation.java @@ -37,9 +37,7 @@ import java.io.Serializable; import java.util.List; import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.RowVisitor; @@ -55,7 +53,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.operations.EngineDependentMassCellOperation; import com.google.refine.operations.OnError; -import com.google.refine.operations.OperationRegistry; public class TextTransformOperation extends EngineDependentMassCellOperation { final protected String _expression; @@ -110,22 +107,6 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { _repeatCount = repeatCount; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("expression"); writer.value(_expression); - writer.key("onError"); writer.value(onErrorToString(_onError)); - writer.key("repeat"); writer.value(_repeat); - writer.key("repeatCount"); writer.value(_repeatCount); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Text transform on cells in column " + _columnName + " using expression " + _expression; diff --git a/main/src/com/google/refine/operations/cell/TransposeColumnsIntoRowsOperation.java b/main/src/com/google/refine/operations/cell/TransposeColumnsIntoRowsOperation.java index c45e8782c..41dc0774e 100644 --- a/main/src/com/google/refine/operations/cell/TransposeColumnsIntoRowsOperation.java +++ b/main/src/com/google/refine/operations/cell/TransposeColumnsIntoRowsOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.cell; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; @@ -48,7 +45,6 @@ import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowColumnChange; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class TransposeColumnsIntoRowsOperation extends AbstractOperation { @@ -131,28 +127,6 @@ public class TransposeColumnsIntoRowsOperation extends AbstractOperation { _valueColumnName = valueColumnName; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription()); - writer.key("startColumnName"); writer.value(_startColumnName); - writer.key("columnCount"); writer.value(_columnCount); - writer.key("ignoreBlankCells"); writer.value(_ignoreBlankCells); - writer.key("fillDown"); writer.value(_fillDown); - if (_combinedColumnName != null) { - writer.key("combinedColumnName"); writer.value(_combinedColumnName); - writer.key("prependColumnName"); writer.value(_prependColumnName); - writer.key("separator"); writer.value(_separator); - } else { - writer.key("keyColumnName"); writer.value(_keyColumnName); - writer.key("valueColumnName"); writer.value(_valueColumnName); - } - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return getBriefDescription(); diff --git a/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java b/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java index bb145be4a..a5455397f 100644 --- a/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java +++ b/main/src/com/google/refine/operations/cell/TransposeRowsIntoColumnsOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.cell; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -50,7 +47,6 @@ import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowColumnChange; -import com.google.refine.operations.OperationRegistry; public class TransposeRowsIntoColumnsOperation extends AbstractOperation { final protected String _columnName; @@ -70,18 +66,6 @@ public class TransposeRowsIntoColumnsOperation extends AbstractOperation { _columnName = columnName; _rowCount = rowCount; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Transpose every " + _rowCount + " cells in column " + _columnName + " into separate columns"); - writer.key("columnName"); writer.value(_columnName); - writer.key("rowCount"); writer.value(_rowCount); - writer.endObject(); - } @JsonProperty("rowCount") public int getRowCount() { diff --git a/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java b/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java index 3e623c92b..f8f7cd4c8 100644 --- a/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnAdditionByFetchingURLsOperation.java @@ -48,7 +48,6 @@ import java.util.concurrent.TimeUnit; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -56,7 +55,6 @@ import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; -import com.google.refine.Jsonizable; import com.google.refine.browsing.Engine; import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.FilteredRows; @@ -76,7 +74,6 @@ import com.google.refine.model.changes.CellAtRow; import com.google.refine.model.changes.ColumnAdditionChange; import com.google.refine.operations.EngineDependentOperation; import com.google.refine.operations.OnError; -import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.TextTransformOperation; import com.google.refine.process.LongRunningProcess; import com.google.refine.process.Process; @@ -84,7 +81,7 @@ import com.google.refine.util.ParsingUtilities; public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperation { - public static final class HttpHeader implements Jsonizable { + public static final class HttpHeader { @JsonProperty("name") final public String name; @JsonProperty("value") @@ -94,15 +91,6 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat this.name = name; this.value = value; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("name"); writer.value(name); - writer.key("value"); writer.value(value); - writer.endObject(); - } } final protected String _baseColumnName; @@ -166,32 +154,6 @@ public class ColumnAdditionByFetchingURLsOperation extends EngineDependentOperat _cacheResponses = cacheResponses; _httpHeadersJson = httpHeadersJson; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("newColumnName"); writer.value(_newColumnName); - writer.key("columnInsertIndex"); writer.value(_columnInsertIndex); - writer.key("baseColumnName"); writer.value(_baseColumnName); - writer.key("urlExpression"); writer.value(_urlExpression); - writer.key("onError"); writer.value(TextTransformOperation.onErrorToString(_onError)); - writer.key("delay"); writer.value(_delay); - writer.key("cacheResponses"); writer.value(_cacheResponses); - if (_httpHeadersJson != null) { - writer.key("httpHeadersJson"); - writer.array(); - for(HttpHeader header : _httpHeadersJson) { - header.write(writer, options); - } - writer.endArray(); - } - writer.endObject(); - } @JsonProperty("newColumnName") public String getNewColumnName() { diff --git a/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java b/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java index 0d4334a07..ae4b8077e 100644 --- a/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnAdditionOperation.java @@ -38,9 +38,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -63,7 +61,6 @@ import com.google.refine.model.changes.CellAtRow; import com.google.refine.model.changes.ColumnAdditionChange; import com.google.refine.operations.EngineDependentOperation; import com.google.refine.operations.OnError; -import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.cell.TextTransformOperation; public class ColumnAdditionOperation extends EngineDependentOperation { @@ -104,22 +101,6 @@ public class ColumnAdditionOperation extends EngineDependentOperation { _newColumnName = newColumnName; _columnInsertIndex = columnInsertIndex; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("newColumnName"); writer.value(_newColumnName); - writer.key("columnInsertIndex"); writer.value(_columnInsertIndex); - writer.key("baseColumnName"); writer.value(_baseColumnName); - writer.key("expression"); writer.value(_expression); - writer.key("onError"); writer.value(TextTransformOperation.onErrorToString(_onError)); - writer.endObject(); - } @JsonProperty("newColumnName") public String getNewColumnName() { diff --git a/main/src/com/google/refine/operations/column/ColumnMoveOperation.java b/main/src/com/google/refine/operations/column/ColumnMoveOperation.java index a000859da..2b6cc7df0 100644 --- a/main/src/com/google/refine/operations/column/ColumnMoveOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnMoveOperation.java @@ -33,11 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.column; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -46,7 +42,6 @@ import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; import com.google.refine.model.changes.ColumnMoveChange; -import com.google.refine.operations.OperationRegistry; public class ColumnMoveOperation extends AbstractOperation { final protected String _columnName; @@ -67,18 +62,6 @@ public class ColumnMoveOperation extends AbstractOperation { _index = index; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Move column " + _columnName + " to position " + _index); - writer.key("columnName"); writer.value(_columnName); - writer.key("index"); writer.value(_index); - writer.endObject(); - } - @JsonProperty("columnName") public String getColumnName() { return _columnName; diff --git a/main/src/com/google/refine/operations/column/ColumnRemovalOperation.java b/main/src/com/google/refine/operations/column/ColumnRemovalOperation.java index 5de7a5895..8e48c87de 100644 --- a/main/src/com/google/refine/operations/column/ColumnRemovalOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnRemovalOperation.java @@ -33,11 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.column; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -47,7 +43,6 @@ import com.google.refine.model.AbstractOperation; import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.changes.ColumnRemovalChange; -import com.google.refine.operations.OperationRegistry; public class ColumnRemovalOperation extends AbstractOperation { final protected String _columnName; @@ -64,17 +59,6 @@ public class ColumnRemovalOperation extends AbstractOperation { _columnName = columnName; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Remove column " + _columnName); - writer.key("columnName"); writer.value(_columnName); - writer.endObject(); - } - @JsonProperty("columnName") public String getColumnName() { return _columnName; diff --git a/main/src/com/google/refine/operations/column/ColumnRenameOperation.java b/main/src/com/google/refine/operations/column/ColumnRenameOperation.java index 0d4b85c9a..d76f928a7 100644 --- a/main/src/com/google/refine/operations/column/ColumnRenameOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnRenameOperation.java @@ -33,11 +33,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.column; -import java.util.Properties; - -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -46,7 +42,6 @@ import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; import com.google.refine.model.changes.ColumnRenameChange; -import com.google.refine.operations.OperationRegistry; public class ColumnRenameOperation extends AbstractOperation { final protected String _oldColumnName; @@ -67,18 +62,6 @@ public class ColumnRenameOperation extends AbstractOperation { _newColumnName = newColumnName; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Rename column " + _oldColumnName + " to " + _newColumnName); - writer.key("oldColumnName"); writer.value(_oldColumnName); - writer.key("newColumnName"); writer.value(_newColumnName); - writer.endObject(); - } - @JsonProperty("oldColumnName") public String getOldColumnName() { return _oldColumnName; diff --git a/main/src/com/google/refine/operations/column/ColumnReorderOperation.java b/main/src/com/google/refine/operations/column/ColumnReorderOperation.java index 3b7f906a8..2b1fe8d93 100644 --- a/main/src/com/google/refine/operations/column/ColumnReorderOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnReorderOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.column; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -47,7 +44,6 @@ import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; import com.google.refine.model.Project; import com.google.refine.model.changes.ColumnReorderChange; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class ColumnReorderOperation extends AbstractOperation { @@ -64,21 +60,6 @@ public class ColumnReorderOperation extends AbstractOperation { public ColumnReorderOperation(List columnNames) { _columnNames = columnNames; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("columnNames"); writer.array(); - for (String n : _columnNames) { - writer.value(n); - } - writer.endArray(); - writer.endObject(); - } @JsonProperty("columnNames") public List getColumnNames() { diff --git a/main/src/com/google/refine/operations/column/ColumnSplitOperation.java b/main/src/com/google/refine/operations/column/ColumnSplitOperation.java index adc7d1860..330efa1e7 100644 --- a/main/src/com/google/refine/operations/column/ColumnSplitOperation.java +++ b/main/src/com/google/refine/operations/column/ColumnSplitOperation.java @@ -36,13 +36,10 @@ package com.google.refine.operations.column; import java.io.Serializable; import java.util.ArrayList; import java.util.List; -import java.util.Properties; import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; @@ -62,7 +59,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.ColumnSplitChange; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class ColumnSplitOperation extends EngineDependentOperation { @@ -145,32 +141,6 @@ public class ColumnSplitOperation extends EngineDependentOperation { _fieldLengths = fieldLengths; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("guessCellType"); writer.value(_guessCellType); - writer.key("removeOriginalColumn"); writer.value(_removeOriginalColumn); - writer.key("mode"); writer.value(_mode); - if ("separator".equals(_mode)) { - writer.key("separator"); writer.value(_separator); - writer.key("regex"); writer.value(_regex); - writer.key("maxColumns"); writer.value(_maxColumns); - } else { - writer.key("fieldLengths"); writer.array(); - for (int l : _fieldLengths) { - writer.value(l); - } - writer.endArray(); - } - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ExtendDataOperation.java b/main/src/com/google/refine/operations/recon/ExtendDataOperation.java index 3aaa5858c..fac3243ed 100644 --- a/main/src/com/google/refine/operations/recon/ExtendDataOperation.java +++ b/main/src/com/google/refine/operations/recon/ExtendDataOperation.java @@ -43,7 +43,6 @@ import java.util.Set; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -66,7 +65,6 @@ import com.google.refine.model.recon.ReconciledDataExtensionJob.ColumnInfo; import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtension; import com.google.refine.model.recon.ReconciledDataExtensionJob.DataExtensionConfig; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; import com.google.refine.process.LongRunningProcess; import com.google.refine.process.Process; @@ -120,23 +118,6 @@ public class ExtendDataOperation extends EngineDependentOperation { _columnInsertIndex = columnInsertIndex; } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnInsertIndex"); writer.value(_columnInsertIndex); - writer.key("baseColumnName"); writer.value(_baseColumnName); - writer.key("endpoint"); writer.value(_endpoint); - writer.key("identifierSpace"); writer.value(_identifierSpace); - writer.key("schemaSpace"); writer.value(_schemaSpace); - writer.key("extension"); _extension.write(writer, options); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Extend data at index " + _columnInsertIndex + diff --git a/main/src/com/google/refine/operations/recon/ReconClearSimilarCellsOperation.java b/main/src/com/google/refine/operations/recon/ReconClearSimilarCellsOperation.java index 2b30ce3aa..8c3f2ca8d 100644 --- a/main/src/com/google/refine/operations/recon/ReconClearSimilarCellsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconClearSimilarCellsOperation.java @@ -34,11 +34,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.operations.recon; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -53,7 +50,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconClearSimilarCellsOperation extends EngineDependentMassCellOperation { final protected String _similarValue; @@ -75,20 +71,6 @@ public class ReconClearSimilarCellsOperation extends EngineDependentMassCellOper super(engineConfig, columnName, false); this._similarValue = similarValue; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("similarValue"); writer.value(_similarValue); - - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconCopyAcrossColumnsOperation.java b/main/src/com/google/refine/operations/recon/ReconCopyAcrossColumnsOperation.java index 5d8c5c237..ae9cf5a31 100644 --- a/main/src/com/google/refine/operations/recon/ReconCopyAcrossColumnsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconCopyAcrossColumnsOperation.java @@ -38,13 +38,10 @@ import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; -import java.util.Properties; import java.util.Set; import org.apache.commons.lang3.StringUtils; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -63,7 +60,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.MassChange; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; import com.google.refine.util.JSONUtilities; public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation { @@ -95,31 +91,6 @@ public class ReconCopyAcrossColumnsOperation extends EngineDependentOperation { _judgments = judgments; _applyToJudgedCells = applyToJudgedCells; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("fromColumnName"); writer.value(_fromColumnName); - writer.key("toColumnNames"); - writer.array(); - for (String s : _toColumnNames) { - writer.value(s); - } - writer.endArray(); - writer.key("judgments"); - writer.array(); - for (String s : _judgments) { - writer.value(s); - } - writer.endArray(); - writer.key("applyToJudgedCells"); writer.value(_applyToJudgedCells); - writer.endObject(); - } @JsonProperty("fromColumnName") public String getFromColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java b/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java index c95524805..aeb49118b 100644 --- a/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconDiscardJudgmentsOperation.java @@ -36,11 +36,8 @@ package com.google.refine.operations.recon; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -57,7 +54,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation { final protected boolean _clearData; @@ -75,19 +71,6 @@ public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOpera super(engineConfig, columnName, false); _clearData = clearData; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("clearData"); writer.value(_clearData); - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconJudgeSimilarCellsOperation.java b/main/src/com/google/refine/operations/recon/ReconJudgeSimilarCellsOperation.java index 5afc6ce98..18521988b 100644 --- a/main/src/com/google/refine/operations/recon/ReconJudgeSimilarCellsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconJudgeSimilarCellsOperation.java @@ -36,16 +36,14 @@ package com.google.refine.operations.recon; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.browsing.EngineConfig; import com.google.refine.browsing.RowVisitor; @@ -63,7 +61,6 @@ import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.model.recon.ReconConfig; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOperation { final protected String _similarValue; @@ -71,7 +68,7 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper final protected ReconCandidate _match; final protected boolean _shareNewTopics; - static public AbstractOperation reconstruct(JSONObject obj) throws JSONException { + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws JSONException { JSONObject engineConfig = obj.getJSONObject("engineConfig"); ReconCandidate match = null; @@ -121,25 +118,6 @@ public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOper this._match = match; this._shareNewTopics = shareNewTopics; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("similarValue"); writer.value(_similarValue); - writer.key("judgment"); writer.value(Recon.judgmentToString(_judgment)); - if (_match != null) { - writer.key("match"); _match.write(writer, options); - } - writer.key("shareNewTopics"); writer.value(_shareNewTopics); - - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java b/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java index 363b52564..8d3efb59b 100644 --- a/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMarkNewTopicsOperation.java @@ -36,11 +36,8 @@ package com.google.refine.operations.recon; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -58,7 +55,6 @@ import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.model.recon.ReconConfig; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation { final protected boolean _shareNewTopics; @@ -77,19 +73,6 @@ public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperatio super(engineConfig, columnName, false); _shareNewTopics = shareNewTopics; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("shareNewTopics"); writer.value(_shareNewTopics); - writer.endObject(); - } @JsonProperty("columnName") public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java b/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java index c17bf4346..9819ecef1 100644 --- a/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMatchBestCandidatesOperation.java @@ -36,11 +36,8 @@ package com.google.refine.operations.recon; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -58,7 +55,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOperation { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { @@ -74,18 +70,6 @@ public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOp public ReconMatchBestCandidatesOperation(EngineConfig engineConfig, String columnName) { super(engineConfig, columnName, false); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.endObject(); - } @JsonProperty public String getColumnName() { diff --git a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java index 1dce15216..3e7f85ccf 100644 --- a/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconMatchSpecificTopicOperation.java @@ -36,12 +36,9 @@ package com.google.refine.operations.recon; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Properties; import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -61,7 +58,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.CellChange; import com.google.refine.model.changes.ReconChange; import com.google.refine.operations.EngineDependentMassCellOperation; -import com.google.refine.operations.OperationRegistry; public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOperation { @@ -131,31 +127,6 @@ public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOpe this.identifierSpace = identifierSpace; this.schemaSpace = schemaSpace; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("columnName"); writer.value(_columnName); - writer.key("match"); - writer.object(); - writer.key("id"); writer.value(match.id); - writer.key("name"); writer.value(match.name); - writer.key("types"); - writer.array(); - for (String typeID : match.types) { - writer.value(typeID); - } - writer.endArray(); - writer.endObject(); - writer.key("identifierSpace"); writer.value(identifierSpace); - writer.key("schemaSpace"); writer.value(schemaSpace); - writer.endObject(); - } @Override protected String getBriefDescription(Project project) { diff --git a/main/src/com/google/refine/operations/recon/ReconOperation.java b/main/src/com/google/refine/operations/recon/ReconOperation.java index 278b93e35..34593b77c 100644 --- a/main/src/com/google/refine/operations/recon/ReconOperation.java +++ b/main/src/com/google/refine/operations/recon/ReconOperation.java @@ -40,9 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +54,6 @@ import com.google.refine.browsing.RowVisitor; import com.google.refine.expr.ExpressionUtils; import com.google.refine.history.Change; import com.google.refine.history.HistoryEntry; -import com.google.refine.model.AbstractOperation; import com.google.refine.model.Cell; import com.google.refine.model.Column; import com.google.refine.model.Project; @@ -68,7 +65,6 @@ import com.google.refine.model.recon.ReconConfig; import com.google.refine.model.recon.ReconJob; import com.google.refine.model.recon.StandardReconConfig; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; import com.google.refine.process.LongRunningProcess; import com.google.refine.process.Process; import com.google.refine.util.ParsingUtilities; @@ -112,19 +108,6 @@ public class ReconOperation extends EngineDependentOperation { protected String getBriefDescription(Project project) { return _reconConfig.getBriefDescription(project, _columnName); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("columnName"); writer.value(_columnName); - writer.key("config"); _reconConfig.write(writer, options); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.endObject(); - } @JsonProperty("config") public ReconConfig getReconConfig() { @@ -205,50 +188,6 @@ public class ReconOperation extends EngineDependentOperation { } } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(hashCode()); - writer.key("description"); writer.value(_description); - writer.key("immediate"); writer.value(false); - writer.key("status"); writer.value(_thread == null ? "pending" : (_thread.isAlive() ? "running" : "done")); - writer.key("progress"); writer.value(_progress); - writer.key("onDone"); - writer.array(); - writer.object(); - writer.key("action"); writer.value("createFacet"); - writer.key("facetType"); writer.value("list"); - writer.key("facetConfig"); - writer.object(); - writer.key("name"); writer.value(_columnName + ": judgment"); - writer.key("columnName"); writer.value(_columnName); - writer.key("expression"); writer.value("forNonBlank(cell.recon.judgment, v, v, if(isNonBlank(value), \"(unreconciled)\", \"(blank)\"))"); - writer.endObject(); - writer.key("facetOptions"); - writer.object(); - writer.key("scroll"); writer.value(false); - writer.endObject(); - writer.endObject(); - - if (_reconConfig instanceof StandardReconConfig) { - writer.object(); - writer.key("action"); writer.value("createFacet"); - writer.key("facetType"); writer.value("range"); - writer.key("facetConfig"); - writer.object(); - writer.key("name"); writer.value(_columnName + ": best candidate's score"); - writer.key("columnName"); writer.value(_columnName); - writer.key("expression"); writer.value("cell.recon.best.score"); - writer.key("mode"); writer.value("range"); - writer.endObject(); - writer.endObject(); - } - writer.endArray(); - writer.endObject(); - } - @JsonProperty("onDone") public List onDoneActions() { List onDone = new ArrayList<>(); diff --git a/main/src/com/google/refine/operations/row/DenormalizeOperation.java b/main/src/com/google/refine/operations/row/DenormalizeOperation.java index 605654ed7..9daf246e9 100644 --- a/main/src/com/google/refine/operations/row/DenormalizeOperation.java +++ b/main/src/com/google/refine/operations/row/DenormalizeOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.row; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.history.HistoryEntry; import com.google.refine.model.AbstractOperation; @@ -49,7 +46,6 @@ import com.google.refine.model.RecordModel.CellDependency; import com.google.refine.model.RecordModel.RowDependency; import com.google.refine.model.Row; import com.google.refine.model.changes.MassRowChange; -import com.google.refine.operations.OperationRegistry; public class DenormalizeOperation extends AbstractOperation { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { @@ -58,17 +54,6 @@ public class DenormalizeOperation extends AbstractOperation { public DenormalizeOperation() { } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value("Denormalize"); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { diff --git a/main/src/com/google/refine/operations/row/RowFlagOperation.java b/main/src/com/google/refine/operations/row/RowFlagOperation.java index fe8a1dbfc..b251d5ba8 100644 --- a/main/src/com/google/refine/operations/row/RowFlagOperation.java +++ b/main/src/com/google/refine/operations/row/RowFlagOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.row; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -55,7 +52,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.MassChange; import com.google.refine.model.changes.RowFlagChange; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; public class RowFlagOperation extends EngineDependentOperation { final protected boolean _flagged; @@ -74,18 +70,6 @@ public class RowFlagOperation extends EngineDependentOperation { super(engineConfig); _flagged = flagged; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("flagged"); writer.value(_flagged); - writer.endObject(); - } @JsonProperty("flagged") public boolean getFlagged() { diff --git a/main/src/com/google/refine/operations/row/RowRemovalOperation.java b/main/src/com/google/refine/operations/row/RowRemovalOperation.java index 3d7ee7a44..3445fadfe 100644 --- a/main/src/com/google/refine/operations/row/RowRemovalOperation.java +++ b/main/src/com/google/refine/operations/row/RowRemovalOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.row; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.google.refine.browsing.Engine; import com.google.refine.browsing.EngineConfig; @@ -51,7 +48,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Row; import com.google.refine.model.changes.RowRemovalChange; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; public class RowRemovalOperation extends EngineDependentOperation { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { @@ -66,17 +62,6 @@ public class RowRemovalOperation extends EngineDependentOperation { super(engineConfig); } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.endObject(); - } - @Override protected String getBriefDescription(Project project) { return "Remove rows"; diff --git a/main/src/com/google/refine/operations/row/RowReorderOperation.java b/main/src/com/google/refine/operations/row/RowReorderOperation.java index ee63cd799..340687732 100644 --- a/main/src/com/google/refine/operations/row/RowReorderOperation.java +++ b/main/src/com/google/refine/operations/row/RowReorderOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.row; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -53,7 +50,6 @@ import com.google.refine.model.Project; import com.google.refine.model.Record; import com.google.refine.model.Row; import com.google.refine.model.changes.RowReorderChange; -import com.google.refine.operations.OperationRegistry; import com.google.refine.sorting.SortingConfig; import com.google.refine.sorting.SortingRecordVisitor; import com.google.refine.sorting.SortingRowVisitor; @@ -74,18 +70,6 @@ public class RowReorderOperation extends AbstractOperation { _mode = mode; _sorting = sorting; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("mode"); writer.value(Engine.modeToString(_mode)); - writer.key("sorting"); _sorting.write(writer, options); - writer.endObject(); - } @JsonProperty("mode") public Mode getMode() { diff --git a/main/src/com/google/refine/operations/row/RowStarOperation.java b/main/src/com/google/refine/operations/row/RowStarOperation.java index 5508449b1..d7be153b4 100644 --- a/main/src/com/google/refine/operations/row/RowStarOperation.java +++ b/main/src/com/google/refine/operations/row/RowStarOperation.java @@ -35,11 +35,8 @@ package com.google.refine.operations.row; import java.util.ArrayList; import java.util.List; -import java.util.Properties; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; @@ -55,7 +52,6 @@ import com.google.refine.model.Row; import com.google.refine.model.changes.MassChange; import com.google.refine.model.changes.RowStarChange; import com.google.refine.operations.EngineDependentOperation; -import com.google.refine.operations.OperationRegistry; public class RowStarOperation extends EngineDependentOperation { final protected boolean _starred; @@ -74,18 +70,6 @@ public class RowStarOperation extends EngineDependentOperation { super(engineConfig); _starred = starred; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); - writer.key("description"); writer.value(getBriefDescription(null)); - writer.key("engineConfig"); getEngineConfig().write(writer, options); - writer.key("starred"); writer.value(_starred); - writer.endObject(); - } @JsonProperty("starred") public boolean getStarred() { diff --git a/main/src/com/google/refine/preference/PreferenceStore.java b/main/src/com/google/refine/preference/PreferenceStore.java index 7358ad9d1..3e64a4a77 100644 --- a/main/src/com/google/refine/preference/PreferenceStore.java +++ b/main/src/com/google/refine/preference/PreferenceStore.java @@ -38,25 +38,22 @@ import java.lang.reflect.Method; import java.util.HashMap; import java.util.Iterator; import java.util.Map; -import java.util.Properties; import java.util.Set; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.RefineServlet; -public class PreferenceStore implements Jsonizable { +public class PreferenceStore { public static final String USER_METADATA_KEY = "userMetadata"; // use to populate "creator" filed in metadata. https://github.com/OpenRefine/OpenRefine/issues/1393 @@ -101,28 +98,6 @@ public class PreferenceStore implements Jsonizable { return _prefs.keySet(); } - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - - writer.key("entries"); - writer.object(); - for (String k : _prefs.keySet()) { - writer.key(k); - - Object o = _prefs.get(k); - if (o instanceof Jsonizable) { - ((Jsonizable) o).write(writer, options); - } else { - writer.value(o); - } - } - writer.endObject(); - - writer.endObject(); - dirty = false; - } - /** * @return true if the preference store has unsaved changes */ diff --git a/main/src/com/google/refine/preference/TopList.java b/main/src/com/google/refine/preference/TopList.java index 846d579bd..79b9802f3 100644 --- a/main/src/com/google/refine/preference/TopList.java +++ b/main/src/com/google/refine/preference/TopList.java @@ -36,20 +36,17 @@ package com.google.refine.preference; import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.Properties; import org.apache.commons.collections.list.UnmodifiableList; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; -public class TopList implements Jsonizable, Iterable { +public class TopList implements Iterable { @JsonProperty("top") final protected int _top; @@ -82,21 +79,6 @@ public class TopList implements Jsonizable, Iterable { public String getClassName() { return this.getClass().getName(); } - - @Override - public void write(JSONWriter writer, Properties options) throws JSONException { - writer.object(); - writer.key("class"); writer.value(getClassName()); - - writer.key("top"); writer.value(_top); - writer.key("list"); - writer.array(); - for (String element : _list) { - writer.value(element); - } - writer.endArray(); - writer.endObject(); - } static public TopList load(JSONObject obj) throws JSONException { int top = obj.has("top") && !obj.isNull("top") ? obj.getInt("top") : 10; diff --git a/main/src/com/google/refine/process/LongRunningProcess.java b/main/src/com/google/refine/process/LongRunningProcess.java index 1e18949f4..b8e12c669 100644 --- a/main/src/com/google/refine/process/LongRunningProcess.java +++ b/main/src/com/google/refine/process/LongRunningProcess.java @@ -33,11 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.process; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; @@ -67,19 +62,6 @@ abstract public class LongRunningProcess extends Process { } } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(hashCode()); - writer.key("description"); writer.value(_description); - writer.key("immediate"); writer.value(false); - writer.key("status"); writer.value(getStatus()); - writer.key("progress"); writer.value(_progress); - writer.endObject(); - } - @JsonProperty("status") public String getStatus() { return _thread == null ? "pending" : (_thread.isAlive() ? "running" : "done"); diff --git a/main/src/com/google/refine/process/Process.java b/main/src/com/google/refine/process/Process.java index 8b42bab71..21af244fa 100644 --- a/main/src/com/google/refine/process/Process.java +++ b/main/src/com/google/refine/process/Process.java @@ -36,10 +36,9 @@ package com.google.refine.process; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.history.HistoryEntry; -public abstract class Process implements Jsonizable { +public abstract class Process { @JsonProperty("immediate") abstract public boolean isImmediate(); diff --git a/main/src/com/google/refine/process/ProcessManager.java b/main/src/com/google/refine/process/ProcessManager.java index 6d22177fb..3f5a48283 100644 --- a/main/src/com/google/refine/process/ProcessManager.java +++ b/main/src/com/google/refine/process/ProcessManager.java @@ -36,22 +36,17 @@ package com.google.refine.process; import java.util.Collections; import java.util.LinkedList; import java.util.List; -import java.util.Properties; import java.util.stream.Collectors; -import org.json.JSONException; -import org.json.JSONWriter; - -import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.history.HistoryEntry; import com.google.refine.history.HistoryProcess; -public class ProcessManager implements Jsonizable { +public class ProcessManager { @JsonProperty("processes") protected List _processes = Collections.synchronizedList(new LinkedList()); @JsonIgnore @@ -69,32 +64,6 @@ public class ProcessManager implements Jsonizable { } - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("processes"); writer.array(); - synchronized (_processes) { - for (Process p : _processes) { - p.write(writer, options); - } - } - writer.endArray(); - - if (_latestExceptions != null) { - writer.key("exceptions"); writer.array(); - for (Exception e : _latestExceptions) { - writer.object(); - writer.key("message"); writer.value(e.getLocalizedMessage()); - writer.endObject(); - } - writer.endArray(); - } - - writer.endObject(); - } - @JsonProperty("exceptions") @JsonInclude(Include.NON_NULL) public List getJsonExceptions() { diff --git a/main/src/com/google/refine/process/QuickHistoryEntryProcess.java b/main/src/com/google/refine/process/QuickHistoryEntryProcess.java index 9d9c51726..7f16f68e4 100644 --- a/main/src/com/google/refine/process/QuickHistoryEntryProcess.java +++ b/main/src/com/google/refine/process/QuickHistoryEntryProcess.java @@ -33,11 +33,6 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.process; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; - import com.fasterxml.jackson.annotation.JsonProperty; import com.google.refine.history.HistoryEntry; @@ -85,18 +80,6 @@ abstract public class QuickHistoryEntryProcess extends Process { public void startPerforming(ProcessManager manager) { throw new RuntimeException("Not a long-running process"); } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("id"); writer.value(hashCode()); - writer.key("description"); writer.value(getDescription()); - writer.key("immediate"); writer.value(true); - writer.key("status"); writer.value(getStatus()); - writer.endObject(); - } @JsonProperty("status") public String getStatus() { diff --git a/main/src/com/google/refine/sorting/Criterion.java b/main/src/com/google/refine/sorting/Criterion.java index e19b69dd6..4cae65d14 100644 --- a/main/src/com/google/refine/sorting/Criterion.java +++ b/main/src/com/google/refine/sorting/Criterion.java @@ -33,22 +33,18 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.sorting; -import java.util.Properties; - import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.expr.ExpressionUtils; import com.google.refine.model.Column; import com.google.refine.model.Project; import com.google.refine.model.Record; import com.google.refine.model.Row; -abstract public class Criterion implements Jsonizable { +abstract public class Criterion { public String columnName; protected int cellIndex = -2; @@ -99,19 +95,6 @@ abstract public class Criterion implements Jsonizable { return c; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("valueType"); writer.value(getValueType()); - writer.key("reverse"); writer.value(getReverse()); - writer.key("column"); writer.value(getColumnName()); - writer.key("blankPosition"); writer.value(getBlankPosition()); - writer.key("errorPosition"); writer.value(getErrorPosition()); - writer.endObject(); - } - @JsonProperty("valueType") public abstract String getValueType(); diff --git a/main/src/com/google/refine/sorting/DateCriterion.java b/main/src/com/google/refine/sorting/DateCriterion.java index 161abb2f0..363888b4e 100644 --- a/main/src/com/google/refine/sorting/DateCriterion.java +++ b/main/src/com/google/refine/sorting/DateCriterion.java @@ -35,10 +35,6 @@ package com.google.refine.sorting; import java.time.Instant; import java.time.OffsetDateTime; -import java.util.Properties; - -import org.json.JSONException; -import org.json.JSONWriter; import com.google.refine.expr.EvalError; import com.google.refine.expr.ExpressionUtils; diff --git a/main/src/com/google/refine/sorting/SortingConfig.java b/main/src/com/google/refine/sorting/SortingConfig.java index cc96ee85e..a1c342d92 100644 --- a/main/src/com/google/refine/sorting/SortingConfig.java +++ b/main/src/com/google/refine/sorting/SortingConfig.java @@ -1,23 +1,18 @@ package com.google.refine.sorting; -import java.util.Properties; - import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; -import org.json.JSONWriter; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; /** * Stores the configuration of a row/record sorting setup. * @author Antonin Delpeuch * */ -public final class SortingConfig implements Jsonizable { +public final class SortingConfig { protected Criterion[] _criteria; @@ -32,19 +27,6 @@ public final class SortingConfig implements Jsonizable { public Criterion[] getCriteria() { return _criteria; } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - writer.object(); - writer.key("criteria"); - writer.array(); - for (int i = 0; i != _criteria.length; i++) { - _criteria[i].write(writer, options); - } - writer.endArray(); - writer.endObject(); - } public static SortingConfig reconstruct(JSONObject obj) { Criterion[] criteria; diff --git a/main/src/com/google/refine/util/JSONUtilities.java b/main/src/com/google/refine/util/JSONUtilities.java index db88eeb79..925adcc1a 100644 --- a/main/src/com/google/refine/util/JSONUtilities.java +++ b/main/src/com/google/refine/util/JSONUtilities.java @@ -33,25 +33,21 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. package com.google.refine.util; -import java.io.StringWriter; -import java.io.Writer; import java.time.LocalDateTime; -import java.time.ZoneId; import java.time.OffsetDateTime; +import java.time.ZoneId; import java.util.ArrayList; import java.util.Arrays; import java.util.Calendar; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Properties; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.JSONWriter; -import com.google.refine.Jsonizable; public class JSONUtilities { static public JSONObject getObject(JSONObject obj, String key) { @@ -376,16 +372,4 @@ public class JSONUtilities { destArray.put(srcArray.get(i)); } } - - static public String serialize(Jsonizable obj, Properties options) { - Writer w = new StringWriter(); - JSONWriter jsonWriter = new JSONWriter(w); - obj.write(jsonWriter, options); - return w.toString(); - } - - static public String serialize(Jsonizable obj) { - Properties options = new Properties(); - return serialize(obj, options); - } } diff --git a/main/src/com/google/refine/util/ParsingUtilities.java b/main/src/com/google/refine/util/ParsingUtilities.java index e067a26fd..6b906ce17 100644 --- a/main/src/com/google/refine/util/ParsingUtilities.java +++ b/main/src/com/google/refine/util/ParsingUtilities.java @@ -61,6 +61,8 @@ import org.json.JSONTokener; import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; import com.fasterxml.jackson.annotation.PropertyAccessor; +import com.fasterxml.jackson.core.JsonFactory; +import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; @@ -69,13 +71,18 @@ import com.fasterxml.jackson.databind.ser.FilterProvider; import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider; public class ParsingUtilities { - - public static final ObjectMapper mapper = new ObjectMapper(); + public static JsonFactory jsonFactory = new JsonFactory(); + static { + jsonFactory.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false); + } + public static final ObjectMapper mapper = new ObjectMapper(jsonFactory); static { SimpleModule module = new SimpleModule(); module.addSerializer(Double.class, new SerializationFilters.DoubleSerializer()); module.addSerializer(double.class, new SerializationFilters.DoubleSerializer()); module.addSerializer(OffsetDateTime.class, new SerializationFilters.DateSerializer()); + + mapper.registerModule(module); mapper.setVisibility(PropertyAccessor.ALL, Visibility.NONE); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); diff --git a/main/src/com/google/refine/util/Pool.java b/main/src/com/google/refine/util/Pool.java index 941d01388..0ac44ab0e 100644 --- a/main/src/com/google/refine/util/Pool.java +++ b/main/src/com/google/refine/util/Pool.java @@ -44,13 +44,9 @@ import java.io.Writer; import java.util.Collection; import java.util.HashMap; import java.util.Map; -import java.util.Map.Entry; -import java.util.Properties; -import org.json.JSONException; -import org.json.JSONWriter; +import com.fasterxml.jackson.annotation.JsonProperty; -import com.google.refine.Jsonizable; import com.google.refine.RefineServlet; import com.google.refine.model.Recon; import com.google.refine.model.ReconCandidate; @@ -59,7 +55,8 @@ import com.google.refine.model.ReconCandidate; * A serializable pool of ReconCandidates indexed by ID. * */ -public class Pool implements Jsonizable { +public class Pool { + @JsonProperty("recons") final protected Map recons = new HashMap(); // This is only for backward compatibility while loading old project files @@ -104,23 +101,12 @@ public class Pool implements Jsonizable { public void save(Writer writer) throws IOException { writer.write(RefineServlet.VERSION); writer.write('\n'); - - Properties options = new Properties(); - options.setProperty("mode", "save"); - options.put("pool", this); Collection recons2 = recons.values(); writer.write("reconCount=" + recons2.size()); writer.write('\n'); for (Recon recon : recons2) { - JSONWriter jsonWriter = new JSONWriter(writer); - try { - recon.write(jsonWriter, options); - - writer.write('\n'); - } catch (JSONException e) { - e.printStackTrace(); - } + ParsingUtilities.saveWriter.writeValue(writer, recon); } } @@ -167,19 +153,4 @@ public class Pool implements Jsonizable { } } } - - @Override - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("recons"); - writer.object(); - for (Entry entry : recons.entrySet()) { - writer.key(entry.getKey().toString()); - entry.getValue().write(writer, options); - } - writer.endObject(); - writer.endObject(); - } } diff --git a/main/tests/server/src/com/google/refine/tests/model/CellTests.java b/main/tests/server/src/com/google/refine/tests/model/CellTests.java index cab82c55d..1083cb772 100644 --- a/main/tests/server/src/com/google/refine/tests/model/CellTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/CellTests.java @@ -36,11 +36,8 @@ public class CellTests { when(pool.getRecon("1533649346002675326")).thenReturn(recon); String json = "{\"v\":\"http://www.wikidata.org/entity/Q41522540\",\"r\":\"1533649346002675326\"}"; - Properties options = mock(Properties.class); - when(options.get("pool")).thenReturn(pool); Cell c = Cell.loadStreaming(json, pool); - TestUtils.isSerializedTo(c, json, options); - verify(pool, times(1)).pool(recon); + TestUtils.isSerializedTo(c, json); } @Test diff --git a/main/tests/server/src/com/google/refine/tests/model/RowTests.java b/main/tests/server/src/com/google/refine/tests/model/RowTests.java index 6d36f4838..5241be71e 100644 --- a/main/tests/server/src/com/google/refine/tests/model/RowTests.java +++ b/main/tests/server/src/com/google/refine/tests/model/RowTests.java @@ -111,7 +111,8 @@ public class RowTests extends RefineTest { "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}]}"); } - @Test + // This way of serializing a row with indices is now deprecated, see GetRowsCommand. + @Test(expectedExceptions=IllegalArgumentException.class) public void saveRowWithRecordIndex() { Row row = new Row(5); row.setCell(0, new Cell("I'm not empty", null)); @@ -120,9 +121,6 @@ public class RowTests extends RefineTest { when(options.containsKey("recordIndex")).thenReturn(true); when(options.get("recordIndex")).thenReturn(1); row.save(writer, options); - TestUtils.assertEqualAsJson( - writer.getBuffer().toString(), - "{\"flagged\":false,\"starred\":false,\"cells\":[{\"v\":\"I'm not empty\"}],\"i\":0,\"j\":1}"); } @Test @@ -150,8 +148,7 @@ public class RowTests extends RefineTest { + " {\"v\":\"\"}" + "]}"; Row row = Row.load(json, pool); - when(options.get("pool")).thenReturn(pool); - TestUtils.isSerializedTo(row, json, options); + TestUtils.isSerializedTo(row, json); } @Test diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java index 528656da4..02df8cfb5 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ExtendDataOperationTests.java @@ -119,7 +119,7 @@ public class ExtendDataOperationTests extends RefineTest { super(obj, endpoint); } - public String formulateQueryStub(Set ids, DataExtensionConfig node) throws JSONException { + public String formulateQueryStub(Set ids, DataExtensionConfig node) throws IOException { StringWriter writer = new StringWriter(); super.formulateQuery(ids, node, writer); return writer.toString(); @@ -181,7 +181,7 @@ public class ExtendDataOperationTests extends RefineTest { } @Test - public void testFormulateQuery() { + public void testFormulateQuery() throws IOException { DataExtensionConfig config = DataExtensionConfig.reconstruct(new JSONObject(dataExtensionConfigJson)); Set ids = Collections.singleton("Q2"); String json = "{\"ids\":[\"Q2\"],\"properties\":[{\"id\":\"P571\"},{\"id\":\"P159\"},{\"id\":\"P625\"}]}"; diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java index 4662cd016..76cf1e39e 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsOperationTests.java @@ -2,7 +2,9 @@ package com.google.refine.tests.operations.recon; import org.json.JSONObject; import org.testng.annotations.BeforeSuite; import org.testng.annotations.Test; +import static org.mockito.Mockito.mock; +import com.google.refine.model.Project; import com.google.refine.operations.OperationRegistry; import com.google.refine.operations.recon.ReconJudgeSimilarCellsOperation; import com.google.refine.tests.RefineTest; @@ -24,6 +26,6 @@ public class ReconJudgeSimilarCellsOperationTests extends RefineTest { + "\"judgment\":\"matched\"," + "\"match\":{\"id\":\"Q7884717\",\"name\":\"Unicef Indonesia\",\"score\":71.42857142857143,\"types\":[\"Q43229\"]}," + "\"shareNewTopics\":false}"; - TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(new JSONObject(json)), json); + TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(mock(Project.class), new JSONObject(json)), json); } } diff --git a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java index 413797e7f..79075a6fa 100644 --- a/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java +++ b/main/tests/server/src/com/google/refine/tests/operations/recon/ReconJudgeSimilarCellsTests.java @@ -2,6 +2,7 @@ package com.google.refine.tests.operations.recon; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import static org.mockito.Mockito.mock; import java.util.Collections; import java.util.Properties; @@ -46,7 +47,7 @@ public class ReconJudgeSimilarCellsTests extends RefineTest { + "\"similarValue\":\"foo\"," + "\"judgment\":\"new\"," + "\"shareNewTopics\":true}"; - TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(new JSONObject(json)), json); + TestUtils.isSerializedTo(ReconJudgeSimilarCellsOperation.reconstruct(mock(Project.class), new JSONObject(json)), json); } @Test diff --git a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java index 26e5b8f47..7cd3d0a2d 100644 --- a/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java +++ b/main/tests/server/src/com/google/refine/tests/process/ProcessManagerTests.java @@ -6,7 +6,7 @@ import org.testng.annotations.Test; import com.google.refine.process.Process; import com.google.refine.process.ProcessManager; import com.google.refine.tests.util.TestUtils; -import com.google.refine.util.JSONUtilities; +import com.google.refine.util.ParsingUtilities; public class ProcessManagerTests { @@ -25,7 +25,7 @@ public class ProcessManagerTests { processManager.queueProcess(process1); processManager.queueProcess(process2); processManager.onFailedProcess(process1, new IllegalArgumentException("unexpected error")); - String processJson = JSONUtilities.serialize(process2); + String processJson = ParsingUtilities.defaultWriter.writeValueAsString(process2); TestUtils.isSerializedTo(processManager, "{" + "\"processes\":["+processJson+"],\n" + "\"exceptions\":[{\"message\":\"unexpected error\"}]" diff --git a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java index 68f51e3fd..f35f20184 100644 --- a/main/tests/server/src/com/google/refine/tests/util/TestUtils.java +++ b/main/tests/server/src/com/google/refine/tests/util/TestUtils.java @@ -8,7 +8,6 @@ import java.io.IOException; import java.io.LineNumberReader; import java.io.StringReader; import java.io.StringWriter; -import java.util.Properties; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonProcessingException; @@ -19,8 +18,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectWriter; import com.fasterxml.jackson.databind.SerializationFeature; -import com.google.refine.Jsonizable; -import com.google.refine.util.JSONUtilities; import com.google.refine.util.ParsingUtilities; @@ -54,6 +51,9 @@ public class TestUtils { try { JsonNode jsonA = mapper.readValue(expected, JsonNode.class); JsonNode jsonB = mapper.readValue(actual, JsonNode.class); + if (!jsonA.equals(jsonB)) { + jsonDiff(expected, actual); + } assertEquals(jsonA, jsonB); } catch(Exception e) { fail("\""+expected+"\" and \""+actual+"\" are not equal as JSON strings."); @@ -74,24 +74,12 @@ public class TestUtils { * Checks that a serializable object is serialized to the target JSON string. * @throws IOException */ - public static void isSerializedTo(Jsonizable o, String targetJson, Properties options) { - String orgJson = JSONUtilities.serialize(o, options); - if(!equalAsJson(targetJson, orgJson)) { - System.out.println("org.json, "+o.getClass().getName()); - try { - jsonDiff(targetJson, orgJson); - } catch (JsonParseException | JsonMappingException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - assertEqualAsJson(targetJson, orgJson); - + public static void isSerializedTo(Object o, String targetJson, boolean saveMode) { + // also check Jackson serialization try { - String saveMode = options.getProperty("mode"); ObjectWriter writer = null; - if("save".equals(saveMode)) { + if(saveMode) { writer = ParsingUtilities.saveWriter; } else { writer = ParsingUtilities.defaultWriter; @@ -111,22 +99,8 @@ public class TestUtils { /** * Checks that a serializable object is serialized to the target JSON string. */ - public static void isSerializedTo(Jsonizable o, String targetJson) { - isSerializedTo(o, targetJson, new Properties()); - } - - /** - * Checks that a serializable object is serialized to the target JSON string. - * This specifies the "save mode" for objects that are stored differently depending on - * whether they are written to disk or sent over the network. - */ - public static void isSerializedTo(Jsonizable o, String targetJson, boolean saveMode) { - Properties options = new Properties(); - if(saveMode) { - options.setProperty("mode", "save"); - options.put("mode", "save"); - } - isSerializedTo(o, targetJson, options); + public static void isSerializedTo(Object o, String targetJson) { + isSerializedTo(o, targetJson, false); } public static void jsonDiff(String a, String b) throws JsonParseException, JsonMappingException {