Major refactoring: everything is now saved to disk using our own formats, mostly json-based, some inside zip files.

git-svn-id: http://google-refine.googlecode.com/svn/trunk@226 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-03-07 22:37:26 +00:00
parent f7b0caa1b8
commit 694f09fb0a
56 changed files with 605 additions and 1728 deletions

View File

@ -27,6 +27,7 @@ import com.metaweb.util.signal.SignalHandler;
import com.metaweb.util.threads.ThreadPoolExecutorAdapter; import com.metaweb.util.threads.ThreadPoolExecutorAdapter;
public class Gridworks extends Server { public class Gridworks extends Server {
final static public String s_version = "1.0";
private static Logger root = Logger.getRootLogger(); private static Logger root = Logger.getRootLogger();
private static Logger logger = Logger.getLogger("com.metaweb.gridworks"); private static Logger logger = Logger.getLogger("com.metaweb.gridworks");

View File

@ -1,19 +1,13 @@
package com.metaweb.gridworks; package com.metaweb.gridworks;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileReader; import java.io.FileReader;
import java.io.FileWriter; import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
@ -26,9 +20,8 @@ import com.codeberry.jdatapath.JDataPathSystem;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.JSONUtilities; import com.metaweb.gridworks.util.JSONUtilities;
public class ProjectManager implements Serializable { public class ProjectManager {
private static final long serialVersionUID = -2967415873336723962L;
private static final int s_expressionHistoryMax = 100; // last n expressions used across all projects private static final int s_expressionHistoryMax = 100; // last n expressions used across all projects
protected File _workspaceDir; protected File _workspaceDir;
@ -44,14 +37,9 @@ public class ProjectManager implements Serializable {
File dir = getProjectLocation(); File dir = getProjectLocation();
Gridworks.log("Using data directory: " + dir.getAbsolutePath()); Gridworks.log("Using data directory: " + dir.getAbsolutePath());
if (dir.exists()) {
singleton = load(dir);
}
if (singleton == null) {
singleton = new ProjectManager(dir); singleton = new ProjectManager(dir);
} }
} }
}
static protected File getProjectLocation() { static protected File getProjectLocation() {
String data_dir = Configurations.get("gridworks.data_dir"); String data_dir = Configurations.get("gridworks.data_dir");
@ -98,20 +86,26 @@ public class ProjectManager implements Serializable {
_projectsMetadata = new HashMap<Long, ProjectMetadata>(); _projectsMetadata = new HashMap<Long, ProjectMetadata>();
_expressions = new LinkedList<String>(); _expressions = new LinkedList<String>();
_projects = new HashMap<Long, Project>(); _projects = new HashMap<Long, Project>();
load();
} }
public File getWorkspaceDir() { public File getWorkspaceDir() {
return _workspaceDir; return _workspaceDir;
} }
public File getProjectDir(long projectID) { static public File getProjectDir(File workspaceDir, long projectID) {
File dir = new File(_workspaceDir, projectID + ".project"); File dir = new File(workspaceDir, projectID + ".project");
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdir(); dir.mkdir();
} }
return dir; return dir;
} }
public File getProjectDir(long projectID) {
return getProjectDir(_workspaceDir, projectID);
}
public void registerProject(Project project, ProjectMetadata projectMetadata) { public void registerProject(Project project, ProjectMetadata projectMetadata) {
_projects.put(project.id, project); _projects.put(project.id, project);
_projectsMetadata.put(project.id, projectMetadata); _projectsMetadata.put(project.id, projectMetadata);
@ -129,34 +123,7 @@ public class ProjectManager implements Serializable {
if (_projects.containsKey(id)) { if (_projects.containsKey(id)) {
return _projects.get(id); return _projects.get(id);
} else { } else {
File file = new File(getProjectDir(id), "raw-data"); Project project = Project.load(getProjectDir(id), id);
Project project = null;
FileInputStream fis = null;
ObjectInputStream in = null;
try {
fis = new FileInputStream(file);
in = new ObjectInputStream(fis);
project = (Project) in.readObject();
} catch(IOException e) {
e.printStackTrace();
} catch(ClassNotFoundException e) {
e.printStackTrace();
} finally {
if (fis != null) {
try {
fis.close();
} catch (Exception e) {
}
}
if (in != null) {
try {
in.close();
} catch (Exception e) {
}
}
}
_projects.put(id, project); _projects.put(id, project);
@ -177,20 +144,20 @@ public class ProjectManager implements Serializable {
} }
public void save() { public void save() {
Gridworks.log("Saving project metadata ..."); Gridworks.log("Saving all projects' metadata ...");
File tempFile = new File(_workspaceDir, "projects.json.temp"); File tempFile = new File(_workspaceDir, "workspace.temp.json");
try { try {
saveToFile(tempFile); saveToFile(tempFile);
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
Gridworks.log("Failed to save project"); Gridworks.log("Failed to save projects' metadata.");
return; return;
} }
File file = new File(_workspaceDir, "projects.json"); File file = new File(_workspaceDir, "workspace.json");
File oldFile = new File(_workspaceDir, "projects.json.old"); File oldFile = new File(_workspaceDir, "workspace.old.json");
if (file.exists()) { if (file.exists()) {
file.renameTo(oldFile); file.renameTo(oldFile);
@ -201,25 +168,25 @@ public class ProjectManager implements Serializable {
oldFile.delete(); oldFile.delete();
} }
Gridworks.log("Project metadata saved."); Gridworks.log("All projects' metadata saved.");
} }
public void saveToFile(File file) throws IOException, JSONException { protected void saveToFile(File file) throws IOException, JSONException {
FileWriter writer = new FileWriter(file); FileWriter writer = new FileWriter(file);
try { try {
JSONWriter jsonWriter = new JSONWriter(writer); JSONWriter jsonWriter = new JSONWriter(writer);
Properties options = new Properties();
options.setProperty("mode", "save");
jsonWriter.object(); jsonWriter.object();
jsonWriter.key("projectMetadata"); jsonWriter.key("projectIDs");
jsonWriter.array(); jsonWriter.array();
for (Long id : _projectsMetadata.keySet()) { for (Long id : _projectsMetadata.keySet()) {
jsonWriter.object(); jsonWriter.value(id);
jsonWriter.key("id"); jsonWriter.value(id);
jsonWriter.key("metadata"); _projectsMetadata.get(id).write(jsonWriter, options); ProjectMetadata metadata = _projectsMetadata.get(id);
jsonWriter.endObject(); try {
writer.write('\n'); metadata.save(getProjectDir(id));
} catch (Exception e) {
e.printStackTrace();
}
} }
jsonWriter.endArray(); jsonWriter.endArray();
writer.write('\n'); writer.write('\n');
@ -231,106 +198,78 @@ public class ProjectManager implements Serializable {
} }
} }
static protected ProjectManager load(File dir) {
try {
return loadFromFile(new File(dir, "projects.json"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "projects.json.temp"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "projects.json.old"));
} catch (Exception e) {
}
return null;
}
static protected ProjectManager loadFromFile(File file) throws IOException, JSONException {
Gridworks.log("Loading project metadata from " + file.getAbsolutePath());
FileReader reader = new FileReader(file);
try {
JSONTokener tokener = new JSONTokener(reader);
ProjectManager pm = new ProjectManager(file.getParentFile());
JSONObject obj = (JSONObject) tokener.nextValue();
JSONArray a = obj.getJSONArray("projectMetadata");
int count = a.length();
for (int i = 0; i < count; i++) {
JSONObject obj2 = a.getJSONObject(i);
long id = obj2.getLong("id");
pm._projectsMetadata.put(id, ProjectMetadata.loadFromJSON(obj2.getJSONObject("metadata")));
}
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
} finally {
reader.close();
}
}
public void saveAllProjects() { public void saveAllProjects() {
Gridworks.log("Saving all projects ..."); Gridworks.log("Saving all projects ...");
for (Project project : _projects.values()) { for (Project project : _projects.values()) {
try { try {
saveProject(project); project.save();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
protected void saveProject(Project project) { public void deleteProject(Project project) {
File file = new File(getProjectDir(project.id), "raw-data");
FileOutputStream fos = null;
ObjectOutputStream out = null;
try {
fos = new FileOutputStream(file);
out = new ObjectOutputStream(fos);
out.writeObject(project);
out.flush();
} catch(IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.close();
} catch (Exception e) {
}
}
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
}
}
public boolean deleteProject(Project project) {
if (_projectsMetadata.containsKey(project.id)) { if (_projectsMetadata.containsKey(project.id)) {
_projects.remove(project.id);
_projectsMetadata.remove(project.id); _projectsMetadata.remove(project.id);
}
if (_projects.containsKey(project.id)) {
_projects.remove(project.id);
}
File file = new File(getProjectDir(project.id), "raw-data"); File dir = getProjectDir(project.id);
if (file.exists()) { if (dir.exists()) {
file.delete(); dir.delete();
} }
save(); save();
}
return true; protected void load() {
} else { try {
return false; loadFromFile(new File(_workspaceDir, "workspace.json"));
return;
} catch (Exception e) {
}
try {
loadFromFile(new File(_workspaceDir, "workspace.temp.json"));
return;
} catch (Exception e) {
}
try {
loadFromFile(new File(_workspaceDir, "workspace.old.json"));
return;
} catch (Exception e) {
}
}
protected void loadFromFile(File file) throws IOException, JSONException {
Gridworks.log("Loading project metadata from " + file.getAbsolutePath());
_projectsMetadata.clear();
_expressions.clear();
FileReader reader = new FileReader(file);
try {
JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue();
JSONArray a = obj.getJSONArray("projectIDs");
int count = a.length();
for (int i = 0; i < count; i++) {
long id = a.getLong(i);
File projectDir = getProjectDir(id);
ProjectMetadata metadata = ProjectMetadata.load(projectDir);
_projectsMetadata.put(id, metadata);
}
JSONUtilities.getStringList(obj, "expressions", _expressions);
} finally {
reader.close();
} }
} }
} }

View File

@ -1,5 +1,10 @@
package com.metaweb.gridworks; package com.metaweb.gridworks;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Date; import java.util.Date;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
@ -7,6 +12,7 @@ import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import org.json.JSONTokener;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.util.JSONUtilities; import com.metaweb.gridworks.util.JSONUtilities;
@ -24,21 +30,6 @@ public class ProjectMetadata implements Jsonizable {
private int _encodingConfidence; private int _encodingConfidence;
private List<String> _expressions = new LinkedList<String>(); private List<String> _expressions = new LinkedList<String>();
static public ProjectMetadata loadFromJSON(JSONObject obj) {
ProjectMetadata pm = new ProjectMetadata(JSONUtilities.getDate(obj, "modified", new Date()));
pm._modified = JSONUtilities.getDate(obj, "modified", new Date());
pm._name = JSONUtilities.getString(obj, "name", "<Error recovering project name>");
pm._password = JSONUtilities.getString(obj, "password", "");
pm._encoding = JSONUtilities.getString(obj, "encoding", "");
pm._encodingConfidence = JSONUtilities.getInt(obj, "encodingConfidence", 0);
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
}
protected ProjectMetadata(Date date) { protected ProjectMetadata(Date date) {
_created = date; _created = date;
} }
@ -66,6 +57,90 @@ public class ProjectMetadata implements Jsonizable {
writer.endObject(); writer.endObject();
} }
public void save(File dir) throws Exception {
File tempFile = new File(dir, "metadata.temp.json");
try {
saveToFile(tempFile);
} catch (Exception e) {
e.printStackTrace();
Gridworks.log("Failed to save project metadata");
return;
}
File file = new File(dir, "metadata.json");
File oldFile = new File(dir, "metadata.old.json");
if (file.exists()) {
file.renameTo(oldFile);
}
tempFile.renameTo(file);
if (oldFile.exists()) {
oldFile.delete();
}
}
protected void saveToFile(File file) throws Exception {
Writer writer = new OutputStreamWriter(new FileOutputStream(file));
try {
Properties options = new Properties();
options.setProperty("mode", "save");
JSONWriter jsonWriter = new JSONWriter(writer);
write(jsonWriter, options);
} finally {
writer.close();
}
}
static public ProjectMetadata load(File dir) {
try {
return loadFromFile(new File(dir, "metadata.json"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "metadata.temp.json"));
} catch (Exception e) {
}
try {
return loadFromFile(new File(dir, "metadata.old.json"));
} catch (Exception e) {
}
return null;
}
static protected ProjectMetadata loadFromFile(File file) throws Exception {
FileReader reader = new FileReader(file);
try {
JSONTokener tokener = new JSONTokener(reader);
JSONObject obj = (JSONObject) tokener.nextValue();
return loadFromJSON(obj);
} finally {
reader.close();
}
}
static protected ProjectMetadata loadFromJSON(JSONObject obj) {
ProjectMetadata pm = new ProjectMetadata(JSONUtilities.getDate(obj, "modified", new Date()));
pm._modified = JSONUtilities.getDate(obj, "modified", new Date());
pm._name = JSONUtilities.getString(obj, "name", "<Error recovering project name>");
pm._password = JSONUtilities.getString(obj, "password", "");
pm._encoding = JSONUtilities.getString(obj, "encoding", "");
pm._encodingConfidence = JSONUtilities.getInt(obj, "encodingConfidence", 0);
JSONUtilities.getStringList(obj, "expressions", pm._expressions);
return pm;
}
public Date getCreated() { public Date getCreated() {
return _created; return _created;
} }

View File

@ -1,7 +1,6 @@
package com.metaweb.gridworks.commands.edit; package com.metaweb.gridworks.commands.edit;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.util.Properties; import java.util.Properties;
import javax.servlet.ServletException; import javax.servlet.ServletException;
@ -46,28 +45,15 @@ public class ApplyOperationsCommand extends Command {
} }
protected void reconstructOperation(Project project, JSONObject obj) { protected void reconstructOperation(Project project, JSONObject obj) {
try { AbstractOperation operation = OperationRegistry.reconstruct(project, obj);
String op = obj.getString("op");
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass == null) {
return;
}
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct == null) {
return;
}
AbstractOperation operation = (AbstractOperation) reconstruct.invoke(null, project, obj);
if (operation != null) { if (operation != null) {
try {
Process process = operation.createProcess(project, new Properties()); Process process = operation.createProcess(project, new Properties());
project.processManager.queueProcess(process); project.processManager.queueProcess(process);
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
}
} }
} }

View File

@ -15,9 +15,9 @@ public class DeleteProjectCommand extends Command {
throws ServletException, IOException { throws ServletException, IOException {
try { try {
boolean result = ProjectManager.singleton.deleteProject(getProject(request)); ProjectManager.singleton.deleteProject(getProject(request));
respond(response, "{ \"code\" : " + (result ? "\"ok\"" : "\"error\"") + " }"); respond(response, "{ \"code\" : \"ok\" }");
} catch (Exception e) { } catch (Exception e) {
respondException(response, e); respondException(response, e);

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,8 @@
package com.metaweb.gridworks.history; package com.metaweb.gridworks.history;
import java.io.IOException;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.Serializable; import java.io.Writer;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.LinkedList; import java.util.LinkedList;
@ -11,14 +12,15 @@ import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.Gridworks;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.ProjectManager; import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.model.Project; import com.metaweb.gridworks.model.Project;
public class History implements Serializable, Jsonizable { public class History implements Jsonizable {
private static final long serialVersionUID = -1529783362243627391L;
static public Change readOneChange(LineNumberReader reader) throws Exception { static public Change readOneChange(LineNumberReader reader) throws Exception {
/* String version = */ reader.readLine();
String className = reader.readLine(); String className = reader.readLine();
Class<? extends Change> klass = getChangeClass(className); Class<? extends Change> klass = getChangeClass(className);
@ -27,6 +29,16 @@ public class History implements Serializable, Jsonizable {
return (Change) load.invoke(null, reader); return (Change) load.invoke(null, reader);
} }
static public void writeOneChange(Writer writer, Change change) throws Exception {
writer.write(Gridworks.s_version); writer.write('\n');
writer.write(change.getClass().getName()); writer.write('\n');
Properties options = new Properties();
options.setProperty("mode", "save");
change.save(writer, options);
}
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
static public Class<? extends Change> getChangeClass(String className) throws ClassNotFoundException { static public Class<? extends Change> getChangeClass(String className) throws ClassNotFoundException {
return (Class<? extends Change>) Class.forName(className); return (Class<? extends Change>) Class.forName(className);
@ -152,4 +164,41 @@ public class History implements Serializable, Jsonizable {
writer.endObject(); writer.endObject();
} }
public void save(Writer writer, Properties options) throws IOException {
writer.write("pastEntryCount="); writer.write(Integer.toString(_pastEntries.size())); writer.write('\n');
for (HistoryEntry entry : _pastEntries) {
entry.save(writer, options); writer.write('\n');
}
writer.write("futureEntryCount="); writer.write(Integer.toString(_futureEntries.size())); writer.write('\n');
for (HistoryEntry entry : _futureEntries) {
entry.save(writer, options); writer.write('\n');
}
writer.write("/e/\n");
}
public void load(Project project, LineNumberReader reader) throws Exception {
String line;
while ((line = reader.readLine()) != null && !"/e/".equals(line)) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("pastEntryCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
_pastEntries.add(HistoryEntry.load(project, reader.readLine()));
}
} else if ("futureEntryCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
_futureEntries.add(HistoryEntry.load(project, reader.readLine()));
}
}
}
}
} }

View File

@ -3,13 +3,11 @@ package com.metaweb.gridworks.history;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.LineNumberReader; import java.io.LineNumberReader;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.Serializable; import java.io.Serializable;
import java.io.Writer; import java.io.Writer;
import java.text.SimpleDateFormat;
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.ZipEntry;
@ -17,12 +15,15 @@ import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.ProjectManager; import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.model.AbstractOperation; 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.util.ParsingUtilities;
public class HistoryEntry implements Serializable, Jsonizable { public class HistoryEntry implements Serializable, Jsonizable {
private static final long serialVersionUID = 532766467813930262L; private static final long serialVersionUID = 532766467813930262L;
@ -45,15 +46,24 @@ public class HistoryEntry implements Serializable, Jsonizable {
_change = change; _change = change;
} }
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, Date time) {
this.id = id;
this.projectID = projectID;
this.description = description;
this.operation = operation;
this.time = time;
}
public void write(JSONWriter writer, Properties options) public void write(JSONWriter writer, Properties options)
throws JSONException { throws JSONException {
SimpleDateFormat sdf = (SimpleDateFormat) SimpleDateFormat.getDateTimeInstance();
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);
writer.key("time"); writer.value(sdf.format(time)); writer.key("time"); writer.value(ParsingUtilities.dateToString(time));
if ("save".equals(options.getProperty("mode")) && operation != null) {
writer.key("operation"); operation.write(writer, options);
}
writer.endObject(); writer.endObject();
} }
@ -70,7 +80,7 @@ public class HistoryEntry implements Serializable, Jsonizable {
try { try {
saveChange(); saveChange();
} catch (IOException e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
_change.revert(project); _change.revert(project);
@ -94,6 +104,33 @@ public class HistoryEntry implements Serializable, Jsonizable {
} }
} }
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 {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
AbstractOperation operation = null;
if (obj.has("operation") && !obj.isNull("operation")) {
operation = OperationRegistry.reconstruct(project, obj.getJSONObject("operation"));
}
return new HistoryEntry(
obj.getLong("id"),
project.id,
obj.getString("description"),
operation,
ParsingUtilities.stringToDate(obj.getString("time"))
);
}
protected void loadChange() { protected void loadChange() {
File changeFile = getChangeFile(); File changeFile = getChangeFile();
@ -122,26 +159,21 @@ public class HistoryEntry implements Serializable, Jsonizable {
} }
} }
protected void saveChange() throws IOException { protected void saveChange() throws Exception {
File changeFile = getChangeFile(); File changeFile = getChangeFile();
if (!(changeFile.exists())) { if (!(changeFile.exists())) {
saveChange(changeFile); saveChange(changeFile);
} }
} }
protected void saveChange(File file) throws IOException { protected void saveChange(File file) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file)); ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
try { try {
out.putNextEntry(new ZipEntry("change.txt")); out.putNextEntry(new ZipEntry("change.txt"));
try { try {
Writer writer = new OutputStreamWriter(out); Writer writer = new OutputStreamWriter(out);
try { try {
Properties options = new Properties(); History.writeOneChange(writer, _change);
options.setProperty("mode", "save");
writer.write(_change.getClass().getName()); writer.write('\n');
_change.save(writer, options);
} finally { } finally {
writer.flush(); writer.flush();
} }

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties; import java.util.Properties;
import org.apache.commons.lang.NotImplementedException; import org.apache.commons.lang.NotImplementedException;
@ -14,9 +13,7 @@ import com.metaweb.gridworks.process.QuickHistoryEntryProcess;
* An abstract operation can be applied to different but similar * An abstract operation can be applied to different but similar
* projects. * projects.
*/ */
abstract public class AbstractOperation implements Serializable, Jsonizable { abstract public class AbstractOperation implements Jsonizable {
private static final long serialVersionUID = 3916055862440019600L;
public Process createProcess(Project project, Properties options) throws Exception { public Process createProcess(Project project, Properties options) throws Exception {
return new QuickHistoryEntryProcess(project, getBriefDescription(null)) { return new QuickHistoryEntryProcess(project, getBriefDescription(null)) {
@Override @Override

View File

@ -16,9 +16,7 @@ import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.expr.HasFields; import com.metaweb.gridworks.expr.HasFields;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class Cell implements Serializable, HasFields, Jsonizable { public class Cell implements HasFields, Jsonizable {
private static final long serialVersionUID = -5891067829205458102L;
final public Serializable value; final public Serializable value;
final public Recon recon; final public Recon recon;

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer; import java.io.Writer;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -14,9 +13,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.model.recon.ReconConfig; import com.metaweb.gridworks.model.recon.ReconConfig;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class Column implements Serializable, Jsonizable { public class Column implements Jsonizable {
private static final long serialVersionUID = -1063342490951563563L;
final private int _cellIndex; final private int _cellIndex;
final private String _originalName; final private String _originalName;
private String _name; private String _name;

View File

@ -2,19 +2,19 @@ package com.metaweb.gridworks.model;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.Serializable; import java.io.Writer;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.util.ParsingUtilities;
public class ColumnGroup implements Serializable, Jsonizable { public class ColumnGroup implements Jsonizable {
private static final long serialVersionUID = 2161780779920066118L;
final public int startColumnIndex; final public int startColumnIndex;
final public int columnSpan; final public int columnSpan;
final public int keyColumnIndex; // could be -1 if there is no key cell final public int keyColumnIndex; // could be -1 if there is no key cell
@ -38,6 +38,7 @@ public class ColumnGroup implements Serializable, Jsonizable {
writer.key("columnSpan"); writer.value(columnSpan); writer.key("columnSpan"); writer.value(columnSpan);
writer.key("keyColumnIndex"); writer.value(keyColumnIndex); writer.key("keyColumnIndex"); writer.value(keyColumnIndex);
if (!"save".equals(options.get("mode"))) {
if (subgroups != null && subgroups.size() > 0) { if (subgroups != null && subgroups.size() > 0) {
writer.key("subgroups"); writer.array(); writer.key("subgroups"); writer.array();
for (ColumnGroup g : subgroups) { for (ColumnGroup g : subgroups) {
@ -45,7 +46,7 @@ public class ColumnGroup implements Serializable, Jsonizable {
} }
writer.endArray(); writer.endArray();
} }
}
writer.endObject(); writer.endObject();
} }
@ -54,6 +55,25 @@ public class ColumnGroup implements Serializable, Jsonizable {
g.startColumnIndex < startColumnIndex + columnSpan); g.startColumnIndex < startColumnIndex + columnSpan);
} }
public void save(Writer writer) {
JSONWriter jsonWriter = new JSONWriter(writer);
try {
write(jsonWriter, new Properties());
} catch (JSONException e) {
e.printStackTrace();
}
}
static public ColumnGroup load(String s) throws Exception {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
return new ColumnGroup(
obj.getInt("startColumnIndex"),
obj.getInt("columnSpan"),
obj.getInt("keyColumnIndex")
);
}
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
in.defaultReadObject(); in.defaultReadObject();
internalInitialize(); internalInitialize();

View File

@ -1,8 +1,8 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.LineNumberReader;
import java.io.Serializable; import java.io.Writer;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
@ -16,9 +16,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
public class ColumnModel implements Serializable, Jsonizable { public class ColumnModel implements Jsonizable {
private static final long serialVersionUID = 7679639795211544511L;
final public List<Column> columns = new LinkedList<Column>(); final public List<Column> columns = new LinkedList<Column>();
final public List<ColumnGroup> columnGroups = new LinkedList<ColumnGroup>(); final public List<ColumnGroup> columnGroups = new LinkedList<ColumnGroup>();
@ -90,8 +88,49 @@ public class ColumnModel implements Serializable, Jsonizable {
writer.endObject(); writer.endObject();
} }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { public void save(Writer writer, Properties options) throws IOException {
in.defaultReadObject(); writer.write("maxCellIndex="); writer.write(Integer.toString(_maxCellIndex)); writer.write('\n');
writer.write("keyColumnIndex="); writer.write(Integer.toString(_keyColumnIndex)); writer.write('\n');
writer.write("columnCount="); writer.write(Integer.toString(columns.size())); writer.write('\n');
for (Column column : columns) {
column.save(writer); writer.write('\n');
}
writer.write("columnGroupCount="); writer.write(Integer.toString(columnGroups.size())); writer.write('\n');
for (ColumnGroup group : columnGroups) {
group.save(writer); writer.write('\n');
}
writer.write("/e/\n");
}
public void load(LineNumberReader reader) throws Exception {
String line;
while ((line = reader.readLine()) != null && !"/e/".equals(line)) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("maxCellIndex".equals(field)) {
_maxCellIndex = Integer.parseInt(value);
} else if ("keyColumnIndex".equals(field)) {
_keyColumnIndex = Integer.parseInt(value);
} else if ("columnCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
columns.add(Column.load(reader.readLine()));
}
} else if ("columnGroupCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
columnGroups.add(ColumnGroup.load(reader.readLine()));
}
}
}
internalInitialize(); internalInitialize();
} }

View File

@ -1,13 +1,23 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.InputStreamReader;
import java.io.Serializable; import java.io.LineNumberReader;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import com.metaweb.gridworks.Gridworks;
import com.metaweb.gridworks.ProjectManager; import com.metaweb.gridworks.ProjectManager;
import com.metaweb.gridworks.ProjectMetadata; import com.metaweb.gridworks.ProjectMetadata;
import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.ExpressionUtils;
@ -15,40 +25,181 @@ import com.metaweb.gridworks.history.History;
import com.metaweb.gridworks.process.ProcessManager; import com.metaweb.gridworks.process.ProcessManager;
import com.metaweb.gridworks.protograph.Protograph; import com.metaweb.gridworks.protograph.Protograph;
public class Project implements Serializable { public class Project {
private static final long serialVersionUID = -5089046824819472570L;
final public long id; final public long id;
final public ColumnModel columnModel = new ColumnModel(); final public ColumnModel columnModel = new ColumnModel();
final public List<Row> rows = new ArrayList<Row>(); final public List<Row> rows = new ArrayList<Row>();
final public History history; final public History history;
public Protograph protograph; public Protograph protograph;
transient public ProcessManager processManager; transient public ProcessManager processManager;
public Project() { public Project() {
id = Math.round(Math.random() * 1000000) + System.currentTimeMillis(); id = System.currentTimeMillis() + Math.round(Math.random() * 1000000000000L);
history = new History(this); history = new History(this);
processManager = new ProcessManager();
}
internalInitialize(); protected Project(long id) {
this.id = id;
this.history = new History(this);
this.processManager = new ProcessManager();
} }
public ProjectMetadata getMetadata() { public ProjectMetadata getMetadata() {
return ProjectManager.singleton.getProjectMetadata(id); return ProjectManager.singleton.getProjectMetadata(id);
} }
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { public void save() {
in.defaultReadObject(); Gridworks.log("Saving project " + id + " ...");
internalInitialize();
File dir = ProjectManager.singleton.getProjectDir(id);
File tempFile = new File(dir, "data.temp.zip");
try {
saveToFile(tempFile);
} catch (Exception e) {
e.printStackTrace();
Gridworks.log("Failed to save project data");
return;
} }
protected void internalInitialize() { File file = new File(dir, "data.zip");
processManager = new ProcessManager(); File oldFile = new File(dir, "data.old.zip");
recomputeRowContextDependencies(); if (file.exists()) {
file.renameTo(oldFile);
} }
tempFile.renameTo(file);
if (oldFile.exists()) {
oldFile.delete();
}
Gridworks.log("Project saved.");
}
protected void saveToFile(File file) throws Exception {
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(file));
try {
out.putNextEntry(new ZipEntry("data.txt"));
try {
Writer writer = new OutputStreamWriter(out);
try {
Properties options = new Properties();
options.setProperty("mode", "save");
saveToWriter(writer, options);
} finally {
writer.flush();
}
} finally {
out.closeEntry();
}
} finally {
out.close();
}
}
protected void saveToWriter(Writer writer, Properties options) throws IOException {
writer.write(Gridworks.s_version); writer.write('\n');
writer.write("columnModel=\n"); columnModel.save(writer, options);
writer.write("history=\n"); history.save(writer, options);
if (protograph != null) {
writer.write("protograph="); protograph.save(writer, options); writer.write('\n');
}
writer.write("rowCount="); writer.write(Integer.toString(rows.size())); writer.write('\n');
for (Row row : rows) {
row.save(writer); writer.write('\n');
}
}
static public Project load(File dir, long id) {
try {
File file = new File(dir, "data.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File(dir, "data.temp.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
try {
File file = new File(dir, "data.old.zip");
if (file.exists()) {
return loadFromFile(file, id);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
static protected Project loadFromFile(File file, long id) throws Exception {
ZipInputStream in = new ZipInputStream(new FileInputStream(file));
try {
ZipEntry entry = in.getNextEntry();
assert "data.txt".equals(entry.getName());
LineNumberReader reader = new LineNumberReader(new InputStreamReader(in));
try {
return loadFromReader(reader, id);
} finally {
reader.close();
}
} finally {
in.close();
}
}
static protected Project loadFromReader(LineNumberReader reader, long id) throws Exception {
/* String version = */ reader.readLine();
Project project = new Project(id);
String line;
while ((line = reader.readLine()) != null) {
int equal = line.indexOf('=');
CharSequence field = line.subSequence(0, equal);
String value = line.substring(equal + 1);
if ("columnModel".equals(field)) {
project.columnModel.load(reader);
} else if ("history".equals(field)) {
project.history.load(project, reader);
} else if ("protograph".equals(field)) {
project.protograph = Protograph.load(project, value);
} else if ("rowCount".equals(field)) {
int count = Integer.parseInt(value);
for (int i = 0; i < count; i++) {
project.rows.add(Row.load(reader.readLine()));
}
}
}
project.recomputeRowContextDependencies();
return project;
}
static protected class Group { static protected class Group {
int[] cellIndices; int[] cellIndices;
int keyCellIndex; int keyCellIndex;

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -15,9 +14,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields; import com.metaweb.gridworks.expr.HasFields;
public class Recon implements Serializable, HasFields, Jsonizable { public class Recon implements HasFields, Jsonizable {
private static final long serialVersionUID = 8906257833709315762L;
static public enum Judgment { static public enum Judgment {
None, None,
Matched, Matched,

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.util.Properties; import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
@ -11,9 +10,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields; import com.metaweb.gridworks.expr.HasFields;
import com.metaweb.gridworks.util.JSONUtilities; import com.metaweb.gridworks.util.JSONUtilities;
public class ReconCandidate implements Serializable, HasFields, Jsonizable { public class ReconCandidate implements HasFields, Jsonizable {
private static final long serialVersionUID = -8013997214978715606L;
final public String topicID; final public String topicID;
final public String topicGUID; final public String topicGUID;
final public String topicName; final public String topicName;

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer; import java.io.Writer;
import java.util.Properties; import java.util.Properties;
@ -12,9 +11,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.ExpressionUtils; import com.metaweb.gridworks.expr.ExpressionUtils;
import com.metaweb.gridworks.model.Recon.Judgment; import com.metaweb.gridworks.model.Recon.Judgment;
public class ReconStats implements Serializable, Jsonizable { public class ReconStats implements Jsonizable {
private static final long serialVersionUID = -4831409797104437854L;
static public ReconStats load(JSONObject obj) throws Exception { static public ReconStats load(JSONObject obj) throws Exception {
return new ReconStats( return new ReconStats(
obj.getInt("nonBlanks"), obj.getInt("nonBlanks"),

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model; package com.metaweb.gridworks.model;
import java.io.Serializable;
import java.io.Writer; import java.io.Writer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -15,9 +14,7 @@ import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.expr.HasFields; import com.metaweb.gridworks.expr.HasFields;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class Row implements Serializable, HasFields, Jsonizable { public class Row implements HasFields, Jsonizable {
private static final long serialVersionUID = -689264211730915507L;
public boolean flagged; public boolean flagged;
public boolean starred; public boolean starred;
final public List<Cell> cells; final public List<Cell> cells;

View File

@ -7,7 +7,7 @@ import java.util.Properties;
import com.metaweb.gridworks.model.Cell; import com.metaweb.gridworks.model.Cell;
public class CellAtRow implements Serializable { public class CellAtRow {
private static final long serialVersionUID = 7280920621006690944L; private static final long serialVersionUID = 7280920621006690944L;
final public int row; final public int row;

View File

@ -24,8 +24,6 @@ import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class GuidBasedReconConfig extends StrictReconConfig { public class GuidBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 1857895989346775294L;
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {
return new GuidBasedReconConfig(); return new GuidBasedReconConfig();
} }

View File

@ -1,7 +1,6 @@
package com.metaweb.gridworks.model.recon; package com.metaweb.gridworks.model.recon;
import java.io.InputStream; import java.io.InputStream;
import java.io.Serializable;
import java.io.StringWriter; import java.io.StringWriter;
import java.net.URL; import java.net.URL;
import java.net.URLConnection; import java.net.URLConnection;
@ -28,11 +27,7 @@ import com.metaweb.gridworks.protograph.FreebaseProperty;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class HeuristicReconConfig extends ReconConfig { public class HeuristicReconConfig extends ReconConfig {
private static final long serialVersionUID = 423145327938373362L; static public class ColumnDetail {
static public class ColumnDetail implements Serializable {
private static final long serialVersionUID = -8996704822460155543L;
final public String columnName; final public String columnName;
final public FreebaseProperty property; final public FreebaseProperty property;

View File

@ -24,8 +24,6 @@ import com.metaweb.gridworks.model.Recon.Judgment;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class IdBasedReconConfig extends StrictReconConfig { public class IdBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 1857895989346775294L;
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {
return new IdBasedReconConfig(); return new IdBasedReconConfig();
} }

View File

@ -25,8 +25,6 @@ import com.metaweb.gridworks.protograph.FreebaseTopic;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class KeyBasedReconConfig extends StrictReconConfig { public class KeyBasedReconConfig extends StrictReconConfig {
private static final long serialVersionUID = 2363754609522023900L;
final public FreebaseTopic namespace; final public FreebaseTopic namespace;
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.model.recon; package com.metaweb.gridworks.model.recon;
import java.io.Serializable;
import java.io.Writer; import java.io.Writer;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -15,9 +14,7 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.Recon; import com.metaweb.gridworks.model.Recon;
import com.metaweb.gridworks.model.Row; import com.metaweb.gridworks.model.Row;
abstract public class ReconConfig implements Serializable, Jsonizable { abstract public class ReconConfig implements Jsonizable {
private static final long serialVersionUID = -4831409797104437854L;
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {
String mode = obj.getString("mode"); String mode = obj.getString("mode");
if ("heuristic".equals(mode)) { if ("heuristic".equals(mode)) {

View File

@ -3,8 +3,6 @@ package com.metaweb.gridworks.model.recon;
import org.json.JSONObject; import org.json.JSONObject;
abstract public class StrictReconConfig extends ReconConfig { abstract public class StrictReconConfig extends ReconConfig {
private static final long serialVersionUID = 4454059850557793074L;
final static protected String s_mqlreadService = "http://api.freebase.com/api/service/mqlread"; final static protected String s_mqlreadService = "http://api.freebase.com/api/service/mqlread";
static public ReconConfig reconstruct(JSONObject obj) throws Exception { static public ReconConfig reconstruct(JSONObject obj) throws Exception {

View File

@ -26,8 +26,6 @@ import com.metaweb.gridworks.model.changes.CellAtRow;
import com.metaweb.gridworks.model.changes.ColumnAdditionChange; import com.metaweb.gridworks.model.changes.ColumnAdditionChange;
public class ColumnAdditionOperation extends EngineDependentOperation { public class ColumnAdditionOperation extends EngineDependentOperation {
private static final long serialVersionUID = -5672677479629932356L;
final protected String _baseColumnName; final protected String _baseColumnName;
final protected String _expression; final protected String _expression;
final protected OnError _onError; final protected OnError _onError;

View File

@ -14,8 +14,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.model.changes.ColumnRemovalChange; import com.metaweb.gridworks.model.changes.ColumnRemovalChange;
public class ColumnRemovalOperation extends AbstractOperation { public class ColumnRemovalOperation extends AbstractOperation {
private static final long serialVersionUID = 8422079695048733734L;
final protected String _columnName; final protected String _columnName;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -16,8 +16,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.MassCellChange; import com.metaweb.gridworks.model.changes.MassCellChange;
abstract public class EngineDependentMassCellOperation extends EngineDependentOperation { abstract public class EngineDependentMassCellOperation extends EngineDependentOperation {
private static final long serialVersionUID = -8962461328087299452L;
final protected String _columnName; final protected String _columnName;
final protected boolean _updateRowContextDependencies; final protected boolean _updateRowContextDependencies;

View File

@ -9,8 +9,6 @@ import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
abstract public class EngineDependentOperation extends AbstractOperation { abstract public class EngineDependentOperation extends AbstractOperation {
private static final long serialVersionUID = -2800091595856881731L;
final private String _engineConfigString; final private String _engineConfigString;
transient protected JSONObject _engineConfig; transient protected JSONObject _engineConfig;

View File

@ -26,14 +26,10 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class MassEditOperation extends EngineDependentMassCellOperation { public class MassEditOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L;
final protected String _expression; final protected String _expression;
final protected List<Edit> _edits; final protected List<Edit> _edits;
static public class Edit implements Serializable, Jsonizable { static public class Edit implements Jsonizable {
private static final long serialVersionUID = -4799990738910328002L;
final public List<String> from; final public List<String> from;
final public Serializable to; final public Serializable to;

View File

@ -18,8 +18,6 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange; import com.metaweb.gridworks.model.changes.MassRowChange;
public class MultiValuedCellJoinOperation extends AbstractOperation { public class MultiValuedCellJoinOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
final protected String _columnName; final protected String _columnName;
final protected String _keyColumnName; final protected String _keyColumnName;
final protected String _separator; final protected String _separator;

View File

@ -18,8 +18,6 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.MassRowChange; import com.metaweb.gridworks.model.changes.MassRowChange;
public class MultiValuedCellSplitOperation extends AbstractOperation { public class MultiValuedCellSplitOperation extends AbstractOperation {
private static final long serialVersionUID = 8217930220439070322L;
final protected String _columnName; final protected String _columnName;
final protected String _keyColumnName; final protected String _keyColumnName;
final protected String _separator; final protected String _separator;

View File

@ -1,9 +1,13 @@
package com.metaweb.gridworks.operations; package com.metaweb.gridworks.operations;
import java.lang.reflect.Method;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.json.JSONObject;
import com.metaweb.gridworks.model.AbstractOperation; import com.metaweb.gridworks.model.AbstractOperation;
import com.metaweb.gridworks.model.Project;
public abstract class OperationRegistry { public abstract class OperationRegistry {
static public Map<String, Class<? extends AbstractOperation>> s_opNameToClass; static public Map<String, Class<? extends AbstractOperation>> s_opNameToClass;
@ -37,4 +41,21 @@ public abstract class OperationRegistry {
register("text-transform", TextTransformOperation.class); register("text-transform", TextTransformOperation.class);
register("mass-edit", MassEditOperation.class); register("mass-edit", MassEditOperation.class);
} }
static public AbstractOperation reconstruct(Project project, JSONObject obj) {
try {
String op = obj.getString("op");
Class<? extends AbstractOperation> klass = OperationRegistry.s_opNameToClass.get(op);
if (klass != null) {
Method reconstruct = klass.getMethod("reconstruct", Project.class, JSONObject.class);
if (reconstruct != null) {
return (AbstractOperation) reconstruct.invoke(null, project, obj);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
} }

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange; import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation { public class ReconDiscardJudgmentsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = 6799029731665369179L;
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 columnName = obj.getString("columnName"); String columnName = obj.getString("columnName");

View File

@ -25,8 +25,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange; import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOperation { public class ReconJudgeSimilarCellsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected String _similarValue; final protected String _similarValue;
final protected Judgment _judgment; final protected Judgment _judgment;
final protected ReconCandidate _match; final protected ReconCandidate _match;

View File

@ -22,8 +22,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange; import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation { public class ReconMarkNewTopicsOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected boolean _shareNewTopics; final protected boolean _shareNewTopics;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange; import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOperation { public class ReconMatchBestCandidatesOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = 5393888241057341155L;
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 columnName = obj.getString("columnName"); String columnName = obj.getString("columnName");

View File

@ -22,8 +22,6 @@ import com.metaweb.gridworks.model.changes.CellChange;
import com.metaweb.gridworks.model.changes.ReconChange; import com.metaweb.gridworks.model.changes.ReconChange;
public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOperation { public class ReconMatchSpecificTopicOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -5205694623711144436L;
final protected ReconCandidate match; final protected ReconCandidate match;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -30,8 +30,6 @@ import com.metaweb.gridworks.process.LongRunningProcess;
import com.metaweb.gridworks.process.Process; import com.metaweb.gridworks.process.Process;
public class ReconOperation extends EngineDependentOperation { public class ReconOperation extends EngineDependentOperation {
private static final long serialVersionUID = 838795186905314865L;
final protected String _columnName; final protected String _columnName;
final protected ReconConfig _reconConfig; final protected ReconConfig _reconConfig;

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.changes.MassChange;
import com.metaweb.gridworks.model.changes.RowStarChange; import com.metaweb.gridworks.model.changes.RowStarChange;
public class RowStarOperation extends EngineDependentOperation { public class RowStarOperation extends EngineDependentOperation {
private static final long serialVersionUID = 7047630960948704761L;
final protected boolean _starred; final protected boolean _starred;
static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception { static public AbstractOperation reconstruct(Project project, JSONObject obj) throws Exception {

View File

@ -17,8 +17,6 @@ import com.metaweb.gridworks.protograph.Protograph;
import com.metaweb.gridworks.util.ParsingUtilities; import com.metaweb.gridworks.util.ParsingUtilities;
public class SaveProtographOperation extends AbstractOperation { public class SaveProtographOperation extends AbstractOperation {
private static final long serialVersionUID = 3134524625206033285L;
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 {

View File

@ -20,8 +20,6 @@ import com.metaweb.gridworks.model.Row;
import com.metaweb.gridworks.model.changes.CellChange; import com.metaweb.gridworks.model.changes.CellChange;
public class TextTransformOperation extends EngineDependentMassCellOperation { public class TextTransformOperation extends EngineDependentMassCellOperation {
private static final long serialVersionUID = -7698202759999537298L;
final protected String _expression; final protected String _expression;
final protected OnError _onError; final protected OnError _onError;
final protected boolean _repeat; final protected boolean _repeat;

View File

@ -8,8 +8,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class AnonymousNode implements Node, NodeWithLinks { public class AnonymousNode implements Node, NodeWithLinks {
private static final long serialVersionUID = -6956243664838720646L;
final public FreebaseType type; final public FreebaseType type;
final public List<Link> links = new LinkedList<Link>(); final public List<Link> links = new LinkedList<Link>();

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class CellKeyNode extends CellNode { public class CellKeyNode extends CellNode {
private static final long serialVersionUID = 1684854896739592911L;
final public FreebaseTopic namespace; final public FreebaseTopic namespace;
public CellKeyNode( public CellKeyNode(

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
abstract public class CellNode implements Node { abstract public class CellNode implements Node {
private static final long serialVersionUID = 5820786756175547307L;
final public String columnName; final public String columnName;
public CellNode( public CellNode(

View File

@ -8,8 +8,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class CellTopicNode extends CellNode implements NodeWithLinks { public class CellTopicNode extends CellNode implements NodeWithLinks {
private static final long serialVersionUID = 1684854896739592911L;
final public boolean createForNoReconMatch; final public boolean createForNoReconMatch;
final public FreebaseType type; final public FreebaseType type;
final public List<Link> links = new LinkedList<Link>(); final public List<Link> links = new LinkedList<Link>();

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class CellValueNode extends CellNode { public class CellValueNode extends CellNode {
private static final long serialVersionUID = 7311884925532708576L;
final public String valueType; final public String valueType;
final public String lang; final public String lang;

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
public class FreebaseProperty extends FreebaseTopic { public class FreebaseProperty extends FreebaseTopic {
private static final long serialVersionUID = 7909539492956342421L;
//final protected FreebaseType _expectedType; //final protected FreebaseType _expectedType;
public FreebaseProperty(String id, String name) { public FreebaseProperty(String id, String name) {

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import java.util.Properties; import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
@ -8,9 +7,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
public class FreebaseTopic implements Serializable, Jsonizable { public class FreebaseTopic implements Jsonizable {
private static final long serialVersionUID = -3427885694129112432L;
final public String id; final public String id;
final public String name; final public String name;

View File

@ -8,8 +8,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class FreebaseTopicNode implements Node, NodeWithLinks { public class FreebaseTopicNode implements Node, NodeWithLinks {
private static final long serialVersionUID = 8418548867745587387L;
final public FreebaseTopic topic; final public FreebaseTopic topic;
final public List<Link> links = new LinkedList<Link>(); final public List<Link> links = new LinkedList<Link>();

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
public class FreebaseType extends FreebaseTopic { public class FreebaseType extends FreebaseTopic {
private static final long serialVersionUID = -3070300264980791404L;
public FreebaseType(String id, String name) { public FreebaseType(String id, String name) {
super(id, name); super(id, name);
} }

View File

@ -1,6 +1,5 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import java.util.Properties; import java.util.Properties;
import org.json.JSONException; import org.json.JSONException;
@ -8,9 +7,7 @@ import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
public class Link implements Serializable, Jsonizable { public class Link implements Jsonizable {
private static final long serialVersionUID = 2908086768260322876L;
final public FreebaseProperty property; final public FreebaseProperty property;
final public Node target; final public Node target;

View File

@ -1,8 +1,6 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
import java.io.Serializable;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
public interface Node extends Serializable, Jsonizable { public interface Node extends Jsonizable {
} }

View File

@ -1,6 +1,6 @@
package com.metaweb.gridworks.protograph; package com.metaweb.gridworks.protograph;
import java.io.Serializable; import java.io.Writer;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
@ -11,10 +11,10 @@ import org.json.JSONObject;
import org.json.JSONWriter; import org.json.JSONWriter;
import com.metaweb.gridworks.Jsonizable; import com.metaweb.gridworks.Jsonizable;
import com.metaweb.gridworks.model.Project;
import com.metaweb.gridworks.util.ParsingUtilities;
public class Protograph implements Serializable, Jsonizable { public class Protograph implements Jsonizable {
private static final long serialVersionUID = 706700643851582450L;
final protected List<Node> _rootNodes = new LinkedList<Node>(); final protected List<Node> _rootNodes = new LinkedList<Node>();
public int getRootNodeCount() { public int getRootNodeCount() {
@ -137,4 +137,18 @@ public class Protograph implements Serializable, Jsonizable {
writer.endObject(); writer.endObject();
} }
public void save(Writer writer, Properties options) {
JSONWriter jsonWriter = new JSONWriter(writer);
try {
write(jsonWriter, options);
} catch (JSONException e) {
e.printStackTrace();
}
}
static public Protograph load(Project project, String s) throws Exception {
JSONObject obj = ParsingUtilities.evaluateJsonStringToObject(s);
return reconstruct(obj);
}
} }

View File

@ -6,8 +6,6 @@ import org.json.JSONException;
import org.json.JSONWriter; import org.json.JSONWriter;
public class ValueNode implements Node { public class ValueNode implements Node {
private static final long serialVersionUID = -5626883493437735688L;
final public Object value; final public Object value;
final public String valueType; final public String valueType;
final public String lang; final public String lang;

View File

@ -1,23 +0,0 @@
package gridworks;
option java_package = "com.metaweb.gridworks.data";
option java_outer_classname = "Model";
message Expression {
required string value = 1;
}
message Project {
required string name = 1;
required int64 created = 2;
required int64 modified = 3;
required string encoding = 4;
optional int32 encoding_confidence = 5;
optional string creator = 6;
optional string password = 7;
repeated Expression expression = 8;
}
message ProjectManager {
repeated Project projects = 1;
}