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
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public void toFile(List<ParamReplacement> outputSubst, FileLike file) throws Exc
}
}

public Collection<ParamReplacement> fromFile(FileLike file) throws Exception
public Collection<ParamReplacement> fromFile(FileLike file) throws IOException
{
Map<String, ParamReplacement> outputSubstMap = new HashMap<>();
if (file.exists())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
return;

out.write("<table class=\"labkey-output\">");
renderTitle(model, out);
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td>");
else
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/reports/report/r/view/HtmlOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public HtmlOutputView(ParamReplacement param, String label)
@Override
protected String renderInternalAsString(FileLike file) throws Exception
{
if (file.exists())
if (existsWithContent(file))
return PageFlowUtil.addScriptNonces(PageFlowUtil.getStreamContentsAsString(file.openInputStream()));

return null;
Expand All @@ -113,7 +113,7 @@ protected void renderInternal(Object model, PrintWriter out) throws Exception
if (null != html)
{
out.write("<table class=\"labkey-output\">");
renderTitle(model, out);
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td>");
else
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/reports/report/r/view/ImageOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected String renderInternalAsString(FileLike file) throws IOException
{
String imgUrl = null;

if (file.exists())
if (existsWithContent(file))
{
FileLike imgFile;
if (!_deleteFile)
Expand Down Expand Up @@ -157,7 +157,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
if (null != imgUrl)
{
out.write("<table class=\"labkey-output\">");
renderTitle(model, out);
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td>");
else
Expand Down
6 changes: 3 additions & 3 deletions api/src/org/labkey/api/reports/report/r/view/JsonOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public JsonOutput()
}

@Override
public HttpView getView(ViewContext context)
public HttpView<?> getView(ViewContext context)
{
return new JsonOutputView(this);
}
Expand Down Expand Up @@ -85,7 +85,7 @@ public JsonOutputView(ParamReplacement param)
@Override
protected String renderInternalAsString(FileLike file) throws IOException
{
if (file.exists())
if (existsWithContent(file))
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());

return null;
Expand All @@ -101,7 +101,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
if (null != rawValue)
{
out.write("<table class=\"labkey-output\">");
renderTitle(model, out);
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td><pre>");
else
Expand Down
25 changes: 7 additions & 18 deletions api/src/org/labkey/api/reports/report/r/view/ROutputView.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,8 @@
import org.labkey.vfs.FileLike;

import java.io.File;
import java.io.FileFilter;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -128,7 +125,7 @@ protected String renderInternalAsString(FileLike file) throws Exception
return null;
}

protected void renderTitle(Object model, PrintWriter out)
protected void renderTitle(PrintWriter out)
{
StringBuilder sb = new StringBuilder();

Expand Down Expand Up @@ -164,7 +161,7 @@ protected FileLike moveToTemp(FileLike file) throws IOException
return null;
}

protected boolean exists(File file)
protected boolean existsWithContent(FileLike file)
{
long size = 0;

Expand All @@ -181,11 +178,7 @@ protected boolean exists(File file)
if (ALLOW_REMOTE_FILESIZE_BYPASS && _isRemote)
return true;

try
{
size = Files.size(Paths.get(file.getAbsolutePath()));
}
catch(IOException ignore){}
size = file.getSize();
}

return (size > 0);
Expand All @@ -199,16 +192,12 @@ public static void cleanUpTemp(final long cutoff)

if (tempDir.exists())
{
File[] filesToDelete = tempDir.listFiles(new FileFilter(){
@Override
public boolean accept(File file)
File[] filesToDelete = tempDir.listFiles(file -> {
if (!file.isDirectory() && file.getName().startsWith(PREFIX))
{
if (!file.isDirectory() && file.getName().startsWith(PREFIX))
{
return file.lastModified() < cutoff;
}
return false;
return file.lastModified() < cutoff;
}
return false;
});

for (File file : filesToDelete)
Expand Down
4 changes: 2 additions & 2 deletions api/src/org/labkey/api/reports/report/r/view/TextOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public TextOutputView(ParamReplacement param)
@Override
protected String renderInternalAsString(FileLike file) throws IOException
{
if (file.exists())
if (existsWithContent(file))
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());

return null;
Expand All @@ -101,7 +101,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
if (null != rawValue)
{
out.write("<table class=\"labkey-output\">");
renderTitle(model, out);
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td><pre>");
else
Expand Down
169 changes: 88 additions & 81 deletions api/src/org/labkey/api/reports/report/r/view/TsvOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static class TabReportView extends ROutputView
@Override
protected String renderInternalAsString(FileLike file) throws IOException
{
if (file.exists())
if (existsWithContent(file))
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());

return null;
Expand All @@ -126,104 +126,111 @@ protected void renderInternal(Object model, PrintWriter out) throws Exception
TabLoader tabLoader = createTabLoader(file);
if (tabLoader != null)
{
ColumnDescriptor[] cols = tabLoader.getColumns();
List<Map<String, Object>> data = tabLoader.load();
try
{
ColumnDescriptor[] cols = tabLoader.getColumns();
List<Map<String, Object>> data = tabLoader.load();

List<ColumnDescriptor> display = new ArrayList<>();
HashMap<String, ColumnDescriptor> hrefs = new HashMap<>(tabLoader.getColumns().length * 2);
HashMap<String, ColumnDescriptor> styles = new HashMap<>(tabLoader.getColumns().length * 2);
List<ColumnDescriptor> display = new ArrayList<>();
HashMap<String, ColumnDescriptor> hrefs = new HashMap<>(tabLoader.getColumns().length * 2);
HashMap<String, ColumnDescriptor> styles = new HashMap<>(tabLoader.getColumns().length * 2);

for (ColumnDescriptor col : cols)
hrefs.put(col.name, null);
for (ColumnDescriptor col : cols)
hrefs.put(col.name, null);

for (ColumnDescriptor col : cols)
{
if (col.name.endsWith(".href") || col.name.endsWith("_href"))
for (ColumnDescriptor col : cols)
{
String name = col.name.substring(0,col.name.length()-".href".length());
if (hrefs.containsKey(name))
if (col.name.endsWith(".href") || col.name.endsWith("_href"))
{
hrefs.put(name,col);
continue;
String name = col.name.substring(0, col.name.length() - ".href".length());
if (hrefs.containsKey(name))
{
hrefs.put(name, col);
continue;
}
}
}
if (col.name.endsWith(".style") || col.name.endsWith("_style"))
{
String name = col.name.substring(0,col.name.length()-".style".length());
if (hrefs.containsKey(name))
if (col.name.endsWith(".style") || col.name.endsWith("_style"))
{
styles.put(name,col);
continue;
String name = col.name.substring(0, col.name.length() - ".style".length());
if (hrefs.containsKey(name))
{
styles.put(name, col);
continue;
}
}
display.add(col);
}
display.add(col);
}

int row = 0;
out.write("<table class=\"labkey-data-region-legacy labkey-show-borders\">");
renderTitle(model, out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td><table>");
else
out.write("<tr><td><table class=\"labkey-r-tsvout\">");
out.write("<tr>");
for (ColumnDescriptor col : display)
{
if (Number.class.isAssignableFrom(col.getDataClass()))
out.write("<td class=\"labkey-column-header\" align=\"right\">");
int row = 0;
out.write("<table class=\"labkey-data-region-legacy labkey-show-borders\">");
renderTitle(out);
if (isCollapse())
out.write("<tr style=\"display:none\"><td><table>");
else
out.write("<td class=\"labkey-column-header\">");
out.write(PageFlowUtil.filter(col.name, true, true));
out.write("</td>");
row++;
}
out.write("</tr>");

for (Map<String, Object> m : data)
{
if (row % 2 == 0)
out.write("<tr class=\"labkey-row\">");
else
out.write("<tr class=\"labkey-alternate-row\">");
out.write("<tr><td><table class=\"labkey-r-tsvout\">");
out.write("<tr>");
for (ColumnDescriptor col : display)
{
Object colVal = m.get(col.name);
if ("NA".equals(colVal))
colVal = null;
ColumnDescriptor hrefCol = hrefs.get(col.name);
String href = hrefCol == null ? null : ConvertUtils.convert((m.get(hrefCol.name)));
ColumnDescriptor styleCol = styles.get(col.name);
String style = styleCol == null ? null : ConvertUtils.convert((m.get(styleCol.name)));

out.write("<td");
if (Number.class.isAssignableFrom(col.clazz))
out.write(" align=\"right\"");
if (null != style)
{
out.write(" style=\"");
out.write(PageFlowUtil.filter(style));
out.write("\"");
}
out.write(">");
if (null != href)
{
out.write("<a href=\"");
out.write(PageFlowUtil.filter(href));
out.write("\">");
}
if (null == colVal)
out.write("&nbsp;");
if (Number.class.isAssignableFrom(col.getDataClass()))
out.write("<td class=\"labkey-column-header\" align=\"right\">");
else
out.write(PageFlowUtil.filter(ConvertUtils.convert(colVal), true, true));
if (null != href)
out.write("</a>");
out.write("<td class=\"labkey-column-header\">");
out.write(PageFlowUtil.filter(col.name, true, true));
out.write("</td>");
row++;
}
out.write("</tr>");
row++;

for (Map<String, Object> m : data)
{
if (row % 2 == 0)
out.write("<tr class=\"labkey-row\">");
else
out.write("<tr class=\"labkey-alternate-row\">");
for (ColumnDescriptor col : display)
{
Object colVal = m.get(col.name);
if ("NA".equals(colVal))
colVal = null;
ColumnDescriptor hrefCol = hrefs.get(col.name);
String href = hrefCol == null ? null : ConvertUtils.convert((m.get(hrefCol.name)));
ColumnDescriptor styleCol = styles.get(col.name);
String style = styleCol == null ? null : ConvertUtils.convert((m.get(styleCol.name)));

out.write("<td");
if (Number.class.isAssignableFrom(col.clazz))
out.write(" align=\"right\"");
if (null != style)
{
out.write(" style=\"");
out.write(PageFlowUtil.filter(style));
out.write("\"");
}
out.write(">");
if (null != href)
{
out.write("<a href=\"");
out.write(PageFlowUtil.filter(href));
out.write("\">");
}
if (null == colVal)
out.write("&nbsp;");
else
out.write(PageFlowUtil.filter(ConvertUtils.convert(colVal), true, true));
if (null != href)
out.write("</a>");
out.write("</td>");
}
out.write("</tr>");
row++;
}
out.write("</table></td></tr>");
out.write("</table>");
}
finally
{
tabLoader.close();
}
out.write("</table></td></tr>");
out.write("</table>");
}
}
}
Expand Down