2010-02-22 19:42:25 +01:00
|
|
|
package com.metaweb.gridworks.operations;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-02-22 23:15:48 +01:00
|
|
|
import java.util.HashMap;
|
2010-02-04 21:51:44 +01:00
|
|
|
import java.util.List;
|
2010-02-22 23:15:48 +01:00
|
|
|
import java.util.Map;
|
2010-02-04 21:51:44 +01:00
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
2010-02-27 00:33:16 +01:00
|
|
|
import com.metaweb.gridworks.history.Change;
|
2010-02-22 05:23:25 +01:00
|
|
|
import com.metaweb.gridworks.model.AbstractOperation;
|
2010-02-04 21:51:44 +01:00
|
|
|
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;
|
2010-02-27 00:33:16 +01:00
|
|
|
import com.metaweb.gridworks.model.changes.ReconChange;
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation {
|
2010-02-04 21:51:44 +01:00
|
|
|
private static final long serialVersionUID = -5205694623711144436L;
|
2010-02-22 05:23:25 +01:00
|
|
|
|
2010-02-22 23:15:48 +01:00
|
|
|
final protected boolean _shareNewTopics;
|
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
|
|
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
|
|
|
|
|
|
|
return new ReconMarkNewTopicsOperation(
|
|
|
|
engineConfig,
|
2010-02-22 23:15:48 +01:00
|
|
|
obj.getString("columnName"),
|
|
|
|
obj.has("shareNewTopics") ? obj.getBoolean("shareNewTopics") : false
|
2010-02-22 05:23:25 +01:00
|
|
|
);
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
2010-02-22 23:15:48 +01:00
|
|
|
public ReconMarkNewTopicsOperation(JSONObject engineConfig, String columnName, boolean shareNewTopics) {
|
2010-02-17 01:26:38 +01:00
|
|
|
super(engineConfig, columnName, false);
|
2010-02-22 23:15:48 +01:00
|
|
|
_shareNewTopics = shareNewTopics;
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void write(JSONWriter writer, Properties options)
|
|
|
|
throws JSONException {
|
|
|
|
|
2010-02-17 01:26:38 +01:00
|
|
|
writer.object();
|
2010-02-22 05:23:25 +01:00
|
|
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
|
|
|
writer.key("description"); writer.value(getBriefDescription());
|
2010-02-17 02:40:41 +01:00
|
|
|
writer.key("engineConfig"); writer.value(getEngineConfig());
|
2010-02-17 01:26:38 +01:00
|
|
|
writer.key("columnName"); writer.value(_columnName);
|
2010-02-22 23:15:48 +01:00
|
|
|
writer.key("shareNewTopics"); writer.value(_shareNewTopics);
|
2010-02-17 01:26:38 +01:00
|
|
|
writer.endObject();
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|
2010-02-19 00:27:40 +01:00
|
|
|
|
|
|
|
protected String getBriefDescription() {
|
2010-02-22 23:15:48 +01:00
|
|
|
return "Mark to create new topics for cells in column " + _columnName +
|
|
|
|
(_shareNewTopics ?
|
|
|
|
", one topic for each group of similar cells" :
|
|
|
|
", one topic for each cell");
|
2010-02-19 00:27:40 +01:00
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
protected String createDescription(Column column,
|
|
|
|
List<CellChange> cellChanges) {
|
|
|
|
|
2010-02-22 05:23:25 +01:00
|
|
|
return "Mark to create new topics for " + cellChanges.size() +
|
2010-02-22 23:15:48 +01:00
|
|
|
" cells in column " + column.getHeaderLabel() +
|
|
|
|
(_shareNewTopics ?
|
|
|
|
", one topic for each group of similar cells" :
|
|
|
|
", one topic for each cell");
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges) throws Exception {
|
2010-02-17 01:26:38 +01:00
|
|
|
Column column = project.columnModel.getColumnByName(_columnName);
|
|
|
|
|
2010-02-04 21:51:44 +01:00
|
|
|
return new RowVisitor() {
|
|
|
|
int cellIndex;
|
|
|
|
List<CellChange> cellChanges;
|
2010-02-22 23:15:48 +01:00
|
|
|
Map<String, Recon> _sharedRecons = new HashMap<String, Recon>();
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
public RowVisitor init(int cellIndex, List<CellChange> cellChanges) {
|
|
|
|
this.cellIndex = cellIndex;
|
|
|
|
this.cellChanges = cellChanges;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-02-06 00:05:00 +01:00
|
|
|
public boolean visit(Project project, int rowIndex, Row row, boolean contextual) {
|
2010-02-22 23:15:48 +01:00
|
|
|
Cell cell = row.getCell(cellIndex);
|
|
|
|
if (cell != null) {
|
|
|
|
Recon recon = null;
|
|
|
|
if (_shareNewTopics) {
|
|
|
|
String s = cell.value == null ? "" : cell.value.toString();
|
|
|
|
if (_sharedRecons.containsKey(s)) {
|
|
|
|
recon = _sharedRecons.get(s);
|
|
|
|
} else {
|
|
|
|
recon = new Recon();
|
|
|
|
recon.judgment = Judgment.New;
|
|
|
|
|
|
|
|
_sharedRecons.put(s, recon);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
recon = cell.recon == null ? new Recon() : cell.recon.dup();
|
|
|
|
recon.match = null;
|
|
|
|
recon.judgment = Judgment.New;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell newCell = new Cell(cell.value, recon);
|
2010-02-04 21:51:44 +01:00
|
|
|
|
|
|
|
CellChange cellChange = new CellChange(rowIndex, cellIndex, cell, newCell);
|
|
|
|
cellChanges.add(cellChange);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2010-02-17 01:26:38 +01:00
|
|
|
}.init(column.getCellIndex(), cellChanges);
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|
2010-02-27 00:33:16 +01:00
|
|
|
|
|
|
|
protected Change createChange(Project project, Column column, List<CellChange> cellChanges) {
|
|
|
|
return new ReconChange(
|
|
|
|
cellChanges,
|
|
|
|
_columnName,
|
|
|
|
column.getReconConfig(),
|
|
|
|
null
|
|
|
|
);
|
|
|
|
}
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|