From eae32376d5a6a4a96c8e00fbb0f86f2b8fb3d831 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sun, 2 Jan 2011 18:56:57 +0100 Subject: [PATCH] Add methods to set and remove trust for identities. --- .../java/net/pterodactylus/sone/core/Core.java | 37 ++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index fc3d99c..2349481 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -47,6 +47,7 @@ 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.validation.Validation; import freenet.keys.FreenetURI; /** @@ -920,6 +921,42 @@ public class Core implements IdentityListener { } /** + * Sets the trust value of the given origin Sone for the target Sone. + * + * @param origin + * The origin Sone + * @param target + * The target Sone + * @param trustValue + * The trust value (from {@code -100} to {@code 100}) + */ + public void setTrust(Sone origin, Sone target, int trustValue) { + Validation.begin().isNotNull("Trust Origin", origin).check().isInstanceOf("Trust Origin", origin.getIdentity(), OwnIdentity.class).isNotNull("Trust Target", target).isLessOrEqual("Trust Value", trustValue, 100).isGreaterOrEqual("Trust Value", trustValue, -100).check(); + try { + ((OwnIdentity) origin.getIdentity()).setTrust(target.getIdentity(), trustValue, "Set from Sone Web Interface"); + } catch (WebOfTrustException wote1) { + logger.log(Level.WARNING, "Could not set trust for Sone: " + target, wote1); + } + } + + /** + * Removes any trust assignment for the given target Sone. + * + * @param origin + * The trust origin + * @param target + * The trust target + */ + public void removeTrust(Sone origin, Sone target) { + Validation.begin().isNotNull("Trust Origin", origin).isNotNull("Trust Target", target).check().isInstanceOf("Trust Origin Identity", origin.getIdentity(), OwnIdentity.class).check(); + try { + ((OwnIdentity) origin.getIdentity()).removeTrust(target.getIdentity()); + } catch (WebOfTrustException wote1) { + logger.log(Level.WARNING, "Could not remove trust for Sone: " + target, wote1); + } + } + + /** * Updates the stores Sone with the given Sone. * * @param sone -- 2.7.4