InternalAccountQuery: Add back the oneByExternalId method
Change I45ccec5ed removed several methods from InternalAccountQuery
that are no longer used in core Gerrit. One of them, however, is
used in CollabNet's integration.
Add back the method that is used, and annotate it with @UsedAt.
Make adaptations compared to the original version that was removed:
- Use the FluentLogger rather than slf4j's Logger
- Use the Stream API rather than Guava's Lists.transform
This partially reverts commit 69f297f568
.
Change-Id: I9170932646960754ef2ec4b9287d7c71844403a2
This commit is contained in:
@@ -35,6 +35,7 @@ public @interface UsedAt {
|
||||
/** Enumeration of projects that call a method that would otherwise be private. */
|
||||
enum Project {
|
||||
GOOGLE,
|
||||
COLLABNET,
|
||||
PLUGIN_DELETE_PROJECT,
|
||||
PLUGIN_SERVICEUSER,
|
||||
PLUGINS_ALL, // Use this project if a method/type is generally made available to all plugins.
|
||||
|
@@ -17,15 +17,18 @@ package com.google.gerrit.server.query.account;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
import com.google.common.base.Joiner;
|
||||
import com.google.common.collect.ArrayListMultimap;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.flogger.FluentLogger;
|
||||
import com.google.gerrit.index.FieldDef;
|
||||
import com.google.gerrit.index.IndexConfig;
|
||||
import com.google.gerrit.index.Schema;
|
||||
import com.google.gerrit.index.query.InternalQuery;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.UsedAt;
|
||||
import com.google.gerrit.server.account.AccountState;
|
||||
import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import com.google.gerrit.server.index.account.AccountField;
|
||||
@@ -43,6 +46,8 @@ import java.util.Set;
|
||||
* holding on to a single instance.
|
||||
*/
|
||||
public class InternalAccountQuery extends InternalQuery<AccountState> {
|
||||
private static final FluentLogger logger = FluentLogger.forEnclosingClass();
|
||||
|
||||
@Inject
|
||||
InternalAccountQuery(
|
||||
AccountQueryProcessor queryProcessor,
|
||||
@@ -88,6 +93,22 @@ public class InternalAccountQuery extends InternalQuery<AccountState> {
|
||||
return query(AccountPredicates.externalIdIncludingSecondaryEmails(externalId.toString()));
|
||||
}
|
||||
|
||||
@UsedAt(UsedAt.Project.COLLABNET)
|
||||
public AccountState oneByExternalId(ExternalId.Key externalId) throws OrmException {
|
||||
List<AccountState> accountStates = byExternalId(externalId);
|
||||
if (accountStates.size() == 1) {
|
||||
return accountStates.get(0);
|
||||
} else if (accountStates.size() > 0) {
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Ambiguous external ID ").append(externalId).append(" for accounts: ");
|
||||
Joiner.on(", ")
|
||||
.appendTo(
|
||||
msg, accountStates.stream().map(AccountState.ACCOUNT_ID_FUNCTION).collect(toList()));
|
||||
logger.atWarning().log(msg.toString());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<AccountState> byFullName(String fullName) throws OrmException {
|
||||
return query(AccountPredicates.fullName(fullName));
|
||||
}
|
||||
|
Reference in New Issue
Block a user