- * Update job that sets the trust relation between two identities.
- *
- * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
- */
- @VisibleForTesting
- class SetTrustJob extends WebOfTrustUpdateJob {
-
- /** The identity giving the trust. */
- private final OwnIdentity truster;
-
- /** The identity receiving the trust. */
- private final Identity trustee;
-
- /** The score of the relation. */
- private final Integer score;
-
- /** The comment of the relation. */
- private final String comment;
-
- /**
- * Creates a new set trust job.
- *
- * @param truster
- * The identity giving the trust
- * @param trustee
- * The identity receiving the trust
- * @param score
- * The score of the trust (from -100 to 100, may be {@code null} to remote
- * the trust relation completely)
- * @param comment
- * The comment of the trust relation
- */
- public SetTrustJob(OwnIdentity truster, Identity trustee, Integer score, String comment) {
- this.truster = checkNotNull(truster, "truster must not be null");
- this.trustee = checkNotNull(trustee, "trustee must not be null");
- this.score = score;
- this.comment = comment;
- }
-
- /** {@inheritDoc} */
- @Override
- @SuppressWarnings("synthetic-access")
- public void run() {
- try {
- if (score != null) {
- webOfTrustConnector.setTrust(truster, trustee, score, comment);
- trustee.setTrust(truster, new Trust(score, null, 0));
- } else {
- webOfTrustConnector.removeTrust(truster, trustee);
- trustee.removeTrust(truster);
- }
- finish(true);
- } catch (WebOfTrustException wote1) {
- logger.log(Level.WARNING, "Could not set Trust value for " + truster + " -> " + trustee + " to " + score + " (" + comment + ")!", wote1);
- finish(false);
- }
- }
-
- //
- // OBJECT METHODS
- //
-
- /** {@inheritDoc} */
- @Override
- public boolean equals(Object object) {
- if ((object == null) || !object.getClass().equals(getClass())) {
- return false;
- }
- SetTrustJob updateJob = (SetTrustJob) object;
- return updateJob.truster.equals(truster) && updateJob.trustee.equals(trustee);
- }
-
- /** {@inheritDoc} */
- @Override
- public int hashCode() {
- return getClass().hashCode() ^ truster.hashCode() ^ trustee.hashCode();
- }
-
- /** {@inheritDoc} */
- @Override
- public String toString() {
- return String.format("%s[truster=%s,trustee=%s]", getClass().getSimpleName(), truster.getId(), trustee.getId());
- }
-
- }
-
- /**