load and save nodes in projects
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 3 Jun 2008 06:53:16 +0000 (08:53 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 3 Jun 2008 06:53:16 +0000 (08:53 +0200)
don't create ids for new projects

src/net/pterodactylus/jsite/core/ProjectManager.java

index 782a5d6..2619650 100644 (file)
@@ -35,10 +35,8 @@ import java.util.Map.Entry;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
-import net.pterodactylus.jsite.util.IdGenerator;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
-import net.pterodactylus.util.number.Hex;
 
 /**
  * Manages projects, taking care of persistence, lifetime statistics, and other
@@ -137,6 +135,7 @@ public class ProjectManager implements PropertyChangeListener {
                        String projectPublicKey = projectProperties.getProperty(projectPrefix + ".publicKey");
                        String projectBasePath = projectProperties.getProperty(projectPrefix + ".basePath");
                        String projectDefaultFile = projectProperties.getProperty(projectPrefix + ".defaultFile");
+                       String projectNode = projectProperties.getProperty(projectPrefix + ".node");
                        Project project = new Project();
                        project.setId(projectId);
                        project.setName(projectName);
@@ -145,6 +144,10 @@ public class ProjectManager implements PropertyChangeListener {
                        project.setPublicKey(projectPublicKey);
                        project.setBasePath(projectBasePath);
                        project.setDefaultFile(projectDefaultFile);
+                       if (projectNode != null) {
+                               Node node = nodeManager.getNode(projectNode);
+                               project.setNode(node);
+                       }
                        int overrideIndex = 0;
                        while (projectProperties.containsKey(projectPrefix + ".overrides." + overrideIndex + ".override")) {
                                String filePath = projectProperties.getProperty(projectPrefix + ".overrides." + overrideIndex + ".filePath");
@@ -183,6 +186,9 @@ public class ProjectManager implements PropertyChangeListener {
                        projectProperties.setProperty(projectPrefix + ".publicKey", project.getPublicKey());
                        projectProperties.setProperty(projectPrefix + ".basePath", project.getBasePath());
                        projectProperties.setProperty(projectPrefix + ".defaultFile", project.getDefaultFile());
+                       if (project.getNode() != null) {
+                               projectProperties.setProperty(projectPrefix + ".node", project.getNode().getId());
+                       }
                        int overrideIndex = 0;
                        for (Entry<String, FileOverride> overrideEntry : project.getFileOverrides().entrySet()) {
                                projectProperties.setProperty(projectPrefix + ".overrides." + overrideIndex + ".filePath", overrideEntry.getKey());
@@ -214,7 +220,6 @@ public class ProjectManager implements PropertyChangeListener {
        public Project createProject() throws IOException, JSiteException {
                Project project = new Project();
                String[] keyPair = nodeManager.generateKeyPair();
-               project.setId(Hex.toHex(IdGenerator.generateId()));
                project.setName("");
                project.setDescription("");
                project.setPrivateKey(keyPair[0]);
@@ -243,7 +248,6 @@ public class ProjectManager implements PropertyChangeListener {
        public Project cloneProject(Project project) {
                Project projectClone = new Project(project);
                projects.add(projectClone);
-               projectClone.setId(Hex.toHex(IdGenerator.generateId()));
                projectClone.addPropertyChangeListener(this);
                try {
                        save();