Skip to content

Commit

Permalink
CLDR-13152 EmbeddedReport.jsp needs to set content type of JSON (unic…
Browse files Browse the repository at this point in the history
…ode-org#417)

-Move jsp to java

-Call setContentType with application/json for Dashboard

-Delete dead code

-Fix warnings

-Comments
  • Loading branch information
btangmu committed Apr 9, 2020
1 parent 90203b5 commit 68a69ef
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 203 deletions.
35 changes: 0 additions & 35 deletions tools/cldr-apps/WebContent/EmbeddedReport.jsp

This file was deleted.

8 changes: 0 additions & 8 deletions tools/cldr-apps/WebContent/WEB-INF/jspf/report_top.jspf

This file was deleted.

19 changes: 0 additions & 19 deletions tools/cldr-apps/WebContent/WEB-INF/tmpl/r_compact.jsp

This file was deleted.

18 changes: 0 additions & 18 deletions tools/cldr-apps/WebContent/WEB-INF/tmpl/r_datetime.jsp

This file was deleted.

46 changes: 0 additions & 46 deletions tools/cldr-apps/WebContent/WEB-INF/tmpl/r_vetting_json.jsp

This file was deleted.

19 changes: 0 additions & 19 deletions tools/cldr-apps/WebContent/WEB-INF/tmpl/r_zones.jsp

This file was deleted.

2 changes: 1 addition & 1 deletion tools/cldr-apps/WebContent/js/CldrSurveyVettingLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,7 @@ function showV() {
) {
ready(function() {

var url = contextPath + "/EmbeddedReport.jsp?x=" + surveyCurrentSpecial + "&_=" + surveyCurrentLocale + "&s=" + surveySessionId + cacheKill();
var url = contextPath + "/SurveyAjax?what=report&x=" + surveyCurrentSpecial + "&_=" + surveyCurrentLocale + "&s=" + surveySessionId + cacheKill();
var errFunction = function errFunction(err) {
console.log("Error: loading " + url + " -> " + err);
hideLoader(null, stui.loading2);
Expand Down
2 changes: 1 addition & 1 deletion tools/cldr-apps/WebContent/js/CldrSurveyVettingTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const cldrSurveyTable = (function() {
*
* IMPORTANT: this function is used for the Dashboard as well as the main Vetting table.
* Mostly the Dashboard tables are currently created by review.js showReviewPage
* (invoked through EmbeddedReport.jsp, r_vetting_json.jsp, writeVettingViewerOutput);
* (invoked through writeVettingViewerOutput);
* they're not created here. Nevertheless the calls here to isDashboard() do serve a purpose,
* isDashboard() is true here when called by insertFixInfo in review.js. To see this, put
* a breakpoint in this function, go to Dashboard, and click on a "Fix" button, whose pop-up
Expand Down
151 changes: 151 additions & 0 deletions tools/cldr-apps/src/org/unicode/cldr/web/SurveyAjax.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import org.unicode.cldr.util.CLDRLocale;
import org.unicode.cldr.util.CldrUtility;
import org.unicode.cldr.util.CoverageInfo;
import org.unicode.cldr.util.DateTimeFormats;
import org.unicode.cldr.util.DtdData.IllegalByDtdException;
import org.unicode.cldr.util.Factory;
import org.unicode.cldr.util.Level;
Expand Down Expand Up @@ -346,6 +347,8 @@ private void processRequest(HttpServletRequest request, HttpServletResponse resp
sendError(out, "Missing parameter: " + REQ_WHAT, ErrorCode.E_INTERNAL);
} else if (what.equals(WHAT_GETROW)) {
getRow(request, response, out, sm, sess, l, xpath);
} else if (what.equals(WHAT_REPORT)) {
generateReport(request, response, out, sm, sess, l);
} else if (what.equals(WHAT_STATS_BYLOC)) {
JSONWriter r = newJSONStatusQuick(sm);
JSONObject query = DBUtils.queryToCachedJSON(what, 5 * 60 * 1000, StatisticsUtils.QUERY_ALL_VOTES);
Expand Down Expand Up @@ -3097,4 +3100,152 @@ public static void includeJavaScript(HttpServletRequest request, Writer out) thr
out.write(prefix + "redesign.js" + v + tail);
out.write(prefix + "review.js" + v + tail);
}

/**
* Generate a report, such as Date/Times or Dashboard.
*
* @param request the HttpServletRequest
* @param response the HttpServletResponse
* @param out the Writer
* @param sm the SurveyMain
* @param sess the session id
* @param l the CLDRLocale
*
* @throws IOException
*
* Some code was moved to this function and those it calls, from EmbeddedReport.jsp and other jsp files.
* Reference: https://unicode-org.atlassian.net/browse/CLDR-13152
*/
static private void generateReport(HttpServletRequest request, HttpServletResponse response,
Writer out, SurveyMain sm, String sess, CLDRLocale l) throws IOException {

CookieSession cs = CookieSession.retrieve(sess);
if (cs == null) {
response.setContentType("text/html");
out.write("<b>Invalid or expired session (try reloading the page)</b>");
return;
}
String which = request.getParameter("x");

if (SurveyMain.R_VETTING_JSON.equals(which)) {
response.setContentType("application/json");
WebContext ctx = new WebContext(request, response);
request.setAttribute(WebContext.CLDR_WEBCONTEXT, ctx);
ctx.session = cs;
ctx.sm = sm;
ctx.setLocale(l);
generateDashboard(out, cs, l, ctx);
} else {
response.setContentType("text/html");
if ("r_datetime".equals(which)) {
generateDateTimesReport(out, sm, l);
} else if ("r_zones".equals(which)) {
generateZonesReport(out, sm, l);
} else if ("r_compact".equals(which)) {
generateNumbersReport(out, sm, l);
} else {
out.write("<i>Unrecognized report name: " + which + "</i><br/>\n");
}
}
}

/**
* Generate the Dashboard, as json
*
* @param out the Writer
* @param cs the CookieSession
* @param l the CLDRLocale
* @param ctx the WebContext
* @throws IOException
*/
private static void generateDashboard(Writer out, CookieSession cs, CLDRLocale l, WebContext ctx) throws IOException {

try {
StringBuffer sb = new StringBuffer();
VettingViewerQueue.getInstance().writeVettingViewerOutput(l, sb, ctx, cs);
out.write(sb.toString());
} catch (Throwable t) {
/*
* catch ALL errors, because we need to return JSON
*/
SurveyLog.logException(t, "when loading the Dashboard", ctx);
try {
new org.json.JSONWriter(out).object().key("err").value("Exception: " + t.getMessage()
+ " while loading the Dashboard").key("err_code").value("E_INTERNAL").endObject();
} catch (JSONException e) {
SurveyLog.logException(e, "when loading the Dashboard", ctx);
}
}
}

/**
* Generate the Date/Times report, as html
*
* @param out the Writer
* @param sm the SurveyMain
* @param l the CLDRLocale
* @throws IOException
*/
private static void generateDateTimesReport(Writer out, SurveyMain sm, CLDRLocale l) throws IOException {

final String calendarType = "gregorian";
final String title = com.ibm.icu.lang.UCharacter.toTitleCase(SurveyMain.TRANS_HINT_LOCALE.toLocale(), calendarType, null);
final String href = "http://cldr.unicode.org/translation/date-time-review"; // TODO: broken link

out.write("<h3>Review Date/Times : " + title + "</h3>");
out.write("<p>Please read the <a target='CLDR-ST-DOCS' href='" + href + "'>instructions</a> before continuing.</p>");

STFactory fac = sm.getSTFactory();
CLDRFile englishFile = fac.make("en", true);
CLDRFile nativeFile = fac.make(l, true);

DateTimeFormats formats = new DateTimeFormats().set(nativeFile, calendarType);
DateTimeFormats english = new DateTimeFormats().set(englishFile, calendarType);

formats.addTable(english, out);
formats.addDateTable(englishFile, out);
formats.addDayPeriods(englishFile, out);
}

/**
* Generate the Zones report, as html
*
* @param out the Writer
* @param sm the SurveyMain
* @param l the CLDRLocale
* @throws IOException
*/
private static void generateZonesReport(Writer out, SurveyMain sm, CLDRLocale l) throws IOException {

final String href = "http://cldr.unicode.org/translation/review-zones"; // TODO: broken link

out.write("<h3>Review Zones</h3>");
out.write("<p>Please read the <a target='CLDR-ST-DOCS' href='" + href + "'>instructions</a> before continuing.</p>");

CLDRFile englishFile = sm.getDiskFactory().make("en", true);
CLDRFile nativeFile = sm.getSTFactory().make(l, true);

org.unicode.cldr.util.VerifyZones.showZones(null, englishFile, nativeFile, out);
}

/**
* Generate the Numbers report, as html
*
* @param out the Writer
* @param sm the SurveyMain
* @param l the CLDRLocale
* @throws IOException
*/
private static void generateNumbersReport(Writer out, SurveyMain sm, CLDRLocale l) throws IOException {

final String href = "http://cldr.unicode.org/translation/review-numbers"; // TODO: broken link

out.write("<h3>Review Numbers</h3>");
out.write("<p>Please read the <a target='CLDR-ST-DOCS' href='" + href + "'>instructions</a> before continuing.</p>");

STFactory fac = sm.getSTFactory();
CLDRFile nativeFile = fac.make(l, true);

org.unicode.cldr.util.VerifyCompactNumbers.showNumbers(nativeFile, true, "EUR", out, fac);
}
}
21 changes: 6 additions & 15 deletions tools/cldr-apps/src/org/unicode/cldr/web/SurveyMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ public class SurveyMain extends HttpServlet implements CLDRProgressIndicator, Ex
/**
* The "r_" prefix is for r_vetting_json.jsp (Dashboard);
* also "r_datetime", "r_zones", and "r_compact" -- see ReportMenu.
* TODO: document "r_directiontest.jsp", "r_monkey.jsp"
*/
private static final String REPORT_PREFIX = "r_";

Expand Down Expand Up @@ -302,6 +301,10 @@ public static final boolean hostBusy() {
// ===== Special bug numbers.
public static final String URL_HOST = "http://www.unicode.org/";
public static final String URL_CLDR = URL_HOST + "cldr/";

/*
* TODO: CLDR no longer uses trac; change BUG_URL_BASE to link to github instead
*/
public static final String BUG_URL_BASE = URL_CLDR + "trac";
public static final String GENERAL_HELP_URL = URL_CLDR + "survey_tool.html";
public static final String GENERAL_HELP_NAME = "Instructions";
Expand Down Expand Up @@ -3989,17 +3992,13 @@ public void showLocale(WebContext ctx, String which, String whyBad) {
return;
}

if (which.startsWith(REPORT_PREFIX)) {
if (!subCtx.doReport(which)) {
doMain(ctx);
}
} else if (pageId != null && !which.equals(xMAIN)) {
if (pageId != null && !which.equals(xMAIN)) {
showPathList(subCtx, which, pageId);
} else if (RAW_MENU_ITEM.equals(which)) {
getOutputFileManager().doRaw(subCtx);
} else {
which = xMAIN;
doMain(subCtx);
doMain(subCtx); // TODO: does this ever happen? Or is doMain effectively dead code?
}
}
}
Expand Down Expand Up @@ -5720,14 +5719,6 @@ void doShutdownDB() {
t.printStackTrace();
SurveyLog.logger.warning("While shutting down reg ");
}
try {
if (xpt != null)
xpt.shutdownDB();
} catch (Throwable t) {
t.printStackTrace();
SurveyLog.logger.warning("While shutting down xpt ");
}

if (dbUtils != null) {
dbUtils.doShutdown();
}
Expand Down
Loading

0 comments on commit 68a69ef

Please sign in to comment.