diff --git a/main/src/com/metaweb/gridworks/ProjectManager.java b/main/src/com/metaweb/gridworks/ProjectManager.java index 7b27cdfc3..1f8675b18 100644 --- a/main/src/com/metaweb/gridworks/ProjectManager.java +++ b/main/src/com/metaweb/gridworks/ProjectManager.java @@ -86,10 +86,33 @@ public abstract class ProjectManager { public abstract void exportProject(long projectId, TarOutputStream tos) throws IOException; /** - * + * Saves a project and its metadata to the data store * @param id */ - public abstract void ensureProjectSaved(long id); + public void ensureProjectSaved(long id) { + synchronized(this){ + ProjectMetadata metadata = _projectsMetadata.get(id); + if (metadata != null) { + try { + saveMetadata(metadata, id); + } catch (Exception e) { + e.printStackTrace(); + } + } + + Project project = _projects.get(id); + if (project != null && metadata.getModified().after(project.lastSave)) { + try { + saveProject(project); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + + } + protected abstract void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception; + protected abstract void saveProject(Project project); public ProjectMetadata getProjectMetadata(long id) { return _projectsMetadata.get(id); diff --git a/main/src/com/metaweb/gridworks/io/FileProjectManager.java b/main/src/com/metaweb/gridworks/io/FileProjectManager.java index 317880350..c41fbe7fb 100644 --- a/main/src/com/metaweb/gridworks/io/FileProjectManager.java +++ b/main/src/com/metaweb/gridworks/io/FileProjectManager.java @@ -179,37 +179,17 @@ public class FileProjectManager extends ProjectManager { } } - /** - * Make sure that a project's metadata and data are saved to file. For example, - * this method is called before the project is exported to a .tar file. - * - * @param id - */ - public void ensureProjectSaved(long id) { - synchronized (this) { - File projectDir = getProjectDir(id); - - ProjectMetadata metadata = _projectsMetadata.get(id); - if (metadata != null) { - try { - ProjectMetadataUtilities.save(metadata, projectDir); - } catch (Exception e) { - e.printStackTrace(); - } - } - - Project project = _projects.get(id); - if (project != null && metadata.getModified().after(project.lastSave)) { - try { - ProjectUtilities.save(project); - } catch (Exception e) { - e.printStackTrace(); - } - } - } + @Override + protected void saveMetadata(ProjectMetadata metadata, long projectId) throws Exception { + File projectDir = getProjectDir(projectId); + ProjectMetadataUtilities.save(metadata, projectDir); } @Override + protected void saveProject(Project project){ + ProjectUtilities.save(project); + } + public Project loadProject(long id) { return ProjectUtilities.load(getProjectDir(id), id); }