Remove unused DirectoryException

Callers of AccountDirectory#fillAccountInfo converted DirectoryException
into OrmException. By removing the throws DirectoryException clause from
that method a lot of callers no longer need to deal with OrmException.

Change-Id: I23a74bd35f98f8c728f28c9b4ef5e49680f1d270
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2018-06-20 11:05:33 +02:00
parent 09177ad9a8
commit 6fc34edb31
10 changed files with 20 additions and 50 deletions

View File

@@ -47,17 +47,6 @@ public abstract class AccountDirectory {
STATUS
}
public abstract void fillAccountInfo(Iterable<? extends AccountInfo> in, Set<FillOptions> options)
throws DirectoryException;
@SuppressWarnings("serial")
public static class DirectoryException extends Exception {
public DirectoryException(String message, Throwable why) {
super(message, why);
}
public DirectoryException(Throwable why) {
super(why);
}
}
public abstract void fillAccountInfo(
Iterable<? extends AccountInfo> in, Set<FillOptions> options);
}

View File

@@ -16,13 +16,10 @@ package com.google.gerrit.server.account;
import static com.google.common.base.Preconditions.checkArgument;
import com.google.common.base.Throwables;
import com.google.common.collect.Iterables;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.AccountDirectory.DirectoryException;
import com.google.gerrit.server.account.AccountDirectory.FillOptions;
import com.google.gwtorm.server.OrmException;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
import java.util.ArrayList;
@@ -86,23 +83,18 @@ public class AccountLoader {
provided.add(info);
}
public void fill() throws OrmException {
try {
directory.fillAccountInfo(Iterables.concat(created.values(), provided), options);
} catch (DirectoryException e) {
Throwables.throwIfInstanceOf(e.getCause(), OrmException.class);
throw new OrmException(e);
}
public void fill() {
directory.fillAccountInfo(Iterables.concat(created.values(), provided), options);
}
public void fill(Collection<? extends AccountInfo> infos) throws OrmException {
public void fill(Collection<? extends AccountInfo> infos) {
for (AccountInfo info : infos) {
put(info);
}
fill();
}
public AccountInfo fillOne(Account.Id id) throws OrmException {
public AccountInfo fillOne(Account.Id id) {
AccountInfo info = get(id);
fill();
return info;

View File

@@ -63,8 +63,7 @@ public class InternalAccountDirectory extends AccountDirectory {
}
@Override
public void fillAccountInfo(Iterable<? extends AccountInfo> in, Set<FillOptions> options)
throws DirectoryException {
public void fillAccountInfo(Iterable<? extends AccountInfo> in, Set<FillOptions> options) {
if (options.equals(ID_ONLY)) {
return;
}

View File

@@ -415,8 +415,7 @@ public class ChangeJson {
return format(cd, Optional.of(rsrc.getPatchSet().getId()), true);
}
public List<List<ChangeInfo>> formatQueryResults(List<QueryResult<ChangeData>> in)
throws OrmException {
public List<List<ChangeInfo>> formatQueryResults(List<QueryResult<ChangeData>> in) {
try (Timer0.Context ignored = metrics.formatQueryResultsLatency.start()) {
accountLoader = accountLoaderFactory.create(has(DETAILED_ACCOUNTS));
List<List<ChangeInfo>> res = new ArrayList<>(in.size());

View File

@@ -14,11 +14,9 @@
package com.google.gerrit.server.restapi.account;
import com.google.common.base.Throwables;
import com.google.gerrit.extensions.common.AccountInfo;
import com.google.gerrit.extensions.restapi.RestReadView;
import com.google.gerrit.reviewdb.client.Account;
import com.google.gerrit.server.account.AccountDirectory.DirectoryException;
import com.google.gerrit.server.account.AccountDirectory.FillOptions;
import com.google.gerrit.server.account.AccountResource;
import com.google.gerrit.server.account.InternalAccountDirectory;
@@ -45,12 +43,7 @@ public class GetDetail implements RestReadView<AccountResource> {
AccountDetailInfo info = new AccountDetailInfo(a.getId().get());
info.registeredOn = a.getRegisteredOn();
info.inactive = !a.isActive() ? true : null;
try {
directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
} catch (DirectoryException e) {
Throwables.throwIfInstanceOf(e.getCause(), OrmException.class);
throw new OrmException(e);
}
directory.fillAccountInfo(Collections.singleton(info), EnumSet.allOf(FillOptions.class));
return info;
}

View File

@@ -32,7 +32,6 @@ import com.google.gerrit.reviewdb.client.FixReplacement;
import com.google.gerrit.reviewdb.client.FixSuggestion;
import com.google.gerrit.reviewdb.client.RobotComment;
import com.google.gerrit.server.account.AccountLoader;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.Collections;
@@ -71,7 +70,7 @@ class CommentJson {
}
private abstract class BaseCommentFormatter<F extends Comment, T extends CommentInfo> {
public T format(F comment) throws OrmException {
public T format(F comment) {
AccountLoader loader = fillAccounts ? accountLoaderFactory.create(true) : null;
T info = toInfo(comment, loader);
if (loader != null) {
@@ -80,7 +79,7 @@ class CommentJson {
return info;
}
public Map<String, List<T>> format(Iterable<F> comments) throws OrmException {
public Map<String, List<T>> format(Iterable<F> comments) {
AccountLoader loader = fillAccounts ? accountLoaderFactory.create(true) : null;
Map<String, List<T>> out = new TreeMap<>();
@@ -106,7 +105,7 @@ class CommentJson {
return out;
}
public List<T> formatAsList(Iterable<F> comments) throws OrmException {
public List<T> formatAsList(Iterable<F> comments) {
AccountLoader loader = fillAccounts ? accountLoaderFactory.create(true) : null;
List<T> out =

View File

@@ -299,7 +299,7 @@ public class ReviewersUtil {
}
private List<SuggestedReviewerInfo> loadAccounts(List<Account.Id> accountIds)
throws OrmException, PermissionBackendException {
throws PermissionBackendException {
Set<FillOptions> fillOptions =
permissionBackend.currentUser().test(GlobalPermission.MODIFY_ACCOUNT)
? EnumSet.of(FillOptions.SECONDARY_EMAILS)

View File

@@ -201,7 +201,7 @@ public class AddMembers implements RestModifyView<GroupResource, Input> {
}
}
private List<AccountInfo> toAccountInfoList(Set<Account.Id> accountIds) throws OrmException {
private List<AccountInfo> toAccountInfoList(Set<Account.Id> accountIds) {
List<AccountInfo> result = new ArrayList<>();
AccountLoader loader = infoFactory.create(true);
for (Account.Id accId : accountIds) {

View File

@@ -75,7 +75,7 @@ public class ListMembers implements RestReadView<GroupResource> {
return getDirectMembers(group, resource.getControl());
}
public List<AccountInfo> getTransitiveMembers(AccountGroup.UUID groupUuid) throws OrmException {
public List<AccountInfo> getTransitiveMembers(AccountGroup.UUID groupUuid) {
Optional<InternalGroup> group = groupCache.get(groupUuid);
if (group.isPresent()) {
InternalGroupDescription internalGroup = new InternalGroupDescription(group.get());
@@ -86,7 +86,7 @@ public class ListMembers implements RestReadView<GroupResource> {
}
private List<AccountInfo> getTransitiveMembers(
GroupDescription.Internal group, GroupControl groupControl) throws OrmException {
GroupDescription.Internal group, GroupControl groupControl) {
checkSameGroup(group, groupControl);
Set<Account.Id> members =
getTransitiveMemberIds(
@@ -94,19 +94,19 @@ public class ListMembers implements RestReadView<GroupResource> {
return toAccountInfos(members);
}
public List<AccountInfo> getDirectMembers(InternalGroup group) throws OrmException {
public List<AccountInfo> getDirectMembers(InternalGroup group) {
InternalGroupDescription internalGroup = new InternalGroupDescription(group);
return getDirectMembers(internalGroup, groupControlFactory.controlFor(internalGroup));
}
public List<AccountInfo> getDirectMembers(
GroupDescription.Internal group, GroupControl groupControl) throws OrmException {
GroupDescription.Internal group, GroupControl groupControl) {
checkSameGroup(group, groupControl);
Set<Account.Id> directMembers = getDirectMemberIds(group, groupControl);
return toAccountInfos(directMembers);
}
private List<AccountInfo> toAccountInfos(Set<Account.Id> members) throws OrmException {
private List<AccountInfo> toAccountInfos(Set<Account.Id> members) {
List<AccountInfo> memberInfos = new ArrayList<>(members.size());
for (Account.Id member : members) {
memberInfos.add(accountLoader.get(member));

View File

@@ -28,7 +28,6 @@ import com.google.gerrit.server.ioutil.ColumnFormatter;
import com.google.gerrit.server.restapi.group.ListMembers;
import com.google.gerrit.sshd.CommandMetaData;
import com.google.gerrit.sshd.SshCommand;
import com.google.gwtorm.server.OrmException;
import com.google.inject.Inject;
import java.io.PrintWriter;
import java.util.List;
@@ -68,7 +67,7 @@ public class ListMembersCommand extends SshCommand {
this.groupCache = groupCache;
}
void display(PrintWriter writer) throws OrmException {
void display(PrintWriter writer) {
Optional<InternalGroup> group = groupCache.get(new AccountGroup.NameKey(name));
String errorText = "Group not found or not visible\n";