X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FRequestManager.java;h=54ae5ac97ed5cba8e0ac9688692399321f9658e4;hb=eeea1af877d2a2e0f05d396718df58c2650ca2c3;hp=831c9b3ff145ff4e35862086f4efc52dad8172d6;hpb=392d893dbfff0879ebb9d6bc2367729790f54e52;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/RequestManager.java b/src/net/pterodactylus/jsite/core/RequestManager.java index 831c9b3..54ae5ac 100644 --- a/src/net/pterodactylus/jsite/core/RequestManager.java +++ b/src/net/pterodactylus/jsite/core/RequestManager.java @@ -98,6 +98,34 @@ public class RequestManager implements NodeListener { public void save() throws IOException { } + /** + * Starts inserting the given project. + * + * @param project + * The project to insert + * @throws JSiteException + * if the project’s node is not connected, or no node is + * connected at all + */ + public void insertProject(Project project) throws JSiteException { + Request request = new Request(); + request.setClientToken(generateClientToken(project)); + Node wantedNode = project.getNode(); + if (wantedNode == null) { + for (Node node : nodeManager.getNodes()) { + if (nodeManager.getFcpClient(node) != null) { + wantedNode = node; + break; + } + } + } + if (wantedNode == null) { + /* TODO use custom exception */ + throw new JSiteException("No node connected."); + } + FcpClient fcpClient = nodeManager.getFcpClient(wantedNode); + } + // // PRIVATE METHODS // @@ -120,11 +148,17 @@ public class RequestManager implements NodeListener { if (projectIdString.length() != (IdGenerator.DEFAULT_LENGTH * 2)) { return false; } + int clientTokenHashCode = -1; try { Hex.toByte(projectIdString); + Long.valueOf(clientTokenParts[1]); + clientTokenHashCode = Integer.valueOf(clientTokenParts[2]); } catch (NumberFormatException nfe1) { return false; } + if ((clientTokenParts[0] + "." + clientTokenParts[1]).hashCode() != clientTokenHashCode) { + return false; + } return true; }