Migrate accounts to NoteDb (part 2)
This is the second part of migrating accounts from ReviewDb to NoteDb. This change: * migrates the accounts from ReviewDb to NoteDb (for single instance Gerrit servers) * adds a configuration parameter (user.readAccountsFromGit) that controls whether external IDs are read from ReviewDb or NoteDb AccountIT is now loading external IDs of an account directly from NoteDb instead of retrieving them via the account cache. This is because for the test deleteUserBranchWithAccessDatabaseCapability() the admin account gets deleted by deleting its user branch and then the @After restoreExternalIds() method couldn't delete the external IDs of that account anymore (because the account was deleted it couldn't be retrieved via the account cache anymore). Change-Id: I41fa3a6bdb76f497c79a05bdc76e97a7e73624a6 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
@@ -23,12 +23,14 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import org.eclipse.jgit.errors.ConfigInvalidException;
|
||||
|
||||
@Singleton
|
||||
public class AccountResolver {
|
||||
@@ -61,7 +63,8 @@ public class AccountResolver {
|
||||
* @return the single account that matches; null if no account matches or there are multiple
|
||||
* candidates.
|
||||
*/
|
||||
public Account find(ReviewDb db, String nameOrEmail) throws OrmException {
|
||||
public Account find(ReviewDb db, String nameOrEmail)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
Set<Account.Id> r = findAll(db, nameOrEmail);
|
||||
if (r.size() == 1) {
|
||||
return byId.get(r.iterator().next()).getAccount();
|
||||
@@ -90,7 +93,8 @@ public class AccountResolver {
|
||||
* name ("username").
|
||||
* @return the accounts that match, empty collection if none. Never null.
|
||||
*/
|
||||
public Set<Account.Id> findAll(ReviewDb db, String nameOrEmail) throws OrmException {
|
||||
public Set<Account.Id> findAll(ReviewDb db, String nameOrEmail)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
Matcher m = Pattern.compile("^.* \\(([1-9][0-9]*)\\)$").matcher(nameOrEmail);
|
||||
if (m.matches()) {
|
||||
Account.Id id = Account.Id.parse(m.group(1));
|
||||
@@ -118,7 +122,8 @@ public class AccountResolver {
|
||||
return findAllByNameOrEmail(db, nameOrEmail);
|
||||
}
|
||||
|
||||
private boolean exists(ReviewDb db, Account.Id id) throws OrmException {
|
||||
private boolean exists(ReviewDb db, Account.Id id)
|
||||
throws OrmException, IOException, ConfigInvalidException {
|
||||
return accounts.get(db, id) != null;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user