Implemented but disabled the denormalize operation.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@571 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-04-29 22:07:07 +00:00
parent 270f147d92
commit 3f40195ea1
5 changed files with 133 additions and 0 deletions

View File

@ -25,6 +25,7 @@ import com.metaweb.gridworks.commands.edit.AnnotateRowsCommand;
import com.metaweb.gridworks.commands.edit.ApplyOperationsCommand;
import com.metaweb.gridworks.commands.edit.CreateProjectCommand;
import com.metaweb.gridworks.commands.edit.DeleteProjectCommand;
import com.metaweb.gridworks.commands.edit.DenormalizeCommand;
import com.metaweb.gridworks.commands.edit.EditOneCellCommand;
import com.metaweb.gridworks.commands.edit.ExportProjectCommand;
import com.metaweb.gridworks.commands.edit.ExtendDataCommand;
@ -119,6 +120,8 @@ public class GridworksServlet extends HttpServlet {
_commands.put("split-column", new SplitColumnCommand());
_commands.put("extend-data", new ExtendDataCommand());
_commands.put("denormalize", new DenormalizeCommand());
_commands.put("reconcile", new ReconcileCommand());
_commands.put("recon-match-best-candidates", new ReconMatchBestCandidatesCommand());
_commands.put("recon-mark-new-topics", new ReconMarkNewTopicsCommand());

View File

@ -0,0 +1,32 @@
package com.metaweb.gridworks.commands.edit;
import java.io.IOException;
import java.util.Properties;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
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.operations.DenormalizeOperation;
import com.metaweb.gridworks.process.Process;
public class DenormalizeCommand extends Command {
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
try {
Project project = getProject(request);
AbstractOperation op = new DenormalizeOperation();
Process process = op.createProcess(project, new Properties());
performProcessAndRespond(request, response, project, process);
} catch (Exception e) {
respondException(response, e);
}
}
}

View File

@ -0,0 +1,75 @@
package com.metaweb.gridworks.operations;
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.history.HistoryEntry;
import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Cell;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange;
public class DenormalizeOperation extends AbstractOperation {
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
return new DenormalizeOperation();
}
public DenormalizeOperation() {
}
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();
}
protected String getBriefDescription(Project project) {
return "Denormalize";
}
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
List<Row> newRows = new ArrayList<Row>();
List<Row> oldRows = project.rows;
for (int r = 0; r < oldRows.size(); r++) {
Row oldRow = oldRows.get(r);
Row newRow = null;
if (oldRow.contextCellSlots != null && oldRow.contextRowSlots != null) {
newRow = oldRow.dup();
for (int c = 0; c < oldRow.contextCellSlots.length && c < oldRow.contextRowSlots.length; c++) {
int contextRowIndex = oldRow.contextRowSlots[c];
int contextCellIndex = oldRow.contextCellSlots[c];
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
Row contextRow = oldRows.get(contextRowIndex);
Cell contextCell = contextRow.getCell(contextCellIndex);
newRow.setCell(contextCellIndex, contextCell);
}
}
}
newRows.add(newRow != null ? newRow : oldRow);
}
return new HistoryEntry(
historyEntryID,
project,
getBriefDescription(project),
DenormalizeOperation.this,
new MassRowChange(newRows)
);
}
}

View File

@ -43,6 +43,8 @@ public abstract class OperationRegistry {
register("save-protograph", SaveProtographOperation.class);
register("text-transform", TextTransformOperation.class);
register("mass-edit", MassEditOperation.class);
register("denormalize", DenormalizeOperation.class);
}
static public AbstractOperation reconstruct(Project project, JSONObject obj) {

View File

@ -16,6 +16,18 @@ MenuBar.prototype._initializeUI = function() {
var self = this;
this._createTopLevelMenuItem("Project", [
/*
{
"label": "Data Model",
"submenu": [
{
"label": "Denormalize Records",
"click": function() { self._doDenormalizeRecords(); }
}
]
},
{},
*/
{
"label": "Export Filtered Rows",
"submenu": [
@ -148,6 +160,15 @@ MenuBar.prototype._deactivateMenu = function() {
this._mode = "inactive";
};
MenuBar.prototype._doDenormalizeRecords = function() {
Gridworks.postProcess(
"denormalize",
{},
null,
{ modelsChanged: true }
);
};
MenuBar.prototype._doExportTripleloader = function() {
if (!theProject.protograph) {
alert(