From: David ‘Bombe’ Roden Date: Fri, 23 May 2008 15:32:11 +0000 (+0000) Subject: add id to projects X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d3f2f9e164ee7a71aca4297742ca871274af1cc3;p=jSite2.git add id to projects git-svn-id: http://trooper/svn/projects/jSite/trunk@938 c3eda9e8-030b-0410-8277-bc7414b0a119 --- diff --git a/src/net/pterodactylus/jsite/project/Project.java b/src/net/pterodactylus/jsite/project/Project.java index 4dd3819..5a3b848 100644 --- a/src/net/pterodactylus/jsite/project/Project.java +++ b/src/net/pterodactylus/jsite/project/Project.java @@ -47,6 +47,9 @@ public class Project extends AbstractBean { /** Name of the “local path” property. */ public static final String PROPERTY_BASE_PATH = "basePath"; + /** Internal ID. */ + private String id; + /** The name of the project. */ private String name; @@ -62,9 +65,24 @@ public class Project extends AbstractBean { /** The base path of the project. */ private String basePath; - // - // EVENT MANAGEMENT - // + /** + * Returns the internal ID. + * + * @return The internal ID + */ + String getId() { + return id; + } + + /** + * Sets the internal ID. + * + * @param id + * The internal ID + */ + void setId(String id) { + this.id = id; + } /** * Returns the name of the project. diff --git a/src/net/pterodactylus/jsite/project/ProjectManager.java b/src/net/pterodactylus/jsite/project/ProjectManager.java index fd62061..e3529c6 100644 --- a/src/net/pterodactylus/jsite/project/ProjectManager.java +++ b/src/net/pterodactylus/jsite/project/ProjectManager.java @@ -29,12 +29,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Properties; +import java.util.Random; import java.util.logging.Logger; import net.pterodactylus.jsite.core.JSiteException; import net.pterodactylus.jsite.core.NodeManager; 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 @@ -48,6 +50,9 @@ public class ProjectManager { /** Logger. */ private static final Logger logger = Logging.getLogger(ProjectManager.class.getName()); + /** The RNG used to create project IDs. */ + private static final Random random = new Random(); + /** The directory the projects are stored in. */ private final String directory; @@ -127,11 +132,13 @@ public class ProjectManager { int projectIndex = 0; while (projectProperties.containsKey("projects." + projectIndex + ".name")) { String projectPrefix = "projects." + projectIndex; + String projectId = projectProperties.getProperty(projectPrefix + ".id"); String projectName = projectProperties.getProperty(projectPrefix + ".name"); String projectDescription = projectProperties.getProperty(projectPrefix + ".description"); String projectPrivateKey = projectProperties.getProperty(projectPrefix + ".privateKey"); String projectPublicKey = projectProperties.getProperty(projectPrefix + ".publicKey"); Project project = new Project(); + project.setId(projectId); project.setName(projectName); project.setDescription(projectDescription); project.setPrivateKey(projectPrivateKey); @@ -159,6 +166,7 @@ public class ProjectManager { int projectIndex = 0; for (Project project: projects) { String projectPrefix = "projects." + projectIndex; + projectProperties.setProperty(projectPrefix + ".id", project.getId()); projectProperties.setProperty(projectPrefix + ".name", project.getName()); projectProperties.setProperty(projectPrefix + ".description", project.getDescription()); projectProperties.setProperty(projectPrefix + ".privateKey", project.getPrivateKey()); @@ -188,6 +196,9 @@ public class ProjectManager { public Project createProject() throws IOException, JSiteException { Project project = new Project(); String[] keyPair = nodeManager.generateKeyPair(); + byte[] idBytes = new byte[16]; + random.nextBytes(idBytes); + project.setId(Hex.toHex(idBytes)); project.setPrivateKey(keyPair[0]); project.setPublicKey(keyPair[1]); projects.add(project);