BecomeAnyAccountLoginServlet: Remove SchemaFactory
Change-Id: I090f886e47ef9b695ffe9c19970802610a81a762
This commit is contained in:
@@ -24,7 +24,6 @@ import com.google.gerrit.httpd.LoginUrlToken;
|
||||
import com.google.gerrit.httpd.WebSession;
|
||||
import com.google.gerrit.httpd.template.SiteHeaderFooter;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountCache;
|
||||
import com.google.gerrit.server.account.AccountException;
|
||||
import com.google.gerrit.server.account.AccountManager;
|
||||
@@ -36,7 +35,6 @@ import com.google.gerrit.server.account.externalids.ExternalId;
|
||||
import com.google.gerrit.server.query.account.InternalAccountQuery;
|
||||
import com.google.gerrit.util.http.CacheHeaders;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.Singleton;
|
||||
@@ -59,7 +57,6 @@ import org.w3c.dom.Element;
|
||||
@Singleton
|
||||
class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
private final DynamicItem<WebSession> webSession;
|
||||
private final SchemaFactory<ReviewDb> schema;
|
||||
private final Accounts accounts;
|
||||
private final AccountCache accountCache;
|
||||
private final AccountManager accountManager;
|
||||
@@ -69,14 +66,12 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
@Inject
|
||||
BecomeAnyAccountLoginServlet(
|
||||
DynamicItem<WebSession> ws,
|
||||
SchemaFactory<ReviewDb> sf,
|
||||
Accounts a,
|
||||
AccountCache ac,
|
||||
AccountManager am,
|
||||
SiteHeaderFooter shf,
|
||||
Provider<InternalAccountQuery> qp) {
|
||||
webSession = ws;
|
||||
schema = sf;
|
||||
accounts = a;
|
||||
accountCache = ac;
|
||||
accountManager = am;
|
||||
@@ -91,8 +86,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse rsp)
|
||||
throws IOException, ServletException {
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse rsp) throws IOException {
|
||||
CacheHeaders.setNotCacheable(rsp);
|
||||
|
||||
final AuthResult res;
|
||||
@@ -110,11 +104,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
|
||||
} else {
|
||||
byte[] raw;
|
||||
try {
|
||||
raw = prepareHtmlOutput();
|
||||
} catch (OrmException e) {
|
||||
throw new ServletException(e);
|
||||
}
|
||||
raw = prepareHtmlOutput();
|
||||
rsp.setContentType("text/html");
|
||||
rsp.setCharacterEncoding(HtmlDomUtil.ENC.name());
|
||||
rsp.setContentLength(raw.length);
|
||||
@@ -150,7 +140,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] prepareHtmlOutput() throws IOException, OrmException {
|
||||
private byte[] prepareHtmlOutput() throws IOException {
|
||||
final String pageName = "BecomeAnyAccount.html";
|
||||
Document doc = headers.parse(getClass(), pageName);
|
||||
if (doc == null) {
|
||||
@@ -158,30 +148,28 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
Element userlistElement = HtmlDomUtil.find(doc, "userlist");
|
||||
try (ReviewDb db = schema.open()) {
|
||||
for (Account.Id accountId : accounts.firstNIds(100)) {
|
||||
Optional<AccountState> accountState = accountCache.get(accountId);
|
||||
if (!accountState.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
Account account = accountState.get().getAccount();
|
||||
String displayName;
|
||||
if (accountState.get().getUserName().isPresent()) {
|
||||
displayName = accountState.get().getUserName().get();
|
||||
} else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
|
||||
displayName = account.getFullName();
|
||||
} else if (account.getPreferredEmail() != null) {
|
||||
displayName = account.getPreferredEmail();
|
||||
} else {
|
||||
displayName = accountId.toString();
|
||||
}
|
||||
|
||||
Element linkElement = doc.createElement("a");
|
||||
linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
|
||||
linkElement.setTextContent(displayName);
|
||||
userlistElement.appendChild(linkElement);
|
||||
userlistElement.appendChild(doc.createElement("br"));
|
||||
for (Account.Id accountId : accounts.firstNIds(100)) {
|
||||
Optional<AccountState> accountState = accountCache.get(accountId);
|
||||
if (!accountState.isPresent()) {
|
||||
continue;
|
||||
}
|
||||
Account account = accountState.get().getAccount();
|
||||
String displayName;
|
||||
if (accountState.get().getUserName().isPresent()) {
|
||||
displayName = accountState.get().getUserName().get();
|
||||
} else if (account.getFullName() != null && !account.getFullName().isEmpty()) {
|
||||
displayName = account.getFullName();
|
||||
} else if (account.getPreferredEmail() != null) {
|
||||
displayName = account.getPreferredEmail();
|
||||
} else {
|
||||
displayName = accountId.toString();
|
||||
}
|
||||
|
||||
Element linkElement = doc.createElement("a");
|
||||
linkElement.setAttribute("href", "?account_id=" + account.getId().toString());
|
||||
linkElement.setTextContent(displayName);
|
||||
userlistElement.appendChild(linkElement);
|
||||
userlistElement.appendChild(doc.createElement("br"));
|
||||
}
|
||||
|
||||
return HtmlDomUtil.toUTF8(doc);
|
||||
@@ -218,7 +206,7 @@ class BecomeAnyAccountLoginServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
private Optional<AuthResult> byPreferredEmail(String email) {
|
||||
try (ReviewDb db = schema.open()) {
|
||||
try {
|
||||
Optional<AccountState> match =
|
||||
queryProvider.get().byPreferredEmail(email).stream().findFirst();
|
||||
return auth(match);
|
||||
|
||||
Reference in New Issue
Block a user