From b621439b18b409255cf877d54a5b2b78a43a98d8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Tue, 2 Dec 2014 22:09:56 +0100 Subject: [PATCH] Require a local Sone when rescuing. --- src/main/java/net/pterodactylus/sone/core/Core.java | 5 ++--- src/main/java/net/pterodactylus/sone/core/SoneRescuer.java | 5 +++-- src/main/java/net/pterodactylus/sone/web/RescuePage.java | 4 ++-- src/test/java/net/pterodactylus/sone/core/SoneRescuerTest.java | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index b485445..84e7499 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -156,7 +156,7 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, /** Sone rescuers. */ /* synchronize access on this on sones. */ - private final Map soneRescuers = new HashMap(); + private final Map soneRescuers = new HashMap(); /** All known Sones. */ private final Set knownSones = new HashSet(); @@ -269,9 +269,8 @@ public class Core extends AbstractService implements SoneProvider, PostProvider, * The local Sone to get the rescuer for * @return The Sone rescuer for the given Sone */ - public SoneRescuer getSoneRescuer(Sone sone) { + public SoneRescuer getSoneRescuer(LocalSone sone) { checkNotNull(sone, "sone must not be null"); - checkArgument(sone.isLocal(), "sone must be local"); synchronized (soneRescuers) { SoneRescuer soneRescuer = soneRescuers.get(sone); if (soneRescuer == null) { diff --git a/src/main/java/net/pterodactylus/sone/core/SoneRescuer.java b/src/main/java/net/pterodactylus/sone/core/SoneRescuer.java index f45e351..6f8d6c8 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneRescuer.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneRescuer.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.core; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.service.AbstractService; import freenet.keys.FreenetURI; @@ -36,7 +37,7 @@ public class SoneRescuer extends AbstractService { private final SoneDownloader soneDownloader; /** The Sone being rescued. */ - private final Sone sone; + private final LocalSone sone; /** Whether the rescuer is currently fetching a Sone. */ private volatile boolean fetching; @@ -57,7 +58,7 @@ public class SoneRescuer extends AbstractService { * @param sone * The Sone to rescue */ - public SoneRescuer(Core core, SoneDownloader soneDownloader, Sone sone) { + public SoneRescuer(Core core, SoneDownloader soneDownloader, LocalSone sone) { super("Sone Rescuer for " + sone.getName()); this.core = core; this.soneDownloader = soneDownloader; diff --git a/src/main/java/net/pterodactylus/sone/web/RescuePage.java b/src/main/java/net/pterodactylus/sone/web/RescuePage.java index 569aaaa..24a8f11 100644 --- a/src/main/java/net/pterodactylus/sone/web/RescuePage.java +++ b/src/main/java/net/pterodactylus/sone/web/RescuePage.java @@ -20,7 +20,7 @@ package net.pterodactylus.sone.web; import static net.pterodactylus.sone.utils.NumberParsers.parseLong; import net.pterodactylus.sone.core.SoneRescuer; -import net.pterodactylus.sone.data.Sone; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.web.page.FreenetRequest; import net.pterodactylus.util.template.Template; import net.pterodactylus.util.template.TemplateContext; @@ -56,7 +56,7 @@ public class RescuePage extends SoneTemplatePage { @Override protected void processTemplate(FreenetRequest request, TemplateContext templateContext) throws RedirectException { super.processTemplate(request, templateContext); - Sone currentSone = getCurrentSone(request.getToadletContext(), false).get(); + LocalSone currentSone = getCurrentSone(request.getToadletContext(), false).get(); SoneRescuer soneRescuer = webInterface.getCore().getSoneRescuer(currentSone); if (request.getMethod() == Method.POST) { if ("true".equals(request.getHttpRequest().getPartAsStringFailsafe("fetch", 4))) { diff --git a/src/test/java/net/pterodactylus/sone/core/SoneRescuerTest.java b/src/test/java/net/pterodactylus/sone/core/SoneRescuerTest.java index ede6f13..8331863 100644 --- a/src/test/java/net/pterodactylus/sone/core/SoneRescuerTest.java +++ b/src/test/java/net/pterodactylus/sone/core/SoneRescuerTest.java @@ -10,6 +10,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import net.pterodactylus.sone.data.LocalSone; import net.pterodactylus.sone.data.Sone; import freenet.keys.FreenetURI; @@ -30,7 +31,7 @@ public class SoneRescuerTest { private static final long SOME_OTHER_EDITION = 15L; private final Core core = mock(Core.class); private final SoneDownloader soneDownloader = mock(SoneDownloader.class); - private final Sone sone = mock(Sone.class); + private final LocalSone sone = mock(LocalSone.class); private SoneRescuer soneRescuer; @Before -- 2.7.4