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