Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static double getEarliestUpgradeVersion()
*/
public static String getDocumentationVersion()
{
return "26.7";
return "26.11";
}

/**
Expand Down
2 changes: 1 addition & 1 deletion api/src/org/labkey/api/reports/Report.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public interface Report extends AttachmentParent, ThumbnailProvider
/**
* Render this report in the specified context
*/
HttpView renderReport(ViewContext context) throws Exception;
HttpView<?> renderReport(ViewContext context) throws Exception;

/**
* Return the data view (if any) for this report. Many reports are created from a source
Expand Down
14 changes: 2 additions & 12 deletions api/src/org/labkey/api/reports/report/DockerScriptReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,11 @@
import org.labkey.api.query.JavaScriptExportScriptFactory;
import org.labkey.api.query.JavaScriptExportScriptModel;
import org.labkey.api.query.QueryView;
import org.labkey.api.reports.report.r.ParamReplacement;
import org.labkey.api.settings.AppProps;
import org.labkey.api.view.ViewContext;
import org.labkey.vfs.FileLike;

import javax.script.ScriptException;
import java.io.File;
import java.util.List;
import java.util.Map;

/**
* This is a base class for Reports that encapsulate their report executing in a Docker container, for security and/or configuration control.
Expand All @@ -43,15 +39,9 @@
*/
abstract public class DockerScriptReport extends ScriptProcessReport
{
protected DockerScriptReport(String reportType, String defaultDescriptorType)
protected DockerScriptReport(String defaultDescriptorType)
{
super(reportType, defaultDescriptorType);
}

@Override
public String runScript(ViewContext context, List<ParamReplacement> outputSubst, File inputDataTsv, Map<String, Object> inputParameters) throws ScriptException
{
return "I'm abstract";
super(defaultDescriptorType);
}

protected JSONObject createReportConfig(ViewContext context, FileLike ipynb)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,30 @@ public Thumbnail render(List<ParamReplacement> parameters) throws IOException
}
}

private Thumbnail getThumbnail(List<ParamReplacement> parameters) throws IOException
{
return handleParameters(this, parameters, new ParameterHandler<>()
{
private Thumbnail _thumbnail = null;

@Override
public boolean handleParameter(ViewContext context, Report report, ParamReplacement param, List<String> sectionNames) throws IOException
{
_thumbnail = param.renderThumbnail(context);

// Return true (keep iterating) if we can't render this output as a thumbnail
return null == _thumbnail;
}

@Override
public Thumbnail cleanup(ContainerUser context)
{
// TODO: Delete file?
return _thumbnail;
}
});
}


interface Renderer<K>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public String getDefaultScript()
{
try
{
return (new JspTemplate("/org/labkey/api/reports/report/view/javaScriptReportExample.jsp")).render();
return (new JspTemplate<>("/org/labkey/api/reports/report/view/javaScriptReportExample.jsp")).render();
}
catch (Exception e)
{
Expand Down
55 changes: 8 additions & 47 deletions api/src/org/labkey/api/reports/report/ScriptEngineReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import org.labkey.api.reports.report.r.view.SvgOutput;
import org.labkey.api.reports.report.r.view.TextOutput;
import org.labkey.api.reports.report.r.view.TsvOutput;
import org.labkey.api.thumbnail.Thumbnail;
import org.labkey.api.util.FileUtil;
import org.labkey.api.util.UnexpectedException;
import org.labkey.api.view.HttpView;
Expand Down Expand Up @@ -444,7 +443,7 @@ public boolean handleParameter(ViewContext context, Report report, ParamReplacem
}

@Override
public List<ScriptOutput> cleanup(ScriptEngineReport report, ContainerUser context)
public List<ScriptOutput> cleanup(ContainerUser context)
{
if (report.shouldCleanup())
FileUtil.deleteDir(report.getReportDirFileLike(context.getContainer().getId()).toNioPathForWrite(), null);
Expand Down Expand Up @@ -472,7 +471,7 @@ public boolean handleParameter(ViewContext context, Report report, ParamReplacem
}

@Override
public HttpView<?> cleanup(ScriptEngineReport report, ContainerUser context)
public HttpView<?> cleanup(ContainerUser context)
{
if (report.shouldCleanup())
view.addView(new TempFileCleanup(report.getReportDirFileLike(context.getContainer().getId())));
Expand All @@ -487,42 +486,15 @@ public boolean shouldCleanup()
return !BooleanUtils.toBoolean(getDescriptor().getProperty(ScriptReportDescriptor.Prop.runInBackground));
}


public Thumbnail getThumbnail(List<ParamReplacement> parameters) throws IOException
{
return handleParameters(this, parameters, new ParameterHandler<>()
{
private Thumbnail _thumbnail = null;

@Override
public boolean handleParameter(ViewContext context, Report report, ParamReplacement param, List<String> sectionNames) throws IOException
{
_thumbnail = param.renderThumbnail(context);

// Return true (keep iterating) if we can't render this output as a thumbnail
return null == _thumbnail;
}

@Override
public Thumbnail cleanup(ScriptEngineReport report, ContainerUser context)
{
// TODO: Delete file?
return _thumbnail;
}
});
}


private static <K> K handleParameters(ScriptEngineReport report, Collection<ParamReplacement> parameters, ParameterHandler<K> handler) throws IOException
protected static <K> K handleParameters(ScriptEngineReport report, Collection<ParamReplacement> parameters, ParameterHandler<K> handler) throws IOException
{
String sections = HttpView.currentContext().getString(renderParam.showSection.name());
ViewContext context = HttpView.currentContext();
String sections = context.getString(renderParam.showSection.name());
List<String> sectionNames = Collections.emptyList();

if (sections != null)
sectionNames = Arrays.asList(sections.split("&"));

ViewContext context = HttpView.currentContext();

for (ParamReplacement param : parameters)
{
if (isViewable(param, sectionNames))
Expand All @@ -534,18 +506,16 @@ private static <K> K handleParameters(ScriptEngineReport report, Collection<Para
}
}

return handler.cleanup(report, context);
return handler.cleanup(context);
}


private interface ParameterHandler<K>
protected interface ParameterHandler<K>
{
boolean handleParameter(ViewContext context, Report report, ParamReplacement param, List<String> sectionNames) throws IOException;

K cleanup(ScriptEngineReport report, ContainerUser context);
K cleanup(ContainerUser context);
}


protected static boolean isViewable(ParamReplacement param, List<String> sectionNames)
{
for (FileLike data : param.getFiles())
Expand All @@ -567,7 +537,6 @@ protected String createScript(ScriptEngine engine, ViewContext context, List<Par

/**
* Create the script to be executed by the scripting engine
*
*/
protected String createScript(ScriptEngine engine, ViewContext context, List<ParamReplacement> outputSubst, FileLike inputDataTsv, Map<String, Object> inputParameters, boolean isRStudio) throws Exception
{
Expand Down Expand Up @@ -616,14 +585,6 @@ protected String processOutputReplacements(ScriptEngine engine, String script, L
return ParamReplacementSvc.get().processParamReplacement(script, reportDir, null, replacements, isRStudio);
}


@Override
public ScriptReportDescriptor getDescriptor()
{
return super.getDescriptor();
}


@Override
protected String getDefaultExtension(FolderExportContext context)
{
Expand Down
Loading
Loading