Rename exceptions and events.

This commit is contained in:
akwizgran
2019-05-03 13:49:26 +01:00
parent 9c08073e49
commit e5fc91b620
5 changed files with 28 additions and 28 deletions

View File

@@ -1,9 +1,9 @@
package org.briarproject.bramble.api.db; package org.briarproject.bramble.api.db;
/** /**
* Thrown when a database operation is attempted for a pseudonym that is not in * Thrown when a database operation is attempted for an identity that is not in
* the database. This exception may occur due to concurrent updates and does * the database. This exception may occur due to concurrent updates and does
* not indicate a database error. * not indicate a database error.
*/ */
public class NoSuchLocalAuthorException extends DbException { public class NoSuchIdentityException extends DbException {
} }

View File

@@ -7,15 +7,15 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
/** /**
* An event that is broadcast when a local pseudonym is added. * An event that is broadcast when an identity is added.
*/ */
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class LocalAuthorAddedEvent extends Event { public class IdentityAddedEvent extends Event {
private final AuthorId authorId; private final AuthorId authorId;
public LocalAuthorAddedEvent(AuthorId authorId) { public IdentityAddedEvent(AuthorId authorId) {
this.authorId = authorId; this.authorId = authorId;
} }

View File

@@ -7,15 +7,15 @@ import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import javax.annotation.concurrent.Immutable; import javax.annotation.concurrent.Immutable;
/** /**
* An event that is broadcast when a local pseudonym is removed. * An event that is broadcast when an identity is removed.
*/ */
@Immutable @Immutable
@NotNullByDefault @NotNullByDefault
public class LocalAuthorRemovedEvent extends Event { public class IdentityRemovedEvent extends Event {
private final AuthorId authorId; private final AuthorId authorId;
public LocalAuthorRemovedEvent(AuthorId authorId) { public IdentityRemovedEvent(AuthorId authorId) {
this.authorId = authorId; this.authorId = authorId;
} }

View File

@@ -20,7 +20,7 @@ import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.db.MigrationListener; import org.briarproject.bramble.api.db.MigrationListener;
import org.briarproject.bramble.api.db.NoSuchContactException; import org.briarproject.bramble.api.db.NoSuchContactException;
import org.briarproject.bramble.api.db.NoSuchGroupException; import org.briarproject.bramble.api.db.NoSuchGroupException;
import org.briarproject.bramble.api.db.NoSuchLocalAuthorException; import org.briarproject.bramble.api.db.NoSuchIdentityException;
import org.briarproject.bramble.api.db.NoSuchMessageException; import org.briarproject.bramble.api.db.NoSuchMessageException;
import org.briarproject.bramble.api.db.NoSuchPendingContactException; import org.briarproject.bramble.api.db.NoSuchPendingContactException;
import org.briarproject.bramble.api.db.NoSuchTransportException; import org.briarproject.bramble.api.db.NoSuchTransportException;
@@ -33,8 +33,8 @@ import org.briarproject.bramble.api.event.EventExecutor;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.AuthorId; import org.briarproject.bramble.api.identity.AuthorId;
import org.briarproject.bramble.api.identity.Identity; import org.briarproject.bramble.api.identity.Identity;
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent; import org.briarproject.bramble.api.identity.event.IdentityAddedEvent;
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent; import org.briarproject.bramble.api.identity.event.IdentityRemovedEvent;
import org.briarproject.bramble.api.lifecycle.ShutdownManager; import org.briarproject.bramble.api.lifecycle.ShutdownManager;
import org.briarproject.bramble.api.nullsafety.NotNullByDefault; import org.briarproject.bramble.api.nullsafety.NotNullByDefault;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
@@ -238,7 +238,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
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 NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
if (db.containsIdentity(txn, remote.getId())) if (db.containsIdentity(txn, remote.getId()))
throw new ContactExistsException(); throw new ContactExistsException();
if (db.containsContact(txn, remote.getId(), local)) if (db.containsContact(txn, remote.getId(), local))
@@ -289,7 +289,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsIdentity(txn, i.getId())) { if (!db.containsIdentity(txn, i.getId())) {
db.addIdentity(txn, i); db.addIdentity(txn, i);
transaction.attach(new LocalAuthorAddedEvent(i.getId())); transaction.attach(new IdentityAddedEvent(i.getId()));
} }
} }
@@ -346,7 +346,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
AuthorId local) throws DbException { AuthorId local) throws DbException {
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsIdentity(txn, local)) if (!db.containsIdentity(txn, local))
throw new NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
return db.containsContact(txn, remote, local); return db.containsContact(txn, remote, local);
} }
@@ -506,7 +506,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
AuthorId a) throws DbException { AuthorId a) throws DbException {
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsIdentity(txn, a)) if (!db.containsIdentity(txn, a))
throw new NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
return db.getContacts(txn, a); return db.getContacts(txn, a);
} }
@@ -558,7 +558,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
throws DbException { throws DbException {
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsIdentity(txn, a)) if (!db.containsIdentity(txn, a))
throw new NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
return db.getIdentity(txn, a); return db.getIdentity(txn, a);
} }
@@ -910,9 +910,9 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
if (transaction.isReadOnly()) throw new IllegalArgumentException(); if (transaction.isReadOnly()) throw new IllegalArgumentException();
T txn = unbox(transaction); T txn = unbox(transaction);
if (!db.containsIdentity(txn, a)) if (!db.containsIdentity(txn, a))
throw new NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
db.removeIdentity(txn, a); db.removeIdentity(txn, a);
transaction.attach(new LocalAuthorRemovedEvent(a)); transaction.attach(new IdentityRemovedEvent(a));
} }
@Override @Override
@@ -1041,7 +1041,7 @@ class DatabaseComponentImpl<T> implements DatabaseComponent {
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 NoSuchLocalAuthorException(); throw new NoSuchIdentityException();
db.setHandshakeKeyPair(txn, local, publicKey, privateKey); db.setHandshakeKeyPair(txn, local, publicKey, privateKey);
} }

View File

@@ -11,7 +11,7 @@ import org.briarproject.bramble.api.db.DatabaseComponent;
import org.briarproject.bramble.api.db.Metadata; import org.briarproject.bramble.api.db.Metadata;
import org.briarproject.bramble.api.db.NoSuchContactException; import org.briarproject.bramble.api.db.NoSuchContactException;
import org.briarproject.bramble.api.db.NoSuchGroupException; import org.briarproject.bramble.api.db.NoSuchGroupException;
import org.briarproject.bramble.api.db.NoSuchLocalAuthorException; import org.briarproject.bramble.api.db.NoSuchIdentityException;
import org.briarproject.bramble.api.db.NoSuchMessageException; import org.briarproject.bramble.api.db.NoSuchMessageException;
import org.briarproject.bramble.api.db.NoSuchPendingContactException; import org.briarproject.bramble.api.db.NoSuchPendingContactException;
import org.briarproject.bramble.api.db.NoSuchTransportException; import org.briarproject.bramble.api.db.NoSuchTransportException;
@@ -20,8 +20,8 @@ import org.briarproject.bramble.api.event.EventBus;
import org.briarproject.bramble.api.identity.Author; import org.briarproject.bramble.api.identity.Author;
import org.briarproject.bramble.api.identity.Identity; import org.briarproject.bramble.api.identity.Identity;
import org.briarproject.bramble.api.identity.LocalAuthor; import org.briarproject.bramble.api.identity.LocalAuthor;
import org.briarproject.bramble.api.identity.event.LocalAuthorAddedEvent; import org.briarproject.bramble.api.identity.event.IdentityAddedEvent;
import org.briarproject.bramble.api.identity.event.LocalAuthorRemovedEvent; import org.briarproject.bramble.api.identity.event.IdentityRemovedEvent;
import org.briarproject.bramble.api.lifecycle.ShutdownManager; import org.briarproject.bramble.api.lifecycle.ShutdownManager;
import org.briarproject.bramble.api.plugin.TransportId; import org.briarproject.bramble.api.plugin.TransportId;
import org.briarproject.bramble.api.settings.Settings; import org.briarproject.bramble.api.settings.Settings;
@@ -166,7 +166,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
oneOf(database).containsIdentity(txn, localAuthor.getId()); oneOf(database).containsIdentity(txn, localAuthor.getId());
will(returnValue(false)); will(returnValue(false));
oneOf(database).addIdentity(txn, identity); oneOf(database).addIdentity(txn, identity);
oneOf(eventBus).broadcast(with(any(LocalAuthorAddedEvent.class))); oneOf(eventBus).broadcast(with(any(IdentityAddedEvent.class)));
// addContact() // addContact()
oneOf(database).containsIdentity(txn, localAuthor.getId()); oneOf(database).containsIdentity(txn, localAuthor.getId());
will(returnValue(true)); will(returnValue(true));
@@ -210,7 +210,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
oneOf(database).containsIdentity(txn, localAuthor.getId()); oneOf(database).containsIdentity(txn, localAuthor.getId());
will(returnValue(true)); will(returnValue(true));
oneOf(database).removeIdentity(txn, localAuthor.getId()); oneOf(database).removeIdentity(txn, localAuthor.getId());
oneOf(eventBus).broadcast(with(any(LocalAuthorRemovedEvent.class))); oneOf(eventBus).broadcast(with(any(IdentityRemovedEvent.class)));
// endTransaction() // endTransaction()
oneOf(database).commitTransaction(txn); oneOf(database).commitTransaction(txn);
// close() // close()
@@ -455,7 +455,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.addContact(transaction, author, localAuthor.getId(), db.addContact(transaction, author, localAuthor.getId(),
true)); true));
fail(); fail();
} catch (NoSuchLocalAuthorException expected) { } catch (NoSuchIdentityException expected) {
// Expected // Expected
} }
@@ -463,7 +463,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.getIdentity(transaction, localAuthor.getId())); db.getIdentity(transaction, localAuthor.getId()));
fail(); fail();
} catch (NoSuchLocalAuthorException expected) { } catch (NoSuchIdentityException expected) {
// Expected // Expected
} }
@@ -471,7 +471,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.transaction(false, transaction -> db.transaction(false, transaction ->
db.removeIdentity(transaction, localAuthor.getId())); db.removeIdentity(transaction, localAuthor.getId()));
fail(); fail();
} catch (NoSuchLocalAuthorException expected) { } catch (NoSuchIdentityException expected) {
// Expected // Expected
} }
@@ -482,7 +482,7 @@ public class DatabaseComponentImplTest extends BrambleMockTestCase {
db.setHandshakeKeyPair(transaction, localAuthor.getId(), db.setHandshakeKeyPair(transaction, localAuthor.getId(),
publicKey, privateKey)); publicKey, privateKey));
fail(); fail();
} catch (NoSuchLocalAuthorException expected) { } catch (NoSuchIdentityException expected) {
// Expected // Expected
} }
} }