/** 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;
/** 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.
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
/** 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;
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);
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());
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);