Remove methods to manipulate a Sone’s request and insert URI.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 19 Oct 2013 15:04:34 +0000 (17:04 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:30 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/core/Core.java
src/main/java/net/pterodactylus/sone/core/FreenetInterface.java
src/main/java/net/pterodactylus/sone/core/SoneDownloader.java
src/main/java/net/pterodactylus/sone/core/SoneInserter.java
src/main/java/net/pterodactylus/sone/core/SoneRescuer.java
src/main/java/net/pterodactylus/sone/data/Sone.java

index 612398d..7ea8134 100644 (file)
@@ -25,6 +25,7 @@ import static com.google.common.base.Predicates.not;
 import static com.google.common.collect.FluentIterable.from;
 import static net.pterodactylus.sone.data.Identified.GET_ID;
 import static net.pterodactylus.sone.data.Sone.LOCAL_SONE_FILTER;
+import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
 
 import java.net.MalformedURLException;
 import java.util.Collection;
@@ -558,12 +559,7 @@ public class Core extends AbstractService implements SoneProvider {
                logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity));
                synchronized (sones) {
                        final Sone sone;
-                       try {
-                               sone = database.newSoneBuilder().by(ownIdentity.getId()).local().build(Optional.<SoneCreated>absent()).setInsertUri(new FreenetURI(ownIdentity.getInsertUri())).setRequestUri(new FreenetURI(ownIdentity.getRequestUri()));
-                       } catch (MalformedURLException mue1) {
-                               logger.log(Level.SEVERE, String.format("Could not convert the Identity’s URIs to Freenet URIs: %s, %s", ownIdentity.getInsertUri(), ownIdentity.getRequestUri()), mue1);
-                               return null;
-                       }
+                       sone = database.newSoneBuilder().by(ownIdentity.getId()).local().build(Optional.<SoneCreated>absent());
                        sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), (long) 0));
                        sone.setClient(new Client("Sone", SonePlugin.VERSION.toString()));
                        sone.setKnown(true);
@@ -622,7 +618,6 @@ public class Core extends AbstractService implements SoneProvider {
                        }
                        boolean newSone = !existingSone.isPresent();
                        final Sone sone = newSone ? database.newSoneBuilder().by(identity.getId()).build(Optional.<SoneCreated>absent()) : existingSone.get();
-                       sone.setRequestUri(SoneUri.create(identity.getRequestUri()));
                        sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), (long) 0));
                        if (newSone) {
                                synchronized (knownSones) {
@@ -644,7 +639,7 @@ public class Core extends AbstractService implements SoneProvider {
                                @Override
                                @SuppressWarnings("synthetic-access")
                                public void run() {
-                                       soneDownloader.fetchSone(sone, sone.getRequestUri());
+                                       soneDownloader.fetchSone(sone, TO_FREENET_URI.apply(sone));
                                }
 
                        });
index af9aa5a..bea268b 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.core;
 
+import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
+
 import java.net.MalformedURLException;
 import java.util.Collections;
 import java.util.HashMap;
@@ -34,6 +36,10 @@ import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.sone.data.TemporaryImage;
 import net.pterodactylus.util.logging.Logging;
 
+import com.db4o.ObjectContainer;
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.eventbus.EventBus;
+import com.google.inject.Inject;
 import freenet.client.ClientMetadata;
 import freenet.client.FetchException;
 import freenet.client.FetchResult;
@@ -56,11 +62,6 @@ import freenet.node.RequestClient;
 import freenet.node.RequestStarter;
 import freenet.support.api.Bucket;
 import freenet.support.io.ArrayBucket;
-import com.db4o.ObjectContainer;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.common.eventbus.EventBus;
-import com.google.inject.Inject;
 
 /**
  * Contains all necessary functionality for interacting with the Freenet node.
@@ -216,7 +217,7 @@ public class FreenetInterface {
         */
        public void registerUsk(final Sone sone, final SoneDownloader soneDownloader) {
                try {
-                       logger.log(Level.FINE, String.format("Registering Sone “%s” for USK updates at %s…", sone, sone.getRequestUri().setMetaString(new String[] { "sone.xml" })));
+                       logger.log(Level.FINE, String.format("Registering Sone “%s” for USK updates at %s…", sone, TO_FREENET_URI.apply(sone).setMetaString(new String[]{"sone.xml"})));
                        USKCallback uskCallback = new USKCallback() {
 
                                @Override
@@ -247,9 +248,9 @@ public class FreenetInterface {
                        };
                        soneUskCallbacks.put(sone.getId(), uskCallback);
                        boolean runBackgroundFetch = (System.currentTimeMillis() - sone.getTime()) < TimeUnit.DAYS.toMillis(7);
-                       uskManager.subscribe(USK.create(sone.getRequestUri()), uskCallback, runBackgroundFetch, requestClient);
+                       uskManager.subscribe(USK.create(TO_FREENET_URI.apply(sone)), uskCallback, runBackgroundFetch, requestClient);
                } catch (MalformedURLException mue1) {
-                       logger.log(Level.WARNING, String.format("Could not subscribe USK “%s”!", sone.getRequestUri()), mue1);
+                       logger.log(Level.WARNING, String.format("Could not subscribe USK “%s”!", TO_FREENET_URI.apply(sone)), mue1);
                }
        }
 
@@ -266,9 +267,9 @@ public class FreenetInterface {
                }
                try {
                        logger.log(Level.FINEST, String.format("Unsubscribing from USK for %s…", sone));
-                       uskManager.unsubscribe(USK.create(sone.getRequestUri()), uskCallback);
+                       uskManager.unsubscribe(USK.create(TO_FREENET_URI.apply(sone)), uskCallback);
                } catch (MalformedURLException mue1) {
-                       logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", sone.getRequestUri()), mue1);
+                       logger.log(Level.FINE, String.format("Could not unsubscribe USK “%s”!", TO_FREENET_URI.apply(sone)), mue1);
                }
        }
 
index d0f9055..6eaa1b0 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.core;
 
+import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
+
 import java.io.InputStream;
 import java.util.HashSet;
 import java.util.Set;
@@ -107,7 +109,7 @@ public class SoneDownloader extends AbstractService {
         *            The Sone to fetch
         */
        public void fetchSone(Sone sone) {
-               fetchSone(sone, sone.getRequestUri().sskForUSK());
+               fetchSone(sone, TO_FREENET_URI.apply(sone).sskForUSK());
        }
 
        /**
@@ -181,11 +183,6 @@ public class SoneDownloader extends AbstractService {
                        Sone parsedSone = parseSone(originalSone, soneInputStream);
                        if (parsedSone != null) {
                                parsedSone.setLatestEdition(requestUri.getEdition());
-                               if (requestUri.getKeyType().equals("USK")) {
-                                       parsedSone.setRequestUri(requestUri.setMetaString(new String[0]));
-                               } else {
-                                       parsedSone.setRequestUri(requestUri.setKeyType("USK").setDocName("Sone").setMetaString(new String[0]));
-                               }
                        }
                        return parsedSone;
                } catch (Exception e1) {
index 36eb300..c4d2e85 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.core;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static net.pterodactylus.sone.data.Album.NOT_EMPTY;
+import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
 
 import java.io.InputStreamReader;
 import java.io.StringWriter;
@@ -299,7 +300,7 @@ public class SoneInserter extends AbstractService {
                        soneProperties.put("id", sone.getId());
                        soneProperties.put("name", sone.getName());
                        soneProperties.put("time", sone.getTime());
-                       soneProperties.put("requestUri", sone.getRequestUri());
+                       soneProperties.put("requestUri", TO_FREENET_URI.apply(sone));
                        soneProperties.put("profile", sone.getProfile());
                        soneProperties.put("posts", Ordering.from(Post.TIME_COMPARATOR).sortedCopy(sone.getPosts()));
                        soneProperties.put("replies", Ordering.from(Reply.TIME_COMPARATOR).reverse().sortedCopy(sone.getReplies()));
index d3924aa..173a67e 100644 (file)
@@ -17,6 +17,8 @@
 
 package net.pterodactylus.sone.core;
 
+import static net.pterodactylus.sone.data.Sone.TO_FREENET_URI;
+
 import net.pterodactylus.sone.data.Sone;
 import net.pterodactylus.util.service.AbstractService;
 import freenet.keys.FreenetURI;
@@ -62,7 +64,7 @@ public class SoneRescuer extends AbstractService {
                this.core = core;
                this.soneDownloader = soneDownloader;
                this.sone = sone;
-               currentEdition = sone.getRequestUri().getEdition();
+               currentEdition = TO_FREENET_URI.apply(sone).getEdition();
        }
 
        //
@@ -154,7 +156,7 @@ public class SoneRescuer extends AbstractService {
                        }
                        if (fetching) {
                                core.lockSone(sone);
-                               FreenetURI soneUri = sone.getRequestUri().setKeyType("SSK").setDocName("Sone-" + currentEdition).setMetaString(new String[] { "sone.xml" });
+                               FreenetURI soneUri = TO_FREENET_URI.apply(sone).setKeyType("SSK").setDocName("Sone-" + currentEdition).setMetaString(new String[] { "sone.xml" });
                                System.out.println("URI: " + soneUri);
                                Sone fetchedSone = soneDownloader.fetchSone(sone, soneUri, true);
                                System.out.println("Sone: " + fetchedSone);
index 96b1287..c01e120 100644 (file)
@@ -200,38 +200,6 @@ public interface Sone extends Identified, Fingerprintable, Comparable<Sone> {
        boolean isLocal();
 
        /**
-        * Returns the request URI of this Sone.
-        *
-        * @return The request URI of this Sone
-        */
-       FreenetURI getRequestUri();
-
-       /**
-        * Sets the request URI of this Sone.
-        *
-        * @param requestUri
-        *              The request URI of this Sone
-        * @return This Sone (for method chaining)
-        */
-       Sone setRequestUri(FreenetURI requestUri);
-
-       /**
-        * Returns the insert URI of this Sone.
-        *
-        * @return The insert URI of this Sone
-        */
-       FreenetURI getInsertUri();
-
-       /**
-        * Sets the insert URI of this Sone.
-        *
-        * @param insertUri
-        *              The insert URI of this Sone
-        * @return This Sone (for method chaining)
-        */
-       Sone setInsertUri(FreenetURI insertUri);
-
-       /**
         * Returns the latest edition of this Sone.
         *
         * @return The latest edition of this Sone