Skip to content

Commit abb0bb1

Browse files
Fix BiologicsReportTest - don't offer files with no content
1 parent 875ff79 commit abb0bb1

File tree

8 files changed

+106
-110
lines changed

8 files changed

+106
-110
lines changed

api/src/org/labkey/api/reports/report/r/ParamReplacementSvc.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ public void toFile(List<ParamReplacement> outputSubst, FileLike file) throws Exc
659659
}
660660
}
661661

662-
public Collection<ParamReplacement> fromFile(FileLike file) throws Exception
662+
public Collection<ParamReplacement> fromFile(FileLike file) throws IOException
663663
{
664664
Map<String, ParamReplacement> outputSubstMap = new HashMap<>();
665665
if (file.exists())

api/src/org/labkey/api/reports/report/r/view/DownloadOutputView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
8686
return;
8787

8888
out.write("<table class=\"labkey-output\">");
89-
renderTitle(model, out);
89+
renderTitle(out);
9090
if (isCollapse())
9191
out.write("<tr style=\"display:none\"><td>");
9292
else

api/src/org/labkey/api/reports/report/r/view/HtmlOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public HtmlOutputView(ParamReplacement param, String label)
9898
@Override
9999
protected String renderInternalAsString(FileLike file) throws Exception
100100
{
101-
if (file.exists())
101+
if (existsWithContent(file))
102102
return PageFlowUtil.addScriptNonces(PageFlowUtil.getStreamContentsAsString(file.openInputStream()));
103103

104104
return null;
@@ -113,7 +113,7 @@ protected void renderInternal(Object model, PrintWriter out) throws Exception
113113
if (null != html)
114114
{
115115
out.write("<table class=\"labkey-output\">");
116-
renderTitle(model, out);
116+
renderTitle(out);
117117
if (isCollapse())
118118
out.write("<tr style=\"display:none\"><td>");
119119
else

api/src/org/labkey/api/reports/report/r/view/ImageOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ protected String renderInternalAsString(FileLike file) throws IOException
123123
{
124124
String imgUrl = null;
125125

126-
if (file.exists())
126+
if (existsWithContent(file))
127127
{
128128
FileLike imgFile;
129129
if (!_deleteFile)
@@ -157,7 +157,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
157157
if (null != imgUrl)
158158
{
159159
out.write("<table class=\"labkey-output\">");
160-
renderTitle(model, out);
160+
renderTitle(out);
161161
if (isCollapse())
162162
out.write("<tr style=\"display:none\"><td>");
163163
else

api/src/org/labkey/api/reports/report/r/view/JsonOutput.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public JsonOutput()
5757
}
5858

5959
@Override
60-
public HttpView getView(ViewContext context)
60+
public HttpView<?> getView(ViewContext context)
6161
{
6262
return new JsonOutputView(this);
6363
}
@@ -85,7 +85,7 @@ public JsonOutputView(ParamReplacement param)
8585
@Override
8686
protected String renderInternalAsString(FileLike file) throws IOException
8787
{
88-
if (file.exists())
88+
if (existsWithContent(file))
8989
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());
9090

9191
return null;
@@ -101,7 +101,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
101101
if (null != rawValue)
102102
{
103103
out.write("<table class=\"labkey-output\">");
104-
renderTitle(model, out);
104+
renderTitle(out);
105105
if (isCollapse())
106106
out.write("<tr style=\"display:none\"><td><pre>");
107107
else

api/src/org/labkey/api/reports/report/r/view/ROutputView.java

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@
2929
import org.labkey.vfs.FileLike;
3030

3131
import java.io.File;
32-
import java.io.FileFilter;
3332
import java.io.IOException;
3433
import java.io.PrintWriter;
35-
import java.nio.file.Files;
36-
import java.nio.file.Paths;
3734
import java.util.ArrayList;
3835
import java.util.List;
3936
import java.util.Map;
@@ -128,7 +125,7 @@ protected String renderInternalAsString(FileLike file) throws Exception
128125
return null;
129126
}
130127

131-
protected void renderTitle(Object model, PrintWriter out)
128+
protected void renderTitle(PrintWriter out)
132129
{
133130
StringBuilder sb = new StringBuilder();
134131

@@ -164,7 +161,7 @@ protected FileLike moveToTemp(FileLike file) throws IOException
164161
return null;
165162
}
166163

167-
protected boolean exists(File file)
164+
protected boolean existsWithContent(FileLike file)
168165
{
169166
long size = 0;
170167

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

184-
try
185-
{
186-
size = Files.size(Paths.get(file.getAbsolutePath()));
187-
}
188-
catch(IOException ignore){}
181+
size = file.getSize();
189182
}
190183

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

200193
if (tempDir.exists())
201194
{
202-
File[] filesToDelete = tempDir.listFiles(new FileFilter(){
203-
@Override
204-
public boolean accept(File file)
195+
File[] filesToDelete = tempDir.listFiles(file -> {
196+
if (!file.isDirectory() && file.getName().startsWith(PREFIX))
205197
{
206-
if (!file.isDirectory() && file.getName().startsWith(PREFIX))
207-
{
208-
return file.lastModified() < cutoff;
209-
}
210-
return false;
198+
return file.lastModified() < cutoff;
211199
}
200+
return false;
212201
});
213202

214203
for (File file : filesToDelete)

api/src/org/labkey/api/reports/report/r/view/TextOutput.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public TextOutputView(ParamReplacement param)
8585
@Override
8686
protected String renderInternalAsString(FileLike file) throws IOException
8787
{
88-
if (file.exists())
88+
if (existsWithContent(file))
8989
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());
9090

9191
return null;
@@ -101,7 +101,7 @@ protected void renderInternal(Object model, PrintWriter out) throws IOException
101101
if (null != rawValue)
102102
{
103103
out.write("<table class=\"labkey-output\">");
104-
renderTitle(model, out);
104+
renderTitle(out);
105105
if (isCollapse())
106106
out.write("<tr style=\"display:none\"><td><pre>");
107107
else

api/src/org/labkey/api/reports/report/r/view/TsvOutput.java

Lines changed: 88 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ public static class TabReportView extends ROutputView
112112
@Override
113113
protected String renderInternalAsString(FileLike file) throws IOException
114114
{
115-
if (file.exists())
115+
if (existsWithContent(file))
116116
return PageFlowUtil.getStreamContentsAsString(file.openInputStream());
117117

118118
return null;
@@ -126,104 +126,111 @@ protected void renderInternal(Object model, PrintWriter out) throws Exception
126126
TabLoader tabLoader = createTabLoader(file);
127127
if (tabLoader != null)
128128
{
129-
ColumnDescriptor[] cols = tabLoader.getColumns();
130-
List<Map<String, Object>> data = tabLoader.load();
129+
try
130+
{
131+
ColumnDescriptor[] cols = tabLoader.getColumns();
132+
List<Map<String, Object>> data = tabLoader.load();
131133

132-
List<ColumnDescriptor> display = new ArrayList<>();
133-
HashMap<String, ColumnDescriptor> hrefs = new HashMap<>(tabLoader.getColumns().length * 2);
134-
HashMap<String, ColumnDescriptor> styles = new HashMap<>(tabLoader.getColumns().length * 2);
134+
List<ColumnDescriptor> display = new ArrayList<>();
135+
HashMap<String, ColumnDescriptor> hrefs = new HashMap<>(tabLoader.getColumns().length * 2);
136+
HashMap<String, ColumnDescriptor> styles = new HashMap<>(tabLoader.getColumns().length * 2);
135137

136-
for (ColumnDescriptor col : cols)
137-
hrefs.put(col.name, null);
138+
for (ColumnDescriptor col : cols)
139+
hrefs.put(col.name, null);
138140

139-
for (ColumnDescriptor col : cols)
140-
{
141-
if (col.name.endsWith(".href") || col.name.endsWith("_href"))
141+
for (ColumnDescriptor col : cols)
142142
{
143-
String name = col.name.substring(0,col.name.length()-".href".length());
144-
if (hrefs.containsKey(name))
143+
if (col.name.endsWith(".href") || col.name.endsWith("_href"))
145144
{
146-
hrefs.put(name,col);
147-
continue;
145+
String name = col.name.substring(0, col.name.length() - ".href".length());
146+
if (hrefs.containsKey(name))
147+
{
148+
hrefs.put(name, col);
149+
continue;
150+
}
148151
}
149-
}
150-
if (col.name.endsWith(".style") || col.name.endsWith("_style"))
151-
{
152-
String name = col.name.substring(0,col.name.length()-".style".length());
153-
if (hrefs.containsKey(name))
152+
if (col.name.endsWith(".style") || col.name.endsWith("_style"))
154153
{
155-
styles.put(name,col);
156-
continue;
154+
String name = col.name.substring(0, col.name.length() - ".style".length());
155+
if (hrefs.containsKey(name))
156+
{
157+
styles.put(name, col);
158+
continue;
159+
}
157160
}
161+
display.add(col);
158162
}
159-
display.add(col);
160-
}
161163

162-
int row = 0;
163-
out.write("<table class=\"labkey-data-region-legacy labkey-show-borders\">");
164-
renderTitle(model, out);
165-
if (isCollapse())
166-
out.write("<tr style=\"display:none\"><td><table>");
167-
else
168-
out.write("<tr><td><table class=\"labkey-r-tsvout\">");
169-
out.write("<tr>");
170-
for (ColumnDescriptor col : display)
171-
{
172-
if (Number.class.isAssignableFrom(col.getDataClass()))
173-
out.write("<td class=\"labkey-column-header\" align=\"right\">");
164+
int row = 0;
165+
out.write("<table class=\"labkey-data-region-legacy labkey-show-borders\">");
166+
renderTitle(out);
167+
if (isCollapse())
168+
out.write("<tr style=\"display:none\"><td><table>");
174169
else
175-
out.write("<td class=\"labkey-column-header\">");
176-
out.write(PageFlowUtil.filter(col.name, true, true));
177-
out.write("</td>");
178-
row++;
179-
}
180-
out.write("</tr>");
181-
182-
for (Map<String, Object> m : data)
183-
{
184-
if (row % 2 == 0)
185-
out.write("<tr class=\"labkey-row\">");
186-
else
187-
out.write("<tr class=\"labkey-alternate-row\">");
170+
out.write("<tr><td><table class=\"labkey-r-tsvout\">");
171+
out.write("<tr>");
188172
for (ColumnDescriptor col : display)
189173
{
190-
Object colVal = m.get(col.name);
191-
if ("NA".equals(colVal))
192-
colVal = null;
193-
ColumnDescriptor hrefCol = hrefs.get(col.name);
194-
String href = hrefCol == null ? null : ConvertUtils.convert((m.get(hrefCol.name)));
195-
ColumnDescriptor styleCol = styles.get(col.name);
196-
String style = styleCol == null ? null : ConvertUtils.convert((m.get(styleCol.name)));
197-
198-
out.write("<td");
199-
if (Number.class.isAssignableFrom(col.clazz))
200-
out.write(" align=\"right\"");
201-
if (null != style)
202-
{
203-
out.write(" style=\"");
204-
out.write(PageFlowUtil.filter(style));
205-
out.write("\"");
206-
}
207-
out.write(">");
208-
if (null != href)
209-
{
210-
out.write("<a href=\"");
211-
out.write(PageFlowUtil.filter(href));
212-
out.write("\">");
213-
}
214-
if (null == colVal)
215-
out.write("&nbsp;");
174+
if (Number.class.isAssignableFrom(col.getDataClass()))
175+
out.write("<td class=\"labkey-column-header\" align=\"right\">");
216176
else
217-
out.write(PageFlowUtil.filter(ConvertUtils.convert(colVal), true, true));
218-
if (null != href)
219-
out.write("</a>");
177+
out.write("<td class=\"labkey-column-header\">");
178+
out.write(PageFlowUtil.filter(col.name, true, true));
220179
out.write("</td>");
180+
row++;
221181
}
222182
out.write("</tr>");
223-
row++;
183+
184+
for (Map<String, Object> m : data)
185+
{
186+
if (row % 2 == 0)
187+
out.write("<tr class=\"labkey-row\">");
188+
else
189+
out.write("<tr class=\"labkey-alternate-row\">");
190+
for (ColumnDescriptor col : display)
191+
{
192+
Object colVal = m.get(col.name);
193+
if ("NA".equals(colVal))
194+
colVal = null;
195+
ColumnDescriptor hrefCol = hrefs.get(col.name);
196+
String href = hrefCol == null ? null : ConvertUtils.convert((m.get(hrefCol.name)));
197+
ColumnDescriptor styleCol = styles.get(col.name);
198+
String style = styleCol == null ? null : ConvertUtils.convert((m.get(styleCol.name)));
199+
200+
out.write("<td");
201+
if (Number.class.isAssignableFrom(col.clazz))
202+
out.write(" align=\"right\"");
203+
if (null != style)
204+
{
205+
out.write(" style=\"");
206+
out.write(PageFlowUtil.filter(style));
207+
out.write("\"");
208+
}
209+
out.write(">");
210+
if (null != href)
211+
{
212+
out.write("<a href=\"");
213+
out.write(PageFlowUtil.filter(href));
214+
out.write("\">");
215+
}
216+
if (null == colVal)
217+
out.write("&nbsp;");
218+
else
219+
out.write(PageFlowUtil.filter(ConvertUtils.convert(colVal), true, true));
220+
if (null != href)
221+
out.write("</a>");
222+
out.write("</td>");
223+
}
224+
out.write("</tr>");
225+
row++;
226+
}
227+
out.write("</table></td></tr>");
228+
out.write("</table>");
229+
}
230+
finally
231+
{
232+
tabLoader.close();
224233
}
225-
out.write("</table></td></tr>");
226-
out.write("</table>");
227234
}
228235
}
229236
}

0 commit comments

Comments
 (0)