Fixed bug introduced recently by changing the preference key of the expression history from "expressions" to "scripting.expressions".

Added code in FileProjectManager for trying to recover projects in the workspace dir but are not recorded in the workspace json file.


git-svn-id: http://google-refine.googlecode.com/svn/trunk@1144 7d457c2a-affb-35e4-300a-418c747d4874
This commit is contained in:
David Huynh 2010-08-07 20:25:31 +00:00
parent 586fcc8f52
commit e70f16025b
3 changed files with 38 additions and 8 deletions

View File

@ -344,7 +344,7 @@ public abstract class ProjectManager {
* @return * @return
*/ */
public List<String> getExpressions() { public List<String> getExpressions() {
return ((TopList) _preferenceStore.get("expressions")).getList(); return ((TopList) _preferenceStore.get("scripting.expressions")).getList();
} }
/** /**
@ -406,7 +406,7 @@ public abstract class ProjectManager {
*/ */
public void addLatestExpression(String s) { public void addLatestExpression(String s) {
synchronized (this) { synchronized (this) {
((TopList) _preferenceStore.get("expressions")).add(s); ((TopList) _preferenceStore.get("scripting.expressions")).add(s);
} }
} }

View File

@ -95,9 +95,9 @@ public class ProjectMetadata implements Jsonizable {
} }
} }
if (obj.has("expressions") && !obj.isNull("expressions")) { if (obj.has("expressions") && !obj.isNull("expressions")) { // backward compatibility
try { try {
((TopList) pm._preferenceStore.get("expressions")) ((TopList) pm._preferenceStore.get("scripting.expressions"))
.load(obj.getJSONArray("expressions")); .load(obj.getJSONArray("expressions"));
} catch (JSONException e) { } catch (JSONException e) {
// ignore // ignore

View File

@ -29,6 +29,7 @@ import com.google.gridworks.model.Project;
import com.google.gridworks.preference.TopList; import com.google.gridworks.preference.TopList;
public class FileProjectManager extends ProjectManager { public class FileProjectManager extends ProjectManager {
final static protected String s_projectDirNameSuffix = ".project";
protected File _workspaceDir; protected File _workspaceDir;
@ -48,6 +49,7 @@ public class FileProjectManager extends ProjectManager {
_workspaceDir.mkdirs(); _workspaceDir.mkdirs();
load(); load();
recover();
} }
public File getWorkspaceDir() { public File getWorkspaceDir() {
@ -55,7 +57,7 @@ public class FileProjectManager extends ProjectManager {
} }
static public File getProjectDir(File workspaceDir, long projectID) { static public File getProjectDir(File workspaceDir, long projectID) {
File dir = new File(workspaceDir, projectID + ".project"); File dir = new File(workspaceDir, projectID + s_projectDirNameSuffix);
if (!dir.exists()) { if (!dir.exists()) {
dir.mkdir(); dir.mkdir();
} }
@ -309,8 +311,8 @@ public class FileProjectManager extends ProjectManager {
_preferenceStore.load(obj.getJSONObject("preferences")); _preferenceStore.load(obj.getJSONObject("preferences"));
} }
if (obj.has("expressions") && !obj.isNull("expressions")) { if (obj.has("expressions") && !obj.isNull("expressions")) { // backward compatibility
((TopList) _preferenceStore.get("expressions")) ((TopList) _preferenceStore.get("scripting.expressions"))
.load(obj.getJSONArray("expressions")); .load(obj.getJSONArray("expressions"));
} }
@ -330,7 +332,35 @@ public class FileProjectManager extends ProjectManager {
return found; return found;
} }
protected void recover() {
for (File file : _workspaceDir.listFiles()) {
if (file.isDirectory() && !file.isHidden()) {
String name = file.getName();
if (file.getName().endsWith(s_projectDirNameSuffix)) {
String idString = name.substring(0, name.length() - s_projectDirNameSuffix.length());
long id = -1;
try {
id = Long.parseLong(idString);
} catch (NumberFormatException e) {
// ignore
}
if (id > 0 && !_projectsMetadata.containsKey(id)) {
if (loadProjectMetadata(id)) {
logger.info(
"Recovered project named " +
getProjectMetadata(id).getName() +
" in directory " + name);
} else {
logger.warn("Failed to recover project in directory " + name);
}
}
}
}
}
}
public HistoryEntryManager getHistoryEntryManager(){ public HistoryEntryManager getHistoryEntryManager(){
return new FileHistoryEntryManager(); return new FileHistoryEntryManager();
} }