X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=87f59c200557759db9e7584f95f0dcede2c03051;hp=9269ea61c58c58a4f32300d4da312ffa94c86864;hb=a108af80df7846c28e24e59e5710bee69627483b;hpb=16172b8d60c485ac52907ba45a354b754bce53e5 diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 9269ea6..87f59c2 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -23,6 +23,7 @@ import static com.google.common.base.Preconditions.checkNotNull; import static com.google.common.primitives.Longs.tryParse; import static java.lang.String.format; import static java.util.logging.Level.WARNING; +import static java.util.logging.Logger.getLogger; import java.util.Collection; import java.util.HashMap; @@ -79,7 +80,6 @@ import net.pterodactylus.sone.database.PostReplyBuilder; import net.pterodactylus.sone.database.PostReplyProvider; import net.pterodactylus.sone.database.SoneBuilder; import net.pterodactylus.sone.database.SoneProvider; -import net.pterodactylus.sone.fcp.FcpInterface; import net.pterodactylus.sone.freenet.wot.Identity; import net.pterodactylus.sone.freenet.wot.IdentityManager; import net.pterodactylus.sone.freenet.wot.OwnIdentity; @@ -91,8 +91,6 @@ import net.pterodactylus.sone.freenet.wot.event.OwnIdentityRemovedEvent; import net.pterodactylus.sone.main.SonePlugin; import net.pterodactylus.util.config.Configuration; import net.pterodactylus.util.config.ConfigurationException; -import net.pterodactylus.util.logging.Logging; -import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.service.AbstractService; import net.pterodactylus.util.thread.NamedThreadFactory; @@ -116,7 +114,7 @@ import com.google.inject.Singleton; public class Core extends AbstractService implements SoneProvider, PostProvider, PostReplyProvider { /** The logger. */ - private static final Logger logger = Logging.getLogger(Core.class); + private static final Logger logger = getLogger("Sone.Core"); /** The start time. */ private final long startupTime = System.currentTimeMillis(); @@ -636,7 +634,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, } logger.info(String.format("Adding Sone from OwnIdentity: %s", ownIdentity)); Sone sone = database.newSoneBuilder().local().from(ownIdentity).build(); - sone.setLatestEdition(Numbers.safeParseLong(ownIdentity.getProperty("Sone.LatestEdition"), 0L)); + sone.setLatestEdition(fromNullable(tryParse(ownIdentity.getProperty("Sone.LatestEdition"))).or(0L)); sone.setClient(new Client("Sone", SonePlugin.VERSION.toString())); sone.setKnown(true); SoneInserter soneInserter = new SoneInserter(this, eventBus, freenetInterface, ownIdentity.getId()); @@ -928,10 +926,9 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, logger.log(Level.WARNING, String.format("Tried to delete non-local Sone: %s", sone)); return; } - // FIXME – implement in database -// sones.remove(sone.getId()); SoneInserter soneInserter = soneInserters.remove(sone); soneInserter.stop(); + database.removeSone(sone); webOfTrustUpdater.removeContext((OwnIdentity) sone.getIdentity(), "Sone"); webOfTrustUpdater.removeProperty((OwnIdentity) sone.getIdentity(), "Sone.LatestEdition"); try { @@ -1734,7 +1731,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, if (sone.isLocal()) { return; } - sone.setLatestEdition(Numbers.safeParseLong(identity.getProperty("Sone.LatestEdition"), sone.getLatestEdition())); + sone.setLatestEdition(fromNullable(tryParse(identity.getProperty("Sone.LatestEdition"))).or(sone.getLatestEdition())); soneDownloader.addSone(sone); soneDownloaders.execute(soneDownloader.fetchSoneAction(sone)); } @@ -1763,16 +1760,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /* TODO - we don’t have the Sone anymore. should this happen? */ return; } - database.removePosts(sone.get()); - for (Post post : sone.get().getPosts()) { - eventBus.post(new PostRemovedEvent(post)); - } - database.removePostReplies(sone.get()); - for (PostReply reply : sone.get().getReplies()) { - eventBus.post(new PostReplyRemovedEvent(reply)); - } -// TODO – implement in database -// sones.remove(identity.getId()); + database.removeSone(sone.get()); eventBus.post(new SoneRemovedEvent(sone.get())); }