mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 02:39:05 +01:00
Attach information to ContactExistsException.
This commit is contained in:
@@ -1,8 +1,27 @@
|
||||
package org.briarproject.bramble.api.db;
|
||||
|
||||
import org.briarproject.bramble.api.identity.Author;
|
||||
import org.briarproject.bramble.api.identity.AuthorId;
|
||||
|
||||
/**
|
||||
* Thrown when a duplicate contact is added to the database. This exception may
|
||||
* occur due to concurrent updates and does not indicate a database error.
|
||||
*/
|
||||
public class ContactExistsException extends DbException {
|
||||
|
||||
private final AuthorId local;
|
||||
private final Author remote;
|
||||
|
||||
public ContactExistsException(AuthorId local, Author remote) {
|
||||
this.local = local;
|
||||
this.remote = remote;
|
||||
}
|
||||
|
||||
public AuthorId getLocalAuthorId() {
|
||||
return local;
|
||||
}
|
||||
|
||||
public Author getRemoteAuthor() {
|
||||
return remote;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,7 +229,7 @@ class ContactExchangeManagerImpl implements ContactExchangeManager {
|
||||
logException(LOG, WARNING, e);
|
||||
tryToClose(conn);
|
||||
eventBus.broadcast(
|
||||
new ContactExchangeFailedEvent(remoteInfo.author));
|
||||
new ContactExchangeFailedEvent(e.getRemoteAuthor()));
|
||||
} catch (DbException e) {
|
||||
logException(LOG, WARNING, e);
|
||||
tryToClose(conn);
|
||||
|
||||
@@ -234,16 +234,15 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
|
||||
|
||||
@Override
|
||||
public ContactId addContact(Transaction transaction, Author remote,
|
||||
AuthorId local, boolean verified)
|
||||
throws DbException {
|
||||
AuthorId local, boolean verified) throws DbException {
|
||||
if (transaction.isReadOnly()) throw new IllegalArgumentException();
|
||||
T txn = unbox(transaction);
|
||||
if (!db.containsIdentity(txn, local))
|
||||
throw new NoSuchIdentityException();
|
||||
if (db.containsIdentity(txn, remote.getId()))
|
||||
throw new ContactExistsException();
|
||||
throw new ContactExistsException(local, remote);
|
||||
if (db.containsContact(txn, remote.getId(), local))
|
||||
throw new ContactExistsException();
|
||||
throw new ContactExistsException(local, remote);
|
||||
ContactId c = db.addContact(txn, remote, local, verified);
|
||||
transaction.attach(new ContactAddedEvent(c));
|
||||
return c;
|
||||
|
||||
@@ -1459,7 +1459,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
true));
|
||||
fail();
|
||||
} catch (ContactExistsException expected) {
|
||||
// Expected
|
||||
assertEquals(localAuthor.getId(), expected.getLocalAuthorId());
|
||||
assertEquals(author, expected.getRemoteAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1488,7 +1489,8 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
|
||||
true));
|
||||
fail();
|
||||
} catch (ContactExistsException expected) {
|
||||
// Expected
|
||||
assertEquals(localAuthor.getId(), expected.getLocalAuthorId());
|
||||
assertEquals(author, expected.getRemoteAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user