*
* @param projectName
* The name of the project
- * @return A newly created project, or <code>null</code> if key generation
- * failed
+ * @return A newly created project
* @throws IOException
* if an I/O error occured communicating with the node
+ * @throws NoNodeException
+ * if no node is configured
*/
- public Project addProject(String projectName) throws IOException;
+ public Project createProject(String projectName) throws IOException, NoNodeException;
}
/**
* {@inheritDoc}
*/
- public Project addProject(String projectName) throws IOException {
+ public Project createProject(String projectName) throws IOException, NoNodeException {
Project project = new Project();
project.setName(projectName);
String[] keyPair = nodeManager.generateKeyPair();
- if (keyPair == null) {
- return null;
- }
project.setPrivateKey(keyPair[0]);
project.setPublicKey(keyPair[1]);
return project;
* public key at index <code>1</code>
* @throws IOException
* if an I/O error occurs communicating with the node
+ * @throws NoNodeException
+ * if no node is configured
*/
- public String[] generateKeyPair() throws IOException {
- if (!nodes.isEmpty()) {
- Node node = nodes.get(0);
- HighLevelClient highLevelClient = nodeClients.get(node);
- try {
- KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
- return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
- } catch (InterruptedException e) {
- /* ignore. */
- }
+ public String[] generateKeyPair() throws IOException, NoNodeException {
+ if (nodes.isEmpty()) {
+ throw new NoNodeException("no node configured");
+ }
+ Node node = nodes.get(0);
+ HighLevelClient highLevelClient = nodeClients.get(node);
+ try {
+ KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
+ return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+ } catch (InterruptedException e) {
+ /* ignore. */
}
return null;
}
import net.pterodactylus.jsite.core.Core;
import net.pterodactylus.jsite.core.CoreListener;
+import net.pterodactylus.jsite.core.NoNodeException;
import net.pterodactylus.jsite.core.Node;
import net.pterodactylus.jsite.core.Project;
import net.pterodactylus.jsite.core.Request;
*/
private void addProject() {
try {
- Project project = core.addProject("New Project");
+ Project project = core.createProject("New Project");
System.out.println("private: " + project.getPrivateKey() + ", public: " + project.getPublicKey());
mainWindow.addProject(project);
+ } catch (NoNodeException nne1) {
+ /* TODO - add i18n */
+ JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
} catch (IOException e) {
+ /* TODO - add i18n */
JOptionPane.showMessageDialog(mainWindow, I18n.get(""), I18n.get(""), JOptionPane.ERROR_MESSAGE);
}
}