Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 50179: Exceptions logged by Radeox are difficult to track #5802

Merged
merged 4 commits into from
Aug 27, 2024
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 @@ -1370,7 +1370,7 @@ public EmailNotificationBean(Container c,
if (settings.isSecureWithEmailOn() || settings.isSecureOff())
{
WikiRenderingService renderingService = WikiRenderingService.get();
this.body = renderingService.getFormattedHtml(currentRendererType, a.getBody());
this.body = renderingService.getFormattedHtml(currentRendererType, a.getBody(), "Announcement " + a.getRowId() + " in " + a.getContainerPath());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,10 +245,11 @@ private HtmlString getFormattedHtml(@Nullable String attachPrefix)
if (_rendererType == null)
_rendererType = DEFAULT_MESSAGE_RENDERER_TYPE;

String sourceDescription = "Announcement " + getRowId() + " in " + getContainerPath();
if (null == attachPrefix)
return renderingService.getFormattedHtml(_rendererType, _body);
return renderingService.getFormattedHtml(_rendererType, _body, sourceDescription);
else
return renderingService.getFormattedHtml(_rendererType, _body, attachPrefix, getAttachments());
return renderingService.getFormattedHtml(_rendererType, _body, sourceDescription, attachPrefix, getAttachments());
}

public String getStatus()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public TableInfo getLookupTableInfo()
bodyColumn.setShownInDetailsView(false);

var formattedBodyColumn = wrapColumn("FormattedBody", getRealTable().getColumn("Body"));
formattedBodyColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, renderTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS));
formattedBodyColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, renderTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS,
ctx -> "Announcement " + getColumn("RowId").getValue(ctx)));
addColumn(formattedBodyColumn);
formattedBodyColumn.setReadOnly(true);
formattedBodyColumn.setUserEditable(false);
Expand Down
6 changes: 5 additions & 1 deletion api/src/org/labkey/api/wiki/WikiRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,9 @@
*/
public interface WikiRenderer
{
FormattedHtml format(String text);
/**
* @param text the original text that should be rendered into HTML
* @param sourceDescription info on where the text came from for debugging purposes. For example: Announcement 6654 in /MyContainer
*/
FormattedHtml format(String text, String sourceDescription);
}
10 changes: 8 additions & 2 deletions api/src/org/labkey/api/wiki/WikiRendererDisplayColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import java.util.Map;
import java.util.Set;
import java.util.function.Function;

/**
* Renders the contents of a database column in one of the supported {@link WikiRendererType} formats, as specified
Expand All @@ -38,13 +39,18 @@ public class WikiRendererDisplayColumn extends DataColumn
{
@NotNull
private final String _renderTypeColumnName;
private final Function<RenderContext, String> _sourceDescriptionGenerator;
private WikiRendererType _defaultRenderer = WikiRendererType.TEXT_WITH_LINKS;
private static final Logger _log = LogHelper.getLogger(WikiRendererDisplayColumn.class, "Renders wiki content for grid and detail views");

public WikiRendererDisplayColumn(ColumnInfo contentColumn, @NotNull String renderTypeColumnName, WikiRendererType defaultRenderer)
public WikiRendererDisplayColumn(ColumnInfo contentColumn,
@NotNull String renderTypeColumnName,
WikiRendererType defaultRenderer,
@NotNull Function<RenderContext, String> sourceDescriptionGenerator)
{
super(contentColumn);
_renderTypeColumnName = renderTypeColumnName;
_sourceDescriptionGenerator = sourceDescriptionGenerator;
if (null != defaultRenderer)
_defaultRenderer = defaultRenderer;
}
Expand Down Expand Up @@ -82,7 +88,7 @@ public HtmlString getFormattedHtml(RenderContext ctx)
}
}

rendered = wikiService.getFormattedHtml(rendererType, content);
rendered = wikiService.getFormattedHtml(rendererType, content, _sourceDescriptionGenerator.apply(ctx));

Map<String, Object> newRow = new CaseInsensitiveHashMap<>(ctx.getRow());
newRow.put(renderedFK.encode(), rendered);
Expand Down
12 changes: 10 additions & 2 deletions api/src/org/labkey/api/wiki/WikiRenderingService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.labkey.api.wiki;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.labkey.api.attachments.Attachment;
import org.labkey.api.services.ServiceRegistry;
import org.labkey.api.util.HtmlString;
Expand Down Expand Up @@ -31,8 +32,15 @@ static void setInstance(WikiRenderingService impl)
*/
void registerMacroProvider(String name, MacroProvider provider);

HtmlString getFormattedHtml(WikiRendererType rendererType, String source);
HtmlString getFormattedHtml(WikiRendererType rendererType, String source, String attachPrefix, Collection<? extends Attachment> attachments);
/**
* @param sourceDescription info on where the text came from for debugging purposes. For example: Announcement 6654 in /MyContainer
*/
HtmlString getFormattedHtml(WikiRendererType rendererType, String source, @Nullable String sourceDescription);
/**
* @param sourceDescription info on where the text came from for debugging purposes. For example: Announcement 6654 in /MyContainer
*/
HtmlString getFormattedHtml(WikiRendererType rendererType, String source, @Nullable String sourceDescription,
String attachPrefix, Collection<? extends Attachment> attachments);

WikiRenderer getRenderer(WikiRendererType rendererType, String hrefPrefix,
String attachPrefix, Map<String, String> nameTitleMap,
Expand Down
2 changes: 1 addition & 1 deletion core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ dependencies {
BuildUtils.addExternalDependency(
project,
new ExternalDependency(
'radeox:radeox:1.0.5',
'radeox:radeox:1.0.6',
"Radeox",
"Radeox",
"http://www.radeox.org/",
Expand Down
2 changes: 1 addition & 1 deletion core/src/org/labkey/core/CoreController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2750,7 +2750,7 @@ public ApiResponse execute(TransformWikiForm form, BindException errors)
if (StringUtils.equals(WikiRendererType.HTML.name(), form.getToFormat()))
{
WikiRendererType fromType = WikiRendererType.valueOf(form.getFromFormat());
newBody = WikiRenderingService.get().getFormattedHtml(fromType, newBody).toString();
newBody = WikiRenderingService.get().getFormattedHtml(fromType, newBody, null).toString();
}

response.put("toFormat", form.getToFormat());
Expand Down
4 changes: 2 additions & 2 deletions core/src/org/labkey/core/admin/AdminController.java
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ else if (startupInProgress)
else if (maintenanceMode)
{
WikiRenderingService wikiService = WikiRenderingService.get();
content = wikiService.getFormattedHtml(WikiRendererType.RADEOX, ModuleLoader.getInstance().getAdminOnlyMessage());
content = wikiService.getFormattedHtml(WikiRendererType.RADEOX, ModuleLoader.getInstance().getAdminOnlyMessage(), "Admin only message");
}

if (content == null)
Expand Down Expand Up @@ -1121,7 +1121,7 @@ private static class CreditsView extends WebPartView<Object>
if (StringUtils.isNotEmpty(wikiSource))
{
WikiRenderingService wikiService = WikiRenderingService.get();
HtmlString html = wikiService.getFormattedHtml(WikiRendererType.RADEOX, wikiSource);
HtmlString html = wikiService.getFormattedHtml(WikiRendererType.RADEOX, wikiSource, "Credits page");
_html = HtmlStringBuilder.of(HtmlString.unsafe("<style type=\"text/css\">\ntr.table-odd td { background-color: #EEEEEE; }</style>\n")).append(html).getHtmlString();
}
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/org/labkey/core/login/LoginController.java
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ else if (!ModuleLoader.getInstance().isStartupComplete())
else if (isAdminOnlyMode())
{
WikiRenderingService wikiService = WikiRenderingService.get();
HtmlString content = wikiService.getFormattedHtml(WikiRendererType.RADEOX, ModuleLoader.getInstance().getAdminOnlyMessage());
HtmlString content = wikiService.getFormattedHtml(WikiRendererType.RADEOX, ModuleLoader.getInstance().getAdminOnlyMessage(), "Admin only message");
HtmlView adminMessageView = new HtmlView("The site is currently undergoing maintenance", content);
vBox.addView(adminMessageView);
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/org/labkey/core/wiki/HtmlRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public HtmlRenderer(String hrefPrefix, String attachPrefix, Map<String, String>
}

@Override
public FormattedHtml format(String text)
public FormattedHtml format(String text, String sourceDescription)
{
LinkedList<String> errors = new LinkedList<>();
if (text == null)
Expand Down
8 changes: 4 additions & 4 deletions core/src/org/labkey/core/wiki/MarkdownRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,29 @@ public MarkdownRenderer(String hrefPrefix, String attachPrefix, Map<String, Stri
}

@Override
public FormattedHtml format(String text)
public FormattedHtml format(String text, String sourceDescription)
{
// translate the markdown to html and reuse the html renderer
MarkdownService markdownService = MarkdownService.get();
if (null != markdownService)
{
try
{
return super.format(markdownService.toHtml(text));
return super.format(markdownService.toHtml(text), sourceDescription);
}
catch( NoSuchMethodException | ScriptException e)
{
// if the translation from markdown to html doesnt work then show an error message in the view of the html
StringBuilder errorMsg = new StringBuilder("<div class=\"labkey-error\"><b>An exception occurred while converting markdown to HTML</b></div><br>The error message was: ");
errorMsg.append(e.getMessage());
return super.format(errorMsg.toString());
return super.format(errorMsg.toString(), sourceDescription);
}
}
else
{
// if no markdownService available then show an error message in the view of the html
String errorMsg = "<div class=\"labkey-error\"><b>No markdown service was available to convert the markdown to HTML</b></div><br>";
return super.format(errorMsg);
return super.format(errorMsg, sourceDescription);
}
}
}
2 changes: 1 addition & 1 deletion core/src/org/labkey/core/wiki/PlainTextRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PlainTextRenderer implements WikiRenderer
* @param text Wiki source
*/
@Override
public FormattedHtml format(String text)
public FormattedHtml format(String text, String sourceDescription)
{
if (text == null)
return new FormattedHtml(HtmlString.EMPTY_STRING);
Expand Down
12 changes: 7 additions & 5 deletions core/src/org/labkey/core/wiki/RadeoxRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -115,13 +116,14 @@ public RadeoxRenderer(String hrefPrefix, String attachPrefix,
}

@Override
public FormattedHtml format(String text)
public FormattedHtml format(String text, String sourceDescription)
{
if (text == null)
text = "";

RenderContext context = new BaseRenderContext();
RenderContext context = new BaseRenderContext(sourceDescription);
context.setRenderEngine(this);
context.setParameters(new HashMap<>());
Set<String> dependencies = new HashSet<>();
context.set(WIKI_DEPENDENCIES_KEY, dependencies);
Set<String> anchors = new HashSet<>();
Expand Down Expand Up @@ -948,14 +950,14 @@ public void testRendering()
// Service should wrap rendered HTML in a <div> but renderer shouldn't.
private void test(String wiki, String html)
{
assertEquals(html, HtmlString.toString(_r.format(wiki).getHtml()));
assertEquals(HtmlStringBuilder.of(WikiRenderingService.WIKI_PREFIX).unsafeAppend(html).append(WikiRenderingService.WIKI_SUFFIX).getHtmlString(), _wrs.getFormattedHtml(WikiRendererType.RADEOX, wiki));
assertEquals(html, HtmlString.toString(_r.format(wiki, null).getHtml()));
assertEquals(HtmlStringBuilder.of(WikiRenderingService.WIKI_PREFIX).unsafeAppend(html).append(WikiRenderingService.WIKI_SUFFIX).getHtmlString(), _wrs.getFormattedHtml(WikiRendererType.RADEOX, wiki, null));
}

@Test
public void testWikiDependencies()
{
FormattedHtml html = _r.format("[this] [that] [some text|tother] [some other text|this] nolink anothernolink");
FormattedHtml html = _r.format("[this] [that] [some text|tother] [some other text|this] nolink anothernolink", null);
Set<String> dependencies = html.getWikiDependencies();
assertNotNull(dependencies);
assertEquals(3, dependencies.size());
Expand Down
13 changes: 9 additions & 4 deletions core/src/org/labkey/core/wiki/WikiRenderingServiceImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.labkey.core.wiki;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.attachments.Attachment;
import org.labkey.api.util.HtmlString;
import org.labkey.api.util.HtmlStringBuilder;
Expand All @@ -22,17 +23,21 @@ public void registerMacroProvider(String name, MacroProvider provider)
}

@Override
public HtmlString getFormattedHtml(WikiRendererType rendererType, String source, String attachPrefix, Collection<? extends Attachment> attachments)
public HtmlString getFormattedHtml(WikiRendererType rendererType,
String source,
@Nullable String sourceDescription,
String attachPrefix,
Collection<? extends Attachment> attachments)
{
return HtmlStringBuilder.of(WIKI_PREFIX)
.append(getRenderer(rendererType, null, attachPrefix, null, attachments).format(source).getHtml())
.append(getRenderer(rendererType, null, attachPrefix, null, attachments).format(source, sourceDescription).getHtml())
.append(WIKI_SUFFIX).getHtmlString();
}

@Override
public HtmlString getFormattedHtml(WikiRendererType rendererType, String source)
public HtmlString getFormattedHtml(WikiRendererType rendererType, String source, @Nullable String sourceDescription)
{
return getFormattedHtml(rendererType, source, null, null);
return getFormattedHtml(rendererType, source, sourceDescription, null, null);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion issues/src/org/labkey/issue/actions/ChangeSummary.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static public ChangeSummary createChangeSummary(ViewContext context, IssueListDe
formattedComment.append(sbHTMLChanges);
//render issues as plain text with links
WikiRenderingService renderingService = WikiRenderingService.get();
HtmlString html = renderingService.getFormattedHtml(WikiRendererType.TEXT_WITH_LINKS, comment);
HtmlString html = renderingService.getFormattedHtml(WikiRendererType.TEXT_WITH_LINKS, comment, "Issue change summary for issue " + issue.getIssueId() + " in " + issue.getContainerPath());
formattedComment.append(html);
formattedComment.append("</div>");

Expand Down
4 changes: 2 additions & 2 deletions study/src/org/labkey/study/model/StudyImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -684,7 +684,7 @@ public HtmlString getDescriptionHtml()
{
String description = getDescription();

if (description == null || description.length() == 0)
if (description == null || description.isEmpty())
{
long count = StudyManager.getInstance().getParticipantCount(this);
String subjectNoun = (count == 1 ? this.getSubjectNounSingular() : this.getSubjectNounPlural());
Expand All @@ -701,7 +701,7 @@ public HtmlString getDescriptionHtml()
else
{
WikiRenderingService wrs = WikiRenderingService.get();
return wrs.getFormattedHtml(getDescriptionWikiRendererType(), description);
return wrs.getFormattedHtml(getDescriptionWikiRendererType(), description, "Study description in " + getContainer().getPath());
}
}

Expand Down
2 changes: 1 addition & 1 deletion study/src/org/labkey/study/query/StudyObjectiveTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public TableInfo getLookupTableInfo()
}

descriptionRendererTypeColumn.setHidden(true);
descriptionColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, descriptionRendererTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS));
descriptionColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, descriptionRendererTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS, ctx -> "StudyObjective"));

// setup lookups for the standard fields
addWrapColumn(_rootTable.getColumn(FieldKey.fromParts("Container")));
Expand Down
2 changes: 1 addition & 1 deletion study/src/org/labkey/study/query/StudyPropertiesTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public TableInfo getLookupTableInfo()
});
}

descriptionColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, descriptionRendererTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS));
descriptionColumn.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, descriptionRendererTypeColumn.getName(), WikiRendererType.TEXT_WITH_LINKS, ctx -> "StudyProperties"));

String bTRUE = getSchema().getSqlDialect().getBooleanTRUE();
String bFALSE = getSchema().getSqlDialect().getBooleanFALSE();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
package org.labkey.study.query.studydesign;

import org.jetbrains.annotations.Nullable;
import org.labkey.api.data.BaseColumnInfo;
import org.labkey.api.data.ContainerFilter;
import org.labkey.api.data.MutableColumnInfo;
import org.labkey.api.data.TableInfo;
import org.labkey.api.exp.api.StorageProvisioner;
import org.labkey.api.exp.property.Domain;
import org.labkey.api.query.FieldKey;
import org.labkey.api.query.LookupForeignKey;
import org.labkey.api.query.UserSchema;
import org.labkey.api.wiki.WikiRendererDisplayColumn;
import org.labkey.api.wiki.WikiRendererType;
import org.labkey.api.wiki.WikiService;
Expand Down Expand Up @@ -73,7 +71,7 @@ protected void initColumn(MutableColumnInfo col)
{
if ("Description".equalsIgnoreCase(col.getName()))
{
col.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, "DescriptionRendererType", WikiRendererType.TEXT_WITH_LINKS));
col.setDisplayColumnFactory(colInfo -> new WikiRendererDisplayColumn(colInfo, "DescriptionRendererType", WikiRendererType.TEXT_WITH_LINKS, ctx -> "StudyTreatment"));
}
else if ("DescriptionRendererType".equalsIgnoreCase(col.getName()))
{
Expand Down
4 changes: 4 additions & 0 deletions wiki/radeox/Changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
1.0.6 2024-08-26

- Improve error logging

1.0.5 2022-08-30

- Expunge example and test files
Expand Down
2 changes: 1 addition & 1 deletion wiki/radeox/Radeox.version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.5
1.0.6
2 changes: 1 addition & 1 deletion wiki/radeox/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<property name="test" value="${src}/test"/>
<property name="conf" value="./conf"/>
<property name="jar" value="./lib"/>
<property name="version" value="1.0.5"/>
<property name="version" value="1.0.6"/>
</target>

<target name="prepare" depends="init">
Expand Down
10 changes: 10 additions & 0 deletions wiki/radeox/src/org/radeox/engine/context/BaseRenderContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,14 @@ public class BaseRenderContext implements RenderContext {
private RenderEngine engine;
private Map params;
private Map values;
private final String sourceDescription;

public BaseRenderContext() {
this(null);
}
public BaseRenderContext(String sourceDescription) {
values = new HashMap();
this.sourceDescription = sourceDescription;
}

public Object get(String key) {
Expand Down Expand Up @@ -87,4 +92,9 @@ public void commitCache() {
public boolean isCacheable() {
return cacheable;
}

public String toString()
{
return super.toString() + sourceDescription == null ? "" : (" " + sourceDescription);
}
}
Loading