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;
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);
}
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) {
@Override
@SuppressWarnings("synthetic-access")
public void run() {
- soneDownloader.fetchSone(sone, sone.getRequestUri());
+ soneDownloader.fetchSone(sone, TO_FREENET_URI.apply(sone));
}
});
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;
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;
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.
*/
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
};
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);
}
}
}
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);
}
}
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;
* The Sone to fetch
*/
public void fetchSone(Sone sone) {
- fetchSone(sone, sone.getRequestUri().sskForUSK());
+ fetchSone(sone, TO_FREENET_URI.apply(sone).sskForUSK());
}
/**
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) {
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;
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()));
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;
this.core = core;
this.soneDownloader = soneDownloader;
this.sone = sone;
- currentEdition = sone.getRequestUri().getEdition();
+ currentEdition = TO_FREENET_URI.apply(sone).getEdition();
}
//
}
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);
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