Skip to content

Commit

Permalink
CLDR-16838 Login bug; preliminary refactoring/debugging
Browse files Browse the repository at this point in the history
-Add a temporary debugging boolean HARD_CODE_REDIRECT_PORT to enable testing locally with nginx on port 8888

-Delete dead code and fix compiler warnings in WebContext.java, SurveyMain.java, and related files

-Remove the @deprecated label for the phase BETA since we still use it

-Delete the other deprecated phases and dependent code

-Add warning comments for methods that appear unused but are still accessed by jsp

-Comments
  • Loading branch information
btangmu committed Nov 7, 2023
1 parent 0b9e199 commit 2d83553
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 422 deletions.
46 changes: 17 additions & 29 deletions tools/cldr-apps/src/main/java/org/unicode/cldr/web/AdminPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@

public class AdminPanel {
public void getJson(
SurveyJSONWrapper r,
HttpServletRequest request,
HttpServletResponse response,
SurveyMain sm)
SurveyJSONWrapper r, HttpServletRequest request, HttpServletResponse response)
throws JSONException, IOException {
/*
* Assume caller has already confirmed UserRegistry.userIsAdmin
Expand All @@ -43,7 +40,7 @@ public void getJson(
} else if (action.equals("settings_set")) {
setSettings(r, request);
} else if (action.equals("create_login")) {
createAndLogin(r, request, response, sm);
createAndLogin(r, request, response);
} else {
r.put("err", "Unknown action: " + action);
}
Expand Down Expand Up @@ -99,10 +96,10 @@ private void unlinkUser(SurveyJSONWrapper r, HttpServletRequest request) throws
private void showThreads(SurveyJSONWrapper r) throws JSONException {
JSONObject threads = new JSONObject();
ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
long deadlockedThreads[] = threadBean.findDeadlockedThreads();
long[] deadlockedThreads = threadBean.findDeadlockedThreads();
if (deadlockedThreads != null) {
JSONArray dead = new JSONArray();
ThreadInfo deadThreadInfo[] = threadBean.getThreadInfo(deadlockedThreads, true, true);
ThreadInfo[] deadThreadInfo = threadBean.getThreadInfo(deadlockedThreads, true, true);
for (ThreadInfo deadThread : deadThreadInfo) {
dead.put(
new JSONObject()
Expand Down Expand Up @@ -132,9 +129,9 @@ private void showExceptions(SurveyJSONWrapper r, HttpServletRequest request)
JSONObject exceptions = new JSONObject();
ChunkyReader cr = SurveyLog.getChunkyReader();
exceptions.put("lastTime", cr.getLastTime());
ChunkyReader.Entry e = null;
ChunkyReader.Entry e;
if (request.getParameter("before") != null) {
Long before = Long.parseLong(request.getParameter("before"));
long before = Long.parseLong(request.getParameter("before"));
e = cr.getEntryBelow(before);
} else {
e = cr.getLastEntry();
Expand Down Expand Up @@ -178,17 +175,11 @@ private void setSettings(SurveyJSONWrapper r, HttpServletRequest request) throws
* @param r
* @param request
* @param response
* @param sm
* <p>Earlier version was in createAndLogin.jsp
* @throws JSONException
*/
private void createAndLogin(
SurveyJSONWrapper r,
HttpServletRequest request,
HttpServletResponse response,
SurveyMain sm)
SurveyJSONWrapper r, HttpServletRequest request, HttpServletResponse response)
throws JSONException {
if (SurveyMain.isSetup == false) {
if (!SurveyMain.isSetup) {
r.put("isSetup", false);
return;
}
Expand All @@ -197,7 +188,7 @@ private void createAndLogin(
WebContext.clearCookie(request, response, SurveyMain.QUERY_PASSWORD);
WebContext.clearCookie(request, response, SurveyMain.COOKIE_SAVELOGIN);

String orgs[] = UserRegistry.getOrgList();
String[] orgs = UserRegistry.getOrgList();
String myorg = orgs[(int) Math.rint(Math.random() * (orgs.length - 1))];
JSONObject levels = new JSONObject();
for (final VoteResolver.Level l : VoteResolver.Level.values()) { // like 999
Expand All @@ -216,7 +207,7 @@ private void createAndLogin(
r.put("defaultLevel", UserRegistry.TC);
}

static final String allNames[] = {
static final String[] allNames = {
// http://en.wikipedia.org/wiki/List_of_most_popular_given_names (Greenland)
"Ivaana", "Pipaluk", "Nivi", "Paninnguaq", "Ivalu", "Naasunnguaq", "Julie", "Ane",
"Isabella", "Kimmernaq",
Expand All @@ -226,15 +217,13 @@ private void createAndLogin(

private String randomName() {
// generate random name
StringBuilder genname = new StringBuilder();

genname.append(choose(allNames));
genname.append(' ');
genname.append((char) ('A' + new Random().nextInt(26)));
genname.append('.');
genname.append(' ');
genname.append(
choose(
return choose(allNames)
+ ' '
+ (char) ('A' + new Random().nextInt(26))
+ '.'
+ ' '
+ choose(
"Vetter",
"Linguist",
"User",
Expand All @@ -244,8 +233,7 @@ private String randomName() {
"Person",
"Account",
"Login",
"CLDR"));
return genname.toString();
"CLDR");
}

private String choose(String... option) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void handleError(DataRow p, CheckStatus status, String choice_v) {
ctx.print("<tt class='codebox'>" + p.getDisplayName() + "</tt>: ");
ctx.print("&nbsp;&nbsp; Value: <b>" + choice_v + "</b> ");
String cls = SurveyMain.shortClassName(status.getCause());
ctx.printHelpLink("/" + cls, "<!-- help with -->" + cls, true);
ctx.printHelpLink("/" + cls, "<!-- help with -->" + cls);
if (status.getType().equals(CheckStatus.errorType)) {
ctx.print(ctx.iconHtml("stop", cls));
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ private void processRequest(
mySession.userDidAction();
SurveyJSONWrapper r = newJSONStatus(request, sm);
r.put("what", what);
new AdminPanel().getJson(r, request, response, sm);
new AdminPanel().getJson(r, request, response);
send(r, out);
} else {
sendError(
Expand Down
Loading

0 comments on commit 2d83553

Please sign in to comment.