diff --git a/src/main/java/com/metaweb/gridworks/GridworksServlet.java b/src/main/java/com/metaweb/gridworks/GridworksServlet.java index 44157887f..d2308ebf7 100644 --- a/src/main/java/com/metaweb/gridworks/GridworksServlet.java +++ b/src/main/java/com/metaweb/gridworks/GridworksServlet.java @@ -33,12 +33,12 @@ import com.metaweb.gridworks.commands.info.GetOperationsCommand; import com.metaweb.gridworks.commands.info.GetProcessesCommand; import com.metaweb.gridworks.commands.info.GetProjectMetadataCommand; import com.metaweb.gridworks.commands.info.GetRowsCommand; -import com.metaweb.gridworks.commands.recon.ApproveNewReconcileCommand; -import com.metaweb.gridworks.commands.recon.ApproveReconcileCommand; -import com.metaweb.gridworks.commands.recon.DiscardReconcileCommand; -import com.metaweb.gridworks.commands.recon.JudgeOneCellCommand; -import com.metaweb.gridworks.commands.recon.JudgeSimilarCellsCommand; -import com.metaweb.gridworks.commands.recon.MatchSpecificTopicCommand; +import com.metaweb.gridworks.commands.recon.ReconMarkNewTopicsCommand; +import com.metaweb.gridworks.commands.recon.ReconMatchBestCandidatesCommand; +import com.metaweb.gridworks.commands.recon.ReconDiscardJudgmentsCommand; +import com.metaweb.gridworks.commands.recon.ReconJudgeOneCellCommand; +import com.metaweb.gridworks.commands.recon.ReconJudgeSimilarCellsCommand; +import com.metaweb.gridworks.commands.recon.ReconMatchSpecificTopicCommand; import com.metaweb.gridworks.commands.recon.ReconcileCommand; import com.metaweb.gridworks.commands.util.GetExpressionLanguageInfoCommand; import com.metaweb.gridworks.commands.util.GuessTypesOfColumnCommand; @@ -75,12 +75,12 @@ public class GridworksServlet extends HttpServlet { _commands.put("split-multi-value-cells", new SplitMultiValueCellsCommand()); _commands.put("reconcile", new ReconcileCommand()); - _commands.put("recon-match-best-candidates", new ApproveReconcileCommand()); - _commands.put("recon-mark-new-topics", new ApproveNewReconcileCommand()); - _commands.put("recon-discard-judgments", new DiscardReconcileCommand()); - _commands.put("recon-match-specific-topic-to-cells", new MatchSpecificTopicCommand()); - _commands.put("recon-judge-one-cell", new JudgeOneCellCommand()); - _commands.put("recon-judge-similar-cells", new JudgeSimilarCellsCommand()); + _commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand()); + _commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand()); + _commands.put("recon-discard-judgments", new ReconDiscardJudgmentsCommand()); + _commands.put("recon-match-specific-topic-to-cells", new ReconMatchSpecificTopicCommand()); + _commands.put("recon-judge-one-cell", new ReconJudgeOneCellCommand()); + _commands.put("recon-judge-similar-cells", new ReconJudgeSimilarCellsCommand()); _commands.put("save-protograph", new SaveProtographCommand()); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java index 3e667b55f..90e39c450 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/ApplyOperationsCommand.java @@ -1,6 +1,7 @@ package com.metaweb.gridworks.commands.edit; -import java.io.IOException; + import java.io.IOException; +import java.lang.reflect.Method; import java.util.Properties; import javax.servlet.ServletException; @@ -14,18 +15,8 @@ import org.json.JSONObject; import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.operations.ApproveNewReconOperation; -import com.metaweb.gridworks.model.operations.ApproveReconOperation; -import com.metaweb.gridworks.model.operations.ColumnAdditionOperation; -import com.metaweb.gridworks.model.operations.ColumnRemovalOperation; -import com.metaweb.gridworks.model.operations.DiscardReconOperation; -import com.metaweb.gridworks.model.operations.MultiValueCellJoinOperation; -import com.metaweb.gridworks.model.operations.MultiValueCellSplitOperation; -import com.metaweb.gridworks.model.operations.ReconOperation; -import com.metaweb.gridworks.model.operations.SaveProtographOperation; -import com.metaweb.gridworks.model.operations.TextTransformOperation; +import com.metaweb.gridworks.model.operations.OperationRegistry; import com.metaweb.gridworks.process.Process; -import com.metaweb.gridworks.protograph.Protograph; public class ApplyOperationsCommand extends Command { @@ -53,66 +44,23 @@ public class ApplyOperationsCommand extends Command { protected void reconstructOperation(Project project, JSONObject obj) { try { String op = obj.getString("op"); - AbstractOperation operation = null; - JSONObject engineConfig = obj.has("engineConfig") ? obj.getJSONObject("engineConfig") : null; - String columnName = obj.has("columnName") ? obj.getString("columnName") : null; - - if ("approve-new-recon".equals(op)) { - operation = new ApproveNewReconOperation(engineConfig, columnName); - } else if ("approve-recon".equals(op)) { - operation = new ApproveReconOperation(engineConfig, columnName); - } else if ("add-column".equals(op)) { - operation = new ColumnAdditionOperation( - engineConfig, - obj.getString("baseColumnName"), - obj.getString("expression"), - obj.getString("headerLabel"), - obj.getInt("columnInsertIndex") - ); - } else if ("remove-column".equals(op)) { - operation = new ColumnRemovalOperation(columnName); - } else if ("discard-recon".equals(op)) { - operation = new DiscardReconOperation(engineConfig, columnName); - } else if ("join-multivalued-cells".equals(op)) { - operation = new MultiValueCellJoinOperation( - columnName, - obj.getString("keyColumnName"), - obj.getString("separator") - ); - } else if ("split-multivalued-cells".equals(op)) { - operation = new MultiValueCellSplitOperation( - columnName, - obj.getString("keyColumnName"), - obj.getString("separator"), - obj.getString("mode") - ); - } else if ("recon".equals(op)) { - operation = new ReconOperation( - engineConfig, - columnName, - obj.getString("typeID"), - obj.getString("typeName"), - obj.getBoolean("autoMatch"), - obj.getDouble("minScore") - ); - } else if ("save-protograph".equals(op)) { - operation = new SaveProtographOperation( - Protograph.reconstruct(obj.getJSONObject("protograph")) - ); - } else if ("text-transform".equals(op)) { - operation = new TextTransformOperation( - engineConfig, - columnName, - obj.getString("expression") - ); + Class klass = OperationRegistry.s_opNameToClass.get(op); + if (klass == null) { + return; } - if (operation != null) { - Process process = operation.createProcess(project, new Properties()); - - project.processManager.queueProcess(process); + Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class); + if (reconstruct == null) { + return; } + + AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj); + if (operation != null) { + Process process = operation.createProcess(project, new Properties()); + + project.processManager.queueProcess(process); + } } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java index 7489a8398..316fde289 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/JoinMultiValueCellsCommand.java @@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletResponse; import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.operations.MultiValueCellJoinOperation; +import com.metaweb.gridworks.model.operations.MultiValuedCellJoinOperation; import com.metaweb.gridworks.process.Process; public class JoinMultiValueCellsCommand extends Command { @@ -25,7 +25,7 @@ public class JoinMultiValueCellsCommand extends Command { String keyColumnName = request.getParameter("keyColumnName"); String separator = request.getParameter("separator"); - AbstractOperation op = new MultiValueCellJoinOperation(columnName, keyColumnName, separator); + AbstractOperation op = new MultiValuedCellJoinOperation(columnName, keyColumnName, separator); Process process = op.createProcess(project, new Properties()); boolean done = project.processManager.queueProcess(process); diff --git a/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java b/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java index 0f14f33ee..3ac34b72d 100644 --- a/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/edit/SplitMultiValueCellsCommand.java @@ -10,7 +10,7 @@ import javax.servlet.http.HttpServletResponse; import com.metaweb.gridworks.commands.Command; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Project; -import com.metaweb.gridworks.model.operations.MultiValueCellSplitOperation; +import com.metaweb.gridworks.model.operations.MultiValuedCellSplitOperation; import com.metaweb.gridworks.process.Process; public class SplitMultiValueCellsCommand extends Command { @@ -26,7 +26,7 @@ public class SplitMultiValueCellsCommand extends Command { String separator = request.getParameter("separator"); String mode = request.getParameter("mode"); - AbstractOperation op = new MultiValueCellSplitOperation(columnName, keyColumnName, separator, mode); + AbstractOperation op = new MultiValuedCellSplitOperation(columnName, keyColumnName, separator, mode); Process process = op.createProcess(project, new Properties()); boolean done = project.processManager.queueProcess(process); diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconDiscardJudgmentsCommand.java similarity index 64% rename from src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconDiscardJudgmentsCommand.java index 9c0c6f62f..8a591c5ef 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconDiscardJudgmentsCommand.java @@ -6,16 +6,15 @@ import org.json.JSONObject; import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; -import com.metaweb.gridworks.model.operations.ApproveReconOperation; +import com.metaweb.gridworks.model.operations.ReconDiscardJudgmentsOperation; -public class ApproveReconcileCommand extends EngineDependentCommand { - +public class ReconDiscardJudgmentsCommand extends EngineDependentCommand { @Override protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { String columnName = request.getParameter("columnName"); - return new ApproveReconOperation(engineConfig, columnName); + return new ReconDiscardJudgmentsOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/JudgeOneCellCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeOneCellCommand.java similarity index 95% rename from src/main/java/com/metaweb/gridworks/commands/recon/JudgeOneCellCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeOneCellCommand.java index 4c622fef2..25d67990c 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/JudgeOneCellCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeOneCellCommand.java @@ -21,7 +21,7 @@ import com.metaweb.gridworks.model.ReconCandidate; import com.metaweb.gridworks.model.changes.CellChange; import com.metaweb.gridworks.process.QuickHistoryEntryProcess; -public class JudgeOneCellCommand extends Command { +public class ReconJudgeOneCellCommand extends Command { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/JudgeSimilarCellsCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeSimilarCellsCommand.java similarity index 96% rename from src/main/java/com/metaweb/gridworks/commands/recon/JudgeSimilarCellsCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeSimilarCellsCommand.java index 89bb3d62a..ac949ed9d 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/JudgeSimilarCellsCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconJudgeSimilarCellsCommand.java @@ -26,7 +26,7 @@ import com.metaweb.gridworks.model.changes.CellChange; import com.metaweb.gridworks.model.changes.MassCellChange; import com.metaweb.gridworks.process.QuickHistoryEntryProcess; -public class JudgeSimilarCellsCommand extends Command { +public class ReconJudgeSimilarCellsCommand extends Command { @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMarkNewTopicsCommand.java similarity index 65% rename from src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconMarkNewTopicsCommand.java index 80dc0bee6..78be6eece 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/ApproveNewReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMarkNewTopicsCommand.java @@ -6,9 +6,9 @@ import org.json.JSONObject; import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; -import com.metaweb.gridworks.model.operations.ApproveNewReconOperation; +import com.metaweb.gridworks.model.operations.ReconMarkNewTopicsOperation; -public class ApproveNewReconcileCommand extends EngineDependentCommand { +public class ReconMarkNewTopicsCommand extends EngineDependentCommand { @Override protected AbstractOperation createOperation(HttpServletRequest request, @@ -16,6 +16,6 @@ public class ApproveNewReconcileCommand extends EngineDependentCommand { String columnName = request.getParameter("columnName"); - return new ApproveNewReconOperation(engineConfig, columnName); + return new ReconMarkNewTopicsOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchBestCandidatesCommand.java similarity index 63% rename from src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchBestCandidatesCommand.java index a4a0c7dbf..d292c051c 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/DiscardReconcileCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchBestCandidatesCommand.java @@ -6,15 +6,16 @@ import org.json.JSONObject; import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; -import com.metaweb.gridworks.model.operations.DiscardReconOperation; +import com.metaweb.gridworks.model.operations.ReconMatchBestCandidatesOperation; -public class DiscardReconcileCommand extends EngineDependentCommand { +public class ReconMatchBestCandidatesCommand extends EngineDependentCommand { + @Override protected AbstractOperation createOperation(HttpServletRequest request, JSONObject engineConfig) throws Exception { String columnName = request.getParameter("columnName"); - return new DiscardReconOperation(engineConfig, columnName); + return new ReconMatchBestCandidatesOperation(engineConfig, columnName); } } diff --git a/src/main/java/com/metaweb/gridworks/commands/recon/MatchSpecificTopicCommand.java b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchSpecificTopicCommand.java similarity index 74% rename from src/main/java/com/metaweb/gridworks/commands/recon/MatchSpecificTopicCommand.java rename to src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchSpecificTopicCommand.java index 19cf23c4f..e2bc7aaa4 100644 --- a/src/main/java/com/metaweb/gridworks/commands/recon/MatchSpecificTopicCommand.java +++ b/src/main/java/com/metaweb/gridworks/commands/recon/ReconMatchSpecificTopicCommand.java @@ -7,9 +7,9 @@ import org.json.JSONObject; import com.metaweb.gridworks.commands.EngineDependentCommand; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.ReconCandidate; -import com.metaweb.gridworks.model.operations.MatchSpecificTopicReconOperation; +import com.metaweb.gridworks.model.operations.ReconMatchSpecificTopicOperation; -public class MatchSpecificTopicCommand extends EngineDependentCommand { +public class ReconMatchSpecificTopicCommand extends EngineDependentCommand { @Override protected AbstractOperation createOperation(HttpServletRequest request, @@ -24,6 +24,6 @@ public class MatchSpecificTopicCommand extends EngineDependentCommand { 100 ); - return new MatchSpecificTopicReconOperation(engineConfig, columnName, match); + return new ReconMatchSpecificTopicOperation(engineConfig, columnName, match); } } diff --git a/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java b/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java index fe07e6693..507cb859d 100644 --- a/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java +++ b/src/main/java/com/metaweb/gridworks/expr/OperatorCallExpr.java @@ -43,6 +43,46 @@ public class OperatorCallExpr implements Evaluable { return ((Number) args[0]).doubleValue() / ((Number) args[1]).doubleValue(); } } + } else if (">".equals(_op)) { + if (args.length == 2) { + if (args[0] instanceof Number && args[1] instanceof Number) { + return ((Number) args[0]).doubleValue() > ((Number) args[1]).doubleValue(); + } + } + } else if (">=".equals(_op)) { + if (args.length == 2) { + if (args[0] instanceof Number && args[1] instanceof Number) { + return ((Number) args[0]).doubleValue() >= ((Number) args[1]).doubleValue(); + } + } + } else if ("<".equals(_op)) { + if (args.length == 2) { + if (args[0] instanceof Number && args[1] instanceof Number) { + return ((Number) args[0]).doubleValue() < ((Number) args[1]).doubleValue(); + } + } + } else if ("<=".equals(_op)) { + if (args.length == 2) { + if (args[0] instanceof Number && args[1] instanceof Number) { + return ((Number) args[0]).doubleValue() <= ((Number) args[1]).doubleValue(); + } + } + } else if ("==".equals(_op)) { + if (args.length == 2) { + if (args[0] != null) { + return args[0].equals(args[1]); + } else { + return args[1] == null; + } + } + } else if ("!=".equals(_op)) { + if (args.length == 2) { + if (args[0] != null) { + return !args[0].equals(args[1]); + } else { + return args[1] != null; + } + } } return null; } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java index fab9b852d..e257d8313 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnAdditionOperation.java @@ -16,6 +16,7 @@ import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.Parser; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.history.HistoryEntry; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -32,6 +33,18 @@ public class ColumnAdditionOperation extends EngineDependentOperation { final protected String _headerLabel; final protected int _columnInsertIndex; + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + + return new ColumnAdditionOperation( + engineConfig, + obj.getString("baseColumnName"), + obj.getString("expression"), + obj.getString("headerLabel"), + obj.getInt("columnInsertIndex") + ); + } + public ColumnAdditionOperation( JSONObject engineConfig, String baseColumnName, @@ -48,38 +61,12 @@ public class ColumnAdditionOperation extends EngineDependentOperation { _columnInsertIndex = columnInsertIndex; } - protected HistoryEntry createHistoryEntry(Project project) throws Exception { - Engine engine = createEngine(project); - - Column column = project.columnModel.getColumnByName(_baseColumnName); - if (column == null) { - throw new Exception("No column named " + _baseColumnName); - } - - List cellsAtRows = new ArrayList(project.rows.size()); - - FilteredRows filteredRows = engine.getAllFilteredRows(false); - filteredRows.accept(project, createRowVisitor(project, cellsAtRows)); - - String description = createDescription(column, cellsAtRows); - - Change change = new ColumnAdditionChange(_headerLabel, _columnInsertIndex, cellsAtRows); - - return new HistoryEntry( - project, description, this, change); - } - public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); - writer.key("op"); writer.value("add-column"); - writer.key("description"); writer.value( - "Create column " + _headerLabel + - " at index " + _columnInsertIndex + - " based on column " + _baseColumnName + - " using expression " + _expression); - + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("headerLabel"); writer.value(_headerLabel); writer.key("columnInsertIndex"); writer.value(_columnInsertIndex); @@ -89,7 +76,10 @@ public class ColumnAdditionOperation extends EngineDependentOperation { } protected String getBriefDescription() { - return "Add in column " + _headerLabel + " based on column " + _baseColumnName; + return "Create column " + _headerLabel + + " at index " + _columnInsertIndex + + " based on column " + _baseColumnName + + " using expression " + _expression; } protected String createDescription(Column column, List cellsAtRows) { @@ -99,6 +89,27 @@ public class ColumnAdditionOperation extends EngineDependentOperation { " rows with " + _expression; } + protected HistoryEntry createHistoryEntry(Project project) throws Exception { + Engine engine = createEngine(project); + + Column column = project.columnModel.getColumnByName(_baseColumnName); + if (column == null) { + throw new Exception("No column named " + _baseColumnName); + } + + List cellsAtRows = new ArrayList(project.rows.size()); + + FilteredRows filteredRows = engine.getAllFilteredRows(false); + filteredRows.accept(project, createRowVisitor(project, cellsAtRows)); + + String description = createDescription(column, cellsAtRows); + + Change change = new ColumnAdditionChange(_headerLabel, _columnInsertIndex, cellsAtRows); + + return new HistoryEntry( + project, description, this, change); + } + protected RowVisitor createRowVisitor(Project project, List cellsAtRows) throws Exception { Column column = project.columnModel.getColumnByName(_baseColumnName); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java index 124ae33e2..b3cd8a43d 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ColumnRemovalOperation.java @@ -3,6 +3,7 @@ package com.metaweb.gridworks.model.operations; import java.util.Properties; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; import com.metaweb.gridworks.history.Change; @@ -17,11 +18,28 @@ public class ColumnRemovalOperation extends AbstractOperation { final protected String _columnName; + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + return new ColumnRemovalOperation( + obj.getString("columnName") + ); + } + public ColumnRemovalOperation( String columnName ) { _columnName = columnName; } + + 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(); + } + protected String getBriefDescription() { return "Remove column " + _columnName; @@ -39,14 +57,4 @@ public class ColumnRemovalOperation extends AbstractOperation { return new HistoryEntry(project, description, ColumnRemovalOperation.this, change); } - - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value("remove-column"); - writer.key("description"); writer.value("Remove column " + _columnName); - writer.key("columnName"); writer.value(_columnName); - writer.endObject(); - } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellJoinOperation.java similarity index 70% rename from src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellJoinOperation.java index b4c5ebab1..b697ed039 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellJoinOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellJoinOperation.java @@ -1,14 +1,14 @@ package com.metaweb.gridworks.model.operations; -import java.util.ArrayList; +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.metaweb.gridworks.expr.ExpressionUtils; -import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.history.HistoryEntry; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; @@ -17,14 +17,22 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.changes.MassRowChange; -public class MultiValueCellJoinOperation extends AbstractOperation { +public class MultiValuedCellJoinOperation extends AbstractOperation { private static final long serialVersionUID = 3134524625206033285L; final protected String _columnName; final protected String _keyColumnName; final protected String _separator; - public MultiValueCellJoinOperation( + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + return new MultiValuedCellJoinOperation( + obj.getString("columnName"), + obj.getString("keyColumnName"), + obj.getString("separator") + ); + } + + public MultiValuedCellJoinOperation( String columnName, String keyColumnName, String separator @@ -34,6 +42,18 @@ public class MultiValueCellJoinOperation extends AbstractOperation { _separator = separator; } + 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("columnName"); writer.value(_columnName); + writer.key("keyColumnName"); writer.value(_keyColumnName); + writer.key("separator"); writer.value(_separator); + writer.endObject(); + } + protected String getBriefDescription() { return "Join multi-valued cells in column " + _columnName; } @@ -99,22 +119,12 @@ public class MultiValueCellJoinOperation extends AbstractOperation { r = r2 - 1; // r will be incremented by the for loop anyway } - String description = "Join multi-valued cells in column " + column.getHeaderLabel(); - - Change change = new MassRowChange(newRows); - - return new HistoryEntry(project, description, this, change); + return new HistoryEntry( + project, + getBriefDescription(), + this, + new MassRowChange(newRows) + ); } - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value("join-multivalued-cells"); - writer.key("description"); writer.value("Join multi-valued cells in column " + _columnName); - writer.key("columnName"); writer.value(_columnName); - writer.key("keyColumnName"); writer.value(_keyColumnName); - writer.key("separator"); writer.value(_separator); - writer.endObject(); - } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellSplitOperation.java similarity index 71% rename from src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellSplitOperation.java index 95e72d72c..31a9e51cf 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MultiValueCellSplitOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/MultiValuedCellSplitOperation.java @@ -1,14 +1,14 @@ package com.metaweb.gridworks.model.operations; - import java.util.ArrayList; + import java.util.ArrayList; import java.util.List; import java.util.Properties; import org.apache.commons.lang.StringUtils; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; -import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.history.HistoryEntry; import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; @@ -17,7 +17,7 @@ import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.changes.MassRowChange; -public class MultiValueCellSplitOperation extends AbstractOperation { +public class MultiValuedCellSplitOperation extends AbstractOperation { private static final long serialVersionUID = 8217930220439070322L; final protected String _columnName; @@ -25,7 +25,16 @@ public class MultiValueCellSplitOperation extends AbstractOperation { final protected String _separator; final protected String _mode; - public MultiValueCellSplitOperation( + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + return new MultiValuedCellSplitOperation( + obj.getString("columnName"), + obj.getString("keyColumnName"), + obj.getString("separator"), + obj.getString("mode") + ); + } + + public MultiValuedCellSplitOperation( String columnName, String keyColumnName, String separator, @@ -37,6 +46,19 @@ public class MultiValueCellSplitOperation extends AbstractOperation { _mode = mode; } + 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("separator"); writer.value(_separator); + writer.key("mode"); writer.value(_mode); + writer.endObject(); + } + protected String getBriefDescription() { return "Split multi-valued cells in column " + _columnName; } @@ -115,23 +137,11 @@ public class MultiValueCellSplitOperation extends AbstractOperation { r = r2 - 1; // r will be incremented by the for loop anyway } - String description = "Split multi-valued cells in column " + column.getHeaderLabel(); - - Change change = new MassRowChange(newRows); - - return new HistoryEntry(project, description, this, change); - } - - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value("split-multivalued-cells"); - 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("separator"); writer.value(_separator); - writer.key("mode"); writer.value(_mode); - writer.endObject(); + return new HistoryEntry( + project, + getBriefDescription(), + this, + new MassRowChange(newRows) + ); } } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/OperationRegistry.java b/src/main/java/com/metaweb/gridworks/model/operations/OperationRegistry.java new file mode 100644 index 000000000..4958842aa --- /dev/null +++ b/src/main/java/com/metaweb/gridworks/model/operations/OperationRegistry.java @@ -0,0 +1,36 @@ +package com.metaweb.gridworks.model.operations; + +import java.util.HashMap; +import java.util.Map; + +import com.metaweb.gridworks.model.AbstractOperation; + +public abstract class OperationRegistry { + static public Map> s_opNameToClass; + static public Map, String> s_opClassToName; + + static protected void register(String name, Class klass) { + s_opNameToClass.put(name, klass); + s_opClassToName.put(klass, name); + } + + static { + s_opNameToClass = new HashMap>(); + s_opClassToName = new HashMap, String>(); + + register("recon", ReconOperation.class); + register("recon-mark-new-topics", ReconMarkNewTopicsOperation.class); + register("recon-match-best-candidates", ReconMatchBestCandidatesOperation.class); + register("recon-discard-judgments", ReconDiscardJudgmentsOperation.class); + register("recon-match-specific-topic-to-cells", ReconMatchSpecificTopicOperation.class); + + register("multivalued-cell-join", MultiValuedCellJoinOperation.class); + register("multivalued-cell-split", MultiValuedCellSplitOperation.class); + + register("column-addition", ColumnAdditionOperation.class); + register("column-removal", ColumnRemovalOperation.class); + + register("save-protograph", SaveProtographOperation.class); + register("text-transform", TextTransformOperation.class); + } +} diff --git a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconDiscardJudgmentsOperation.java similarity index 55% rename from src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/ReconDiscardJudgmentsOperation.java index bd5fb9dfb..139719b7a 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/DiscardReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconDiscardJudgmentsOperation.java @@ -8,16 +8,29 @@ import org.json.JSONObject; import org.json.JSONWriter; import com.metaweb.gridworks.browsing.RowVisitor; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; +import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Row; +import com.metaweb.gridworks.model.Recon.Judgment; import com.metaweb.gridworks.model.changes.CellChange; -public class DiscardReconOperation extends EngineDependentMassCellOperation { +public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 6799029731665369179L; - public DiscardReconOperation(JSONObject engineConfig, String columnName) { + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + String columnName = obj.getString("columnName"); + + return new ReconDiscardJudgmentsOperation( + engineConfig, + columnName + ); + } + + public ReconDiscardJudgmentsOperation(JSONObject engineConfig, String columnName) { super(engineConfig, columnName, false); } @@ -25,21 +38,21 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { throws JSONException { writer.object(); - writer.key("op"); writer.value("discard-recon"); - writer.key("description"); writer.value("Discard recon matches in column " + _columnName); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("columnName"); writer.value(_columnName); writer.endObject(); } protected String getBriefDescription() { - return "Discard recon results for cells in column " + _columnName; + return "Discard recon judgments for cells in column " + _columnName; } protected String createDescription(Column column, List cellChanges) { - return "Discard recon results for " + cellChanges.size() + + return "Discard recon judgments for " + cellChanges.size() + " cells in column " + column.getHeaderLabel(); } @@ -59,11 +72,15 @@ public class DiscardReconOperation extends EngineDependentMassCellOperation { public boolean visit(Project project, int rowIndex, Row row, boolean contextual) { if (cellIndex < row.cells.size()) { Cell cell = row.cells.get(cellIndex); - - Cell newCell = new Cell(cell.value, null); - - CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell); - cellChanges.add(cellChange); + if (cell.recon != null) { + Recon recon = cell.recon.dup(); + recon.judgment = Judgment.None; + + Cell newCell = new Cell(cell.value, recon); + + CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell); + cellChanges.add(cellChange); + } } return false; } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconMarkNewTopicsOperation.java similarity index 68% rename from src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/ReconMarkNewTopicsOperation.java index c97e7ba72..83501cf1a 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveNewReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconMarkNewTopicsOperation.java @@ -8,6 +8,7 @@ import org.json.JSONObject; import org.json.JSONWriter; import com.metaweb.gridworks.browsing.RowVisitor; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -16,10 +17,20 @@ import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Recon.Judgment; import com.metaweb.gridworks.model.changes.CellChange; -public class ApproveNewReconOperation extends EngineDependentMassCellOperation { +public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = -5205694623711144436L; + + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + String columnName = obj.getString("columnName"); + + return new ReconMarkNewTopicsOperation( + engineConfig, + columnName + ); + } - public ApproveNewReconOperation(JSONObject engineConfig, String columnName) { + public ReconMarkNewTopicsOperation(JSONObject engineConfig, String columnName) { super(engineConfig, columnName, false); } @@ -27,21 +38,21 @@ public class ApproveNewReconOperation extends EngineDependentMassCellOperation { throws JSONException { writer.object(); - writer.key("op"); writer.value("approve-new-recon"); - writer.key("description"); writer.value("Approve new topics in column " + _columnName); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("columnName"); writer.value(_columnName); writer.endObject(); } protected String getBriefDescription() { - return "Approve new topics for cells in column " + _columnName; + return "Mark to create new topics for cells in column " + _columnName; } protected String createDescription(Column column, List cellChanges) { - return "Approve new topics for " + cellChanges.size() + + return "Mark to create new topics for " + cellChanges.size() + " cells in column " + column.getHeaderLabel(); } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconMatchBestCandidatesOperation.java similarity index 66% rename from src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/ReconMatchBestCandidatesOperation.java index 462f4791d..be8ae886c 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ApproveReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconMatchBestCandidatesOperation.java @@ -8,6 +8,7 @@ import org.json.JSONObject; import org.json.JSONWriter; import com.metaweb.gridworks.browsing.RowVisitor; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -15,10 +16,20 @@ import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Recon.Judgment; import com.metaweb.gridworks.model.changes.CellChange; -public class ApproveReconOperation extends EngineDependentMassCellOperation { +public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = 5393888241057341155L; - public ApproveReconOperation(JSONObject engineConfig, String columnName) { + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + String columnName = obj.getString("columnName"); + + return new ReconMatchBestCandidatesOperation( + engineConfig, + columnName + ); + } + + public ReconMatchBestCandidatesOperation(JSONObject engineConfig, String columnName) { super(engineConfig, columnName, false); } @@ -26,22 +37,22 @@ public class ApproveReconOperation extends EngineDependentMassCellOperation { throws JSONException { writer.object(); - writer.key("op"); writer.value("approve-recon"); - writer.key("description"); writer.value("Approve best recon matches in column " + _columnName); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("columnName"); writer.value(_columnName); writer.endObject(); } protected String getBriefDescription() { - return "Approve best recon candidates for cells in column " + _columnName; + return "Match each cell to its best recon candidate in column " + _columnName; } protected String createDescription(Column column, List cellChanges) { - return "Approve best candidates for " + cellChanges.size() + - " cells in column " + column.getHeaderLabel(); + return "Match each of " + cellChanges.size() + + " cells to its best candidate in column " + column.getHeaderLabel(); } protected RowVisitor createRowVisitor(Project project, List cellChanges) throws Exception { diff --git a/src/main/java/com/metaweb/gridworks/model/operations/MatchSpecificTopicReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconMatchSpecificTopicOperation.java similarity index 58% rename from src/main/java/com/metaweb/gridworks/model/operations/MatchSpecificTopicReconOperation.java rename to src/main/java/com/metaweb/gridworks/model/operations/ReconMatchSpecificTopicOperation.java index e6595c0d1..667cf6b62 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/MatchSpecificTopicReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconMatchSpecificTopicOperation.java @@ -3,11 +3,13 @@ package com.metaweb.gridworks.model.operations; 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.metaweb.gridworks.browsing.RowVisitor; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -17,12 +19,36 @@ import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Recon.Judgment; import com.metaweb.gridworks.model.changes.CellChange; -public class MatchSpecificTopicReconOperation extends EngineDependentMassCellOperation { +public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOperation { private static final long serialVersionUID = -5205694623711144436L; final protected ReconCandidate match; - public MatchSpecificTopicReconOperation(JSONObject engineConfig, String columnName, ReconCandidate match) { + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + + JSONObject match = obj.getJSONObject("match"); + + JSONArray types = obj.getJSONArray("types"); + String[] typeIDs = new String[types.length()]; + for (int i = 0; i < typeIDs.length; i++) { + typeIDs[i] = types.getString(i); + } + + return new ReconMatchSpecificTopicOperation( + engineConfig, + obj.getString("columnName"), + new ReconCandidate( + match.getString("id"), + match.getString("guid"), + match.getString("name"), + typeIDs, + 100 + ) + ); + } + + public ReconMatchSpecificTopicOperation(JSONObject engineConfig, String columnName, ReconCandidate match) { super(engineConfig, columnName, false); this.match = match; } @@ -31,13 +57,22 @@ public class MatchSpecificTopicReconOperation extends EngineDependentMassCellOpe throws JSONException { writer.object(); - writer.key("op"); writer.value("recon-match-specific-topic-to-cells"); - writer.key("description"); writer.value( - "Match specific topic " + - match.topicName + " (" + - match.topicID + ") to cells in column " + _columnName); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("columnName"); writer.value(_columnName); + writer.key("match"); + writer.object(); + writer.key("id"); writer.value(match.topicID); + writer.key("guid"); writer.value(match.topicGUID); + writer.key("name"); writer.value(match.topicName); + writer.key("types"); + writer.array(); + for (String typeID : match.typeIDs) { + writer.value(typeID); + } + writer.endArray(); + writer.endObject(); writer.endObject(); } diff --git a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java index 35be372ef..231848960 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/ReconOperation.java @@ -25,6 +25,7 @@ import com.metaweb.gridworks.browsing.RowVisitor; import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.history.Change; import com.metaweb.gridworks.history.HistoryEntry; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -48,6 +49,19 @@ public class ReconOperation extends EngineDependentOperation { final protected boolean _autoMatch; final protected double _minScore; + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + + return new ReconOperation( + engineConfig, + obj.getString("columnName"), + obj.getString("typeID"), + obj.getString("typeName"), + obj.getBoolean("autoMatch"), + obj.getDouble("minScore") + ); + } + public ReconOperation( JSONObject engineConfig, String columnName, @@ -65,27 +79,23 @@ public class ReconOperation extends EngineDependentOperation { } public Process createProcess(Project project, Properties options) throws Exception { - Column column = project.columnModel.getColumnByName(_columnName); - if (column == null) { - throw new Exception("No column named " + _columnName); - } - - String description = - "Reconcile cells in column " + column.getHeaderLabel() + " to type " + _typeID; - return new ReconProcess( project, getEngineConfig(), - description + getBriefDescription() ); } + + protected String getBriefDescription() { + return "Reconcile cells in column " + _columnName + " to type " + _typeID; + } public void write(JSONWriter writer, Properties options) throws JSONException { writer.object(); - writer.key("op"); writer.value("recon"); - writer.key("description"); writer.value("Reconcile cells in column " + _columnName + " to type " + _typeID); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("columnName"); writer.value(_columnName); writer.key("typeID"); writer.value(_typeID); writer.key("typeName"); writer.value(_typeName); diff --git a/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java index b8987d442..d87d1aeef 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/SaveProtographOperation.java @@ -3,6 +3,7 @@ package com.metaweb.gridworks.model.operations; import java.util.Properties; import org.json.JSONException; +import org.json.JSONObject; import org.json.JSONWriter; import com.metaweb.gridworks.history.Change; @@ -15,13 +16,29 @@ public class SaveProtographOperation extends AbstractOperation { private static final long serialVersionUID = 3134524625206033285L; final protected Protograph _protograph; - + + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + return new SaveProtographOperation( + Protograph.reconstruct(obj.getJSONObject("protograph")) + ); + } + public SaveProtographOperation( Protograph protograph ) { _protograph = protograph; } + 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("Save protograph"); + writer.key("protograph"); _protograph.write(writer, options); + writer.endObject(); + } + protected String getBriefDescription() { return "Save schema skeleton"; } @@ -35,17 +52,6 @@ public class SaveProtographOperation extends AbstractOperation { return new HistoryEntry(project, description, SaveProtographOperation.this, change); } - public void write(JSONWriter writer, Properties options) - throws JSONException { - - writer.object(); - writer.key("op"); writer.value("save-protograph"); - writer.key("description"); writer.value("Save protograph"); - writer.key("protograph"); _protograph.write(writer, options); - writer.endObject(); - } - - static public class ProtographChange implements Change { private static final long serialVersionUID = -564820111174473901L; diff --git a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java index b20f5d070..dce8dce13 100644 --- a/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java +++ b/src/main/java/com/metaweb/gridworks/model/operations/TextTransformOperation.java @@ -11,6 +11,7 @@ import com.metaweb.gridworks.browsing.RowVisitor; import com.metaweb.gridworks.expr.Evaluable; import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.Parser; +import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Column; import com.metaweb.gridworks.model.Project; @@ -22,6 +23,16 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { final protected String _expression; + static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { + JSONObject engineConfig = obj.getJSONObject("engineConfig"); + + return new TextTransformOperation( + engineConfig, + obj.getString("columnName"), + obj.getString("expression") + ); + } + public TextTransformOperation(JSONObject engineConfig, String columnName, String expression) { super(engineConfig, columnName, true); _expression = expression; @@ -31,8 +42,8 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { throws JSONException { writer.object(); - writer.key("op"); writer.value("text-transform"); - writer.key("description"); writer.value("Text transform on cells in column " + _columnName + " with expression " + _expression); + writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass())); + writer.key("description"); writer.value(getBriefDescription()); writer.key("engineConfig"); writer.value(getEngineConfig()); writer.key("columnName"); writer.value(_columnName); writer.key("expression"); writer.value(_expression); @@ -40,7 +51,7 @@ public class TextTransformOperation extends EngineDependentMassCellOperation { } protected String getBriefDescription() { - return "Text transform on cells in column " + _columnName + " using " + _expression; + return "Text transform on cells in column " + _columnName + " using expression " + _expression; } protected String createDescription(Column column,