The file system coupled method getProjectDirectory is now removed from ProjectManager.
Methods of HistoryEntry which directly work with the File System have been moved to FileHistoryEntry in the io directory, and HistoryEntry made abstract. As the abstract HistoryEntry cannot be instantiated directly, the ProjectManager is now responsible for creating new HistoryEntry. git-svn-id: http://google-refine.googlecode.com/svn/trunk@973 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
parent
b07075bed5
commit
17f1dc2e6f
@ -1,6 +1,6 @@
|
|||||||
package com.metaweb.gridworks;
|
package com.metaweb.gridworks;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -8,6 +8,9 @@ import java.util.Map.Entry;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.history.Change;
|
||||||
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
|
||||||
|
|
||||||
@ -44,9 +47,6 @@ public abstract class ProjectManager {
|
|||||||
return _interProjectModel;
|
return _interProjectModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//FIXME this is File System specific, need to remove from this abstract class
|
|
||||||
public abstract File getProjectDir(long id);
|
|
||||||
|
|
||||||
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
public void registerProject(Project project, ProjectMetadata projectMetadata) {
|
||||||
synchronized (this) {
|
synchronized (this) {
|
||||||
_projects.put(project.id, project);
|
_projects.put(project.id, project);
|
||||||
@ -119,4 +119,6 @@ public abstract class ProjectManager {
|
|||||||
|
|
||||||
public abstract void deleteProject(long projectID) ;
|
public abstract void deleteProject(long projectID) ;
|
||||||
|
|
||||||
|
public abstract HistoryEntry createHistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time);
|
||||||
|
public abstract HistoryEntry createHistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.history.Change;
|
import com.metaweb.gridworks.history.Change;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
@ -25,20 +26,20 @@ public class EditOneCellCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
request.setCharacterEncoding("UTF-8");
|
request.setCharacterEncoding("UTF-8");
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
|
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
|
|
||||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||||
|
|
||||||
String type = request.getParameter("type");
|
String type = request.getParameter("type");
|
||||||
String valueString = request.getParameter("value");
|
String valueString = request.getParameter("value");
|
||||||
Serializable value = null;
|
Serializable value = null;
|
||||||
|
|
||||||
if ("number".equals(type)) {
|
if ("number".equals(type)) {
|
||||||
value = Double.parseDouble(valueString);
|
value = Double.parseDouble(valueString);
|
||||||
} else if ("boolean".equals(type)) {
|
} else if ("boolean".equals(type)) {
|
||||||
@ -50,13 +51,13 @@ public class EditOneCellCommand extends Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
EditOneCellProcess process = new EditOneCellProcess(
|
EditOneCellProcess process = new EditOneCellProcess(
|
||||||
project,
|
project,
|
||||||
"Edit single cell",
|
"Edit single cell",
|
||||||
rowIndex,
|
rowIndex,
|
||||||
cellIndex,
|
cellIndex,
|
||||||
value
|
value
|
||||||
);
|
);
|
||||||
|
|
||||||
HistoryEntry historyEntry = project.processManager.queueProcess(process);
|
HistoryEntry historyEntry = project.processManager.queueProcess(process);
|
||||||
if (historyEntry != null) {
|
if (historyEntry != null) {
|
||||||
/*
|
/*
|
||||||
@ -64,11 +65,11 @@ public class EditOneCellCommand extends Command {
|
|||||||
* so the client side can update the cell's rendering right away.
|
* so the client side can update the cell's rendering right away.
|
||||||
*/
|
*/
|
||||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
|
||||||
Pool pool = new Pool();
|
Pool pool = new Pool();
|
||||||
Properties options = new Properties();
|
Properties options = new Properties();
|
||||||
options.put("pool", pool);
|
options.put("pool", pool);
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("code"); writer.value("ok");
|
writer.key("code"); writer.value("ok");
|
||||||
writer.key("historyEntry"); historyEntry.write(writer, options);
|
writer.key("historyEntry"); historyEntry.write(writer, options);
|
||||||
@ -82,22 +83,22 @@ public class EditOneCellCommand extends Command {
|
|||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class EditOneCellProcess extends QuickHistoryEntryProcess {
|
protected static class EditOneCellProcess extends QuickHistoryEntryProcess {
|
||||||
final int rowIndex;
|
final int rowIndex;
|
||||||
final int cellIndex;
|
final int cellIndex;
|
||||||
final Serializable value;
|
final Serializable value;
|
||||||
Cell newCell;
|
Cell newCell;
|
||||||
|
|
||||||
EditOneCellProcess(
|
EditOneCellProcess(
|
||||||
Project project,
|
Project project,
|
||||||
String briefDescription,
|
String briefDescription,
|
||||||
int rowIndex,
|
int rowIndex,
|
||||||
int cellIndex,
|
int cellIndex,
|
||||||
Serializable value
|
Serializable value
|
||||||
) {
|
) {
|
||||||
super(project, briefDescription);
|
super(project, briefDescription);
|
||||||
|
|
||||||
this.rowIndex = rowIndex;
|
this.rowIndex = rowIndex;
|
||||||
this.cellIndex = cellIndex;
|
this.cellIndex = cellIndex;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
@ -109,19 +110,19 @@ public class EditOneCellCommand extends Command {
|
|||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No such column");
|
throw new Exception("No such column");
|
||||||
}
|
}
|
||||||
|
|
||||||
newCell = new Cell(
|
newCell = new Cell(
|
||||||
value,
|
value,
|
||||||
cell != null ? cell.recon : null
|
cell != null ? cell.recon : null
|
||||||
);
|
);
|
||||||
|
|
||||||
String description =
|
String description =
|
||||||
"Edit single cell on row " + (rowIndex + 1) +
|
"Edit single cell on row " + (rowIndex + 1) +
|
||||||
", column " + column.getName();
|
", column " + column.getName();
|
||||||
|
|
||||||
Change change = new CellChange(rowIndex, cellIndex, cell, newCell);
|
Change change = new CellChange(rowIndex, cellIndex, cell, newCell);
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID, _project, description, null, change);
|
historyEntryID, _project, description, null, change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import org.apache.tools.tar.TarOutputStream;
|
|||||||
|
|
||||||
import com.metaweb.gridworks.ProjectManager;
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.io.FileProjectManager;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
|
||||||
public class ExportProjectCommand extends Command {
|
public class ExportProjectCommand extends Command {
|
||||||
@ -22,17 +23,17 @@ public class ExportProjectCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
ProjectManager.singleton.ensureProjectSaved(project.id);
|
ProjectManager.singleton.ensureProjectSaved(project.id);
|
||||||
|
|
||||||
response.setHeader("Content-Type", "application/x-gzip");
|
response.setHeader("Content-Type", "application/x-gzip");
|
||||||
|
|
||||||
OutputStream os = response.getOutputStream();
|
OutputStream os = response.getOutputStream();
|
||||||
try {
|
try {
|
||||||
gzipTarToOutputStream(
|
gzipTarToOutputStream(//FIXME relies on FileProjectManager
|
||||||
ProjectManager.singleton.getProjectDir(project.id),
|
((FileProjectManager)ProjectManager.singleton).getProjectDir(project.id),
|
||||||
os
|
os
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
@ -42,7 +43,7 @@ public class ExportProjectCommand extends Command {
|
|||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void gzipTarToOutputStream(File dir, OutputStream os) throws IOException {
|
protected void gzipTarToOutputStream(File dir, OutputStream os) throws IOException {
|
||||||
GZIPOutputStream gos = new GZIPOutputStream(os);
|
GZIPOutputStream gos = new GZIPOutputStream(os);
|
||||||
try {
|
try {
|
||||||
@ -51,7 +52,7 @@ public class ExportProjectCommand extends Command {
|
|||||||
gos.close();
|
gos.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tarToOutputStream(File dir, OutputStream os) throws IOException {
|
protected void tarToOutputStream(File dir, OutputStream os) throws IOException {
|
||||||
TarOutputStream tos = new TarOutputStream(os);
|
TarOutputStream tos = new TarOutputStream(os);
|
||||||
try {
|
try {
|
||||||
@ -60,43 +61,43 @@ public class ExportProjectCommand extends Command {
|
|||||||
tos.close();
|
tos.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void tarDir(String relative, File dir, TarOutputStream tos) throws IOException {
|
protected void tarDir(String relative, File dir, TarOutputStream tos) throws IOException {
|
||||||
File[] files = dir.listFiles();
|
File[] files = dir.listFiles();
|
||||||
for (File file : files) {
|
for (File file : files) {
|
||||||
if (!file.isHidden()) {
|
if (!file.isHidden()) {
|
||||||
String path = relative + file.getName();
|
String path = relative + file.getName();
|
||||||
|
|
||||||
if (file.isDirectory()) {
|
if (file.isDirectory()) {
|
||||||
tarDir(path + File.separator, file, tos);
|
tarDir(path + File.separator, file, tos);
|
||||||
} else {
|
} else {
|
||||||
TarEntry entry = new TarEntry(path);
|
TarEntry entry = new TarEntry(path);
|
||||||
|
|
||||||
entry.setMode(TarEntry.DEFAULT_FILE_MODE);
|
entry.setMode(TarEntry.DEFAULT_FILE_MODE);
|
||||||
entry.setSize(file.length());
|
entry.setSize(file.length());
|
||||||
entry.setModTime(file.lastModified());
|
entry.setModTime(file.lastModified());
|
||||||
|
|
||||||
tos.putNextEntry(entry);
|
tos.putNextEntry(entry);
|
||||||
|
|
||||||
copyFile(file, tos);
|
copyFile(file, tos);
|
||||||
|
|
||||||
tos.closeEntry();
|
tos.closeEntry();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void copyFile(File file, OutputStream os) throws IOException {
|
protected void copyFile(File file, OutputStream os) throws IOException {
|
||||||
final int buffersize = 4096;
|
final int buffersize = 4096;
|
||||||
|
|
||||||
FileInputStream fis = new FileInputStream(file);
|
FileInputStream fis = new FileInputStream(file);
|
||||||
try {
|
try {
|
||||||
byte[] buf = new byte[buffersize];
|
byte[] buf = new byte[buffersize];
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
while((count = fis.read(buf, 0, buffersize)) != -1) {
|
while((count = fis.read(buf, 0, buffersize)) != -1) {
|
||||||
os.write(buf, 0, count);
|
os.write(buf, 0, count);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
fis.close();
|
fis.close();
|
||||||
}
|
}
|
||||||
|
@ -25,28 +25,29 @@ import org.slf4j.LoggerFactory;
|
|||||||
import com.metaweb.gridworks.ProjectManager;
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.ProjectMetadata;
|
import com.metaweb.gridworks.ProjectMetadata;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
|
import com.metaweb.gridworks.io.FileProjectManager;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
|
|
||||||
public class ImportProjectCommand extends Command {
|
public class ImportProjectCommand extends Command {
|
||||||
|
|
||||||
final static Logger logger = LoggerFactory.getLogger("import-project_command");
|
final static Logger logger = LoggerFactory.getLogger("import-project_command");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
ProjectManager.singleton.setBusy(true);
|
ProjectManager.singleton.setBusy(true);
|
||||||
try {
|
try {
|
||||||
Properties options = ParsingUtilities.parseUrlParameters(request);
|
Properties options = ParsingUtilities.parseUrlParameters(request);
|
||||||
|
|
||||||
long projectID = Project.generateID();
|
long projectID = Project.generateID();
|
||||||
logger.info("Importing existing project using new ID {}", projectID);
|
logger.info("Importing existing project using new ID {}", projectID);
|
||||||
|
|
||||||
internalImport(request, options, projectID);
|
internalImport(request, options, projectID);
|
||||||
|
|
||||||
ProjectManager.singleton.importProject(projectID);
|
ProjectManager.singleton.importProject(projectID);
|
||||||
|
|
||||||
ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(projectID);
|
ProjectMetadata pm = ProjectManager.singleton.getProjectMetadata(projectID);
|
||||||
if (pm != null) {
|
if (pm != null) {
|
||||||
if (options.containsKey("project-name")) {
|
if (options.containsKey("project-name")) {
|
||||||
@ -55,7 +56,7 @@ public class ImportProjectCommand extends Command {
|
|||||||
pm.setName(projectName);
|
pm.setName(projectName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(response, "/project.html?project=" + projectID);
|
redirect(response, "/project.html?project=" + projectID);
|
||||||
} else {
|
} else {
|
||||||
redirect(response, "/error.html?redirect=index.html&msg=" +
|
redirect(response, "/error.html?redirect=index.html&msg=" +
|
||||||
@ -68,17 +69,17 @@ public class ImportProjectCommand extends Command {
|
|||||||
ProjectManager.singleton.setBusy(false);
|
ProjectManager.singleton.setBusy(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalImport(
|
protected void internalImport(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
Properties options,
|
Properties options,
|
||||||
long projectID
|
long projectID
|
||||||
) throws Exception {
|
) throws Exception {
|
||||||
|
|
||||||
String url = null;
|
String url = null;
|
||||||
|
|
||||||
ServletFileUpload upload = new ServletFileUpload();
|
ServletFileUpload upload = new ServletFileUpload();
|
||||||
|
|
||||||
FileItemIterator iter = upload.getItemIterator(request);
|
FileItemIterator iter = upload.getItemIterator(request);
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
FileItemStream item = iter.next();
|
FileItemStream item = iter.next();
|
||||||
@ -98,13 +99,13 @@ public class ImportProjectCommand extends Command {
|
|||||||
stream.close();
|
stream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (url != null && url.length() > 0) {
|
if (url != null && url.length() > 0) {
|
||||||
internalImportURL(request, options, projectID, url);
|
internalImportURL(request, options, projectID, url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalImportURL(
|
protected void internalImportURL(
|
||||||
HttpServletRequest request,
|
HttpServletRequest request,
|
||||||
Properties options,
|
Properties options,
|
||||||
@ -113,7 +114,7 @@ public class ImportProjectCommand extends Command {
|
|||||||
) throws Exception {
|
) throws Exception {
|
||||||
URL url = new URL(urlString);
|
URL url = new URL(urlString);
|
||||||
URLConnection connection = null;
|
URLConnection connection = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
connection = url.openConnection();
|
connection = url.openConnection();
|
||||||
connection.setConnectTimeout(5000);
|
connection.setConnectTimeout(5000);
|
||||||
@ -121,25 +122,25 @@ public class ImportProjectCommand extends Command {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Cannot connect to " + urlString, e);
|
throw new Exception("Cannot connect to " + urlString, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
InputStream inputStream = null;
|
InputStream inputStream = null;
|
||||||
try {
|
try {
|
||||||
inputStream = connection.getInputStream();
|
inputStream = connection.getInputStream();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new Exception("Cannot retrieve content from " + url, e);
|
throw new Exception("Cannot retrieve content from " + url, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
internalImportInputStream(projectID, inputStream, !urlString.endsWith(".tar"));
|
internalImportInputStream(projectID, inputStream, !urlString.endsWith(".tar"));
|
||||||
} finally {
|
} finally {
|
||||||
inputStream.close();
|
inputStream.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void internalImportInputStream(long projectID, InputStream inputStream, boolean gziped) throws IOException {
|
protected void internalImportInputStream(long projectID, InputStream inputStream, boolean gziped) throws IOException {
|
||||||
File destDir = ProjectManager.singleton.getProjectDir(projectID);
|
File destDir = ((FileProjectManager)ProjectManager.singleton).getProjectDir(projectID);//FIXME relies on FileProjectManager
|
||||||
destDir.mkdirs();
|
destDir.mkdirs();
|
||||||
|
|
||||||
if (gziped) {
|
if (gziped) {
|
||||||
GZIPInputStream gis = new GZIPInputStream(inputStream);
|
GZIPInputStream gis = new GZIPInputStream(inputStream);
|
||||||
untar(destDir, gis);
|
untar(destDir, gis);
|
||||||
@ -147,19 +148,19 @@ public class ImportProjectCommand extends Command {
|
|||||||
untar(destDir, inputStream);
|
untar(destDir, inputStream);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void untar(File destDir, InputStream inputStream) throws IOException {
|
protected void untar(File destDir, InputStream inputStream) throws IOException {
|
||||||
TarInputStream tin = new TarInputStream(inputStream);
|
TarInputStream tin = new TarInputStream(inputStream);
|
||||||
TarEntry tarEntry = null;
|
TarEntry tarEntry = null;
|
||||||
|
|
||||||
while ((tarEntry = tin.getNextEntry()) != null) {
|
while ((tarEntry = tin.getNextEntry()) != null) {
|
||||||
File destEntry = new File(destDir, tarEntry.getName());
|
File destEntry = new File(destDir, tarEntry.getName());
|
||||||
File parent = destEntry.getParentFile();
|
File parent = destEntry.getParentFile();
|
||||||
|
|
||||||
if (!parent.exists()) {
|
if (!parent.exists()) {
|
||||||
parent.mkdirs();
|
parent.mkdirs();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tarEntry.isDirectory()) {
|
if (tarEntry.isDirectory()) {
|
||||||
destEntry.mkdirs();
|
destEntry.mkdirs();
|
||||||
} else {
|
} else {
|
||||||
|
@ -9,6 +9,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||||||
|
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||||
import com.metaweb.gridworks.history.Change;
|
import com.metaweb.gridworks.history.Change;
|
||||||
@ -29,19 +30,19 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
|
|
||||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||||
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
int cellIndex = Integer.parseInt(request.getParameter("cell"));
|
||||||
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
Judgment judgment = Recon.stringToJudgment(request.getParameter("judgment"));
|
||||||
|
|
||||||
ReconCandidate match = null;
|
ReconCandidate match = null;
|
||||||
String topicID = request.getParameter("topicID");
|
String topicID = request.getParameter("topicID");
|
||||||
if (topicID != null) {
|
if (topicID != null) {
|
||||||
String scoreString = request.getParameter("score");
|
String scoreString = request.getParameter("score");
|
||||||
|
|
||||||
match = new ReconCandidate(
|
match = new ReconCandidate(
|
||||||
topicID,
|
topicID,
|
||||||
request.getParameter("topicGUID"),
|
request.getParameter("topicGUID"),
|
||||||
@ -50,16 +51,16 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
scoreString != null ? Double.parseDouble(scoreString) : 100
|
scoreString != null ? Double.parseDouble(scoreString) : 100
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
JudgeOneCellProcess process = new JudgeOneCellProcess(
|
JudgeOneCellProcess process = new JudgeOneCellProcess(
|
||||||
project,
|
project,
|
||||||
"Judge one cell's recon result",
|
"Judge one cell's recon result",
|
||||||
judgment,
|
judgment,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
cellIndex,
|
cellIndex,
|
||||||
match
|
match
|
||||||
);
|
);
|
||||||
|
|
||||||
HistoryEntry historyEntry = project.processManager.queueProcess(process);
|
HistoryEntry historyEntry = project.processManager.queueProcess(process);
|
||||||
if (historyEntry != null) {
|
if (historyEntry != null) {
|
||||||
/*
|
/*
|
||||||
@ -67,11 +68,11 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
* client side can update its UI right away.
|
* client side can update its UI right away.
|
||||||
*/
|
*/
|
||||||
JSONWriter writer = new JSONWriter(response.getWriter());
|
JSONWriter writer = new JSONWriter(response.getWriter());
|
||||||
|
|
||||||
Pool pool = new Pool();
|
Pool pool = new Pool();
|
||||||
Properties options = new Properties();
|
Properties options = new Properties();
|
||||||
options.put("pool", pool);
|
options.put("pool", pool);
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("code"); writer.value("ok");
|
writer.key("code"); writer.value("ok");
|
||||||
writer.key("historyEntry"); historyEntry.write(writer, options);
|
writer.key("historyEntry"); historyEntry.write(writer, options);
|
||||||
@ -85,7 +86,7 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class JudgeOneCellProcess extends QuickHistoryEntryProcess {
|
protected static class JudgeOneCellProcess extends QuickHistoryEntryProcess {
|
||||||
|
|
||||||
final int rowIndex;
|
final int rowIndex;
|
||||||
@ -93,17 +94,17 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
final Judgment judgment;
|
final Judgment judgment;
|
||||||
final ReconCandidate match;
|
final ReconCandidate match;
|
||||||
Cell newCell;
|
Cell newCell;
|
||||||
|
|
||||||
JudgeOneCellProcess(
|
JudgeOneCellProcess(
|
||||||
Project project,
|
Project project,
|
||||||
String briefDescription,
|
String briefDescription,
|
||||||
Judgment judgment,
|
Judgment judgment,
|
||||||
int rowIndex,
|
int rowIndex,
|
||||||
int cellIndex,
|
int cellIndex,
|
||||||
ReconCandidate match
|
ReconCandidate match
|
||||||
) {
|
) {
|
||||||
super(project, briefDescription);
|
super(project, briefDescription);
|
||||||
|
|
||||||
this.judgment = judgment;
|
this.judgment = judgment;
|
||||||
this.rowIndex = rowIndex;
|
this.rowIndex = rowIndex;
|
||||||
this.cellIndex = cellIndex;
|
this.cellIndex = cellIndex;
|
||||||
@ -115,63 +116,63 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
if (cell == null || !ExpressionUtils.isNonBlankData(cell.value)) {
|
if (cell == null || !ExpressionUtils.isNonBlankData(cell.value)) {
|
||||||
throw new Exception("Cell is blank or error");
|
throw new Exception("Cell is blank or error");
|
||||||
}
|
}
|
||||||
|
|
||||||
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
|
Column column = _project.columnModel.getColumnByCellIndex(cellIndex);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No such column");
|
throw new Exception("No such column");
|
||||||
}
|
}
|
||||||
|
|
||||||
Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;
|
Judgment oldJudgment = cell.recon == null ? Judgment.None : cell.recon.judgment;
|
||||||
|
|
||||||
newCell = new Cell(
|
newCell = new Cell(
|
||||||
cell.value,
|
cell.value,
|
||||||
cell.recon == null ? new Recon(historyEntryID) : cell.recon.dup(historyEntryID)
|
cell.recon == null ? new Recon(historyEntryID) : cell.recon.dup(historyEntryID)
|
||||||
);
|
);
|
||||||
|
|
||||||
String cellDescription =
|
String cellDescription =
|
||||||
"single cell on row " + (rowIndex + 1) +
|
"single cell on row " + (rowIndex + 1) +
|
||||||
", column " + column.getName() +
|
", column " + column.getName() +
|
||||||
", containing \"" + cell.value + "\"";
|
", containing \"" + cell.value + "\"";
|
||||||
|
|
||||||
String description = null;
|
String description = null;
|
||||||
|
|
||||||
newCell.recon.matchRank = -1;
|
newCell.recon.matchRank = -1;
|
||||||
newCell.recon.judgmentAction = "single";
|
newCell.recon.judgmentAction = "single";
|
||||||
newCell.recon.judgmentBatchSize = 1;
|
newCell.recon.judgmentBatchSize = 1;
|
||||||
|
|
||||||
if (judgment == Judgment.None) {
|
if (judgment == Judgment.None) {
|
||||||
newCell.recon.judgment = Recon.Judgment.None;
|
newCell.recon.judgment = Recon.Judgment.None;
|
||||||
newCell.recon.match = null;
|
newCell.recon.match = null;
|
||||||
|
|
||||||
description = "Discard recon judgment for " + cellDescription;
|
description = "Discard recon judgment for " + cellDescription;
|
||||||
} else if (judgment == Judgment.New) {
|
} else if (judgment == Judgment.New) {
|
||||||
newCell.recon.judgment = Recon.Judgment.New;
|
newCell.recon.judgment = Recon.Judgment.New;
|
||||||
newCell.recon.match = null;
|
newCell.recon.match = null;
|
||||||
|
|
||||||
description = "Mark to create new topic for " + cellDescription;
|
description = "Mark to create new topic for " + cellDescription;
|
||||||
} else {
|
} else {
|
||||||
newCell.recon.judgment = Recon.Judgment.Matched;
|
newCell.recon.judgment = Recon.Judgment.Matched;
|
||||||
newCell.recon.match = this.match;
|
newCell.recon.match = this.match;
|
||||||
|
|
||||||
for (int m = 0; m < newCell.recon.candidates.size(); m++) {
|
for (int m = 0; m < newCell.recon.candidates.size(); m++) {
|
||||||
if (newCell.recon.candidates.get(m).topicGUID.equals(this.match.topicGUID)) {
|
if (newCell.recon.candidates.get(m).topicGUID.equals(this.match.topicGUID)) {
|
||||||
newCell.recon.matchRank = m;
|
newCell.recon.matchRank = m;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
description = "Match " + this.match.topicName +
|
description = "Match " + this.match.topicName +
|
||||||
" (" + match.topicID + ") to " +
|
" (" + match.topicID + ") to " +
|
||||||
cellDescription;
|
cellDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
ReconStats stats = column.getReconStats();
|
ReconStats stats = column.getReconStats();
|
||||||
if (stats == null) {
|
if (stats == null) {
|
||||||
stats = ReconStats.create(_project, cellIndex);
|
stats = ReconStats.create(_project, cellIndex);
|
||||||
} else {
|
} else {
|
||||||
int newChange = 0;
|
int newChange = 0;
|
||||||
int matchChange = 0;
|
int matchChange = 0;
|
||||||
|
|
||||||
if (oldJudgment == Judgment.New) {
|
if (oldJudgment == Judgment.New) {
|
||||||
newChange--;
|
newChange--;
|
||||||
}
|
}
|
||||||
@ -184,21 +185,21 @@ public class ReconJudgeOneCellCommand extends Command {
|
|||||||
if (newCell.recon.judgment == Judgment.Matched) {
|
if (newCell.recon.judgment == Judgment.Matched) {
|
||||||
matchChange++;
|
matchChange++;
|
||||||
}
|
}
|
||||||
|
|
||||||
stats = new ReconStats(
|
stats = new ReconStats(
|
||||||
stats.nonBlanks,
|
stats.nonBlanks,
|
||||||
stats.newTopics + newChange,
|
stats.newTopics + newChange,
|
||||||
stats.matchedTopics + matchChange);
|
stats.matchedTopics + matchChange);
|
||||||
}
|
}
|
||||||
|
|
||||||
Change change = new ReconChange(
|
Change change = new ReconChange(
|
||||||
new CellChange(rowIndex, cellIndex, cell, newCell),
|
new CellChange(rowIndex, cellIndex, cell, newCell),
|
||||||
column.getName(),
|
column.getName(),
|
||||||
column.getReconConfig(),
|
column.getReconConfig(),
|
||||||
stats
|
stats
|
||||||
);
|
);
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID, _project, description, null, change);
|
historyEntryID, _project, description, null, change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import javax.servlet.ServletException;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.commands.Command;
|
import com.metaweb.gridworks.commands.Command;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
@ -17,27 +18,27 @@ public class AnnotateOneRowCommand extends Command {
|
|||||||
@Override
|
@Override
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
public void doPost(HttpServletRequest request, HttpServletResponse response)
|
||||||
throws ServletException, IOException {
|
throws ServletException, IOException {
|
||||||
|
|
||||||
response.setCharacterEncoding("UTF-8");
|
response.setCharacterEncoding("UTF-8");
|
||||||
response.setHeader("Content-Type", "application/json");
|
response.setHeader("Content-Type", "application/json");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Project project = getProject(request);
|
Project project = getProject(request);
|
||||||
|
|
||||||
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
int rowIndex = Integer.parseInt(request.getParameter("row"));
|
||||||
|
|
||||||
String starredString = request.getParameter("starred");
|
String starredString = request.getParameter("starred");
|
||||||
if (starredString != null) {
|
if (starredString != null) {
|
||||||
boolean starred = "true".endsWith(starredString);
|
boolean starred = "true".endsWith(starredString);
|
||||||
String description = (starred ? "Star row " : "Unstar row ") + (rowIndex + 1);
|
String description = (starred ? "Star row " : "Unstar row ") + (rowIndex + 1);
|
||||||
|
|
||||||
StarOneRowProcess process = new StarOneRowProcess(
|
StarOneRowProcess process = new StarOneRowProcess(
|
||||||
project,
|
project,
|
||||||
description,
|
description,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
starred
|
starred
|
||||||
);
|
);
|
||||||
|
|
||||||
performProcessAndRespond(request, response, project, process);
|
performProcessAndRespond(request, response, project, process);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -45,48 +46,48 @@ public class AnnotateOneRowCommand extends Command {
|
|||||||
String flaggedString = request.getParameter("flagged");
|
String flaggedString = request.getParameter("flagged");
|
||||||
if (flaggedString != null) {
|
if (flaggedString != null) {
|
||||||
boolean flagged = "true".endsWith(flaggedString);
|
boolean flagged = "true".endsWith(flaggedString);
|
||||||
String description = (flagged ? "Flag row " : "Unflag row ") + (rowIndex + 1);
|
String description = (flagged ? "Flag row " : "Unflag row ") + (rowIndex + 1);
|
||||||
|
|
||||||
FlagOneRowProcess process = new FlagOneRowProcess(
|
FlagOneRowProcess process = new FlagOneRowProcess(
|
||||||
project,
|
project,
|
||||||
description,
|
description,
|
||||||
rowIndex,
|
rowIndex,
|
||||||
flagged
|
flagged
|
||||||
);
|
);
|
||||||
|
|
||||||
performProcessAndRespond(request, response, project, process);
|
performProcessAndRespond(request, response, project, process);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }");
|
respond(response, "{ \"code\" : \"error\", \"message\" : \"invalid command parameters\" }");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
respondException(response, e);
|
respondException(response, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static class StarOneRowProcess extends QuickHistoryEntryProcess {
|
protected static class StarOneRowProcess extends QuickHistoryEntryProcess {
|
||||||
final int rowIndex;
|
final int rowIndex;
|
||||||
final boolean starred;
|
final boolean starred;
|
||||||
|
|
||||||
StarOneRowProcess(
|
StarOneRowProcess(
|
||||||
Project project,
|
Project project,
|
||||||
String briefDescription,
|
String briefDescription,
|
||||||
int rowIndex,
|
int rowIndex,
|
||||||
boolean starred
|
boolean starred
|
||||||
) {
|
) {
|
||||||
super(project, briefDescription);
|
super(project, briefDescription);
|
||||||
|
|
||||||
this.rowIndex = rowIndex;
|
this.rowIndex = rowIndex;
|
||||||
this.starred = starred;
|
this.starred = starred;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(long historyEntryID) throws Exception {
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
_project,
|
_project,
|
||||||
(starred ? "Star row " : "Unstar row ") + (rowIndex + 1),
|
(starred ? "Star row " : "Unstar row ") + (rowIndex + 1),
|
||||||
null,
|
null,
|
||||||
new RowStarChange(rowIndex, starred)
|
new RowStarChange(rowIndex, starred)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -94,25 +95,25 @@ public class AnnotateOneRowCommand extends Command {
|
|||||||
protected static class FlagOneRowProcess extends QuickHistoryEntryProcess {
|
protected static class FlagOneRowProcess extends QuickHistoryEntryProcess {
|
||||||
final int rowIndex;
|
final int rowIndex;
|
||||||
final boolean flagged;
|
final boolean flagged;
|
||||||
|
|
||||||
FlagOneRowProcess(
|
FlagOneRowProcess(
|
||||||
Project project,
|
Project project,
|
||||||
String briefDescription,
|
String briefDescription,
|
||||||
int rowIndex,
|
int rowIndex,
|
||||||
boolean flagged
|
boolean flagged
|
||||||
) {
|
) {
|
||||||
super(project, briefDescription);
|
super(project, briefDescription);
|
||||||
|
|
||||||
this.rowIndex = rowIndex;
|
this.rowIndex = rowIndex;
|
||||||
this.flagged = flagged;
|
this.flagged = flagged;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(long historyEntryID) throws Exception {
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
_project,
|
_project,
|
||||||
(flagged ? "Flag row " : "Unflag row ") + (rowIndex + 1),
|
(flagged ? "Flag row " : "Unflag row ") + (rowIndex + 1),
|
||||||
null,
|
null,
|
||||||
new RowFlagChange(rowIndex, flagged)
|
new RowFlagChange(rowIndex, flagged)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,14 +1,8 @@
|
|||||||
package com.metaweb.gridworks.history;
|
package com.metaweb.gridworks.history;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipFile;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
@ -20,40 +14,39 @@ import com.metaweb.gridworks.model.AbstractOperation;
|
|||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.operations.OperationRegistry;
|
import com.metaweb.gridworks.operations.OperationRegistry;
|
||||||
import com.metaweb.gridworks.util.ParsingUtilities;
|
import com.metaweb.gridworks.util.ParsingUtilities;
|
||||||
import com.metaweb.gridworks.util.Pool;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is the metadata of a Change. It's small, so we can load it in order to
|
* 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.
|
* obtain information about a change without actually loading the change.
|
||||||
*/
|
*/
|
||||||
public class HistoryEntry implements Jsonizable {
|
public abstract class HistoryEntry implements Jsonizable {
|
||||||
final public long id;
|
final public long id;
|
||||||
final public long projectID;
|
final public long projectID;
|
||||||
final public String description;
|
final public String description;
|
||||||
final public Date time;
|
final public Date time;
|
||||||
|
|
||||||
// the abstract operation, if any, that results in the change
|
// the abstract operation, if any, that results in the change
|
||||||
final public AbstractOperation operation;
|
final public AbstractOperation operation;
|
||||||
|
|
||||||
// the actual change, loaded on demand
|
// the actual change, loaded on demand
|
||||||
transient protected Change _change;
|
transient protected Change _change;
|
||||||
|
|
||||||
private final static String OPERATION = "operation";
|
private final static String OPERATION = "operation";
|
||||||
|
|
||||||
static public long allocateID() {
|
static public long allocateID() {
|
||||||
return Math.round(Math.random() * 1000000) + System.currentTimeMillis();
|
return Math.round(Math.random() * 1000000) + System.currentTimeMillis();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change) {
|
public HistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.projectID = project.id;
|
this.projectID = project.id;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.time = new Date();
|
this.time = new Date();
|
||||||
|
|
||||||
_change = change;
|
_change = change;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time) {
|
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.projectID = projectID;
|
this.projectID = projectID;
|
||||||
@ -61,10 +54,10 @@ public class HistoryEntry implements Jsonizable {
|
|||||||
this.operation = operation;
|
this.operation = operation;
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("id"); writer.value(id);
|
writer.key("id"); writer.value(id);
|
||||||
writer.key("description"); writer.value(description);
|
writer.key("description"); writer.value(description);
|
||||||
@ -74,62 +67,54 @@ public class HistoryEntry implements Jsonizable {
|
|||||||
}
|
}
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(Project project) {
|
public void apply(Project project) {
|
||||||
if (_change == null) {
|
if (_change == null) {
|
||||||
loadChange();
|
loadChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
synchronized (project) {
|
synchronized (project) {
|
||||||
_change.apply(project);
|
_change.apply(project);
|
||||||
|
|
||||||
// When a change is applied, it can hang on to old data (in order to be able
|
// When a change is applied, it can hang on to old data (in order to be able
|
||||||
// to revert later). Hence, we need to save the change out.
|
// to revert later). Hence, we need to save the change out.
|
||||||
|
|
||||||
try {
|
try {
|
||||||
saveChange();
|
saveChange();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
||||||
_change.revert(project);
|
_change.revert(project);
|
||||||
|
|
||||||
throw new RuntimeException("Failed to apply change", e);
|
throw new RuntimeException("Failed to apply change", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revert(Project project) {
|
public void revert(Project project) {
|
||||||
if (_change == null) {
|
if (_change == null) {
|
||||||
loadChange();
|
loadChange();
|
||||||
}
|
}
|
||||||
_change.revert(project);
|
_change.revert(project);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete() {
|
public abstract void loadChange();
|
||||||
File file = getChangeFile();
|
|
||||||
if (file.exists()) {
|
protected abstract void saveChange() throws Exception;
|
||||||
file.delete();
|
|
||||||
}
|
public abstract void save(Writer writer, Properties options);
|
||||||
}
|
|
||||||
|
protected abstract void delete();
|
||||||
public void save(Writer writer, Properties options) {
|
|
||||||
JSONWriter jsonWriter = new JSONWriter(writer);
|
|
||||||
try {
|
|
||||||
write(jsonWriter, options);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static public HistoryEntry load(Project project, String s) throws Exception {
|
static public HistoryEntry load(Project project, String s) throws Exception {
|
||||||
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
|
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
|
||||||
|
|
||||||
AbstractOperation operation = null;
|
AbstractOperation operation = null;
|
||||||
if (obj.has(OPERATION) && !obj.isNull(OPERATION)) {
|
if (obj.has(OPERATION) && !obj.isNull(OPERATION)) {
|
||||||
operation = OperationRegistry.reconstruct(project, obj.getJSONObject(OPERATION));
|
operation = OperationRegistry.reconstruct(project, obj.getJSONObject(OPERATION));
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
obj.getLong("id"),
|
obj.getLong("id"),
|
||||||
project.id,
|
project.id,
|
||||||
obj.getString("description"),
|
obj.getString("description"),
|
||||||
@ -138,72 +123,6 @@ public class HistoryEntry implements Jsonizable {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void loadChange() {
|
|
||||||
File changeFile = getChangeFile();
|
|
||||||
|
|
||||||
try {
|
|
||||||
loadChange(changeFile);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new RuntimeException("Failed to load change file " + changeFile.getAbsolutePath(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void loadChange(File file) throws Exception {
|
|
||||||
ZipFile zipFile = new ZipFile(file);
|
|
||||||
try {
|
|
||||||
Pool pool = new Pool();
|
|
||||||
ZipEntry poolEntry = zipFile.getEntry("pool.txt");
|
|
||||||
if (poolEntry != null) {
|
|
||||||
pool.load(new InputStreamReader(
|
|
||||||
zipFile.getInputStream(poolEntry)));
|
|
||||||
} // else, it's a legacy project file
|
|
||||||
|
|
||||||
_change = History.readOneChange(
|
|
||||||
zipFile.getInputStream(zipFile.getEntry("change.txt")), pool);
|
|
||||||
} finally {
|
|
||||||
zipFile.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void saveChange() throws Exception {
|
|
||||||
File changeFile = getChangeFile();
|
|
||||||
if (!(changeFile.exists())) {
|
|
||||||
saveChange(changeFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void saveChange(File file) throws Exception {
|
|
||||||
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
|
|
||||||
try {
|
|
||||||
Pool pool = new Pool();
|
|
||||||
|
|
||||||
out.putNextEntry(new ZipEntry("change.txt"));
|
|
||||||
try {
|
|
||||||
History.writeOneChange(out, _change, pool);
|
|
||||||
} finally {
|
|
||||||
out.closeEntry();
|
|
||||||
}
|
|
||||||
|
|
||||||
out.putNextEntry(new ZipEntry("pool.txt"));
|
|
||||||
try {
|
|
||||||
pool.save(out);
|
|
||||||
} finally {
|
|
||||||
out.closeEntry();
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
out.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected File getChangeFile() {
|
|
||||||
return new File(getHistoryDir(), id + ".change.zip");
|
|
||||||
}
|
|
||||||
|
|
||||||
protected File getHistoryDir() {
|
|
||||||
File dir = new File(ProjectManager.singleton.getProjectDir(projectID), "history");
|
|
||||||
dir.mkdirs();
|
|
||||||
|
|
||||||
return dir;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
116
main/src/com/metaweb/gridworks/io/FileHistoryEntry.java
Normal file
116
main/src/com/metaweb/gridworks/io/FileHistoryEntry.java
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package com.metaweb.gridworks.io;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipFile;
|
||||||
|
import java.util.zip.ZipOutputStream;
|
||||||
|
import java.io.Writer;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
|
import com.metaweb.gridworks.history.Change;
|
||||||
|
import com.metaweb.gridworks.history.History;
|
||||||
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
|
import com.metaweb.gridworks.model.Project;
|
||||||
|
import com.metaweb.gridworks.util.Pool;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileHistoryEntry extends HistoryEntry{
|
||||||
|
protected FileHistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time) {
|
||||||
|
super(id, projectID, description, operation, time);
|
||||||
|
}
|
||||||
|
protected FileHistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change){
|
||||||
|
super(id, project, description, operation, change);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void delete() {
|
||||||
|
File file = getChangeFile();
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void save(Writer writer, Properties options) {
|
||||||
|
JSONWriter jsonWriter = new JSONWriter(writer);
|
||||||
|
try {
|
||||||
|
write(jsonWriter, options);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadChange() {
|
||||||
|
File changeFile = getChangeFile();
|
||||||
|
|
||||||
|
try {
|
||||||
|
loadChange(changeFile);
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException("Failed to load change file " + changeFile.getAbsolutePath(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void loadChange(File file) throws Exception {
|
||||||
|
ZipFile zipFile = new ZipFile(file);
|
||||||
|
try {
|
||||||
|
Pool pool = new Pool();
|
||||||
|
ZipEntry poolEntry = zipFile.getEntry("pool.txt");
|
||||||
|
if (poolEntry != null) {
|
||||||
|
pool.load(new InputStreamReader(
|
||||||
|
zipFile.getInputStream(poolEntry)));
|
||||||
|
} // else, it's a legacy project file
|
||||||
|
|
||||||
|
_change = History.readOneChange(
|
||||||
|
zipFile.getInputStream(zipFile.getEntry("change.txt")), pool);
|
||||||
|
} finally {
|
||||||
|
zipFile.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void saveChange() throws Exception {
|
||||||
|
File changeFile = getChangeFile();
|
||||||
|
if (!(changeFile.exists())) {
|
||||||
|
saveChange(changeFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void saveChange(File file) throws Exception {
|
||||||
|
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
|
||||||
|
try {
|
||||||
|
Pool pool = new Pool();
|
||||||
|
|
||||||
|
out.putNextEntry(new ZipEntry("change.txt"));
|
||||||
|
try {
|
||||||
|
History.writeOneChange(out, _change, pool);
|
||||||
|
} finally {
|
||||||
|
out.closeEntry();
|
||||||
|
}
|
||||||
|
|
||||||
|
out.putNextEntry(new ZipEntry("pool.txt"));
|
||||||
|
try {
|
||||||
|
pool.save(out);
|
||||||
|
} finally {
|
||||||
|
out.closeEntry();
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
out.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File getChangeFile() {
|
||||||
|
return new File(getHistoryDir(), id + ".change.zip");
|
||||||
|
}
|
||||||
|
|
||||||
|
protected File getHistoryDir() {//FIXME relies on FileProjectManager
|
||||||
|
File dir = new File(((FileProjectManager)ProjectManager.singleton).getProjectDir(projectID), "history");
|
||||||
|
dir.mkdirs();
|
||||||
|
|
||||||
|
return dir;
|
||||||
|
}
|
||||||
|
}
|
@ -22,6 +22,9 @@ import org.slf4j.LoggerFactory;
|
|||||||
|
|
||||||
import com.metaweb.gridworks.ProjectManager;
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.ProjectMetadata;
|
import com.metaweb.gridworks.ProjectMetadata;
|
||||||
|
import com.metaweb.gridworks.history.Change;
|
||||||
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
import com.metaweb.gridworks.model.Project;
|
import com.metaweb.gridworks.model.Project;
|
||||||
import com.metaweb.gridworks.util.JSONUtilities;
|
import com.metaweb.gridworks.util.JSONUtilities;
|
||||||
|
|
||||||
@ -351,4 +354,11 @@ public class FileProjectManager extends ProjectManager{
|
|||||||
|
|
||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HistoryEntry createHistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time){
|
||||||
|
return new FileHistoryEntry(id, projectID, description, operation, time);
|
||||||
|
}
|
||||||
|
public HistoryEntry createHistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change){
|
||||||
|
return new FileHistoryEntry(id, project, description, operation, change);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ public class ProjectUtilities {
|
|||||||
synchronized public static void save(Project project) {
|
synchronized public static void save(Project project) {
|
||||||
synchronized (project) {
|
synchronized (project) {
|
||||||
long id = project.id;
|
long id = project.id;
|
||||||
File dir = ProjectManager.singleton.getProjectDir(id);
|
File dir = ((FileProjectManager)ProjectManager.singleton).getProjectDir(id);
|
||||||
|
|
||||||
File tempFile = new File(dir, "data.temp.zip");
|
File tempFile = new File(dir, "data.temp.zip");
|
||||||
try {
|
try {
|
||||||
|
@ -5,6 +5,7 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -18,7 +19,7 @@ import com.metaweb.gridworks.model.changes.MassCellChange;
|
|||||||
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
|
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
|
||||||
final protected String _columnName;
|
final protected String _columnName;
|
||||||
final protected boolean _updateRowContextDependencies;
|
final protected boolean _updateRowContextDependencies;
|
||||||
|
|
||||||
protected EngineDependentMassCellOperation(
|
protected EngineDependentMassCellOperation(
|
||||||
JSONObject engineConfig, String columnName, boolean updateRowContextDependencies) {
|
JSONObject engineConfig, String columnName, boolean updateRowContextDependencies) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
@ -28,32 +29,32 @@ abstract public class EngineDependentMassCellOperation extends EngineDependentOp
|
|||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
Column column = project.columnModel.getColumnByName(_columnName);
|
Column column = project.columnModel.getColumnByName(_columnName);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CellChange> cellChanges = new ArrayList<CellChange>(project.rows.size());
|
List<CellChange> cellChanges = new ArrayList<CellChange>(project.rows.size());
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
try {
|
try {
|
||||||
filteredRows.accept(project, createRowVisitor(project, cellChanges, historyEntryID));
|
filteredRows.accept(project, createRowVisitor(project, cellChanges, historyEntryID));
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = createDescription(column, cellChanges);
|
String description = createDescription(column, cellChanges);
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID, project, description, this, createChange(project, column, cellChanges));
|
historyEntryID, project, description, this, createChange(project, column, cellChanges));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Change createChange(Project project, Column column, List<CellChange> cellChanges) {
|
protected Change createChange(Project project, Column column, List<CellChange> cellChanges) {
|
||||||
return new MassCellChange(
|
return new MassCellChange(
|
||||||
cellChanges, column.getName(), _updateRowContextDependencies);
|
cellChanges, column.getName(), _updateRowContextDependencies);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception;
|
abstract protected RowVisitor createRowVisitor(Project project, List<CellChange> cellChanges, long historyEntryID) throws Exception;
|
||||||
abstract protected String createDescription(Column column, List<CellChange> cellChanges);
|
abstract protected String createDescription(Column column, List<CellChange> cellChanges);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.history.Change;
|
import com.metaweb.gridworks.history.Change;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
@ -19,20 +20,20 @@ import com.metaweb.gridworks.util.Pool;
|
|||||||
|
|
||||||
public class SaveProtographOperation extends AbstractOperation {
|
public class SaveProtographOperation extends AbstractOperation {
|
||||||
final protected Protograph _protograph;
|
final protected Protograph _protograph;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
return new SaveProtographOperation(
|
return new SaveProtographOperation(
|
||||||
Protograph.reconstruct(obj.getJSONObject("protograph"))
|
Protograph.reconstruct(obj.getJSONObject("protograph"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SaveProtographOperation(Protograph protograph) {
|
public SaveProtographOperation(Protograph protograph) {
|
||||||
_protograph = protograph;
|
_protograph = protograph;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value("Save protograph");
|
writer.key("description"); writer.value("Save protograph");
|
||||||
@ -47,20 +48,20 @@ public class SaveProtographOperation extends AbstractOperation {
|
|||||||
@Override
|
@Override
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
String description = "Save schema-alignment protograph";
|
String description = "Save schema-alignment protograph";
|
||||||
|
|
||||||
Change change = new ProtographChange(_protograph);
|
Change change = new ProtographChange(_protograph);
|
||||||
|
|
||||||
return new HistoryEntry(historyEntryID, project, description, SaveProtographOperation.this, change);
|
return ProjectManager.singleton.createHistoryEntry(historyEntryID, project, description, SaveProtographOperation.this, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
static public class ProtographChange implements Change {
|
static public class ProtographChange implements Change {
|
||||||
final protected Protograph _newProtograph;
|
final protected Protograph _newProtograph;
|
||||||
protected Protograph _oldProtograph;
|
protected Protograph _oldProtograph;
|
||||||
|
|
||||||
public ProtographChange(Protograph protograph) {
|
public ProtographChange(Protograph protograph) {
|
||||||
_newProtograph = protograph;
|
_newProtograph = protograph;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(Project project) {
|
public void apply(Project project) {
|
||||||
synchronized (project) {
|
synchronized (project) {
|
||||||
_oldProtograph = project.protograph;
|
_oldProtograph = project.protograph;
|
||||||
@ -73,36 +74,36 @@ public class SaveProtographOperation extends AbstractOperation {
|
|||||||
project.protograph = _oldProtograph;
|
project.protograph = _oldProtograph;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Writer writer, Properties options) throws IOException {
|
public void save(Writer writer, Properties options) throws IOException {
|
||||||
writer.write("newProtograph="); writeProtograph(_newProtograph, writer); writer.write('\n');
|
writer.write("newProtograph="); writeProtograph(_newProtograph, writer); writer.write('\n');
|
||||||
writer.write("oldProtograph="); writeProtograph(_oldProtograph, writer); writer.write('\n');
|
writer.write("oldProtograph="); writeProtograph(_oldProtograph, writer); writer.write('\n');
|
||||||
writer.write("/ec/\n"); // end of change marker
|
writer.write("/ec/\n"); // end of change marker
|
||||||
}
|
}
|
||||||
|
|
||||||
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
static public Change load(LineNumberReader reader, Pool pool) throws Exception {
|
||||||
Protograph oldProtograph = null;
|
Protograph oldProtograph = null;
|
||||||
Protograph newProtograph = null;
|
Protograph newProtograph = null;
|
||||||
|
|
||||||
String line;
|
String line;
|
||||||
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
while ((line = reader.readLine()) != null && !"/ec/".equals(line)) {
|
||||||
int equal = line.indexOf('=');
|
int equal = line.indexOf('=');
|
||||||
CharSequence field = line.subSequence(0, equal);
|
CharSequence field = line.subSequence(0, equal);
|
||||||
String value = line.substring(equal + 1);
|
String value = line.substring(equal + 1);
|
||||||
|
|
||||||
if ("oldProtograph".equals(field) && value.length() > 0) {
|
if ("oldProtograph".equals(field) && value.length() > 0) {
|
||||||
oldProtograph = Protograph.reconstruct(ParsingUtilities.evaluateJsonStringToObject(value));
|
oldProtograph = Protograph.reconstruct(ParsingUtilities.evaluateJsonStringToObject(value));
|
||||||
} else if ("newProtograph".equals(field) && value.length() > 0) {
|
} else if ("newProtograph".equals(field) && value.length() > 0) {
|
||||||
newProtograph = Protograph.reconstruct(ParsingUtilities.evaluateJsonStringToObject(value));
|
newProtograph = Protograph.reconstruct(ParsingUtilities.evaluateJsonStringToObject(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtographChange change = new ProtographChange(newProtograph);
|
ProtographChange change = new ProtographChange(newProtograph);
|
||||||
change._oldProtograph = oldProtograph;
|
change._oldProtograph = oldProtograph;
|
||||||
|
|
||||||
return change;
|
return change;
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected void writeProtograph(Protograph p, Writer writer) throws IOException {
|
static protected void writeProtograph(Protograph p, Writer writer) throws IOException {
|
||||||
if (p != null) {
|
if (p != null) {
|
||||||
JSONWriter jsonWriter = new JSONWriter(writer);
|
JSONWriter jsonWriter = new JSONWriter(writer);
|
||||||
@ -113,5 +114,5 @@ public class SaveProtographOperation extends AbstractOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.expr.ExpressionUtils;
|
import com.metaweb.gridworks.expr.ExpressionUtils;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
@ -30,7 +31,7 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
obj.getString("separator")
|
obj.getString("separator")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiValuedCellJoinOperation(
|
public MultiValuedCellJoinOperation(
|
||||||
String columnName,
|
String columnName,
|
||||||
String keyColumnName,
|
String keyColumnName,
|
||||||
@ -43,7 +44,7 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -52,7 +53,7 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
writer.key("separator"); writer.value(_separator);
|
writer.key("separator"); writer.value(_separator);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Join multi-valued cells in column " + _columnName;
|
return "Join multi-valued cells in column " + _columnName;
|
||||||
}
|
}
|
||||||
@ -63,34 +64,34 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
int cellIndex = column.getCellIndex();
|
int cellIndex = column.getCellIndex();
|
||||||
|
|
||||||
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
|
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
|
||||||
if (keyColumn == null) {
|
if (keyColumn == null) {
|
||||||
throw new Exception("No key column named " + _keyColumnName);
|
throw new Exception("No key column named " + _keyColumnName);
|
||||||
}
|
}
|
||||||
int keyCellIndex = keyColumn.getCellIndex();
|
int keyCellIndex = keyColumn.getCellIndex();
|
||||||
|
|
||||||
List<Row> newRows = new ArrayList<Row>();
|
List<Row> newRows = new ArrayList<Row>();
|
||||||
|
|
||||||
int oldRowCount = project.rows.size();
|
int oldRowCount = project.rows.size();
|
||||||
for (int r = 0; r < oldRowCount; r++) {
|
for (int r = 0; r < oldRowCount; r++) {
|
||||||
Row oldRow = project.rows.get(r);
|
Row oldRow = project.rows.get(r);
|
||||||
|
|
||||||
if (oldRow.isCellBlank(keyCellIndex)) {
|
if (oldRow.isCellBlank(keyCellIndex)) {
|
||||||
newRows.add(oldRow.dup());
|
newRows.add(oldRow.dup());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int r2 = r + 1;
|
int r2 = r + 1;
|
||||||
while (r2 < oldRowCount && project.rows.get(r2).isCellBlank(keyCellIndex)) {
|
while (r2 < oldRowCount && project.rows.get(r2).isCellBlank(keyCellIndex)) {
|
||||||
r2++;
|
r2++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (r2 == r + 1) {
|
if (r2 == r + 1) {
|
||||||
newRows.add(oldRow.dup());
|
newRows.add(oldRow.dup());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
StringBuffer sb = new StringBuffer();
|
StringBuffer sb = new StringBuffer();
|
||||||
for (int r3 = r; r3 < r2; r3++) {
|
for (int r3 = r; r3 < r2; r3++) {
|
||||||
Object value = project.rows.get(r3).getCellValue(cellIndex);
|
Object value = project.rows.get(r3).getCellValue(cellIndex);
|
||||||
@ -101,7 +102,7 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
sb.append(value.toString());
|
sb.append(value.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int r3 = r; r3 < r2; r3++) {
|
for (int r3 = r; r3 < r2; r3++) {
|
||||||
Row newRow = project.rows.get(r3).dup();
|
Row newRow = project.rows.get(r3).dup();
|
||||||
if (r3 == r) {
|
if (r3 == r) {
|
||||||
@ -109,20 +110,20 @@ public class MultiValuedCellJoinOperation extends AbstractOperation {
|
|||||||
} else {
|
} else {
|
||||||
newRow.setCell(cellIndex, null);
|
newRow.setCell(cellIndex, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!newRow.isEmpty()) {
|
if (!newRow.isEmpty()) {
|
||||||
newRows.add(newRow);
|
newRows.add(newRow);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
r = r2 - 1; // r will be incremented by the for loop anyway
|
r = r2 - 1; // r will be incremented by the for loop anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
getBriefDescription(null),
|
getBriefDescription(null),
|
||||||
this,
|
this,
|
||||||
new MassRowChange(newRows)
|
new MassRowChange(newRows)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
import com.metaweb.gridworks.model.Cell;
|
import com.metaweb.gridworks.model.Cell;
|
||||||
@ -32,7 +33,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
obj.getString("mode")
|
obj.getString("mode")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public MultiValuedCellSplitOperation(
|
public MultiValuedCellSplitOperation(
|
||||||
String columnName,
|
String columnName,
|
||||||
String keyColumnName,
|
String keyColumnName,
|
||||||
@ -47,7 +48,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
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("description"); writer.value("Split multi-valued cells in column " + _columnName);
|
||||||
@ -69,15 +70,15 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
int cellIndex = column.getCellIndex();
|
int cellIndex = column.getCellIndex();
|
||||||
|
|
||||||
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
|
Column keyColumn = project.columnModel.getColumnByName(_keyColumnName);
|
||||||
if (keyColumn == null) {
|
if (keyColumn == null) {
|
||||||
throw new Exception("No key column named " + _keyColumnName);
|
throw new Exception("No key column named " + _keyColumnName);
|
||||||
}
|
}
|
||||||
int keyCellIndex = keyColumn.getCellIndex();
|
int keyCellIndex = keyColumn.getCellIndex();
|
||||||
|
|
||||||
List<Row> newRows = new ArrayList<Row>();
|
List<Row> newRows = new ArrayList<Row>();
|
||||||
|
|
||||||
int oldRowCount = project.rows.size();
|
int oldRowCount = project.rows.size();
|
||||||
for (int r = 0; r < oldRowCount; r++) {
|
for (int r = 0; r < oldRowCount; r++) {
|
||||||
Row oldRow = project.rows.get(r);
|
Row oldRow = project.rows.get(r);
|
||||||
@ -85,7 +86,7 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
newRows.add(oldRow.dup());
|
newRows.add(oldRow.dup());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Object value = oldRow.getCellValue(cellIndex);
|
Object value = oldRow.getCellValue(cellIndex);
|
||||||
String s = value instanceof String ? ((String) value) : value.toString();
|
String s = value instanceof String ? ((String) value) : value.toString();
|
||||||
String[] values = null;
|
String[] values = null;
|
||||||
@ -94,53 +95,53 @@ public class MultiValuedCellSplitOperation extends AbstractOperation {
|
|||||||
} else {
|
} else {
|
||||||
values = StringUtils.splitByWholeSeparator(s, _separator);
|
values = StringUtils.splitByWholeSeparator(s, _separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (values.length < 2) {
|
if (values.length < 2) {
|
||||||
newRows.add(oldRow.dup());
|
newRows.add(oldRow.dup());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// First value goes into the same row
|
// First value goes into the same row
|
||||||
{
|
{
|
||||||
Row firstNewRow = oldRow.dup();
|
Row firstNewRow = oldRow.dup();
|
||||||
firstNewRow.setCell(cellIndex, new Cell(values[0].trim(), null));
|
firstNewRow.setCell(cellIndex, new Cell(values[0].trim(), null));
|
||||||
|
|
||||||
newRows.add(firstNewRow);
|
newRows.add(firstNewRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
int r2 = r + 1;
|
int r2 = r + 1;
|
||||||
for (int v = 1; v < values.length; v++) {
|
for (int v = 1; v < values.length; v++) {
|
||||||
Cell newCell = new Cell(values[v].trim(), null);
|
Cell newCell = new Cell(values[v].trim(), null);
|
||||||
|
|
||||||
if (r2 < project.rows.size()) {
|
if (r2 < project.rows.size()) {
|
||||||
Row oldRow2 = project.rows.get(r2);
|
Row oldRow2 = project.rows.get(r2);
|
||||||
if (oldRow2.isCellBlank(cellIndex) &&
|
if (oldRow2.isCellBlank(cellIndex) &&
|
||||||
oldRow2.isCellBlank(keyCellIndex)) {
|
oldRow2.isCellBlank(keyCellIndex)) {
|
||||||
|
|
||||||
Row newRow = oldRow2.dup();
|
Row newRow = oldRow2.dup();
|
||||||
newRow.setCell(cellIndex, newCell);
|
newRow.setCell(cellIndex, newCell);
|
||||||
|
|
||||||
newRows.add(newRow);
|
newRows.add(newRow);
|
||||||
r2++;
|
r2++;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Row newRow = new Row(cellIndex + 1);
|
Row newRow = new Row(cellIndex + 1);
|
||||||
newRow.setCell(cellIndex, newCell);
|
newRow.setCell(cellIndex, newCell);
|
||||||
|
|
||||||
newRows.add(newRow);
|
newRows.add(newRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
r = r2 - 1; // r will be incremented by the for loop anyway
|
r = r2 - 1; // r will be incremented by the for loop anyway
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
getBriefDescription(null),
|
getBriefDescription(null),
|
||||||
this,
|
this,
|
||||||
new MassRowChange(newRows)
|
new MassRowChange(newRows)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -34,13 +35,13 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
final protected String _baseColumnName;
|
final protected String _baseColumnName;
|
||||||
final protected String _expression;
|
final protected String _expression;
|
||||||
final protected OnError _onError;
|
final protected OnError _onError;
|
||||||
|
|
||||||
final protected String _newColumnName;
|
final protected String _newColumnName;
|
||||||
final protected int _columnInsertIndex;
|
final protected int _columnInsertIndex;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
|
|
||||||
return new ColumnAdditionOperation(
|
return new ColumnAdditionOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
obj.getString("baseColumnName"),
|
obj.getString("baseColumnName"),
|
||||||
@ -50,28 +51,28 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
obj.getInt("columnInsertIndex")
|
obj.getInt("columnInsertIndex")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnAdditionOperation(
|
public ColumnAdditionOperation(
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String baseColumnName,
|
String baseColumnName,
|
||||||
String expression,
|
String expression,
|
||||||
OnError onError,
|
OnError onError,
|
||||||
String newColumnName,
|
String newColumnName,
|
||||||
int columnInsertIndex
|
int columnInsertIndex
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
|
|
||||||
_baseColumnName = baseColumnName;
|
_baseColumnName = baseColumnName;
|
||||||
_expression = expression;
|
_expression = expression;
|
||||||
_onError = onError;
|
_onError = onError;
|
||||||
|
|
||||||
_newColumnName = newColumnName;
|
_newColumnName = newColumnName;
|
||||||
_columnInsertIndex = columnInsertIndex;
|
_columnInsertIndex = columnInsertIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -85,52 +86,52 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Create column " + _newColumnName +
|
return "Create column " + _newColumnName +
|
||||||
" at index " + _columnInsertIndex +
|
" at index " + _columnInsertIndex +
|
||||||
" based on column " + _baseColumnName +
|
" based on column " + _baseColumnName +
|
||||||
" using expression " + _expression;
|
" using expression " + _expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
||||||
return "Create new column " + _newColumnName +
|
return "Create new column " + _newColumnName +
|
||||||
" based on column " + column.getName() +
|
" based on column " + column.getName() +
|
||||||
" by filling " + cellsAtRows.size() +
|
" by filling " + cellsAtRows.size() +
|
||||||
" rows with " + _expression;
|
" rows with " + _expression;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
Column column = project.columnModel.getColumnByName(_baseColumnName);
|
Column column = project.columnModel.getColumnByName(_baseColumnName);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _baseColumnName);
|
throw new Exception("No column named " + _baseColumnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CellAtRow> cellsAtRows = new ArrayList<CellAtRow>(project.rows.size());
|
List<CellAtRow> cellsAtRows = new ArrayList<CellAtRow>(project.rows.size());
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(project, createRowVisitor(project, cellsAtRows));
|
filteredRows.accept(project, createRowVisitor(project, cellsAtRows));
|
||||||
|
|
||||||
String description = createDescription(column, cellsAtRows);
|
String description = createDescription(column, cellsAtRows);
|
||||||
|
|
||||||
Change change = new ColumnAdditionChange(_newColumnName, _columnInsertIndex, cellsAtRows);
|
Change change = new ColumnAdditionChange(_newColumnName, _columnInsertIndex, cellsAtRows);
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID, project, description, this, change);
|
historyEntryID, project, description, this, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected RowVisitor createRowVisitor(Project project, List<CellAtRow> cellsAtRows) throws Exception {
|
protected RowVisitor createRowVisitor(Project project, List<CellAtRow> cellsAtRows) throws Exception {
|
||||||
Column column = project.columnModel.getColumnByName(_baseColumnName);
|
Column column = project.columnModel.getColumnByName(_baseColumnName);
|
||||||
|
|
||||||
Evaluable eval = MetaParser.parse(_expression);
|
Evaluable eval = MetaParser.parse(_expression);
|
||||||
Properties bindings = ExpressionUtils.createBindings(project);
|
Properties bindings = ExpressionUtils.createBindings(project);
|
||||||
|
|
||||||
return new RowVisitor() {
|
return new RowVisitor() {
|
||||||
int cellIndex;
|
int cellIndex;
|
||||||
Properties bindings;
|
Properties bindings;
|
||||||
List<CellAtRow> cellsAtRows;
|
List<CellAtRow> cellsAtRows;
|
||||||
Evaluable eval;
|
Evaluable eval;
|
||||||
|
|
||||||
public RowVisitor init(int cellIndex, Properties bindings, List<CellAtRow> cellsAtRows, Evaluable eval) {
|
public RowVisitor init(int cellIndex, Properties bindings, List<CellAtRow> cellsAtRows, Evaluable eval) {
|
||||||
this.cellIndex = cellIndex;
|
this.cellIndex = cellIndex;
|
||||||
this.bindings = bindings;
|
this.bindings = bindings;
|
||||||
@ -138,23 +139,23 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
this.eval = eval;
|
this.eval = eval;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
Cell cell = row.getCell(cellIndex);
|
Cell cell = row.getCell(cellIndex);
|
||||||
Cell newCell = null;
|
Cell newCell = null;
|
||||||
|
|
||||||
ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell);
|
ExpressionUtils.bind(bindings, row, rowIndex, _baseColumnName, cell);
|
||||||
|
|
||||||
Object o = eval.evaluate(bindings);
|
Object o = eval.evaluate(bindings);
|
||||||
if (o != null) {
|
if (o != null) {
|
||||||
if (o instanceof Cell) {
|
if (o instanceof Cell) {
|
||||||
@ -170,17 +171,17 @@ public class ColumnAdditionOperation extends EngineDependentOperation {
|
|||||||
v = cell != null ? cell.value : null;
|
v = cell != null ? cell.value : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (v != null) {
|
if (v != null) {
|
||||||
newCell = new Cell(v, null);
|
newCell = new Cell(v, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (newCell != null) {
|
if (newCell != null) {
|
||||||
cellsAtRows.add(new CellAtRow(rowIndex, newCell));
|
cellsAtRows.add(new CellAtRow(rowIndex, newCell));
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}.init(column.getCellIndex(), bindings, cellsAtRows, eval);
|
}.init(column.getCellIndex(), bindings, cellsAtRows, eval);
|
||||||
|
@ -6,6 +6,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.history.Change;
|
import com.metaweb.gridworks.history.Change;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
@ -22,16 +23,16 @@ public class ColumnRemovalOperation extends AbstractOperation {
|
|||||||
obj.getString("columnName")
|
obj.getString("columnName")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnRemovalOperation(
|
public ColumnRemovalOperation(
|
||||||
String columnName
|
String columnName
|
||||||
) {
|
) {
|
||||||
_columnName = columnName;
|
_columnName = columnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value("Remove column " + _columnName);
|
writer.key("description"); writer.value("Remove column " + _columnName);
|
||||||
@ -49,11 +50,11 @@ public class ColumnRemovalOperation extends AbstractOperation {
|
|||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
String description = "Remove column " + column.getName();
|
String description = "Remove column " + column.getName();
|
||||||
|
|
||||||
Change change = new ColumnRemovalChange(project.columnModel.columns.indexOf(column));
|
Change change = new ColumnRemovalChange(project.columnModel.columns.indexOf(column));
|
||||||
|
|
||||||
return new HistoryEntry(historyEntryID, project, description, ColumnRemovalOperation.this, change);
|
return ProjectManager.singleton.createHistoryEntry(historyEntryID, project, description, ColumnRemovalOperation.this, change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.history.Change;
|
import com.metaweb.gridworks.history.Change;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
@ -23,7 +24,7 @@ public class ColumnRenameOperation extends AbstractOperation {
|
|||||||
obj.getString("newColumnName")
|
obj.getString("newColumnName")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnRenameOperation(
|
public ColumnRenameOperation(
|
||||||
String oldColumnName,
|
String oldColumnName,
|
||||||
String newColumnName
|
String newColumnName
|
||||||
@ -31,10 +32,10 @@ public class ColumnRenameOperation extends AbstractOperation {
|
|||||||
_oldColumnName = oldColumnName;
|
_oldColumnName = oldColumnName;
|
||||||
_newColumnName = newColumnName;
|
_newColumnName = newColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value("Rename column " + _oldColumnName + " to " + _newColumnName);
|
writer.key("description"); writer.value("Rename column " + _oldColumnName + " to " + _newColumnName);
|
||||||
@ -55,9 +56,9 @@ public class ColumnRenameOperation extends AbstractOperation {
|
|||||||
if (project.columnModel.getColumnByName(_newColumnName) != null) {
|
if (project.columnModel.getColumnByName(_newColumnName) != null) {
|
||||||
throw new Exception("Another column already named " + _newColumnName);
|
throw new Exception("Another column already named " + _newColumnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Change change = new ColumnRenameChange(_oldColumnName, _newColumnName);
|
Change change = new ColumnRenameChange(_oldColumnName, _newColumnName);
|
||||||
|
|
||||||
return new HistoryEntry(historyEntryID, project, getBriefDescription(null), ColumnRenameOperation.this, change);
|
return ProjectManager.singleton.createHistoryEntry(historyEntryID, project, getBriefDescription(null), ColumnRenameOperation.this, change);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,6 +11,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -32,17 +33,17 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
final protected boolean _guessCellType;
|
final protected boolean _guessCellType;
|
||||||
final protected boolean _removeOriginalColumn;
|
final protected boolean _removeOriginalColumn;
|
||||||
final protected String _mode;
|
final protected String _mode;
|
||||||
|
|
||||||
final protected String _separator;
|
final protected String _separator;
|
||||||
final protected boolean _regex;
|
final protected boolean _regex;
|
||||||
final protected int _maxColumns;
|
final protected int _maxColumns;
|
||||||
|
|
||||||
final protected int[] _fieldLengths;
|
final protected int[] _fieldLengths;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
String mode = obj.getString("mode");
|
String mode = obj.getString("mode");
|
||||||
|
|
||||||
if ("separator".equals(mode)) {
|
if ("separator".equals(mode)) {
|
||||||
return new ColumnSplitOperation(
|
return new ColumnSplitOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
@ -63,7 +64,7 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnSplitOperation(
|
public ColumnSplitOperation(
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String columnName,
|
String columnName,
|
||||||
@ -74,19 +75,19 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
int maxColumns
|
int maxColumns
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
|
|
||||||
_columnName = columnName;
|
_columnName = columnName;
|
||||||
_guessCellType = guessCellType;
|
_guessCellType = guessCellType;
|
||||||
_removeOriginalColumn = removeOriginalColumn;
|
_removeOriginalColumn = removeOriginalColumn;
|
||||||
|
|
||||||
_mode = "separator";
|
_mode = "separator";
|
||||||
_separator = separator;
|
_separator = separator;
|
||||||
_regex = regex;
|
_regex = regex;
|
||||||
_maxColumns = maxColumns;
|
_maxColumns = maxColumns;
|
||||||
|
|
||||||
_fieldLengths = null;
|
_fieldLengths = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColumnSplitOperation(
|
public ColumnSplitOperation(
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String columnName,
|
String columnName,
|
||||||
@ -95,22 +96,22 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
int[] fieldLengths
|
int[] fieldLengths
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
|
|
||||||
_columnName = columnName;
|
_columnName = columnName;
|
||||||
_guessCellType = guessCellType;
|
_guessCellType = guessCellType;
|
||||||
_removeOriginalColumn = removeOriginalColumn;
|
_removeOriginalColumn = removeOriginalColumn;
|
||||||
|
|
||||||
_mode = "lengths";
|
_mode = "lengths";
|
||||||
_separator = null;
|
_separator = null;
|
||||||
_regex = false;
|
_regex = false;
|
||||||
_maxColumns = -1;
|
_maxColumns = -1;
|
||||||
|
|
||||||
_fieldLengths = fieldLengths;
|
_fieldLengths = fieldLengths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -134,53 +135,53 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Split column " + _columnName +
|
return "Split column " + _columnName +
|
||||||
("separator".equals(_mode) ? " by separator" : " by field lengths");
|
("separator".equals(_mode) ? " by separator" : " by field lengths");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
Column column = project.columnModel.getColumnByName(_columnName);
|
Column column = project.columnModel.getColumnByName(_columnName);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> columnNames = new ArrayList<String>();
|
List<String> columnNames = new ArrayList<String>();
|
||||||
List<Integer> rowIndices = new ArrayList<Integer>(project.rows.size());
|
List<Integer> rowIndices = new ArrayList<Integer>(project.rows.size());
|
||||||
List<List<Serializable>> tuples = new ArrayList<List<Serializable>>(project.rows.size());
|
List<List<Serializable>> tuples = new ArrayList<List<Serializable>>(project.rows.size());
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
RowVisitor rowVisitor;
|
RowVisitor rowVisitor;
|
||||||
if ("lengths".equals(_mode)) {
|
if ("lengths".equals(_mode)) {
|
||||||
rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
|
rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
|
||||||
protected java.util.List<Serializable> split(String s) {
|
protected java.util.List<Serializable> split(String s) {
|
||||||
List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1);
|
List<Serializable> results = new ArrayList<Serializable>(_fieldLengths.length + 1);
|
||||||
|
|
||||||
int lastIndex = 0;
|
int lastIndex = 0;
|
||||||
for (int i = 0; i < _fieldLengths.length; i++) {
|
for (int i = 0; i < _fieldLengths.length; i++) {
|
||||||
int from = lastIndex;
|
int from = lastIndex;
|
||||||
int length = _fieldLengths[i];
|
int length = _fieldLengths[i];
|
||||||
int to = Math.min(from + length, s.length());
|
int to = Math.min(from + length, s.length());
|
||||||
|
|
||||||
results.add(stringToValue(s.substring(from, to)));
|
results.add(stringToValue(s.substring(from, to)));
|
||||||
|
|
||||||
lastIndex = to;
|
lastIndex = to;
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
} else if (_regex) {
|
} else if (_regex) {
|
||||||
Pattern pattern = Pattern.compile(_separator);
|
Pattern pattern = Pattern.compile(_separator);
|
||||||
|
|
||||||
rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
|
rowVisitor = new ColumnSplitRowVisitor(column.getCellIndex(), columnNames, rowIndices, tuples) {
|
||||||
Pattern _pattern;
|
Pattern _pattern;
|
||||||
|
|
||||||
protected java.util.List<Serializable> split(String s) {
|
protected java.util.List<Serializable> split(String s) {
|
||||||
return stringArrayToValueList(_pattern.split(s, _maxColumns));
|
return stringArrayToValueList(_pattern.split(s, _maxColumns));
|
||||||
};
|
};
|
||||||
|
|
||||||
public RowVisitor init(Pattern pattern) {
|
public RowVisitor init(Pattern pattern) {
|
||||||
_pattern = pattern;
|
_pattern = pattern;
|
||||||
return this;
|
return this;
|
||||||
@ -194,13 +195,13 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
filteredRows.accept(project, rowVisitor);
|
filteredRows.accept(project, rowVisitor);
|
||||||
|
|
||||||
String description =
|
String description =
|
||||||
"Split " + rowIndices.size() +
|
"Split " + rowIndices.size() +
|
||||||
" cell(s) in column " + _columnName +
|
" cell(s) in column " + _columnName +
|
||||||
" into several columns" +
|
" into several columns" +
|
||||||
("separator".equals(_mode) ? " by separator" : " by field lengths");
|
("separator".equals(_mode) ? " by separator" : " by field lengths");
|
||||||
|
|
||||||
Change change = new ColumnSplitChange(
|
Change change = new ColumnSplitChange(
|
||||||
@ -210,8 +211,8 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
tuples,
|
tuples,
|
||||||
_removeOriginalColumn
|
_removeOriginalColumn
|
||||||
);
|
);
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID, project, description, this, change);
|
historyEntryID, project, description, this, change);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,9 +222,9 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
List<String> columnNames;
|
List<String> columnNames;
|
||||||
List<Integer> rowIndices;
|
List<Integer> rowIndices;
|
||||||
List<List<Serializable>> tuples;
|
List<List<Serializable>> tuples;
|
||||||
|
|
||||||
int columnNameIndex = 1;
|
int columnNameIndex = 1;
|
||||||
|
|
||||||
ColumnSplitRowVisitor(
|
ColumnSplitRowVisitor(
|
||||||
int cellIndex,
|
int cellIndex,
|
||||||
List<String> columnNames,
|
List<String> columnNames,
|
||||||
@ -235,27 +236,27 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
this.rowIndices = rowIndices;
|
this.rowIndices = rowIndices;
|
||||||
this.tuples = tuples;
|
this.tuples = tuples;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
Object value = row.getCellValue(cellIndex);
|
Object value = row.getCellValue(cellIndex);
|
||||||
if (ExpressionUtils.isNonBlankData(value)) {
|
if (ExpressionUtils.isNonBlankData(value)) {
|
||||||
String s = value instanceof String ? ((String) value) : value.toString();
|
String s = value instanceof String ? ((String) value) : value.toString();
|
||||||
|
|
||||||
List<Serializable> tuple = split(s);
|
List<Serializable> tuple = split(s);
|
||||||
|
|
||||||
rowIndices.add(rowIndex);
|
rowIndices.add(rowIndex);
|
||||||
tuples.add(tuple);
|
tuples.add(tuple);
|
||||||
|
|
||||||
for (int i = columnNames.size(); i < tuple.size(); i++) {
|
for (int i = columnNames.size(); i < tuple.size(); i++) {
|
||||||
while (true) {
|
while (true) {
|
||||||
String newColumnName = _columnName + " " + columnNameIndex++;
|
String newColumnName = _columnName + " " + columnNameIndex++;
|
||||||
@ -268,21 +269,21 @@ public class ColumnSplitOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Serializable> split(String s) {
|
protected List<Serializable> split(String s) {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Serializable stringToValue(String s) {
|
protected Serializable stringToValue(String s) {
|
||||||
return _guessCellType ? ImporterUtilities.parseCellValue(s) : s;
|
return _guessCellType ? ImporterUtilities.parseCellValue(s) : s;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<Serializable> stringArrayToValueList(String[] cells) {
|
protected List<Serializable> stringArrayToValueList(String[] cells) {
|
||||||
List<Serializable> results = new ArrayList<Serializable>(cells.length);
|
List<Serializable> results = new ArrayList<Serializable>(cells.length);
|
||||||
for (String cell : cells) {
|
for (String cell : cells) {
|
||||||
results.add(stringToValue(cell));
|
results.add(stringToValue(cell));
|
||||||
}
|
}
|
||||||
|
|
||||||
return results;
|
return results;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -38,10 +39,10 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
final protected String _baseColumnName;
|
final protected String _baseColumnName;
|
||||||
final protected JSONObject _extension;
|
final protected JSONObject _extension;
|
||||||
final protected int _columnInsertIndex;
|
final protected int _columnInsertIndex;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
|
|
||||||
return new ExtendDataOperation(
|
return new ExtendDataOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
obj.getString("baseColumnName"),
|
obj.getString("baseColumnName"),
|
||||||
@ -49,15 +50,15 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
obj.getInt("columnInsertIndex")
|
obj.getInt("columnInsertIndex")
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExtendDataOperation(
|
public ExtendDataOperation(
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String baseColumnName,
|
String baseColumnName,
|
||||||
JSONObject extension,
|
JSONObject extension,
|
||||||
int columnInsertIndex
|
int columnInsertIndex
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
|
|
||||||
_baseColumnName = baseColumnName;
|
_baseColumnName = baseColumnName;
|
||||||
_extension = extension;
|
_extension = extension;
|
||||||
_columnInsertIndex = columnInsertIndex;
|
_columnInsertIndex = columnInsertIndex;
|
||||||
@ -65,7 +66,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -77,24 +78,24 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return "Extend data at index " + _columnInsertIndex +
|
return "Extend data at index " + _columnInsertIndex +
|
||||||
" based on column " + _baseColumnName;
|
" based on column " + _baseColumnName;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
protected String createDescription(Column column, List<CellAtRow> cellsAtRows) {
|
||||||
return "Extend data at index " + _columnInsertIndex +
|
return "Extend data at index " + _columnInsertIndex +
|
||||||
" based on column " + column.getName() +
|
" based on column " + column.getName() +
|
||||||
" by filling " + cellsAtRows.size();
|
" by filling " + cellsAtRows.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Process createProcess(Project project, Properties options) throws Exception {
|
public Process createProcess(Project project, Properties options) throws Exception {
|
||||||
return new ExtendDataProcess(
|
return new ExtendDataProcess(
|
||||||
project,
|
project,
|
||||||
getEngineConfig(),
|
getEngineConfig(),
|
||||||
getBriefDescription(null)
|
getBriefDescription(null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ExtendDataProcess extends LongRunningProcess implements Runnable {
|
public class ExtendDataProcess extends LongRunningProcess implements Runnable {
|
||||||
final protected Project _project;
|
final protected Project _project;
|
||||||
final protected JSONObject _engineConfig;
|
final protected JSONObject _engineConfig;
|
||||||
@ -103,21 +104,21 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
protected FreebaseDataExtensionJob _job;
|
protected FreebaseDataExtensionJob _job;
|
||||||
|
|
||||||
public ExtendDataProcess(
|
public ExtendDataProcess(
|
||||||
Project project,
|
Project project,
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String description
|
String description
|
||||||
) throws JSONException {
|
) throws JSONException {
|
||||||
super(description);
|
super(description);
|
||||||
_project = project;
|
_project = project;
|
||||||
_engineConfig = engineConfig;
|
_engineConfig = engineConfig;
|
||||||
_historyEntryID = HistoryEntry.allocateID();
|
_historyEntryID = HistoryEntry.allocateID();
|
||||||
|
|
||||||
_job = new FreebaseDataExtensionJob(_extension);
|
_job = new FreebaseDataExtensionJob(_extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("id"); writer.value(hashCode());
|
writer.key("id"); writer.value(hashCode());
|
||||||
writer.key("description"); writer.value(_description);
|
writer.key("description"); writer.value(_description);
|
||||||
@ -126,111 +127,111 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
writer.key("progress"); writer.value(_progress);
|
writer.key("progress"); writer.value(_progress);
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Runnable getRunnable() {
|
protected Runnable getRunnable() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void populateRowsWithMatches(List<Integer> rowIndices) throws Exception {
|
protected void populateRowsWithMatches(List<Integer> rowIndices) throws Exception {
|
||||||
Engine engine = new Engine(_project);
|
Engine engine = new Engine(_project);
|
||||||
engine.initializeFromJSON(_engineConfig);
|
engine.initializeFromJSON(_engineConfig);
|
||||||
|
|
||||||
Column column = _project.columnModel.getColumnByName(_baseColumnName);
|
Column column = _project.columnModel.getColumnByName(_baseColumnName);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _baseColumnName);
|
throw new Exception("No column named " + _baseColumnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
_cellIndex = column.getCellIndex();
|
_cellIndex = column.getCellIndex();
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(_project, new RowVisitor() {
|
filteredRows.accept(_project, new RowVisitor() {
|
||||||
List<Integer> _rowIndices;
|
List<Integer> _rowIndices;
|
||||||
|
|
||||||
public RowVisitor init(List<Integer> rowIndices) {
|
public RowVisitor init(List<Integer> rowIndices) {
|
||||||
_rowIndices = rowIndices;
|
_rowIndices = rowIndices;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
Cell cell = row.getCell(_cellIndex);
|
Cell cell = row.getCell(_cellIndex);
|
||||||
if (cell != null && cell.recon != null && cell.recon.match != null) {
|
if (cell != null && cell.recon != null && cell.recon.match != null) {
|
||||||
_rowIndices.add(rowIndex);
|
_rowIndices.add(rowIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}.init(rowIndices));
|
}.init(rowIndices));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int extendRows(
|
protected int extendRows(
|
||||||
List<Integer> rowIndices,
|
List<Integer> rowIndices,
|
||||||
List<DataExtension> dataExtensions,
|
List<DataExtension> dataExtensions,
|
||||||
int from,
|
int from,
|
||||||
int limit,
|
int limit,
|
||||||
Map<String, ReconCandidate> reconCandidateMap
|
Map<String, ReconCandidate> reconCandidateMap
|
||||||
) {
|
) {
|
||||||
Set<String> guids = new HashSet<String>();
|
Set<String> guids = new HashSet<String>();
|
||||||
|
|
||||||
int end;
|
int end;
|
||||||
for (end = from; end < limit && guids.size() < 10; end++) {
|
for (end = from; end < limit && guids.size() < 10; end++) {
|
||||||
int index = rowIndices.get(end);
|
int index = rowIndices.get(end);
|
||||||
Row row = _project.rows.get(index);
|
Row row = _project.rows.get(index);
|
||||||
Cell cell = row.getCell(_cellIndex);
|
Cell cell = row.getCell(_cellIndex);
|
||||||
|
|
||||||
guids.add(cell.recon.match.topicGUID);
|
guids.add(cell.recon.match.topicGUID);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, DataExtension> map = null;
|
Map<String, DataExtension> map = null;
|
||||||
try {
|
try {
|
||||||
map = _job.extend(guids, reconCandidateMap);
|
map = _job.extend(guids, reconCandidateMap);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
map = new HashMap<String, DataExtension>();
|
map = new HashMap<String, DataExtension>();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = from; i < end; i++) {
|
for (int i = from; i < end; i++) {
|
||||||
int index = rowIndices.get(i);
|
int index = rowIndices.get(i);
|
||||||
Row row = _project.rows.get(index);
|
Row row = _project.rows.get(index);
|
||||||
Cell cell = row.getCell(_cellIndex);
|
Cell cell = row.getCell(_cellIndex);
|
||||||
String guid = cell.recon.match.topicGUID;
|
String guid = cell.recon.match.topicGUID;
|
||||||
|
|
||||||
if (map.containsKey(guid)) {
|
if (map.containsKey(guid)) {
|
||||||
dataExtensions.add(map.get(guid));
|
dataExtensions.add(map.get(guid));
|
||||||
} else {
|
} else {
|
||||||
dataExtensions.add(null);
|
dataExtensions.add(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
List<Integer> rowIndices = new ArrayList<Integer>();
|
List<Integer> rowIndices = new ArrayList<Integer>();
|
||||||
List<DataExtension> dataExtensions = new ArrayList<DataExtension>();
|
List<DataExtension> dataExtensions = new ArrayList<DataExtension>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
populateRowsWithMatches(rowIndices);
|
populateRowsWithMatches(rowIndices);
|
||||||
} catch (Exception e2) {
|
} catch (Exception e2) {
|
||||||
// TODO : Not sure what to do here?
|
// TODO : Not sure what to do here?
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
int start = 0;
|
int start = 0;
|
||||||
Map<String, ReconCandidate> reconCandidateMap = new HashMap<String, ReconCandidate>();
|
Map<String, ReconCandidate> reconCandidateMap = new HashMap<String, ReconCandidate>();
|
||||||
|
|
||||||
while (start < rowIndices.size()) {
|
while (start < rowIndices.size()) {
|
||||||
int end = extendRows(rowIndices, dataExtensions, start, rowIndices.size(), reconCandidateMap);
|
int end = extendRows(rowIndices, dataExtensions, start, rowIndices.size(), reconCandidateMap);
|
||||||
start = end;
|
start = end;
|
||||||
|
|
||||||
_progress = end * 100 / rowIndices.size();
|
_progress = end * 100 / rowIndices.size();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(200);
|
Thread.sleep(200);
|
||||||
@ -240,23 +241,23 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_canceled) {
|
if (!_canceled) {
|
||||||
List<String> columnNames = new ArrayList<String>();
|
List<String> columnNames = new ArrayList<String>();
|
||||||
for (ColumnInfo info : _job.columns) {
|
for (ColumnInfo info : _job.columns) {
|
||||||
columnNames.add(StringUtils.join(info.names, " - "));
|
columnNames.add(StringUtils.join(info.names, " - "));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<FreebaseType> columnTypes = new ArrayList<FreebaseType>();
|
List<FreebaseType> columnTypes = new ArrayList<FreebaseType>();
|
||||||
for (ColumnInfo info : _job.columns) {
|
for (ColumnInfo info : _job.columns) {
|
||||||
columnTypes.add(info.expectedType);
|
columnTypes.add(info.expectedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
HistoryEntry historyEntry = new HistoryEntry(
|
HistoryEntry historyEntry = ProjectManager.singleton.createHistoryEntry(
|
||||||
_historyEntryID,
|
_historyEntryID,
|
||||||
_project,
|
_project,
|
||||||
_description,
|
_description,
|
||||||
ExtendDataOperation.this,
|
ExtendDataOperation.this,
|
||||||
new DataExtensionChange(
|
new DataExtensionChange(
|
||||||
_baseColumnName,
|
_baseColumnName,
|
||||||
_columnInsertIndex,
|
_columnInsertIndex,
|
||||||
@ -266,7 +267,7 @@ public class ExtendDataOperation extends EngineDependentOperation {
|
|||||||
dataExtensions,
|
dataExtensions,
|
||||||
_historyEntryID)
|
_historyEntryID)
|
||||||
);
|
);
|
||||||
|
|
||||||
_project.history.addEntry(historyEntry);
|
_project.history.addEntry(historyEntry);
|
||||||
_project.processManager.onDoneProcess(this);
|
_project.processManager.onDoneProcess(this);
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -35,20 +36,20 @@ import com.metaweb.gridworks.process.Process;
|
|||||||
public class ReconOperation extends EngineDependentOperation {
|
public class ReconOperation extends EngineDependentOperation {
|
||||||
final protected String _columnName;
|
final protected String _columnName;
|
||||||
final protected ReconConfig _reconConfig;
|
final protected ReconConfig _reconConfig;
|
||||||
|
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
|
|
||||||
return new ReconOperation(
|
return new ReconOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
obj.getString("columnName"),
|
obj.getString("columnName"),
|
||||||
ReconConfig.reconstruct(obj.getJSONObject("config"))
|
ReconConfig.reconstruct(obj.getJSONObject("config"))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReconOperation(
|
public ReconOperation(
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String columnName,
|
String columnName,
|
||||||
ReconConfig reconConfig
|
ReconConfig reconConfig
|
||||||
) {
|
) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
@ -58,19 +59,19 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public Process createProcess(Project project, Properties options) throws Exception {
|
public Process createProcess(Project project, Properties options) throws Exception {
|
||||||
return new ReconProcess(
|
return new ReconProcess(
|
||||||
project,
|
project,
|
||||||
getEngineConfig(),
|
getEngineConfig(),
|
||||||
getBriefDescription(null)
|
getBriefDescription(null)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String getBriefDescription(Project project) {
|
protected String getBriefDescription(Project project) {
|
||||||
return _reconConfig.getBriefDescription(project, _columnName);
|
return _reconConfig.getBriefDescription(project, _columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -83,7 +84,7 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
static protected class ReconEntry {
|
static protected class ReconEntry {
|
||||||
final public int rowIndex;
|
final public int rowIndex;
|
||||||
final public Cell cell;
|
final public Cell cell;
|
||||||
|
|
||||||
public ReconEntry(int rowIndex, Cell cell) {
|
public ReconEntry(int rowIndex, Cell cell) {
|
||||||
this.rowIndex = rowIndex;
|
this.rowIndex = rowIndex;
|
||||||
this.cell = cell;
|
this.cell = cell;
|
||||||
@ -92,22 +93,22 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
static protected class JobGroup {
|
static protected class JobGroup {
|
||||||
final public ReconJob job;
|
final public ReconJob job;
|
||||||
final public List<ReconEntry> entries = new ArrayList<ReconEntry>();
|
final public List<ReconEntry> entries = new ArrayList<ReconEntry>();
|
||||||
|
|
||||||
public JobGroup(ReconJob job) {
|
public JobGroup(ReconJob job) {
|
||||||
this.job = job;
|
this.job = job;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ReconProcess extends LongRunningProcess implements Runnable {
|
public class ReconProcess extends LongRunningProcess implements Runnable {
|
||||||
final protected Project _project;
|
final protected Project _project;
|
||||||
final protected JSONObject _engineConfig;
|
final protected JSONObject _engineConfig;
|
||||||
final protected long _historyEntryID;
|
final protected long _historyEntryID;
|
||||||
protected List<ReconEntry> _entries;
|
protected List<ReconEntry> _entries;
|
||||||
protected int _cellIndex;
|
protected int _cellIndex;
|
||||||
|
|
||||||
public ReconProcess(
|
public ReconProcess(
|
||||||
Project project,
|
Project project,
|
||||||
JSONObject engineConfig,
|
JSONObject engineConfig,
|
||||||
String description
|
String description
|
||||||
) {
|
) {
|
||||||
super(description);
|
super(description);
|
||||||
@ -115,10 +116,10 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
_engineConfig = engineConfig;
|
_engineConfig = engineConfig;
|
||||||
_historyEntryID = HistoryEntry.allocateID();
|
_historyEntryID = HistoryEntry.allocateID();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("id"); writer.value(hashCode());
|
writer.key("id"); writer.value(hashCode());
|
||||||
writer.key("description"); writer.value(_description);
|
writer.key("description"); writer.value(_description);
|
||||||
@ -159,35 +160,35 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
writer.endArray();
|
writer.endArray();
|
||||||
writer.endObject();
|
writer.endObject();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Runnable getRunnable() {
|
protected Runnable getRunnable() {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void populateEntries() throws Exception {
|
protected void populateEntries() throws Exception {
|
||||||
Engine engine = new Engine(_project);
|
Engine engine = new Engine(_project);
|
||||||
engine.initializeFromJSON(_engineConfig);
|
engine.initializeFromJSON(_engineConfig);
|
||||||
|
|
||||||
Column column = _project.columnModel.getColumnByName(_columnName);
|
Column column = _project.columnModel.getColumnByName(_columnName);
|
||||||
if (column == null) {
|
if (column == null) {
|
||||||
throw new Exception("No column named " + _columnName);
|
throw new Exception("No column named " + _columnName);
|
||||||
}
|
}
|
||||||
|
|
||||||
_entries = new ArrayList<ReconEntry>(_project.rows.size());
|
_entries = new ArrayList<ReconEntry>(_project.rows.size());
|
||||||
_cellIndex = column.getCellIndex();
|
_cellIndex = column.getCellIndex();
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(_project, new RowVisitor() {
|
filteredRows.accept(_project, new RowVisitor() {
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
if (_cellIndex < row.cells.size()) {
|
if (_cellIndex < row.cells.size()) {
|
||||||
Cell cell = row.cells.get(_cellIndex);
|
Cell cell = row.cells.get(_cellIndex);
|
||||||
@ -199,7 +200,7 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
populateEntries();
|
populateEntries();
|
||||||
@ -207,18 +208,18 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
// TODO : Not sure what to do here?
|
// TODO : Not sure what to do here?
|
||||||
e2.printStackTrace();
|
e2.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<Integer, JobGroup> jobKeyToGroup = new HashMap<Integer, JobGroup>();
|
Map<Integer, JobGroup> jobKeyToGroup = new HashMap<Integer, JobGroup>();
|
||||||
|
|
||||||
for (ReconEntry entry : _entries) {
|
for (ReconEntry entry : _entries) {
|
||||||
ReconJob job = _reconConfig.createJob(
|
ReconJob job = _reconConfig.createJob(
|
||||||
_project,
|
_project,
|
||||||
entry.rowIndex,
|
entry.rowIndex,
|
||||||
_project.rows.get(entry.rowIndex),
|
_project.rows.get(entry.rowIndex),
|
||||||
_columnName,
|
_columnName,
|
||||||
entry.cell
|
entry.cell
|
||||||
);
|
);
|
||||||
|
|
||||||
int key = job.getKey();
|
int key = job.getKey();
|
||||||
JobGroup group = jobKeyToGroup.get(key);
|
JobGroup group = jobKeyToGroup.get(key);
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
@ -227,42 +228,42 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
group.entries.add(entry);
|
group.entries.add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<CellChange> cellChanges = new ArrayList<CellChange>(_entries.size());
|
List<CellChange> cellChanges = new ArrayList<CellChange>(_entries.size());
|
||||||
List<JobGroup> groups = new ArrayList<JobGroup>(jobKeyToGroup.values());
|
List<JobGroup> groups = new ArrayList<JobGroup>(jobKeyToGroup.values());
|
||||||
|
|
||||||
int batchSize = _reconConfig.getBatchSize();
|
int batchSize = _reconConfig.getBatchSize();
|
||||||
for (int i = 0; i < groups.size(); i += batchSize) {
|
for (int i = 0; i < groups.size(); i += batchSize) {
|
||||||
int to = Math.min(i + batchSize, groups.size());
|
int to = Math.min(i + batchSize, groups.size());
|
||||||
|
|
||||||
List<ReconJob> jobs = new ArrayList<ReconJob>(to - i);
|
List<ReconJob> jobs = new ArrayList<ReconJob>(to - i);
|
||||||
for (int j = i; j < to; j++) {
|
for (int j = i; j < to; j++) {
|
||||||
jobs.add(groups.get(j).job);
|
jobs.add(groups.get(j).job);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<Recon> recons = _reconConfig.batchRecon(jobs, _historyEntryID);
|
List<Recon> recons = _reconConfig.batchRecon(jobs, _historyEntryID);
|
||||||
for (int j = i; j < to; j++) {
|
for (int j = i; j < to; j++) {
|
||||||
Recon recon = recons.get(j - i);
|
Recon recon = recons.get(j - i);
|
||||||
List<ReconEntry> entries = groups.get(j).entries;
|
List<ReconEntry> entries = groups.get(j).entries;
|
||||||
|
|
||||||
if (recon != null) {
|
if (recon != null) {
|
||||||
recon.judgmentBatchSize = entries.size();
|
recon.judgmentBatchSize = entries.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ReconEntry entry : entries) {
|
for (ReconEntry entry : entries) {
|
||||||
Cell oldCell = entry.cell;
|
Cell oldCell = entry.cell;
|
||||||
Cell newCell = new Cell(oldCell.value, recon);
|
Cell newCell = new Cell(oldCell.value, recon);
|
||||||
|
|
||||||
CellChange cellChange = new CellChange(
|
CellChange cellChange = new CellChange(
|
||||||
entry.rowIndex,
|
entry.rowIndex,
|
||||||
_cellIndex,
|
_cellIndex,
|
||||||
oldCell,
|
oldCell,
|
||||||
newCell
|
newCell
|
||||||
);
|
);
|
||||||
cellChanges.add(cellChange);
|
cellChanges.add(cellChange);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_progress = i * 100 / groups.size();
|
_progress = i * 100 / groups.size();
|
||||||
try {
|
try {
|
||||||
Thread.sleep(50);
|
Thread.sleep(50);
|
||||||
@ -272,23 +273,23 @@ public class ReconOperation extends EngineDependentOperation {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!_canceled) {
|
if (!_canceled) {
|
||||||
Change reconChange = new ReconChange(
|
Change reconChange = new ReconChange(
|
||||||
cellChanges,
|
cellChanges,
|
||||||
_columnName,
|
_columnName,
|
||||||
_reconConfig,
|
_reconConfig,
|
||||||
null
|
null
|
||||||
);
|
);
|
||||||
|
|
||||||
HistoryEntry historyEntry = new HistoryEntry(
|
HistoryEntry historyEntry = ProjectManager.singleton.createHistoryEntry(
|
||||||
_historyEntryID,
|
_historyEntryID,
|
||||||
_project,
|
_project,
|
||||||
_description,
|
_description,
|
||||||
ReconOperation.this,
|
ReconOperation.this,
|
||||||
reconChange
|
reconChange
|
||||||
);
|
);
|
||||||
|
|
||||||
_project.history.addEntry(historyEntry);
|
_project.history.addEntry(historyEntry);
|
||||||
_project.processManager.onDoneProcess(this);
|
_project.processManager.onDoneProcess(this);
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.history.HistoryEntry;
|
import com.metaweb.gridworks.history.HistoryEntry;
|
||||||
import com.metaweb.gridworks.model.AbstractOperation;
|
import com.metaweb.gridworks.model.AbstractOperation;
|
||||||
import com.metaweb.gridworks.model.Cell;
|
import com.metaweb.gridworks.model.Cell;
|
||||||
@ -22,13 +23,13 @@ public class DenormalizeOperation extends AbstractOperation {
|
|||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
return new DenormalizeOperation();
|
return new DenormalizeOperation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public DenormalizeOperation() {
|
public DenormalizeOperation() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value("Denormalize");
|
writer.key("description"); writer.value("Denormalize");
|
||||||
@ -42,37 +43,37 @@ public class DenormalizeOperation extends AbstractOperation {
|
|||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
List<Row> newRows = new ArrayList<Row>();
|
List<Row> newRows = new ArrayList<Row>();
|
||||||
|
|
||||||
List<Row> oldRows = project.rows;
|
List<Row> oldRows = project.rows;
|
||||||
for (int r = 0; r < oldRows.size(); r++) {
|
for (int r = 0; r < oldRows.size(); r++) {
|
||||||
Row oldRow = oldRows.get(r);
|
Row oldRow = oldRows.get(r);
|
||||||
Row newRow = null;
|
Row newRow = null;
|
||||||
|
|
||||||
RowDependency rd = project.recordModel.getRowDependency(r);
|
RowDependency rd = project.recordModel.getRowDependency(r);
|
||||||
if (rd.cellDependencies != null) {
|
if (rd.cellDependencies != null) {
|
||||||
newRow = oldRow.dup();
|
newRow = oldRow.dup();
|
||||||
|
|
||||||
for (int c = 0; c < rd.cellDependencies.length; c++) {
|
for (int c = 0; c < rd.cellDependencies.length; c++) {
|
||||||
CellDependency cd = rd.cellDependencies[c];
|
CellDependency cd = rd.cellDependencies[c];
|
||||||
if (cd != null) {
|
if (cd != null) {
|
||||||
int contextRowIndex = cd.rowIndex;
|
int contextRowIndex = cd.rowIndex;
|
||||||
int contextCellIndex = cd.cellIndex;
|
int contextCellIndex = cd.cellIndex;
|
||||||
|
|
||||||
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
|
if (contextRowIndex >= 0 && contextRowIndex < oldRows.size()) {
|
||||||
Row contextRow = oldRows.get(contextRowIndex);
|
Row contextRow = oldRows.get(contextRowIndex);
|
||||||
Cell contextCell = contextRow.getCell(contextCellIndex);
|
Cell contextCell = contextRow.getCell(contextCellIndex);
|
||||||
|
|
||||||
newRow.setCell(contextCellIndex, contextCell);
|
newRow.setCell(contextCellIndex, contextCell);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
newRows.add(newRow != null ? newRow : oldRow);
|
newRows.add(newRow != null ? newRow : oldRow);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
getBriefDescription(project),
|
getBriefDescription(project),
|
||||||
DenormalizeOperation.this,
|
DenormalizeOperation.this,
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -27,13 +28,13 @@ public class RowFlagOperation extends EngineDependentOperation {
|
|||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
boolean flagged = obj.getBoolean("flagged");
|
boolean flagged = obj.getBoolean("flagged");
|
||||||
|
|
||||||
return new RowFlagOperation(
|
return new RowFlagOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
flagged
|
flagged
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowFlagOperation(JSONObject engineConfig, boolean flagged) {
|
public RowFlagOperation(JSONObject engineConfig, boolean flagged) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
_flagged = flagged;
|
_flagged = flagged;
|
||||||
@ -41,7 +42,7 @@ public class RowFlagOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -56,17 +57,17 @@ public class RowFlagOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
List<Change> changes = new ArrayList<Change>(project.rows.size());
|
List<Change> changes = new ArrayList<Change>(project.rows.size());
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(project, createRowVisitor(project, changes));
|
filteredRows.accept(project, createRowVisitor(project, changes));
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
(_flagged ? "Flag" : "Unflag") + " " + changes.size() + " rows",
|
(_flagged ? "Flag" : "Unflag") + " " + changes.size() + " rows",
|
||||||
this,
|
this,
|
||||||
new MassChange(changes, false)
|
new MassChange(changes, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -74,26 +75,26 @@ public class RowFlagOperation extends EngineDependentOperation {
|
|||||||
protected RowVisitor createRowVisitor(Project project, List<Change> changes) throws Exception {
|
protected RowVisitor createRowVisitor(Project project, List<Change> changes) throws Exception {
|
||||||
return new RowVisitor() {
|
return new RowVisitor() {
|
||||||
List<Change> changes;
|
List<Change> changes;
|
||||||
|
|
||||||
public RowVisitor init(List<Change> changes) {
|
public RowVisitor init(List<Change> changes) {
|
||||||
this.changes = changes;
|
this.changes = changes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
if (row.flagged != _flagged) {
|
if (row.flagged != _flagged) {
|
||||||
RowFlagChange change = new RowFlagChange(rowIndex, _flagged);
|
RowFlagChange change = new RowFlagChange(rowIndex, _flagged);
|
||||||
|
|
||||||
changes.add(change);
|
changes.add(change);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -22,19 +23,19 @@ import com.metaweb.gridworks.operations.OperationRegistry;
|
|||||||
public class RowRemovalOperation extends EngineDependentOperation {
|
public class RowRemovalOperation extends EngineDependentOperation {
|
||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
|
|
||||||
return new RowRemovalOperation(
|
return new RowRemovalOperation(
|
||||||
engineConfig
|
engineConfig
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowRemovalOperation(JSONObject engineConfig) {
|
public RowRemovalOperation(JSONObject engineConfig) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -48,17 +49,17 @@ public class RowRemovalOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
List<Integer> rowIndices = new ArrayList<Integer>();
|
List<Integer> rowIndices = new ArrayList<Integer>();
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(project, createRowVisitor(project, rowIndices));
|
filteredRows.accept(project, createRowVisitor(project, rowIndices));
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
"Remove " + rowIndices.size() + " rows",
|
"Remove " + rowIndices.size() + " rows",
|
||||||
this,
|
this,
|
||||||
new RowRemovalChange(rowIndices)
|
new RowRemovalChange(rowIndices)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -66,25 +67,25 @@ public class RowRemovalOperation extends EngineDependentOperation {
|
|||||||
protected RowVisitor createRowVisitor(Project project, List<Integer> rowIndices) throws Exception {
|
protected RowVisitor createRowVisitor(Project project, List<Integer> rowIndices) throws Exception {
|
||||||
return new RowVisitor() {
|
return new RowVisitor() {
|
||||||
List<Integer> rowIndices;
|
List<Integer> rowIndices;
|
||||||
|
|
||||||
public RowVisitor init(List<Integer> rowIndices) {
|
public RowVisitor init(List<Integer> rowIndices) {
|
||||||
this.rowIndices = rowIndices;
|
this.rowIndices = rowIndices;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
rowIndices.add(rowIndex);
|
rowIndices.add(rowIndex);
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}.init(rowIndices);
|
}.init(rowIndices);
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.RecordVisitor;
|
import com.metaweb.gridworks.browsing.RecordVisitor;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -27,13 +28,13 @@ public class RowReorderOperation extends AbstractOperation {
|
|||||||
String mode = obj.getString("mode");
|
String mode = obj.getString("mode");
|
||||||
JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ?
|
JSONObject sorting = obj.has("sorting") && !obj.isNull("sorting") ?
|
||||||
obj.getJSONObject("sorting") : null;
|
obj.getJSONObject("sorting") : null;
|
||||||
|
|
||||||
return new RowReorderOperation(Engine.stringToMode(mode), sorting);
|
return new RowReorderOperation(Engine.stringToMode(mode), sorting);
|
||||||
}
|
}
|
||||||
|
|
||||||
final protected Mode _mode;
|
final protected Mode _mode;
|
||||||
final protected JSONObject _sorting;
|
final protected JSONObject _sorting;
|
||||||
|
|
||||||
public RowReorderOperation(Mode mode, JSONObject sorting) {
|
public RowReorderOperation(Mode mode, JSONObject sorting) {
|
||||||
_mode = mode;
|
_mode = mode;
|
||||||
_sorting = sorting;
|
_sorting = sorting;
|
||||||
@ -41,7 +42,7 @@ public class RowReorderOperation extends AbstractOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -57,50 +58,50 @@ public class RowReorderOperation extends AbstractOperation {
|
|||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = new Engine(project);
|
Engine engine = new Engine(project);
|
||||||
engine.setMode(_mode);
|
engine.setMode(_mode);
|
||||||
|
|
||||||
List<Integer> rowIndices = new ArrayList<Integer>();
|
List<Integer> rowIndices = new ArrayList<Integer>();
|
||||||
if (_mode == Mode.RowBased) {
|
if (_mode == Mode.RowBased) {
|
||||||
RowVisitor visitor = new IndexingVisitor(rowIndices);
|
RowVisitor visitor = new IndexingVisitor(rowIndices);
|
||||||
if (_sorting != null) {
|
if (_sorting != null) {
|
||||||
SortingRowVisitor srv = new SortingRowVisitor(visitor);
|
SortingRowVisitor srv = new SortingRowVisitor(visitor);
|
||||||
|
|
||||||
srv.initializeFromJSON(project, _sorting);
|
srv.initializeFromJSON(project, _sorting);
|
||||||
if (srv.hasCriteria()) {
|
if (srv.hasCriteria()) {
|
||||||
visitor = srv;
|
visitor = srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.getAllRows().accept(project, visitor);
|
engine.getAllRows().accept(project, visitor);
|
||||||
} else {
|
} else {
|
||||||
RecordVisitor visitor = new IndexingVisitor(rowIndices);
|
RecordVisitor visitor = new IndexingVisitor(rowIndices);
|
||||||
if (_sorting != null) {
|
if (_sorting != null) {
|
||||||
SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
|
SortingRecordVisitor srv = new SortingRecordVisitor(visitor);
|
||||||
|
|
||||||
srv.initializeFromJSON(project, _sorting);
|
srv.initializeFromJSON(project, _sorting);
|
||||||
if (srv.hasCriteria()) {
|
if (srv.hasCriteria()) {
|
||||||
visitor = srv;
|
visitor = srv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.getAllRecords().accept(project, visitor);
|
engine.getAllRecords().accept(project, visitor);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
"Reorder rows",
|
"Reorder rows",
|
||||||
this,
|
this,
|
||||||
new RowReorderChange(rowIndices)
|
new RowReorderChange(rowIndices)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
|
static protected class IndexingVisitor implements RowVisitor, RecordVisitor {
|
||||||
List<Integer> _indices;
|
List<Integer> _indices;
|
||||||
|
|
||||||
IndexingVisitor(List<Integer> indices) {
|
IndexingVisitor(List<Integer> indices) {
|
||||||
_indices = indices;
|
_indices = indices;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import org.json.JSONException;
|
|||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.json.JSONWriter;
|
import org.json.JSONWriter;
|
||||||
|
|
||||||
|
import com.metaweb.gridworks.ProjectManager;
|
||||||
import com.metaweb.gridworks.browsing.Engine;
|
import com.metaweb.gridworks.browsing.Engine;
|
||||||
import com.metaweb.gridworks.browsing.FilteredRows;
|
import com.metaweb.gridworks.browsing.FilteredRows;
|
||||||
import com.metaweb.gridworks.browsing.RowVisitor;
|
import com.metaweb.gridworks.browsing.RowVisitor;
|
||||||
@ -27,13 +28,13 @@ public class RowStarOperation extends EngineDependentOperation {
|
|||||||
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {
|
||||||
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
JSONObject engineConfig = obj.getJSONObject("engineConfig");
|
||||||
boolean starred = obj.getBoolean("starred");
|
boolean starred = obj.getBoolean("starred");
|
||||||
|
|
||||||
return new RowStarOperation(
|
return new RowStarOperation(
|
||||||
engineConfig,
|
engineConfig,
|
||||||
starred
|
starred
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public RowStarOperation(JSONObject engineConfig, boolean starred) {
|
public RowStarOperation(JSONObject engineConfig, boolean starred) {
|
||||||
super(engineConfig);
|
super(engineConfig);
|
||||||
_starred = starred;
|
_starred = starred;
|
||||||
@ -41,7 +42,7 @@ public class RowStarOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
public void write(JSONWriter writer, Properties options)
|
public void write(JSONWriter writer, Properties options)
|
||||||
throws JSONException {
|
throws JSONException {
|
||||||
|
|
||||||
writer.object();
|
writer.object();
|
||||||
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
writer.key("op"); writer.value(OperationRegistry.s_opClassToName.get(this.getClass()));
|
||||||
writer.key("description"); writer.value(getBriefDescription(null));
|
writer.key("description"); writer.value(getBriefDescription(null));
|
||||||
@ -56,17 +57,17 @@ public class RowStarOperation extends EngineDependentOperation {
|
|||||||
|
|
||||||
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
protected HistoryEntry createHistoryEntry(Project project, long historyEntryID) throws Exception {
|
||||||
Engine engine = createEngine(project);
|
Engine engine = createEngine(project);
|
||||||
|
|
||||||
List<Change> changes = new ArrayList<Change>(project.rows.size());
|
List<Change> changes = new ArrayList<Change>(project.rows.size());
|
||||||
|
|
||||||
FilteredRows filteredRows = engine.getAllFilteredRows();
|
FilteredRows filteredRows = engine.getAllFilteredRows();
|
||||||
filteredRows.accept(project, createRowVisitor(project, changes));
|
filteredRows.accept(project, createRowVisitor(project, changes));
|
||||||
|
|
||||||
return new HistoryEntry(
|
return ProjectManager.singleton.createHistoryEntry(
|
||||||
historyEntryID,
|
historyEntryID,
|
||||||
project,
|
project,
|
||||||
(_starred ? "Star" : "Unstar") + " " + changes.size() + " rows",
|
(_starred ? "Star" : "Unstar") + " " + changes.size() + " rows",
|
||||||
this,
|
this,
|
||||||
new MassChange(changes, false)
|
new MassChange(changes, false)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -74,26 +75,26 @@ public class RowStarOperation extends EngineDependentOperation {
|
|||||||
protected RowVisitor createRowVisitor(Project project, List<Change> changes) throws Exception {
|
protected RowVisitor createRowVisitor(Project project, List<Change> changes) throws Exception {
|
||||||
return new RowVisitor() {
|
return new RowVisitor() {
|
||||||
List<Change> changes;
|
List<Change> changes;
|
||||||
|
|
||||||
public RowVisitor init(List<Change> changes) {
|
public RowVisitor init(List<Change> changes) {
|
||||||
this.changes = changes;
|
this.changes = changes;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void start(Project project) {
|
public void start(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void end(Project project) {
|
public void end(Project project) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean visit(Project project, int rowIndex, Row row) {
|
public boolean visit(Project project, int rowIndex, Row row) {
|
||||||
if (row.starred != _starred) {
|
if (row.starred != _starred) {
|
||||||
RowStarChange change = new RowStarChange(rowIndex, _starred);
|
RowStarChange change = new RowStarChange(rowIndex, _starred);
|
||||||
|
|
||||||
changes.add(change);
|
changes.add(change);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user