Skip to content

Commit 07fa390

Browse files
Cleanup
1 parent 251daeb commit 07fa390

2 files changed

Lines changed: 18 additions & 37 deletions

File tree

api/src/org/labkey/api/reports/report/InternalScriptEngineReport.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
*/
1616
package org.labkey.api.reports.report;
1717

18-
import org.apache.logging.log4j.LogManager;
18+
import org.apache.logging.log4j.Logger;
1919
import org.labkey.api.ApiModule;
2020
import org.labkey.api.module.ModuleLoader;
21+
import org.labkey.api.query.ValidationException;
2122
import org.labkey.api.reports.ExternalScriptEngine;
2223
import org.labkey.api.reports.report.r.ParamReplacement;
2324
import org.labkey.api.reports.report.r.ParamReplacementSvc;
2425
import org.labkey.api.reports.report.r.view.ConsoleOutput;
2526
import org.labkey.api.usageMetrics.SimpleMetricsService;
2627
import org.labkey.api.util.PageFlowUtil;
28+
import org.labkey.api.util.logging.LogHelper;
2729
import org.labkey.api.view.HtmlView;
2830
import org.labkey.api.view.HttpView;
2931
import org.labkey.api.view.VBox;
@@ -36,20 +38,21 @@
3638
import javax.script.ScriptContext;
3739
import javax.script.ScriptEngine;
3840
import javax.script.ScriptException;
41+
import java.io.IOException;
3942
import java.io.PrintWriter;
4043
import java.io.StringWriter;
44+
import java.sql.SQLException;
4145
import java.util.ArrayList;
4246
import java.util.List;
4347
import java.util.Map;
4448

45-
/*
46-
* User: Karl Lum
47-
* Date: Jan 19, 2009
48-
* Time: 4:11:54 PM
49-
*/
49+
/**
50+
* Executes scripts, such as R, and renders the results.
51+
*/
5052
public class InternalScriptEngineReport extends ScriptEngineReport
5153
{
5254
public static final String TYPE = "ReportService.internalScriptEngineReport";
55+
private static final Logger LOG = LogHelper.getLogger(InternalScriptEngineReport.class, "Executes scripts, such as R, and renders the results.");
5356

5457
@Override
5558
public String getType()
@@ -58,7 +61,7 @@ public String getType()
5861
}
5962

6063
@Override
61-
public HttpView<?> renderReport(ViewContext context) throws Exception
64+
public HttpView<?> renderReport(ViewContext context) throws ValidationException, SQLException, IOException
6265
{
6366
VBox view = new VBox();
6467
String script = getDescriptor().getProperty(ScriptReportDescriptor.Prop.script);
@@ -81,7 +84,7 @@ public HttpView<?> renderReport(ViewContext context) throws Exception
8184
}
8285
catch (ScriptException e)
8386
{
84-
LogManager.getLogger(getClass()).error("Error executing script", e);
87+
LOG.error("Error executing script", e);
8588
final String error1 = "Error executing command";
8689
final String error2 = PageFlowUtil.filter(e.getMessage());
8790

@@ -146,7 +149,7 @@ public String runScript(ViewContext context, List<ParamReplacement> outputSubst,
146149
}
147150
return output != null ? output.toString() : "";
148151
}
149-
catch(Exception e)
152+
catch (Exception e)
150153
{
151154
if (!errors.getBuffer().isEmpty())
152155
throw new ScriptException(e.getMessage() + errors.getBuffer());

api/src/org/labkey/api/reports/report/view/ReportUtil.java

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import org.apache.commons.lang3.StringUtils;
2020
import org.apache.commons.lang3.Strings;
2121
import org.apache.commons.lang3.math.NumberUtils;
22-
import org.apache.logging.log4j.LogManager;
22+
import org.apache.logging.log4j.Logger;
2323
import org.jetbrains.annotations.NotNull;
2424
import org.jetbrains.annotations.Nullable;
2525
import org.json.JSONArray;
@@ -76,6 +76,7 @@
7676
import org.labkey.api.util.ThumbnailUtil;
7777
import org.labkey.api.util.URLHelper;
7878
import org.labkey.api.util.UniqueID;
79+
import org.labkey.api.util.logging.LogHelper;
7980
import org.labkey.api.view.ActionURL;
8081
import org.labkey.api.view.TabStripView;
8182
import org.labkey.api.view.ViewContext;
@@ -90,6 +91,8 @@
9091

9192
public class ReportUtil
9293
{
94+
private static final Logger LOG = LogHelper.getLogger(ReportUtil.class, "Utilities to help with report rendering and management");
95+
9396
public static ActionURL getScriptReportDesignerURL(ViewContext context, ScriptReportBean bean)
9497
{
9598
ActionURL url = PageFlowUtil.urlProvider(ReportUrls.class).urlCreateScriptReport(context.getContainer());
@@ -395,7 +398,7 @@ public static void addErrors(List<ValidationError> reportErrors, Errors errors)
395398

396399
public static String getErrors(List<ValidationError> reportErrors)
397400
{
398-
StringBuffer sb = new StringBuffer();
401+
StringBuilder sb = new StringBuilder();
399402
for (ValidationError error : reportErrors)
400403
sb.append(error.getMessage()).append("\n");
401404

@@ -527,31 +530,6 @@ public static boolean isInherited(CustomViewInfo view, Container container)
527530
return false;
528531
}
529532

530-
public static JSONArray getCreateReportButtons(ViewContext context)
531-
{
532-
List<ReportService.DesignerInfo> designers = new ArrayList<>();
533-
for (ReportService.UIProvider provider : ReportService.get().getUIProviders())
534-
designers.addAll(provider.getDesignerInfo(context));
535-
536-
designers.sort(Comparator.comparing(ReportService.DesignerInfo::getLabel));
537-
538-
JSONArray json = new JSONArray();
539-
540-
for (ReportService.DesignerInfo info : designers)
541-
{
542-
JSONObject o = new JSONObject();
543-
544-
o.put("text", info.getLabel());
545-
o.put("id", info.getId());
546-
o.put("disabled", info.isDisabled());
547-
o.put("icon", info.getIconURL().getLocalURIString());
548-
o.put("redirectUrl", info.getDesignerURL().getLocalURIString());
549-
550-
json.put(o);
551-
}
552-
return json;
553-
}
554-
555533
public static Report getReportById(ViewContext viewContext, String reportIdString)
556534
{
557535
ReportIdentifier reportId = ReportService.get().getReportIdentifier(reportIdString, viewContext.getUser(), viewContext.getContainer());
@@ -609,7 +587,7 @@ public static String createReportSessionId()
609587
*/
610588
public static String makeExceptionString(Exception e, String formatString)
611589
{
612-
LogManager.getLogger(ReportUtil.class).error("Error executing script - makeExceptionString", e);
590+
LOG.warn("Error executing script", e);
613591
final String error1 = "Error executing command";
614592
final String error2 = PageFlowUtil.filter(e.getMessage());
615593
return String.format(formatString, error1, error2);

0 commit comments

Comments
 (0)