2010-02-04 21:51:44 +01:00
|
|
|
package com.metaweb.gridworks.model.operations;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Properties;
|
|
|
|
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
import org.json.JSONWriter;
|
|
|
|
|
|
|
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
|
|
|
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 ApproveNewReconOperation extends EngineDependentMassCellOperation {
|
|
|
|
private static final long serialVersionUID = -5205694623711144436L;
|
|
|
|
|
2010-02-17 01:26:38 +01:00
|
|
|
public ApproveNewReconOperation(JSONObject engineConfig, String columnName) {
|
|
|
|
super(engineConfig, columnName, false);
|
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-17 02:30:09 +01:00
|
|
|
writer.key("op"); writer.value("approve-new-recon");
|
2010-02-17 01:26:38 +01:00
|
|
|
writer.key("description"); writer.value("Approve new topics in column " + _columnName);
|
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);
|
|
|
|
writer.endObject();
|
2010-02-04 21:51:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected String createDescription(Column column,
|
|
|
|
List<CellChange> cellChanges) {
|
|
|
|
|
|
|
|
return "Approve new topics for " + cellChanges.size() +
|
|
|
|
" cells in column " + column.getHeaderLabel();
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
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-04 21:51:44 +01:00
|
|
|
if (cellIndex < row.cells.size()) {
|
|
|
|
Cell cell = row.cells.get(cellIndex);
|
|
|
|
|
|
|
|
Cell newCell = new Cell(
|
|
|
|
cell.value,
|
|
|
|
cell.recon != null ? cell.recon.dup() : new Recon()
|
|
|
|
);
|
|
|
|
newCell.recon.match = null;
|
|
|
|
newCell.recon.judgment = Judgment.New;
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|